textpsys

diff src/effect.cc @ 3:b1c8d2784c72

made the timer internal to the effect, fx_draw doesn't take a time value any more
author John Tsiombikas <nuclear@member.fsf.org>
date Thu, 20 Aug 2015 06:40:23 +0300
parents 4b1360a5d54d
children
line diff
     1.1 --- a/src/effect.cc	Thu Aug 20 04:52:30 2015 +0300
     1.2 +++ b/src/effect.cc	Thu Aug 20 06:40:23 2015 +0300
     1.3 @@ -1,5 +1,7 @@
     1.4  #include <stdio.h>
     1.5  #include <stdlib.h>
     1.6 +#include <unistd.h>
     1.7 +#include <sys/time.h>
     1.8  #include "opengl.h"
     1.9  #include "effect.h"
    1.10  #include "psys.h"
    1.11 @@ -20,6 +22,7 @@
    1.12  static bool exploding;
    1.13  
    1.14  static void explode();
    1.15 +static unsigned long get_msec();
    1.16  
    1.17  bool fx_init()
    1.18  {
    1.19 @@ -105,9 +108,10 @@
    1.20  	delete simg[1];
    1.21  }
    1.22  
    1.23 -void fx_draw(unsigned long msec)
    1.24 +void fx_draw()
    1.25  {
    1.26  	static unsigned long prev_msec, ps_start_time;
    1.27 +	unsigned long msec = get_msec();
    1.28  	float dt = (msec - prev_msec) / 1000.0;
    1.29  	prev_msec = msec;
    1.30  
    1.31 @@ -140,3 +144,17 @@
    1.32  	//psys.explode(Vector3(0, -0.2, 0), 3.0, 1.5);
    1.33  	//psys.pp = ppexpl;
    1.34  }
    1.35 +
    1.36 +static unsigned long get_msec()
    1.37 +{
    1.38 +	static struct timeval tv0;
    1.39 +	struct timeval tv;
    1.40 +
    1.41 +	gettimeofday(&tv, 0);
    1.42 +	if(tv0.tv_sec == 0 && tv0.tv_usec == 0) {
    1.43 +		tv0 = tv;
    1.44 +		return 0;
    1.45 +	}
    1.46 +
    1.47 +	return (tv.tv_sec - tv0.tv_sec) * 1000 + (tv.tv_usec - tv0.tv_usec) / 1000;
    1.48 +}