From 49c1bd5b4ee07beb411c11060eebe4b90e955a2e Mon Sep 17 00:00:00 2001 From: Allanis Date: Wed, 13 Nov 2013 02:42:23 +0000 Subject: [PATCH] [Change] Removed dependancy of the spawn_timer on SDL_GetTicks(). --- src/pause.c | 4 ---- src/space.c | 27 ++++++++++++++------------- src/space.h | 3 ++- 3 files changed, 16 insertions(+), 18 deletions(-) diff --git a/src/pause.c b/src/pause.c index 9f86b50..0d3701e 100644 --- a/src/pause.c +++ b/src/pause.c @@ -9,8 +9,6 @@ int paused = 0; /* Are we paused. */ /* From pilot.c */ extern Pilot** pilot_stack; extern int pilot_nstack; -/* From space.c */ -extern unsigned int spawn_timer; /* From main.c */ extern unsigned int gtime; @@ -23,7 +21,6 @@ void pause_game(void) { if(paused) return; /* Well well.. We are paused already. */ pilot_nstack_pause(); - spawn_timer -= SDL_GetTicks(); paused = 1; /* We should unpause it. */ } @@ -32,7 +29,6 @@ void unpause_game(void) { if(!paused) return; /* We are unpaused already. */ pilot_nstack_unpause(); - spawn_timer += SDL_GetTicks(); paused = 0; } diff --git a/src/space.c b/src/space.c index 7b5296d..3749ddb 100644 --- a/src/space.c +++ b/src/space.c @@ -56,7 +56,8 @@ static int total_planets = 0; /* Total number of loaded planets - A little StarSystem* cur_system = NULL; /* Current star system. */ /* Fleet spawn rate. */ -unsigned int spawn_timer = 0; /* Controls spawn rate. */ +int space_spawn = 1; /**< Spawn enabled by default. */ +static double spawn_timer = 0; /**< Timer that controls spawn rate. */ /* Star stack and co. */ #define STAR_BUF 100 /* Area to leave around screen, more = less repitition. */ @@ -367,20 +368,19 @@ Planet* planet_get(char* planetname) { /* Basically used for spawning fleets. */ void space_update(const double dt) { - unsigned int t; int i, j, f; - (void)dt; /* Don't need it right now. */ - if(cur_system == NULL) return; /* Can't update a null system. */ - t = SDL_GetTicks(); + if(!space_spawn) return; /* Spawning is disabled. */ + + spawn_timer -= dt; if(cur_system->nfleets == 0) /* Please stop checking that there are no fleets. */ - spawn_timer = t + 300000; + spawn_timer = 300.; - if(spawn_timer < t) { + if(spawn_timer < 0.) { /* Time to possibly spawn. */ /* Spawn chance is based on overall percentage. */ @@ -394,7 +394,7 @@ void space_update(const double dt) { break; } } - spawn_timer = t + 60000./(float)cur_system->nfleets; + spawn_timer = 60./(float)cur_system->nfleets; } } @@ -487,10 +487,11 @@ void space_init(const char* sysname) { int i; /* Cleanup some stuff. */ - player_clear(); /* Clears targets. */ - pilots_clean(); /* Destroy all the current pilots, exept player. */ - weapon_clear(); /* Get rid of all the weapons. */ - spfx_clear(); /* Remove of explosions. */ + player_clear(); /* Clears targets. */ + pilots_clean(); /* Destroy all the current pilots, exept player. */ + weapon_clear(); /* Get rid of all the weapons. */ + spfx_clear(); /* Remove of explosions. */ + space_spawn = 1; /* Spawn is enabled by default. */ if((sysname == NULL) && (cur_system == NULL)) ERR("Cannot reinit system if there is no system previously loaded"); @@ -527,7 +528,7 @@ void space_init(const char* sysname) { space_addFleet(cur_system->fleets[i].fleet, 1); /* Start the spawn timer. */ - spawn_timer = SDL_GetTicks() + 120000./(float)(cur_system->nfleets+1); + spawn_timer = 120./(float)(cur_system->nfleets+1); /* We now know this system. */ sys_setFlag(cur_system, SYSTEM_KNOWN); diff --git a/src/space.h b/src/space.h index f0b89eb..c277e5a 100644 --- a/src/space.h +++ b/src/space.h @@ -130,7 +130,8 @@ typedef struct StarSystem_ { unsigned int flags; /**< Flags for system properties. */ } StarSystem; -extern StarSystem* cur_system; /**< Current star system. */ +extern StarSystem* cur_system; /**< Current star system. */ +extern int space_spawn; /**< 1 if spawning is enabled. */ /* Load/Exit. */ void space_init(const char* sysname);