diff --git a/src/audio/music.c b/src/audio/music.c index 18147f72d..21f5d2fc7 100644 --- a/src/audio/music.c +++ b/src/audio/music.c @@ -179,6 +179,8 @@ void playMapMusic() Mix_PlayMusic(music, -1); Mix_VolumeMusic(game.musicDefaultVolume * VOLUME_STEPS); + + Mix_ResumeMusic(); } void stopMusic() diff --git a/src/boss/azriel.c b/src/boss/azriel.c index 7cf023295..cc846860d 100644 --- a/src/boss/azriel.c +++ b/src/boss/azriel.c @@ -35,6 +35,7 @@ Foundation, 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA. #include "../graphics/decoration.h" #include "../graphics/graphics.h" #include "../hud.h" +#include "../init.h" #include "../inventory.h" #include "../item/key_items.h" #include "../map.h" @@ -2052,7 +2053,7 @@ static void becomeTransparent() { printf("%s cannot become transparent!\n", self->name); - exit(1); + cleanup(1); } self->endX--; diff --git a/src/defs.h b/src/defs.h index 6c1505155..2d46bd488 100644 --- a/src/defs.h +++ b/src/defs.h @@ -226,7 +226,7 @@ Foundation, 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA. #define TABLE_SIZE 255 -#define YEAR 2020 +#define YEAR 2021 #ifdef TRUE #undef TRUE diff --git a/src/draw.c b/src/draw.c index d4ae0d86b..02dbf8dfc 100644 --- a/src/draw.c +++ b/src/draw.c @@ -200,6 +200,11 @@ void draw() } break; } + + if (game.frames % 300 == 0) + { + removeUnreferencedEntities(); + } } else diff --git a/src/enemy/ground_spear.c b/src/enemy/ground_spear.c index 7877ce8cb..33ffb5ce9 100644 --- a/src/enemy/ground_spear.c +++ b/src/enemy/ground_spear.c @@ -23,6 +23,9 @@ Foundation, 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA. #include "../collisions.h" #include "../entity.h" #include "../graphics/animation.h" +#if DEV == 1 +#include "../init.h" +#endif #include "../system/error.h" #include "../system/properties.h" @@ -31,7 +34,7 @@ extern Entity *self; static void entityWait(void); static void rise(void); static void sink(void); -static void init(void); +static void initialise(void); Entity *addGroundSpear(int x, int y, char *name) { @@ -47,7 +50,7 @@ Entity *addGroundSpear(int x, int y, char *name) e->x = x; e->y = y; - e->action = &init; + e->action = &initialise; e->draw = &drawLoopingAnimationToMap; e->touch = &entityTouch; @@ -59,7 +62,7 @@ Entity *addGroundSpear(int x, int y, char *name) return e; } -static void init() +static void initialise() { switch (self->mental) { @@ -173,7 +176,7 @@ static void rise() { printf("Loop time %d\n", self->health); - exit(0); + cleanup(0); } #endif } diff --git a/src/entity.c b/src/entity.c index e49975754..2dd16b2e3 100644 --- a/src/entity.c +++ b/src/entity.c @@ -254,8 +254,8 @@ void doEntities() void drawEntities(int depth) { - int i, drawn, removeCount; - EntityList *el, *prev, *el2; + int i, drawn; + EntityList *el; /* Draw standard entities */ @@ -318,45 +318,6 @@ void drawEntities(int depth) } } } - - if (game.frames % 300 == 0) - { - removeCount = 0; - - prev = entities; - - for (el=entities->next;el!=NULL;el=el2) - { - el2 = el->next; - - if (el->entity->inUse == FALSE && isReferenced(el->entity) == FALSE) - { - prev->next = el2; - - removeCount++; - - free(el->entity); - - el->entity = NULL; - - free(el); - - el = NULL; - } - - else - { - prev = prev->next; - } - } - - #if DEV == 1 - if (removeCount != 0) - { - printf("Removed %d entities taking up %d bytes\n", removeCount, (int)sizeof(Entity) * removeCount); - } - #endif - } } void removeEntity() @@ -392,6 +353,48 @@ void removeAllSpawnedIn() } } +void removeUnreferencedEntities() +{ + int removeCount; + EntityList *el, *prev, *el2; + + removeCount = 0; + + prev = entities; + + for (el=entities->next;el!=NULL;el=el2) + { + el2 = el->next; + + if (el->entity->inUse == FALSE && isReferenced(el->entity) == FALSE) + { + prev->next = el2; + + removeCount++; + + free(el->entity); + + el->entity = NULL; + + free(el); + + el = NULL; + } + + else + { + prev = prev->next; + } + } + + #if DEV == 1 + if (removeCount != 0) + { + printf("Removed %d entities taking up %d bytes\n", removeCount, (int)sizeof(Entity) * removeCount); + } + #endif +} + void disableSpawners(int disable) { Entity *e; diff --git a/src/entity.h b/src/entity.h index cfb836116..6eaf7aa5e 100644 --- a/src/entity.h +++ b/src/entity.h @@ -24,6 +24,7 @@ void doEntities(void); void drawEntities(int); void removeEntity(void); void removeAllSpawnedIn(void); +void removeUnreferencedEntities(void); void disableSpawners(int); void doNothing(void); void entityDie(void); diff --git a/src/game.c b/src/game.c index f78a81bed..6bb2a75a6 100644 --- a/src/game.c +++ b/src/game.c @@ -26,6 +26,7 @@ Foundation, 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA. #include "game.h" #include "graphics/graphics.h" #include "hud.h" +#include "init.h" #include "inventory.h" #include "map.h" #include "medal.h" @@ -616,7 +617,7 @@ void pauseGame() break; case IN_EDITOR: - exit(0); + cleanup(0); break; case IN_INVENTORY: diff --git a/src/graphics/font.c b/src/graphics/font.c index b00370696..74a824533 100644 --- a/src/graphics/font.c +++ b/src/graphics/font.c @@ -18,6 +18,7 @@ Foundation, 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA. */ #include "../headers.h" +#include "../init.h" #include "../system/pak.h" #include "graphics.h" @@ -31,7 +32,7 @@ TTF_Font *loadFont(char *name, int size) { printf("Failed to open Font %s: %s\n", name, TTF_GetError()); - exit(1); + cleanup(1); } return font; @@ -45,7 +46,7 @@ TTF_Font *loadCustomFont(char *name, int size) { printf("Failed to open Font %s: %s\n", name, TTF_GetError()); - exit(1); + cleanup(1); } return font; diff --git a/src/graphics/save_png.c b/src/graphics/save_png.c index 64ae29929..f6d9adcca 100644 --- a/src/graphics/save_png.c +++ b/src/graphics/save_png.c @@ -19,6 +19,7 @@ Foundation, 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA. #include "../headers.h" +#include "../init.h" #include "graphics.h" #include @@ -39,7 +40,7 @@ static void writeData(char *name, png_bytep *rows, int w, int h, int colourtype, { printf("Could not save %s\n", name); - exit(1); + cleanup(1); } pngPtr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); @@ -48,7 +49,7 @@ static void writeData(char *name, png_bytep *rows, int w, int h, int colourtype, { printf("Failed to create PNG structure"); - exit(1); + cleanup(1); } infoPtr = png_create_info_struct(pngPtr); @@ -57,14 +58,14 @@ static void writeData(char *name, png_bytep *rows, int w, int h, int colourtype, { printf("Failed to create PNG info"); - exit(1); + cleanup(1); } if (setjmp(png_jmpbuf(pngPtr)) != 0) { printf("PNG Jump point failed\n"); - exit(1); + cleanup(1); } png_init_io(pngPtr, fp); @@ -116,7 +117,7 @@ void savePNG(SDL_Surface *surface, char *name) { printf("Ran out of memory when creating PNG rows\n"); - exit(1); + cleanup(1); } } diff --git a/src/i18n.c b/src/i18n.c index 9674aba8d..86983d7a4 100644 --- a/src/i18n.c +++ b/src/i18n.c @@ -19,6 +19,8 @@ Foundation, 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA. #include "headers.h" +#include "init.h" + static HashTable table; static int hashCode(char *); @@ -134,7 +136,7 @@ void setLanguage(char *applicationName, char *languageCode) { printf("Failed to allocate %d bytes for translation strings\n", (int)sizeof(MOEntry) * header.stringCount); - exit(1); + cleanup(1); } #if DEV == 1 @@ -151,7 +153,7 @@ void setLanguage(char *applicationName, char *languageCode) { printf("Failed to allocate a whole %d bytes for translation strings\n", (int)sizeof(char *) * header.stringCount); - exit(1); + cleanup(1); } for (i=0;ikey = malloc(strlen(key) + 1); @@ -324,7 +326,7 @@ static void put(char *key, char *value) { printf("Failed to allocate a whole %d bytes for a translation\n", (int)strlen(newBucket->key) + 1); - exit(1); + cleanup(1); } STRNCPY(newBucket->key, key, strlen(key) + 1); diff --git a/src/init.c b/src/init.c index 745d76a78..daf3fa1bd 100644 --- a/src/init.c +++ b/src/init.c @@ -21,6 +21,7 @@ Foundation, 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA. #include "audio/audio.h" #include "graphics/texture_cache.h" +#include "init.h" #include "medal.h" #include "system/load_save.h" #include "system/pak.h" @@ -49,7 +50,7 @@ void init(char *title, int joystickNum) { printf("Could not initialize SDL: %s\n", SDL_GetError()); - exit(1); + cleanup(1); } /* Initialise SDL_TTF */ @@ -58,7 +59,7 @@ void init(char *title, int joystickNum) { printf("Couldn't initialize SDL TTF: %s\n", SDL_GetError()); - exit(1); + cleanup(1); } /* Load the settings */ @@ -78,7 +79,7 @@ void init(char *title, int joystickNum) { printf("Couldn't set screen mode to %d x %d: %s\n", SCREEN_WIDTH, SCREEN_HEIGHT, SDL_GetError()); - exit(1); + cleanup(1); } if (game.audio == TRUE) @@ -154,7 +155,45 @@ void toggleFullScreen() SDL_SetWindowFullscreen(game.window, fullScreen); } -void cleanup() +void addJoystick(int joystickNum) +{ + int buttons = 0; + + printf("Detected joystick\n"); + + if (joystickNum == 0) + { + printf("Opening Joystick #%d\n", joystickNum); + + game.joystick = SDL_JoystickOpen(joystickNum); + + buttons = SDL_JoystickNumButtons(game.joystick); + + printf("Joystick has %d buttons\n", buttons); + + printf("Joystick has %d axes\n", SDL_JoystickNumAxes(game.joystick)); + } +} + +int removeJoystick(int joystickNum) +{ + printf("Joystick removed\n"); + + if (joystickNum == 0 && game.joystick != NULL) + { + printf("Closing joystick #%d\n", joystickNum); + + SDL_JoystickClose(game.joystick); + + game.joystick = NULL; + + return TRUE; + } + + return FALSE; +} + +void cleanup(int exitCode) { float fps; @@ -220,9 +259,11 @@ void cleanup() SDL_DestroyWindow(game.window); SDL_Quit(); + + exit(exitCode); } void quitGame() { - exit(0); + cleanup(0); } diff --git a/src/init.h b/src/init.h index e5c386d1c..33fa6ccfd 100644 --- a/src/init.h +++ b/src/init.h @@ -18,6 +18,8 @@ Foundation, 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA. */ void init(char *, int); -void cleanup(void); +void cleanup(int) __attribute__((noreturn)); void toggleFullScreen(void); +void addJoystick(int); +int removeJoystick(int); void quitGame(void); diff --git a/src/input.c b/src/input.c index c65d57263..4601cba06 100644 --- a/src/input.c +++ b/src/input.c @@ -46,7 +46,7 @@ void getInput(int gameType) switch (event.type) { case SDL_QUIT: - exit(0); + cleanup(0); break; case SDL_WINDOWEVENT: @@ -57,6 +57,17 @@ void getInput(int gameType) break; } break; + + case SDL_JOYDEVICEADDED: + addJoystick(event.jdevice.which); + break; + + case SDL_JOYDEVICEREMOVED: + if (removeJoystick(event.jdevice.which) == TRUE) + { + focusLost(); + } + break; case SDL_KEYDOWN: key = event.key.keysym.sym; @@ -67,7 +78,7 @@ void getInput(int gameType) { if (key == SDLK_ESCAPE) { - exit(0); + cleanup(0); } } @@ -717,7 +728,7 @@ int getSingleInput() switch (event.type) { case SDL_QUIT: - exit(0); + cleanup(0); break; case SDL_KEYDOWN: diff --git a/src/main.c b/src/main.c index 648f41bbf..a295c97ca 100644 --- a/src/main.c +++ b/src/main.c @@ -80,7 +80,7 @@ int main(int argc, char *argv[]) printf("You must specify a file to record to\n"); printf("Type %s -h for help\n", argv[0]); - exit(1); + cleanup(1); } if (recordingID == -1) @@ -98,7 +98,7 @@ int main(int argc, char *argv[]) printf("You must specify a file to playback from\n"); printf("Type %s -h for help\n", argv[0]); - exit(1); + cleanup(1); } if (replayingID == -1) @@ -116,7 +116,7 @@ int main(int argc, char *argv[]) printf("You must specify a slot to load from\n"); printf("Type %s -h for help\n", argv[0]); - exit(1); + cleanup(1); } loadSlot = atoi(argv[i + 1]); @@ -136,7 +136,7 @@ int main(int argc, char *argv[]) printf("You must specify a joystick slot to use\n"); printf("Type %s -h for help\n", argv[0]); - exit(1); + cleanup(1); } joystick = atoi(argv[i + 1]); @@ -156,7 +156,7 @@ int main(int argc, char *argv[]) printf("You must specify a language to use\n"); printf("Type %s -h for help\n", argv[0]); - exit(1); + cleanup(1); } languageID = i + 1; @@ -175,7 +175,7 @@ int main(int argc, char *argv[]) printf("\t-showcredits: Shows the end credits\n"); printf("\t-language : Use language . e.g. en_US, es, pl\n\n"); - exit(0); + cleanup(0); } #if DEV == 1 @@ -202,10 +202,6 @@ int main(int argc, char *argv[]) printf("Numeric is %s\n", setlocale(LC_NUMERIC, "C")); printf("atof(2.75) is %f\n", atof("2.75")); - /* Call the cleanup function when the program exits */ - - atexit(cleanup); - /* Start up SDL */ init(_("The Legend of Edgar"), joystick); @@ -382,5 +378,5 @@ int main(int argc, char *argv[]) /* Exit the program */ - exit(0); + cleanup(0); } diff --git a/src/main_editor.c b/src/main_editor.c index 9a8c754df..1294c8bcf 100644 --- a/src/main_editor.c +++ b/src/main_editor.c @@ -46,7 +46,7 @@ int main(int argc, char *argv[]) #if DEV == 0 printf("Editor doesn't work if DEV is set to 0\n"); - exit(1); + cleanup(1); #endif setLanguage("edgar", NULL); @@ -55,10 +55,6 @@ int main(int argc, char *argv[]) init("Map Editor", 1); - /* Call the cleanup function when the program exits */ - - atexit(cleanup); - export = FALSE; go = TRUE; @@ -87,7 +83,7 @@ int main(int argc, char *argv[]) { printf("Usage: %s \n", argv[0]); - exit(1); + cleanup(1); } if (export == TRUE) @@ -188,7 +184,7 @@ int main(int argc, char *argv[]) if (y >= maxY) { - exit(0); + cleanup(0); } } @@ -227,5 +223,5 @@ int main(int argc, char *argv[]) /* Exit the program */ - exit(0); + cleanup(0); } diff --git a/src/map.c b/src/map.c index cebc22670..e70192901 100644 --- a/src/map.c +++ b/src/map.c @@ -840,7 +840,7 @@ void drawMap(int depth) { printf("Tile %d is NULL\n", tileID); - exit(0); + cleanup(0); } */ diff --git a/src/pak_creator.c b/src/pak_creator.c index dfc391277..9d3ced317 100644 --- a/src/pak_creator.c +++ b/src/pak_creator.c @@ -26,7 +26,7 @@ FileData *fileData; char **filenames; static void getFilenames(char *, int *); -static void cleanup(void); +static void cleanup(int); static void compressFile(char *); static void testPak(char *); static int compare (const void *, const void *); @@ -44,7 +44,7 @@ int main(int argc, char *argv[]) { testPak(argv[2]); - exit(0); + cleanup(0); } } @@ -53,10 +53,8 @@ int main(int argc, char *argv[]) printf("Usage : pak \n"); printf("Example : pak data music gfx sound font edgar.pak\n"); - exit(1); + cleanup(1); } - - atexit(cleanup); pak = fopen(argv[argc - 1], "wb"); @@ -83,7 +81,7 @@ int main(int argc, char *argv[]) { printf("Failed to create File Data\n"); - exit(1); + cleanup(1); } SNPRINTF(versionName, sizeof(versionName), "%0.2f", VERSION); @@ -182,7 +180,7 @@ static void getFilenames(char *dirName, int *arraySize) { printf("Failed to allocate %d bytes whilst indexing files\n", *arraySize * (int)sizeof(char *)); - exit(1); + cleanup(1); } } } @@ -199,7 +197,7 @@ static int compare(const void *a, const void *b) return strcmpignorecase(aa, bb); } -static void cleanup() +static void cleanup(int exitCode) { int i; @@ -220,6 +218,8 @@ static void cleanup() { free(fileData); } + + exit(exitCode); } static void compressFile(char *filename) @@ -238,7 +238,7 @@ static void compressFile(char *filename) { printf("Couldn't open %s for reading!\n", filename); - exit(1); + cleanup(1); } fseek(infile, 0L, SEEK_END); @@ -249,7 +249,7 @@ static void compressFile(char *filename) { printf("%s is an empty file.\n", filename); - exit(1); + cleanup(1); } ensuredSize = fileSize * 1.01 + 12; @@ -264,7 +264,7 @@ static void compressFile(char *filename) { printf("Could not create buffer\n"); - exit(1); + cleanup(1); } output = malloc(ensuredSize * sizeof(unsigned char)); @@ -273,7 +273,7 @@ static void compressFile(char *filename) { printf("Could not create output\n"); - exit(1); + cleanup(1); } fp = gzopen(filename, "rb"); @@ -282,7 +282,7 @@ static void compressFile(char *filename) { printf("Couldn't open %s for reading!\n", filename); - exit(1); + cleanup(1); } gzread(fp, buffer, fileSize); @@ -315,7 +315,7 @@ static void compressFile(char *filename) printf("Unknown error\n"); } - exit(1); + cleanup(1); } percentage = fileID; @@ -356,7 +356,7 @@ static void testPak(char *pakFile) { printf("Failed to open PAK file %s\n", pakFile); - exit(1); + cleanup(1); } fseek(fp, -(sizeof(int32_t) + sizeof(int32_t)), SEEK_END); @@ -373,7 +373,7 @@ static void testPak(char *pakFile) { printf("Could not allocate %d bytes for FileData\n", fileCount * (int)sizeof(FileData)); - exit(1); + cleanup(1); } fseek(fp, offset, SEEK_SET); @@ -403,7 +403,7 @@ static void testPak(char *pakFile) { printf("\nFailed to allocate %d bytes to load %s from PAK\n", fileData[i].compressedSize * (int)sizeof(unsigned char), fileData[i].filename); - exit(1); + cleanup(1); } dest = malloc((fileData[i].fileSize + 1) * sizeof(unsigned char)); @@ -412,7 +412,7 @@ static void testPak(char *pakFile) { printf("\nFailed to allocate %d bytes to load %s from PAK\n", fileData[i].fileSize * (int)sizeof(unsigned char), fileData[i].filename); - exit(1); + cleanup(1); } fread(source, fileData[i].compressedSize, 1, fp); @@ -427,7 +427,7 @@ static void testPak(char *pakFile) { printf("\nFailed to decompress %s. Expected %d, got %ld\n", fileData[i].filename, fileData[i].fileSize, size); - exit(1); + cleanup(1); } free(source); diff --git a/src/system/error.c b/src/system/error.c index 82d8a5c71..363751a65 100644 --- a/src/system/error.c +++ b/src/system/error.c @@ -22,6 +22,7 @@ Foundation, 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA. #include "../audio/music.h" #include "../graphics/font.h" #include "../graphics/graphics.h" +#include "../init.h" #include "../input.h" extern Game game; @@ -46,13 +47,13 @@ void showErrorAndExit(char *fmt, ...) if (game.status == IN_ERROR) { - exit(1); + cleanup(1); } printf("%s\n", text); #if DEV == 1 - exit(1); + cleanup(1); #endif game.status = IN_ERROR; diff --git a/src/system/load_save.c b/src/system/load_save.c index 664ed378c..00d9e2ebc 100644 --- a/src/system/load_save.c +++ b/src/system/load_save.c @@ -30,6 +30,7 @@ Foundation, 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA. #include "../graphics/font.h" #include "../graphics/graphics.h" #include "../hud.h" +#include "../init.h" #include "../input.h" #include "../inventory.h" #include "../map.h" @@ -65,7 +66,7 @@ extern Game game; { printf("Couldn't determine the user home directory. Exiting.\n"); - exit(1); + cleanup(1); } userHome = pass->pw_dir; @@ -80,7 +81,7 @@ extern Game game; { printf("Couldn't create required directory '%s'\n", dir); - exit(1); + cleanup(1); } #if MACOS == 1 @@ -93,7 +94,7 @@ extern Game game; { printf("Couldn't create required directory '%s'\n", dir); - exit(1); + cleanup(1); } #if MACOS == 1 @@ -127,7 +128,7 @@ extern Game game; { printf("Couldn't create required directory '%s'\n", dir); - exit(1); + cleanup(1); } SNPRINTF(dir, sizeof(dir), "%s/parallelrealities/edgar", userHome); @@ -136,7 +137,7 @@ extern Game game; { printf("Couldn't create required directory '%s'\n", dir); - exit(1); + cleanup(1); } SNPRINTF(gameSavePath, sizeof(gameSavePath), "%s/parallelrealities/edgar/", userHome); @@ -1572,7 +1573,7 @@ void loadConfig() { showErrorAndExit("Failed to allocate a whole %ld bytes for config file...", length); - exit(1); + cleanup(1); } fseek(fp, 0L, SEEK_SET); @@ -1620,7 +1621,7 @@ void saveConfig() { showErrorAndExit("Could not save settings: %s", strerror(errno)); - exit(1); + cleanup(1); } writeControlsToFile(fp); @@ -1676,7 +1677,7 @@ char **getSaveFileIndex() { showErrorAndExit("Failed to allocate a whole %d bytes for save data", (int)sizeof(char *) * MAX_SAVE_SLOTS); - exit(1); + cleanup(1); } for (i=0;iname, name); #if DEV == 1 - exit(0); + cleanup(0); #endif } } diff --git a/src/system/record.c b/src/system/record.c index 4c5e0d151..3986df042 100644 --- a/src/system/record.c +++ b/src/system/record.c @@ -19,6 +19,7 @@ Foundation, 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA. #include "../headers.h" +#include "../init.h" #include "../map.h" #include "error.h" #include "random.h" @@ -163,7 +164,7 @@ Input getBuffer() { printf("End of replay\n"); - exit(0); + cleanup(0); } input = inputBuffer[bufferID]; diff --git a/src/system/resources.c b/src/system/resources.c index 1229eabb7..81afbe80a 100644 --- a/src/system/resources.c +++ b/src/system/resources.c @@ -37,6 +37,7 @@ Foundation, 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA. #include "../graphics/sprites.h" #include "../graphics/texture_cache.h" #include "../hud.h" +#include "../init.h" #include "../inventory.h" #include "../item/item.h" #include "../item/key_items.h" @@ -344,7 +345,7 @@ char *loadResources(char *buffer) printf("WARNING: Line starts with a space\n"); #if DEV == 1 - exit(0); + cleanup(0); #endif line = strtok_r(NULL, "\n", &savePtr); @@ -392,7 +393,7 @@ char *loadResources(char *buffer) else if (strcmpignorecase(line, "}") == 0) { - e = addEntityFromResource(value[type], value[name], startX == -1 ? 0 : atoi(value[startX]), startY == -1 ? 0 : atoi(value[startY])); + e = addEntityFromResource(value[type], name == -1 ? "" : value[name], startX == -1 ? 0 : atoi(value[startX]), startY == -1 ? 0 : atoi(value[startY])); if (e != NULL) { diff --git a/src/tile_creator.c b/src/tile_creator.c index d5defac32..8664be872 100644 --- a/src/tile_creator.c +++ b/src/tile_creator.c @@ -21,7 +21,7 @@ Foundation, 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA. #include "graphics/save_png.h" -static void cleanup(void); +static void cleanup(int); static SDL_Surface *loadImage(char *); static int isDuplicate(SDL_Surface *, int, int); static Uint32 getPixel(SDL_Surface *, int, int); @@ -43,16 +43,14 @@ int main(int argc, char *argv[]) { printf("Usage: %s \n", argv[0]); - exit(0); + cleanup(0); } - atexit(cleanup); - if (SDL_Init(SDL_INIT_VIDEO|SDL_INIT_JOYSTICK|SDL_INIT_AUDIO) < 0) { printf("Could not initialize SDL: %s\n", SDL_GetError()); - exit(1); + cleanup(1); } screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0); @@ -122,7 +120,7 @@ int main(int argc, char *argv[]) } } - exit(0); + cleanup(0); } static SDL_Surface *loadImage(char *name) @@ -138,7 +136,7 @@ static SDL_Surface *loadImage(char *name) { printf("Failed to load image %s", name); - exit(1); + cleanup(1); } /* Make the background transparent */ @@ -155,7 +153,7 @@ static SDL_Surface *loadImage(char *name) { printf("Failed to convert image %s to native format", name); - exit(1); + cleanup(1); } /* Return the processed image */ @@ -245,7 +243,7 @@ static Uint32 getPixel(SDL_Surface *surface, int x, int y) } } -static void cleanup() +static void cleanup(int exitCode) { if (temp != NULL) { @@ -263,4 +261,6 @@ static void cleanup() } SDL_Quit(); + + exit(exitCode); }