From 74383264c25725de6c90bc3b3e0be3abac2ad21c Mon Sep 17 00:00:00 2001 From: Steve Date: Thu, 8 Mar 2018 07:52:42 +0000 Subject: [PATCH] Use saveDelay, to prevent premature saving while manually quitting levels. --- src/entities/blobs/mia.c | 12 ++++++++---- src/structs.h | 1 + src/world/entities.c | 6 ++++++ src/world/world.c | 18 +++++++++++++++--- src/world/world.h | 1 + 5 files changed, 31 insertions(+), 7 deletions(-) diff --git a/src/entities/blobs/mia.c b/src/entities/blobs/mia.c index ad0a473..1a5b0fe 100644 --- a/src/entities/blobs/mia.c +++ b/src/entities/blobs/mia.c @@ -84,8 +84,7 @@ static void tick(void) m = (MIA*)self; - m->shudderTimer--; - if (m->shudderTimer <= 0) + if (--m->shudderTimer <= 0) { m->x = (m->tx + rand() % 4); m->shudderTimer = 2; @@ -93,12 +92,13 @@ static void tick(void) if (!m->isMissionTarget) { - m->starTimer--; - if (m->starTimer <= 0) + if (--m->starTimer <= 0) { addMIATeleportStars(m->x + rand() % m->w, m->y + rand() % m->h); m->starTimer = 1; } + + world.saveDelay = FPS; } } @@ -132,6 +132,8 @@ static void preTeleport(void) m->flags |= (EF_NO_CLIP | EF_WEIGHTLESS); m->dy = -5; } + + world.saveDelay = FPS; } static void teleport(void) @@ -147,6 +149,8 @@ static void teleport(void) updateObjective("MIA"); m->alive = ALIVE_DEAD; } + + world.saveDelay = FPS; } static void load(cJSON *root) diff --git a/src/structs.h b/src/structs.h index e26c069..cc1b320 100644 --- a/src/structs.h +++ b/src/structs.h @@ -467,6 +467,7 @@ typedef struct { int helperItemTimer; int spawnInterval; int numToSpawn; + int saveDelay; Bob *bob; Boss *boss; Entity *entityToTrack; diff --git a/src/world/entities.c b/src/world/entities.c index c16feda..5cde1e2 100644 --- a/src/world/entities.c +++ b/src/world/entities.c @@ -138,6 +138,7 @@ void doEntities(void) if (self->flags & EF_TELEPORTING) { + world.saveDelay = FPS; handleTeleport(); prev = self; continue; @@ -235,6 +236,11 @@ void doEntities(void) self->die(); } } + + if (self->alive == ALIVE_DYING) + { + world.saveDelay = FPS; + } } if (!(self->flags & (EF_TELEPORTING | EF_GONE))) diff --git a/src/world/world.c b/src/world/world.c index 06d4cf6..6e2d54f 100644 --- a/src/world/world.c +++ b/src/world/world.c @@ -139,6 +139,12 @@ void initWorld(void) app.restrictTrophyAlert = 1; endSectionTransition(); + + /* + startMission(); + world.bob->x = 17 * MAP_TILE_SIZE; + world.bob->y = 89 * MAP_TILE_SIZE; + */ } static void logic(void) @@ -147,6 +153,8 @@ static void logic(void) { world.betweenTimer = 0; + world.saveDelay = limit(world.saveDelay - 1, 0, FPS); + switch (world.state) { case WS_START: @@ -166,6 +174,7 @@ static void logic(void) break; case WS_COMPLETE: + case WS_QUIT: doWorldComplete(); break; @@ -516,13 +525,14 @@ static void doWorldComplete(void) { world.missionCompleteTimer--; - if (world.missionCompleteTimer == 0) + if (world.missionCompleteTimer <= 0 && world.saveDelay <= 0) { + dropCarriedItems(); + initPostMission(); } else if (world.missionCompleteTimer == FPS * 1.5) { - dropCarriedItems(); world.bob->flags |= EF_GONE; addTeleportStars((Entity*)world.bob); playSound(SND_TELEPORT, world.bob->uniqueId % MAX_SND_CHANNELS); @@ -878,7 +888,7 @@ void quitMission(void) { resume(); stopMusic(); - world.state = WS_COMPLETE; + world.state = WS_QUIT; world.missionCompleteTimer = (FPS * 1.5) + 1; if (world.missionType == MT_TRAINING) @@ -926,6 +936,8 @@ void autoCompleteMission(void) break; } } + + world.state = WS_COMPLETE; } void destroyWorld(void) diff --git a/src/world/world.h b/src/world/world.h index b3e3c64..9495328 100644 --- a/src/world/world.h +++ b/src/world/world.h @@ -116,6 +116,7 @@ extern int rrnd(int low, int high); extern void showWidgetGroup(char *group); extern void startSectionTransition(void); extern void stopMusic(void); +extern float limit(float i, float a, float b); extern App app; extern Camera camera;