2525#include " Exception.h"
2626#include " ShaderMove.h"
2727
28+
2829namespace OpenXcom
2930{
3031
@@ -42,12 +43,22 @@ namespace OpenXcom
4243Surface::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)
93104Surface::~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)
143158void 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/* *
0 commit comments