[Change] Switched SPFX timers to something more sane.

This commit is contained in:
Allanis 2013-07-06 13:02:34 +01:00
parent 90707480d9
commit 26211ee1f5
3 changed files with 9 additions and 58 deletions

View File

@ -1,6 +1,4 @@
#include "weapon.h"
#include "pilot.h"
#include "spfx.h"
#include "pause.h"
/* Main thing with pausing is to allow things based on time to */
@ -25,7 +23,6 @@ void pause_game(void) {
if(paused) return; /* Well well.. We are paused already. */
pilot_nstack_pause();
spfx_pause();
spawn_timer -= SDL_GetTicks();
paused = 1; /* We should unpause it. */
@ -35,7 +32,6 @@ void unpause_game(void) {
if(!paused) return; /* We are unpaused already. */
pilot_nstack_unpause();
spfx_unpause();
spawn_timer += SDL_GetTicks();
paused = 0;
@ -44,7 +40,6 @@ void unpause_game(void) {
/* Set the timers back. */
void pause_delay(unsigned int delay) {
pilot_nstack_delay(delay);
spfx_delay(delay);
}
/* Pilots pausing/unpausing. */

View File

@ -24,7 +24,7 @@ static int shake_off = 1;
typedef struct SPFX_Base_ {
char* name;
int anim; /* Total duration in ms. */
double anim; /* Total duration in ms. */
glTexture* gfx; /* Will use each sprite as a frame. */
} SPFX_Base;
@ -36,7 +36,7 @@ typedef struct SPFX_ {
int lastframe; /* Need when pausing. */
int effect; /* Actual effect. */
unsigned int t; /* Start. */
double timer; /* Time left. */
} SPFX;
/* Front stack is for effects on player. */
@ -52,9 +52,6 @@ static int spfx_base_load(char* name, int anim, char* gfx, int sx, int sy);
static void spfx_base_free(SPFX_Base* effect);
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) {
@ -65,7 +62,7 @@ static int spfx_base_load(char* name, int anim, char* gfx, int sx, int sy) {
cur = &spfx_effects[spfx_neffects-1];
cur->name = strdup(name);
cur->anim = anim;
cur->anim = (double)anim / 1000.;
sprintf(buf, SPFX_GFX"%s", gfx);
cur->gfx = gl_newSprite(buf, sx, sy);
@ -143,7 +140,7 @@ void spfx_add(int effect,
cur_spfx->effect = effect;
vect_csetmin(&cur_spfx->pos, px, py);
vect_csetmin(&cur_spfx->vel, vx, vy);
cur_spfx->t = SDL_GetTicks();
cur_spfx->timer = (double)spfx_effects[effect].anim;
}
void spfx_clear(void) {
@ -167,11 +164,12 @@ void spfx_update(const double dt) {
static void spfx_update_layer(SPFX* layer, int* nlayer, const double dt) {
int i;
unsigned int t = SDL_GetTicks();
for(i = 0; i < *nlayer; i++) {
layer[i].timer -= dt; /* Less time to live. */
/* Time to die!!! */
if(t > (layer[i].t + spfx_effects[layer[i].effect].anim)) {
if(layer[i].timer < 0.) {
spfx_destroy(layer, nlayer, i);
i--;
continue;
@ -254,7 +252,6 @@ void spfx_render(const int layer) {
int i, spfx_nstack;
SPFX_Base* effect;
int sx, sy;
unsigned int t = SDL_GetTicks();
/* Get the appropriate layer. */
switch(layer) {
@ -275,7 +272,7 @@ void spfx_render(const int layer) {
if(!paused) /* Don't calculate frame if paused. */
spfx_stack[i].lastframe = sx * sy
* MIN(((double)(t - spfx_stack[i].t)/(double)effect->anim), 1.);
* MIN(((double)(spfx_stack[i].timer)/(double)effect->anim), 1.);
gl_blitSprite(effect->gfx,
VX(spfx_stack[i].pos), VY(spfx_stack[i].pos),
@ -285,39 +282,3 @@ void spfx_render(const int layer) {
}
}
void spfx_pause(void) {
spfx_pause_layer(spfx_stack_front, spfx_nstack_front);
spfx_pause_layer(spfx_stack_back, spfx_nstack_back);
}
static void spfx_pause_layer(SPFX* layer, int nlayer) {
int i;
unsigned int t = SDL_GetTicks();
for(i = 0; i < nlayer; i++)
layer[i].t -= t;
}
void spfx_unpause(void) {
spfx_unpause_layer(spfx_stack_front, spfx_nstack_front);
spfx_unpause_layer(spfx_stack_back, spfx_nstack_back);
}
static void spfx_unpause_layer(SPFX* layer, int nlayer) {
int i;
unsigned int t = SDL_GetTicks();
for(i = 0; i < nlayer; i++)
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

@ -31,8 +31,3 @@ void spfx_cinematic(void);
int spfx_load(void);
void spfx_free(void);
/* Pause/Unpause routines. */
void spfx_pause(void);
void spfx_unpause(void);
void spfx_delay(unsigned int delay);