# HG changeset patch # User John Tsiombikas # Date 1440042023 -10800 # Node ID b1c8d2784c729a92e4f9ae9b19436ca042c47738 # Parent 4b1360a5d54dc1e35df18f7332b5b736982da0b4 made the timer internal to the effect, fx_draw doesn't take a time value any more diff -r 4b1360a5d54d -r b1c8d2784c72 src/effect.cc --- a/src/effect.cc Thu Aug 20 04:52:30 2015 +0300 +++ b/src/effect.cc Thu Aug 20 06:40:23 2015 +0300 @@ -1,5 +1,7 @@ #include #include +#include +#include #include "opengl.h" #include "effect.h" #include "psys.h" @@ -20,6 +22,7 @@ static bool exploding; static void explode(); +static unsigned long get_msec(); bool fx_init() { @@ -105,9 +108,10 @@ delete simg[1]; } -void fx_draw(unsigned long msec) +void fx_draw() { static unsigned long prev_msec, ps_start_time; + unsigned long msec = get_msec(); float dt = (msec - prev_msec) / 1000.0; prev_msec = msec; @@ -140,3 +144,17 @@ //psys.explode(Vector3(0, -0.2, 0), 3.0, 1.5); //psys.pp = ppexpl; } + +static unsigned long get_msec() +{ + static struct timeval tv0; + struct timeval tv; + + gettimeofday(&tv, 0); + if(tv0.tv_sec == 0 && tv0.tv_usec == 0) { + tv0 = tv; + return 0; + } + + return (tv.tv_sec - tv0.tv_sec) * 1000 + (tv.tv_usec - tv0.tv_usec) / 1000; +} diff -r 4b1360a5d54d -r b1c8d2784c72 src/effect.h --- a/src/effect.h Thu Aug 20 04:52:30 2015 +0300 +++ b/src/effect.h Thu Aug 20 06:40:23 2015 +0300 @@ -1,10 +1,9 @@ -#ifndef TBOMB_H_ -#define TBOMB_H_ +#ifndef EFFECT_H_ +#define EFFECT_H_ bool fx_init(); void fx_cleanup(); -void fx_draw(unsigned long msec); -void fx_dbg(); +void fx_draw(); -#endif // TBOMB_H_ +#endif // EFFECT_H_ diff -r 4b1360a5d54d -r b1c8d2784c72 src/main.cc --- a/src/main.cc Thu Aug 20 04:52:30 2015 +0300 +++ b/src/main.cc Thu Aug 20 06:40:23 2015 +0300 @@ -17,8 +17,6 @@ static int win_width = 1280, win_height = 800; static bool fullscreen; -static unsigned long start_time; - int main(int argc, char **argv) { glutInit(&argc, argv); @@ -43,18 +41,15 @@ } atexit(fx_cleanup); - start_time = glutGet(GLUT_ELAPSED_TIME); glutMainLoop(); return 0; } void display() { - unsigned long msec = glutGet(GLUT_ELAPSED_TIME) - start_time; - glClear(GL_COLOR_BUFFER_BIT); - fx_draw(msec); + fx_draw(); glutSwapBuffers(); assert(glGetError() == GL_NO_ERROR);