[Change] Removed dependancy of the spawn_timer on SDL_GetTicks().

This commit is contained in:
Allanis 2013-11-13 02:42:23 +00:00
parent a42c21da4e
commit 49c1bd5b4e
3 changed files with 16 additions and 18 deletions

View File

@ -9,8 +9,6 @@ int paused = 0; /* Are we paused. */
/* From pilot.c */ /* From pilot.c */
extern Pilot** pilot_stack; extern Pilot** pilot_stack;
extern int pilot_nstack; extern int pilot_nstack;
/* From space.c */
extern unsigned int spawn_timer;
/* From main.c */ /* From main.c */
extern unsigned int gtime; extern unsigned int gtime;
@ -23,7 +21,6 @@ void pause_game(void) {
if(paused) return; /* Well well.. We are paused already. */ if(paused) return; /* Well well.. We are paused already. */
pilot_nstack_pause(); pilot_nstack_pause();
spawn_timer -= SDL_GetTicks();
paused = 1; /* We should unpause it. */ paused = 1; /* We should unpause it. */
} }
@ -32,7 +29,6 @@ void unpause_game(void) {
if(!paused) return; /* We are unpaused already. */ if(!paused) return; /* We are unpaused already. */
pilot_nstack_unpause(); pilot_nstack_unpause();
spawn_timer += SDL_GetTicks();
paused = 0; paused = 0;
} }

View File

@ -56,7 +56,8 @@ static int total_planets = 0; /* Total number of loaded planets - A little
StarSystem* cur_system = NULL; /* Current star system. */ StarSystem* cur_system = NULL; /* Current star system. */
/* Fleet spawn rate. */ /* 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. */ /* Star stack and co. */
#define STAR_BUF 100 /* Area to leave around screen, more = less repitition. */ #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. */ /* Basically used for spawning fleets. */
void space_update(const double dt) { void space_update(const double dt) {
unsigned int t;
int i, j, f; int i, j, f;
(void)dt; /* Don't need it right now. */
if(cur_system == NULL) return; /* Can't update a null system. */ 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) if(cur_system->nfleets == 0)
/* Please stop checking that there are no fleets. */ /* 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. */ /* Time to possibly spawn. */
/* Spawn chance is based on overall percentage. */ /* Spawn chance is based on overall percentage. */
@ -394,7 +394,7 @@ void space_update(const double dt) {
break; break;
} }
} }
spawn_timer = t + 60000./(float)cur_system->nfleets; spawn_timer = 60./(float)cur_system->nfleets;
} }
} }
@ -491,6 +491,7 @@ void space_init(const char* sysname) {
pilots_clean(); /* Destroy all the current pilots, exept player. */ pilots_clean(); /* Destroy all the current pilots, exept player. */
weapon_clear(); /* Get rid of all the weapons. */ weapon_clear(); /* Get rid of all the weapons. */
spfx_clear(); /* Remove of explosions. */ spfx_clear(); /* Remove of explosions. */
space_spawn = 1; /* Spawn is enabled by default. */
if((sysname == NULL) && (cur_system == NULL)) if((sysname == NULL) && (cur_system == NULL))
ERR("Cannot reinit system if there is no system previously loaded"); 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); space_addFleet(cur_system->fleets[i].fleet, 1);
/* Start the spawn timer. */ /* 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. */ /* We now know this system. */
sys_setFlag(cur_system, SYSTEM_KNOWN); sys_setFlag(cur_system, SYSTEM_KNOWN);

View File

@ -131,6 +131,7 @@ typedef struct StarSystem_ {
} StarSystem; } 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. */ /* Load/Exit. */
void space_init(const char* sysname); void space_init(const char* sysname);