1
0
mirror of https://github.com/TerryCavanagh/VVVVVV.git synced 2024-06-02 02:53:32 +02:00

Move Graphics cleanup to new function Graphics::destroy()

This makes it so this cleanup code can be re-used without copy-pasting
it over and over again.
This commit is contained in:
Misa 2021-02-15 16:13:18 -08:00 committed by Ethan Lee
parent c955ce4380
commit 3fe1870b32
2 changed files with 24 additions and 18 deletions

View File

@ -148,6 +148,28 @@ void Graphics::init()
kludgeswnlinewidth = false;
}
void Graphics::destroy()
{
#define CLEAR_ARRAY(name) \
for (size_t i = 0; i < name.size(); i += 1) \
{ \
SDL_FreeSurface(name[i]); \
} \
name.clear();
CLEAR_ARRAY(tiles)
CLEAR_ARRAY(tiles2)
CLEAR_ARRAY(tiles3)
CLEAR_ARRAY(entcolours)
CLEAR_ARRAY(sprites)
CLEAR_ARRAY(flipsprites)
CLEAR_ARRAY(tele)
CLEAR_ARRAY(bfont)
CLEAR_ARRAY(flipbfont)
#undef CLEAR_ARRAY
}
int Graphics::font_idx(uint32_t ch) {
if (font_positions.size() > 0) {
std::map<int, int>::iterator iter = font_positions.find(ch);
@ -3150,24 +3172,7 @@ void Graphics::reloadresources()
grphx.destroy();
grphx.init();
#define CLEAR_ARRAY(name) \
for (size_t i = 0; i < name.size(); i += 1) \
{ \
SDL_FreeSurface(name[i]); \
} \
name.clear();
CLEAR_ARRAY(tiles)
CLEAR_ARRAY(tiles2)
CLEAR_ARRAY(tiles3)
CLEAR_ARRAY(entcolours)
CLEAR_ARRAY(sprites)
CLEAR_ARRAY(flipsprites)
CLEAR_ARRAY(tele)
CLEAR_ARRAY(bfont)
CLEAR_ARRAY(flipbfont)
#undef CLEAR_ARRAY
destroy();
MakeTileArray();
MakeSpriteArray();

View File

@ -17,6 +17,7 @@ class Graphics
{
public:
void init();
void destroy();
GraphicsResources grphx;