Skip to content

Commit a9194cd

Browse files
committed
working on Windows now, looks good
1 parent ac96ccc commit a9194cd

2 files changed

Lines changed: 27 additions & 4 deletions

File tree

src/Engine/Surface.cpp

100755100644
Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "Exception.h"
2626
#include "ShaderMove.h"
2727

28+
2829
namespace OpenXcom
2930
{
3031

@@ -42,12 +43,22 @@ namespace OpenXcom
4243
Surface::Surface(int width, int height, int x, int y) : _x(x), _y(y), _visible(true), _hidden(false), _redraw(false), _originalColors(0), _misalignedPixelBuffer(0), _alignedBuffer(0)
4344
{
4445
//_surface = SDL_CreateRGBSurface(SDL_SWSURFACE, width, height, 8, 0, 0, 0, 0);
45-
int rc;
4646
int pitch = ((width+15)& ~0xF);
47+
48+
#ifndef _WIN32
49+
int rc;
4750
if ((rc = posix_memalign(&_alignedBuffer, 16, pitch * height)))
4851
{
4952
throw Exception(strerror(rc));
5053
}
54+
#else
55+
// of course Windows has to be difficult about this!
56+
_alignedBuffer = _aligned_malloc(pitch*height, 16);
57+
if (!_alignedBuffer)
58+
{
59+
throw Exception("Where's the memory, Lebowski?");
60+
}
61+
#endif
5162

5263
memset(_alignedBuffer, 0, pitch * height);
5364

@@ -93,7 +104,11 @@ Surface::Surface(const Surface& other)
93104
Surface::~Surface()
94105
{
95106
//if (_misalignedPixelBuffer) _surface->pixels = _misalignedPixelBuffer;
107+
#ifdef _WIN32
108+
if (_alignedBuffer) _aligned_free(_alignedBuffer);
109+
#else
96110
if (_alignedBuffer) free(_alignedBuffer);
111+
#endif
97112
SDL_FreeSurface(_surface);
98113
}
99114

@@ -143,7 +158,11 @@ void Surface::loadScr(const std::string &filename)
143158
void Surface::loadImage(const std::string &filename)
144159
{
145160
// Destroy current surface (will be replaced)
161+
#ifdef _WIN32
162+
if (_alignedBuffer) _aligned_free(_alignedBuffer);
163+
#else
146164
if (_alignedBuffer) free(_alignedBuffer);
165+
#endif
147166
_alignedBuffer = 0;
148167
SDL_FreeSurface(_surface);
149168
_surface = 0;
@@ -218,7 +237,8 @@ void Surface::clear()
218237
square.y = 0;
219238
square.w = getWidth();
220239
square.h = getHeight();
221-
SDL_FillRect(_surface, &square, 0);
240+
if (_surface->flags & SDL_SWSURFACE) memset(_surface->pixels, 0, _surface->h*_surface->pitch);
241+
else SDL_FillRect(_surface, &square, 0);
222242
}
223243

224244
/**

src/Engine/Zoom.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,12 @@
3030
#include <intrin.h>
3131
#endif
3232

33+
#ifdef __GNUC__
34+
#include <cpuid.h>
35+
#endif
36+
3337
#ifdef __SSE2__
3438
#include <emmintrin.h> // for SSE2 intrinsics; see http://msdn.microsoft.com/en-us/library/has3d153%28v=vs.71%29.aspx
35-
#include <cpuid.h>
3639
#endif
3740

3841

@@ -567,7 +570,7 @@ static int zoomSurface2X_SSE2(SDL_Surface *src, SDL_Surface *dst)
567570

568571
static bool haveSSE2()
569572
{
570-
unsigned int CPUInfo[4];
573+
int CPUInfo[4];
571574

572575
#ifdef __GNUC__
573576
__get_cpuid(1, CPUInfo, CPUInfo+1, CPUInfo+2, CPUInfo+3);

0 commit comments

Comments
 (0)