You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
65 lines
1.7 KiB
65 lines
1.7 KiB
#include "garbo.h" |
|
|
|
static sdl_abstract cleanup_queue[100]; |
|
static int cleanup_queue_length = 0; |
|
|
|
void queue_for_cleanup(void * SDL_thing, sdl_types kind) { |
|
// add item to queue for later cleanup |
|
// TODO: support multiple cleanup queues |
|
|
|
sdl_abstract obj; |
|
obj.kind = kind; |
|
switch (kind) { |
|
case TEXTURE: |
|
obj.thing.texture = SDL_thing; |
|
break; |
|
case WINDOW: |
|
obj.thing.window = SDL_thing; |
|
break; |
|
case RENDERER: |
|
obj.thing.renderer = SDL_thing; |
|
break; |
|
case SURFACE: |
|
obj.thing.surface = SDL_thing; |
|
break; |
|
} |
|
|
|
cleanup_queue_length++; |
|
cleanup_queue[cleanup_queue_length] = obj; |
|
} |
|
|
|
void cleanup(void * thing, sdl_types thing_type) { |
|
// Destroy an SDL object immediately |
|
if (!thing) { |
|
logwrite(DEBUG, "Null passed to cleanup\n"); |
|
return; |
|
} |
|
switch(thing_type) { |
|
case SURFACE: |
|
SDL_FreeSurface(thing); |
|
logwrite(DEBUG, "Freed surface\n"); |
|
break; |
|
case TEXTURE: |
|
SDL_DestroyTexture(thing); |
|
logwrite(DEBUG, "Destroyed texture\n"); |
|
break; |
|
case RENDERER: |
|
SDL_DestroyRenderer(thing); |
|
logwrite(DEBUG, "Destroyed renderer\n"); |
|
break; |
|
case WINDOW: |
|
SDL_DestroyWindow(thing); |
|
logwrite(DEBUG, "Destroyed window\n"); |
|
break; |
|
case NO: |
|
return; |
|
} |
|
} |
|
|
|
void empty_cleanup_queue(void) { |
|
// empty the queue of items scheduled for cleanup |
|
for (; cleanup_queue_length > 0; cleanup_queue_length--) { |
|
sdl_abstract thing = cleanup_queue[cleanup_queue_length]; |
|
cleanup(thing.thing.generic, thing.kind); |
|
} |
|
}
|
|
|