From e87f160e2317db1610087d869cb659e046411768 Mon Sep 17 00:00:00 2001
From: Allanis <allanis@saracraft.net>
Date: Wed, 27 Feb 2013 04:43:16 +0000
Subject: [PATCH] [Add] Hopefully this will prevent dt intervels being too big.

---
 src/lephisto.c |  5 +++++
 src/pause.c    | 19 +++++++++++++++++++
 src/pause.h    |  2 ++
 src/spfx.c     | 12 ++++++++++++
 src/spfx.h     |  1 +
 src/weapon.c   |  8 ++++++++
 src/weapon.h   |  1 +
 7 files changed, 48 insertions(+)

diff --git a/src/lephisto.c b/src/lephisto.c
index 8493d32..f2a96b9 100644
--- a/src/lephisto.c
+++ b/src/lephisto.c
@@ -244,6 +244,11 @@ static void fps_control(void) {
 
 // Update the game.
 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);
 	spfx_update(dt);
   pilots_update(dt);
diff --git a/src/pause.c b/src/pause.c
index 221ddec..719c0df 100644
--- a/src/pause.c
+++ b/src/pause.c
@@ -16,6 +16,7 @@ extern unsigned int gtime;
 
 static void pilots_pause(void);
 static void pilots_unpause(void);
+static void pilots_delay(unsigned int delay);
 
 // Pause the game.
 void pause(void) {
@@ -38,6 +39,13 @@ void unpause(void) {
   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) {
   int i, j;
   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;
+	}
+}
+
diff --git a/src/pause.h b/src/pause.h
index 92c29f9..10b9a7f 100644
--- a/src/pause.h
+++ b/src/pause.h
@@ -5,3 +5,5 @@ extern int paused;
 void pause(void);
 void unpause(void);
 
+void pause_delay(unsigned int delay);
+
diff --git a/src/spfx.c b/src/spfx.c
index e96d267..1d3428f 100644
--- a/src/spfx.c
+++ b/src/spfx.c
@@ -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_pause_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.
 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;
 }
 
+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;
+}
+
diff --git a/src/spfx.h b/src/spfx.h
index 920a556..03d399c 100644
--- a/src/spfx.h
+++ b/src/spfx.h
@@ -21,4 +21,5 @@ void spfx_free(void);
 // Pause/Unpause routines.
 void spfx_pause(void);
 void spfx_unpause(void);
+void spfx_delay(unsigned int delay);
 
diff --git a/src/weapon.c b/src/weapon.c
index d50d7be..662f203 100644
--- a/src/weapon.c
+++ b/src/weapon.c
@@ -105,6 +105,14 @@ void weapons_unpause(void) {
     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) {
 	double diff;
   if(w->target == w->parent) return; // HEY! Self harm is not allowed.
diff --git a/src/weapon.h b/src/weapon.h
index 9ee5b82..6865920 100644
--- a/src/weapon.h
+++ b/src/weapon.h
@@ -10,6 +10,7 @@ void weapon_add(const Outfit* outfit, const double dir, const Vec2* pos,
 // Pausing.
 void weapons_pause(void);
 void weapons_unpause(void);
+void weapons_delay(unsigned int delay);
 
 // Update.
 void weapons_update(const double dt);