1
1
Fork 0
Browse Source

remove old unused code

master
alistair 3 years ago
parent
commit
5a719540f5
  1. 2
      src/draw.c
  2. 1
      src/draw.h
  3. 1
      src/game.h
  4. 65
      src/garbo.c
  5. 41
      src/garbo.h
  6. 70
      src/logger.c
  7. 23
      src/logger.h
  8. 22
      src/main.c

2
src/draw.c

@ -625,10 +625,12 @@ int draw_end_screen(SDL_Renderer *ren) { @@ -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;

1
src/draw.h

@ -4,7 +4,6 @@ @@ -4,7 +4,6 @@
#include <SDL2/SDL.h>
#include <SDL2/SDL_ttf.h>
#include "garbo.h"
#include "c-colours/colours.h"
#include "vect.h"
#include "environment.h"

1
src/game.h

@ -4,7 +4,6 @@ @@ -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"

65
src/garbo.c

@ -1,65 +0,0 @@ @@ -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);
}
}

41
src/garbo.h

@ -1,41 +0,0 @@ @@ -1,41 +0,0 @@
#ifndef _DEFGARBO
#define _DEFGARBO
#include <stdlib.h>
#include <string.h>
#include <SDL2/SDL.h>
#include <string.h>
#include "logger.h"
#include <stdbool.h>
/* 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

70
src/logger.c

@ -1,70 +0,0 @@ @@ -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 <string.h>*/
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(&current_time);
copy_str(time_str, asctime(localtime(&current_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);
}
}

23
src/logger.h

@ -1,23 +0,0 @@ @@ -1,23 +0,0 @@
#include <time.h>
#include <string.h>
#include <stdio.h>
#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

22
src/main.c

@ -15,10 +15,8 @@ @@ -15,10 +15,8 @@
#include <fcntl.h>
#include <sys/stat.h>
#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) { @@ -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) { @@ -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) { @@ -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) { @@ -160,8 +156,8 @@ int main (int argc, char** argv) {
#endif
game();
SDL_Quit();
//empty_cleanup_queue();
return 0;
}

Loading…
Cancel
Save