1
0
Fork 0
mirror of https://github.com/TerryCavanagh/VVVVVV.git synced 2024-12-23 10:09:43 +01: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; 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) { int Graphics::font_idx(uint32_t ch) {
if (font_positions.size() > 0) { if (font_positions.size() > 0) {
std::map<int, int>::iterator iter = font_positions.find(ch); std::map<int, int>::iterator iter = font_positions.find(ch);
@ -3150,24 +3172,7 @@ void Graphics::reloadresources()
grphx.destroy(); grphx.destroy();
grphx.init(); grphx.init();
#define CLEAR_ARRAY(name) \ destroy();
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
MakeTileArray(); MakeTileArray();
MakeSpriteArray(); MakeSpriteArray();

View file

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