From 5a719540f583d1934b594285c84015a301d70547 Mon Sep 17 00:00:00 2001 From: alistair Date: Sun, 9 May 2021 23:18:41 +1000 Subject: [PATCH] remove old unused code --- src/draw.c | 2 ++ src/draw.h | 1 - src/game.h | 1 - src/garbo.c | 65 ------------------------------------------------ src/garbo.h | 41 ------------------------------ src/logger.c | 70 ---------------------------------------------------- src/logger.h | 23 ----------------- src/main.c | 22 +++++++---------- 8 files changed, 11 insertions(+), 214 deletions(-) delete mode 100644 src/garbo.c delete mode 100644 src/garbo.h delete mode 100644 src/logger.c delete mode 100644 src/logger.h diff --git a/src/draw.c b/src/draw.c index 417e9b7..20ed043 100644 --- a/src/draw.c +++ b/src/draw.c @@ -625,10 +625,12 @@ int draw_end_screen(SDL_Renderer *ren) { position.y += 40; } + /* char qual_str[250]; snprintf(qual_str, 250, "physics quality: %d", quality); draw_text(ren, position, colour, qual_str); position.y += 40; + */ minutes = level_time / 60000; diff --git a/src/draw.h b/src/draw.h index a8f5af4..851590e 100644 --- a/src/draw.h +++ b/src/draw.h @@ -4,7 +4,6 @@ #include #include -#include "garbo.h" #include "c-colours/colours.h" #include "vect.h" #include "environment.h" diff --git a/src/game.h b/src/game.h index 613a81e..15267c7 100644 --- a/src/game.h +++ b/src/game.h @@ -4,7 +4,6 @@ #include "environment.h" #include "datastructures/datatypes.h" #include "vect.h" -#include "garbo.h" #include "controlscheme.h" #include "c-colours/colours.h" #include "types.h" diff --git a/src/garbo.c b/src/garbo.c deleted file mode 100644 index fa0815c..0000000 --- a/src/garbo.c +++ /dev/null @@ -1,65 +0,0 @@ -#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); - } -} diff --git a/src/garbo.h b/src/garbo.h deleted file mode 100644 index 24265a0..0000000 --- a/src/garbo.h +++ /dev/null @@ -1,41 +0,0 @@ - -#ifndef _DEFGARBO -#define _DEFGARBO - -#include -#include -#include -#include -#include "logger.h" -#include - - -/* Type definition for object cleanups */ -typedef enum { - NO, SURFACE, TEXTURE, RENDERER, WINDOW -} sdl_types; - -typedef union { - SDL_Window * window; - SDL_Renderer * renderer; - SDL_Surface * surface; - SDL_Texture * texture; - void * generic; -} thing_for_cleanup ; - -typedef struct { - sdl_types kind; - thing_for_cleanup thing; -} sdl_abstract; - - -/* Function prototypes */ - -void queue_for_cleanup(void * SDL_thing, sdl_types kind); - -void cleanup(void * thing, sdl_types thing_type); - -void empty_cleanup_queue(void); - -#endif - diff --git a/src/logger.c b/src/logger.c deleted file mode 100644 index 6bfd67e..0000000 --- a/src/logger.c +++ /dev/null @@ -1,70 +0,0 @@ -#include "logger.h" - -// Defaults - -loggerlevel LOGLEVEL = SILENT; -loggerlevel STDOUTLEVEL = SILENT; - -void set_loglevel(loggerlevel echo, loggerlevel write) { - LOGLEVEL = write; - STDOUTLEVEL = echo; -} - -int copy_str(char * out_string, char * string) { - /* A drop in replacement for strcpy() from */ - int len = 0; - while (*(string + len) != '\0') { - *(out_string + len) = *(string + len); - len++; - } - *(out_string + len) = '\0'; - return (1); -} - -void logwrite(loggerlevel level, char message[]) { - // write a string message - char time_str[100]; - time_t current_time; - time(¤t_time); - - copy_str(time_str, asctime(localtime(¤t_time))); - - // delete the \n - time_str[24] = ' '; - - char prepend[150]; - copy_str(prepend, time_str); - - - switch (level) { - case DEBUG: - strcat(prepend, "DEBUG"); - break; - case INFO: - strcat(prepend, "INFO "); - break; - case WARN: - strcat(prepend, "WARN "); - break; - case ERROR: - strcat(prepend, "ERROR"); - break; - case SILENT: - return; - } - - strcat(prepend, ": "); - - if (level <= LOGLEVEL) { - FILE * logfile = fopen("debug.log", "a"); - fprintf(logfile, "%s", prepend); - fprintf(logfile, message); - fclose(logfile); - } - - if (level <= STDOUTLEVEL) { - printf("%s", prepend); - printf(message); - } - -} diff --git a/src/logger.h b/src/logger.h deleted file mode 100644 index f648f89..0000000 --- a/src/logger.h +++ /dev/null @@ -1,23 +0,0 @@ -#include -#include -#include - -#ifndef _DEFLOGGER -#define _DEFLOGGER - - -typedef enum { - // high-low priority - // low-high verbosity - SILENT, ERROR, WARN, INFO, DEBUG -} loggerlevel; - - -extern loggerlevel LOGLEVEL; -extern loggerlevel STDOUTLEVEL; - -void logwrite(loggerlevel level, char message[]); - -void set_loglevel(loggerlevel echo, loggerlevel write); - -#endif diff --git a/src/main.c b/src/main.c index 0b2af88..ad41a71 100644 --- a/src/main.c +++ b/src/main.c @@ -15,10 +15,8 @@ #include #include -#include "logger.h" #include "game.h" #include "draw.h" -#include "garbo.h" #include "types.h" const int screen_width = 800; @@ -75,19 +73,13 @@ int physics_loop(void *ptr) { } int game(void) { - LOGLEVEL = SILENT; - STDOUTLEVEL = SILENT; - //SDL_SetHint( SDL_HINT_RENDER_SCALE_QUALITY, "2" ); - logwrite(INFO, "Starting\n"); SDL_Window * win = make_window(); SDL_Renderer * ren = SDL_CreateRenderer(win, -1, SDL_RENDERER_ACCELERATED); // | SDL_RENDERER_PRESENTVSYNC); SDL_SetRenderDrawBlendMode(ren, SDL_BLENDMODE_BLEND); - queue_for_cleanup(win, WINDOW); - queue_for_cleanup(ren, RENDERER); in_game = true; resume = SDL_CreateSemaphore(0); @@ -115,16 +107,14 @@ int game(void) { int count = 0; while (!close) { - SDL_Event event; while(SDL_PollEvent(&event)) { switch (event.type) { case SDL_QUIT: - close = 1; - return 0; + goto endfunc; case SDL_KEYDOWN: if (event.key.keysym.scancode == SDL_SCANCODE_Q) { - return 0; + goto endfunc; } if (!in_game && !SDL_SemValue(resume)) { SDL_SemPost(resume); @@ -142,6 +132,12 @@ int game(void) { redraw(ren); } } + +endfunc: + + SDL_DestroyRenderer(ren); + SDL_DestroyWindow(win); + return 0; } @@ -160,8 +156,8 @@ int main (int argc, char** argv) { #endif game(); + SDL_Quit(); - //empty_cleanup_queue(); return 0; }