[Add] Hopefully this will prevent dt intervels being too big.

This commit is contained in:
Allanis 2013-02-27 04:43:16 +00:00
parent 78d0346515
commit e87f160e23
7 changed files with 48 additions and 0 deletions

View File

@ -244,6 +244,11 @@ static void fps_control(void) {
// Update the game. // Update the game.
static void update_space(void) { static void update_space(void) {
if(dt > 1./30.) {
// Slow timers down and re-run calculations.
pause_delay((unsigned int)dt*1000.);
return;
}
weapons_update(dt); weapons_update(dt);
spfx_update(dt); spfx_update(dt);
pilots_update(dt); pilots_update(dt);

View File

@ -16,6 +16,7 @@ extern unsigned int gtime;
static void pilots_pause(void); static void pilots_pause(void);
static void pilots_unpause(void); static void pilots_unpause(void);
static void pilots_delay(unsigned int delay);
// Pause the game. // Pause the game.
void pause(void) { void pause(void) {
@ -38,6 +39,13 @@ void unpause(void) {
paused = 0; paused = 0;
} }
// Set the timers back.
void pause_delay(unsigned int delay) {
pilots_delay(delay);
weapons_delay(delay);
spfx_delay(delay);
}
static void pilots_pause(void) { static void pilots_pause(void) {
int i, j; int i, j;
unsigned int t = SDL_GetTicks(); unsigned int t = SDL_GetTicks();
@ -62,3 +70,14 @@ static void pilots_unpause(void) {
} }
} }
static void pilots_delay(unsigned int delay) {
int i, j;
for(i = 0; i < pilots; i++) {
pilot_stack[i]->ptimer += delay;
pilot_stack[i]->tcontrol += delay;
for(j = 0; j < MAX_AI_TIMERS; j++)
pilot_stack[i]->timer[j] += delay;
}
}

View File

@ -5,3 +5,5 @@ extern int paused;
void pause(void); void pause(void);
void unpause(void); void unpause(void);
void pause_delay(unsigned int delay);

View File

@ -44,6 +44,7 @@ static void spfx_destroy(SPFX* layer, int* nlayer, int spfx);
static void spfx_update_layer(SPFX* layer, int* nlayer, const double dt); static void spfx_update_layer(SPFX* layer, int* nlayer, const double dt);
static void spfx_pause_layer(SPFX* layer, int nlayer); static void spfx_pause_layer(SPFX* layer, int nlayer);
static void spfx_unpause_layer(SPFX* layer, int nlayer); static void spfx_unpause_layer(SPFX* layer, int nlayer);
static void spfx_delay_layer(SPFX* layer, int nlayer, unsigned int delay);
// Load the SPFX_Base. // Load the SPFX_Base.
static int spfx_base_load(char* name, int anim, char* gfx, int sx, int sy) { static int spfx_base_load(char* name, int anim, char* gfx, int sx, int sy) {
@ -228,3 +229,14 @@ static void spfx_unpause_layer(SPFX* layer, int nlayer) {
layer[i].t += t; layer[i].t += t;
} }
void spfx_delay(unsigned int delay) {
spfx_delay_layer(spfx_stack_front, spfx_nstack_front, delay);
spfx_delay_layer(spfx_stack_back, spfx_nstack_back, delay);
}
static void spfx_delay_layer(SPFX* layer, int nlayer, unsigned int delay) {
int i;
for(i = 0; i < nlayer; i++)
layer[i].t += delay;
}

View File

@ -21,4 +21,5 @@ void spfx_free(void);
// Pause/Unpause routines. // Pause/Unpause routines.
void spfx_pause(void); void spfx_pause(void);
void spfx_unpause(void); void spfx_unpause(void);
void spfx_delay(unsigned int delay);

View File

@ -105,6 +105,14 @@ void weapons_unpause(void) {
wfrontLayer[i]->timer += t; wfrontLayer[i]->timer += t;
} }
void weapons_delay(unsigned int delay) {
int i;
for(i = 0; i < nwbackLayer; i++)
wbackLayer[i]->timer += delay;
for(i = 0; i < nwfrontLayer; i++)
wfrontLayer[i]->timer += delay;
}
static void think_seeker(Weapon* w) { static void think_seeker(Weapon* w) {
double diff; double diff;
if(w->target == w->parent) return; // HEY! Self harm is not allowed. if(w->target == w->parent) return; // HEY! Self harm is not allowed.

View File

@ -10,6 +10,7 @@ void weapon_add(const Outfit* outfit, const double dir, const Vec2* pos,
// Pausing. // Pausing.
void weapons_pause(void); void weapons_pause(void);
void weapons_unpause(void); void weapons_unpause(void);
void weapons_delay(unsigned int delay);
// Update. // Update.
void weapons_update(const double dt); void weapons_update(const double dt);