diff --git a/src/battle/battle.c b/src/battle/battle.c index e8b2ae2..f9c43d7 100644 --- a/src/battle/battle.c +++ b/src/battle/battle.c @@ -390,7 +390,7 @@ static void postBattle(void) game.currentMission->completed = (battle.status == MS_COMPLETE || !battle.numObjectivesTotal); - saveGame(); + app.saveGame = 1; } void destroyBattle(void) diff --git a/src/battle/battle.h b/src/battle/battle.h index 438cb11..855d871 100644 --- a/src/battle/battle.h +++ b/src/battle/battle.h @@ -87,7 +87,6 @@ extern void runScriptFunction(const char *format, ...); extern void doSpawners(void); extern void doTrophyAlerts(void); extern void drawTrophyAlert(void); -extern void saveGame(void); extern App app; extern Battle battle; diff --git a/src/challenges/challengeHome.c b/src/challenges/challengeHome.c index f62c8f4..67f06b9 100644 --- a/src/challenges/challengeHome.c +++ b/src/challenges/challengeHome.c @@ -71,7 +71,7 @@ void initChallengeHome(void) awardStatsTrophies(); - saveGame(); + app.saveGame = 1; app.delegate.logic = &logic; app.delegate.draw = &draw; diff --git a/src/challenges/challengeHome.h b/src/challenges/challengeHome.h index 7b03c43..741e619 100644 --- a/src/challenges/challengeHome.h +++ b/src/challenges/challengeHome.h @@ -44,7 +44,6 @@ extern void drawText(int x, int y, int size, int align, SDL_Color c, const char extern void drawWidgets(char *groupName); extern int collision(int x1, int y1, int w1, int h1, int x2, int y2, int w2, int h2); extern Widget *getWidget(const char *name, const char *group); -extern void saveGame(void); extern void initTitle(void); extern void initStatsDisplay(void); extern void drawOptions(void); diff --git a/src/galaxy/galacticMap.c b/src/galaxy/galacticMap.c index 5187f39..b54cef1 100644 --- a/src/galaxy/galacticMap.c +++ b/src/galaxy/galacticMap.c @@ -93,7 +93,7 @@ void initGalacticMap(void) awardStatsTrophies(); - saveGame(); + app.saveGame = 1; pulseTimer = 0; diff --git a/src/galaxy/galacticMap.h b/src/galaxy/galacticMap.h index 45f9b6a..f4a9079 100644 --- a/src/galaxy/galacticMap.h +++ b/src/galaxy/galacticMap.h @@ -33,7 +33,6 @@ extern void loadMission(char *filename); extern SDL_Texture *getTexture(char *filename); extern void startSectionTransition(void); extern void endSectionTransition(void); -extern void saveGame(void); extern void blit(SDL_Texture *t, int x, int y, int centered); extern int collision(int x1, int y1, int w1, int h1, int x2, int y2, int w2, int h2); extern void drawCircle(int cx, int cy, int radius, int r, int g, int b, int a); diff --git a/src/game/trophies.c b/src/game/trophies.c index 4ec434a..eff2b82 100644 --- a/src/game/trophies.c +++ b/src/game/trophies.c @@ -218,6 +218,8 @@ void awardTrophy(char *id) t->notify = 1; SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, "Awarding trophy '%s'", id); + + app.saveGame = 1; } if (!t->awarded) diff --git a/src/main.c b/src/main.c index ffe8fb7..c3ce317 100644 --- a/src/main.c +++ b/src/main.c @@ -163,6 +163,13 @@ int main(int argc, char *argv[]) expireTextTimer = SDL_GetTicks() + (1000 * 10); } + /* trophy unlocks might cause the game to save several times in one frame */ + if (app.saveGame) + { + saveGame(); + app.saveGame = 0; + } + /* always zero the mouse motion */ app.mouse.dx = app.mouse.dy = 0; diff --git a/src/main.h b/src/main.h index a792f1b..5915858 100644 --- a/src/main.h +++ b/src/main.h @@ -51,6 +51,7 @@ extern void doKeyUp(SDL_KeyboardEvent *event); extern void createScreenshotFolder(void); extern int isControl(int type); extern void clearControl(int type); +extern void saveGame(void); App app; Colors colors; diff --git a/src/structs.h b/src/structs.h index ae2b3f3..8a3943f 100644 --- a/src/structs.h +++ b/src/structs.h @@ -460,6 +460,7 @@ typedef struct { typedef struct { int resetTimeDelta; char saveDir[MAX_FILENAME_LENGTH]; + int saveGame; int winWidth; int winHeight; float scaleX;