mirror of
https://github.com/TerryCavanagh/VVVVVV.git
synced 2024-12-23 10:09:43 +01:00
Move Graphics buffer creation to new func create_buffers()
It doesn't feel quite write leaving all the buffer creation code in main(), even though it's perfectly okay to do so and it doesn't result in any memory mismanagement that Valgrind can report; so I'm factoring all of it out to a separate function, Graphics::create_buffers(). As a bonus, we no longer have to keep qualifying with `graphics.` in the buffer creation code, which is nice.
This commit is contained in:
parent
5595bb0964
commit
a505059719
3 changed files with 53 additions and 48 deletions
|
@ -170,6 +170,57 @@ void Graphics::destroy()
|
||||||
#undef CLEAR_ARRAY
|
#undef CLEAR_ARRAY
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Graphics::create_buffers(const SDL_PixelFormat* fmt)
|
||||||
|
{
|
||||||
|
#define CREATE_SURFACE(w, h) \
|
||||||
|
SDL_CreateRGBSurface( \
|
||||||
|
SDL_SWSURFACE, \
|
||||||
|
w, h, \
|
||||||
|
fmt->BitsPerPixel, \
|
||||||
|
fmt->Rmask, fmt->Gmask, fmt->Bmask, fmt->Amask \
|
||||||
|
)
|
||||||
|
backBuffer = CREATE_SURFACE(320, 240);
|
||||||
|
SDL_SetSurfaceBlendMode(backBuffer, SDL_BLENDMODE_NONE);
|
||||||
|
|
||||||
|
footerbuffer = CREATE_SURFACE(320, 10);
|
||||||
|
SDL_SetSurfaceBlendMode(footerbuffer, SDL_BLENDMODE_BLEND);
|
||||||
|
SDL_SetSurfaceAlphaMod(footerbuffer, 127);
|
||||||
|
FillRect(footerbuffer, SDL_MapRGB(fmt, 0, 0, 0));
|
||||||
|
|
||||||
|
ghostbuffer = CREATE_SURFACE(320, 240);
|
||||||
|
SDL_SetSurfaceBlendMode(ghostbuffer, SDL_BLENDMODE_BLEND);
|
||||||
|
SDL_SetSurfaceAlphaMod(ghostbuffer, 127);
|
||||||
|
|
||||||
|
foregroundBuffer = CREATE_SURFACE(320, 240);
|
||||||
|
SDL_SetSurfaceBlendMode(foregroundBuffer, SDL_BLENDMODE_BLEND);
|
||||||
|
|
||||||
|
menubuffer = CREATE_SURFACE(320, 240);
|
||||||
|
SDL_SetSurfaceBlendMode(menubuffer, SDL_BLENDMODE_NONE);
|
||||||
|
|
||||||
|
warpbuffer = CREATE_SURFACE(320 + 16, 240 + 16);
|
||||||
|
SDL_SetSurfaceBlendMode(warpbuffer, SDL_BLENDMODE_NONE);
|
||||||
|
|
||||||
|
warpbuffer_lerp = CREATE_SURFACE(320 + 16, 240 + 16);
|
||||||
|
SDL_SetSurfaceBlendMode(warpbuffer_lerp, SDL_BLENDMODE_NONE);
|
||||||
|
|
||||||
|
towerbg.buffer = CREATE_SURFACE(320 + 16, 240 + 16);
|
||||||
|
SDL_SetSurfaceBlendMode(towerbg.buffer, SDL_BLENDMODE_NONE);
|
||||||
|
|
||||||
|
towerbg.buffer_lerp = CREATE_SURFACE(320 + 16, 240 + 16);
|
||||||
|
SDL_SetSurfaceBlendMode(towerbg.buffer_lerp, SDL_BLENDMODE_NONE);
|
||||||
|
|
||||||
|
titlebg.buffer = CREATE_SURFACE(320 + 16, 240 + 16);
|
||||||
|
SDL_SetSurfaceBlendMode(titlebg.buffer, SDL_BLENDMODE_NONE);
|
||||||
|
|
||||||
|
titlebg.buffer_lerp = CREATE_SURFACE(320 + 16, 240 + 16);
|
||||||
|
SDL_SetSurfaceBlendMode(titlebg.buffer_lerp, SDL_BLENDMODE_NONE);
|
||||||
|
|
||||||
|
tempBuffer = CREATE_SURFACE(320, 240);
|
||||||
|
SDL_SetSurfaceBlendMode(tempBuffer, SDL_BLENDMODE_NONE);
|
||||||
|
|
||||||
|
#undef CREATE_SURFACE
|
||||||
|
}
|
||||||
|
|
||||||
void Graphics::destroy_buffers()
|
void Graphics::destroy_buffers()
|
||||||
{
|
{
|
||||||
#define FREE_SURFACE(SURFACE) \
|
#define FREE_SURFACE(SURFACE) \
|
||||||
|
|
|
@ -19,6 +19,7 @@ public:
|
||||||
void init();
|
void init();
|
||||||
void destroy();
|
void destroy();
|
||||||
|
|
||||||
|
void create_buffers(const SDL_PixelFormat* fmt);
|
||||||
void destroy_buffers();
|
void destroy_buffers();
|
||||||
|
|
||||||
GraphicsResources grphx;
|
GraphicsResources grphx;
|
||||||
|
|
|
@ -245,54 +245,7 @@ int main(int argc, char *argv[])
|
||||||
}
|
}
|
||||||
graphics.screenbuffer = &gameScreen;
|
graphics.screenbuffer = &gameScreen;
|
||||||
|
|
||||||
const SDL_PixelFormat* fmt = gameScreen.GetFormat();
|
graphics.create_buffers(gameScreen.GetFormat());
|
||||||
#define CREATE_SURFACE(w, h) \
|
|
||||||
SDL_CreateRGBSurface( \
|
|
||||||
SDL_SWSURFACE, \
|
|
||||||
w, h, \
|
|
||||||
fmt->BitsPerPixel, \
|
|
||||||
fmt->Rmask, fmt->Gmask, fmt->Bmask, fmt->Amask \
|
|
||||||
)
|
|
||||||
graphics.backBuffer = CREATE_SURFACE(320, 240);
|
|
||||||
SDL_SetSurfaceBlendMode(graphics.backBuffer, SDL_BLENDMODE_NONE);
|
|
||||||
|
|
||||||
graphics.footerbuffer = CREATE_SURFACE(320, 10);
|
|
||||||
SDL_SetSurfaceBlendMode(graphics.footerbuffer, SDL_BLENDMODE_BLEND);
|
|
||||||
SDL_SetSurfaceAlphaMod(graphics.footerbuffer, 127);
|
|
||||||
FillRect(graphics.footerbuffer, SDL_MapRGB(fmt, 0, 0, 0));
|
|
||||||
|
|
||||||
graphics.ghostbuffer = CREATE_SURFACE(320, 240);
|
|
||||||
SDL_SetSurfaceBlendMode(graphics.ghostbuffer, SDL_BLENDMODE_BLEND);
|
|
||||||
SDL_SetSurfaceAlphaMod(graphics.ghostbuffer, 127);
|
|
||||||
|
|
||||||
graphics.foregroundBuffer = CREATE_SURFACE(320, 240);
|
|
||||||
SDL_SetSurfaceBlendMode(graphics.foregroundBuffer, SDL_BLENDMODE_BLEND);
|
|
||||||
|
|
||||||
graphics.menubuffer = CREATE_SURFACE(320, 240);
|
|
||||||
SDL_SetSurfaceBlendMode(graphics.menubuffer, SDL_BLENDMODE_NONE);
|
|
||||||
|
|
||||||
graphics.warpbuffer = CREATE_SURFACE(320 + 16, 240 + 16);
|
|
||||||
SDL_SetSurfaceBlendMode(graphics.warpbuffer, SDL_BLENDMODE_NONE);
|
|
||||||
|
|
||||||
graphics.warpbuffer_lerp = CREATE_SURFACE(320 + 16, 240 + 16);
|
|
||||||
SDL_SetSurfaceBlendMode(graphics.warpbuffer_lerp, SDL_BLENDMODE_NONE);
|
|
||||||
|
|
||||||
graphics.towerbg.buffer = CREATE_SURFACE(320 + 16, 240 + 16);
|
|
||||||
SDL_SetSurfaceBlendMode(graphics.towerbg.buffer, SDL_BLENDMODE_NONE);
|
|
||||||
|
|
||||||
graphics.towerbg.buffer_lerp = CREATE_SURFACE(320 + 16, 240 + 16);
|
|
||||||
SDL_SetSurfaceBlendMode(graphics.towerbg.buffer_lerp, SDL_BLENDMODE_NONE);
|
|
||||||
|
|
||||||
graphics.titlebg.buffer = CREATE_SURFACE(320 + 16, 240 + 16);
|
|
||||||
SDL_SetSurfaceBlendMode(graphics.titlebg.buffer, SDL_BLENDMODE_NONE);
|
|
||||||
|
|
||||||
graphics.titlebg.buffer_lerp = CREATE_SURFACE(320 + 16, 240 + 16);
|
|
||||||
SDL_SetSurfaceBlendMode(graphics.titlebg.buffer_lerp, SDL_BLENDMODE_NONE);
|
|
||||||
|
|
||||||
graphics.tempBuffer = CREATE_SURFACE(320, 240);
|
|
||||||
SDL_SetSurfaceBlendMode(graphics.tempBuffer, SDL_BLENDMODE_NONE);
|
|
||||||
|
|
||||||
#undef CREATE_SURFACE
|
|
||||||
|
|
||||||
if (game.skipfakeload)
|
if (game.skipfakeload)
|
||||||
game.gamestate = TITLEMODE;
|
game.gamestate = TITLEMODE;
|
||||||
|
|
Loading…
Reference in a new issue