textpsys
changeset 3:b1c8d2784c72 tip
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 | |
files | src/effect.cc src/effect.h src/main.cc |
diffstat | 3 files changed, 24 insertions(+), 12 deletions(-) [+] |
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 +}
2.1 --- a/src/effect.h Thu Aug 20 04:52:30 2015 +0300 2.2 +++ b/src/effect.h Thu Aug 20 06:40:23 2015 +0300 2.3 @@ -1,10 +1,9 @@ 2.4 -#ifndef TBOMB_H_ 2.5 -#define TBOMB_H_ 2.6 +#ifndef EFFECT_H_ 2.7 +#define EFFECT_H_ 2.8 2.9 bool fx_init(); 2.10 void fx_cleanup(); 2.11 2.12 -void fx_draw(unsigned long msec); 2.13 -void fx_dbg(); 2.14 +void fx_draw(); 2.15 2.16 -#endif // TBOMB_H_ 2.17 +#endif // EFFECT_H_
3.1 --- a/src/main.cc Thu Aug 20 04:52:30 2015 +0300 3.2 +++ b/src/main.cc Thu Aug 20 06:40:23 2015 +0300 3.3 @@ -17,8 +17,6 @@ 3.4 static int win_width = 1280, win_height = 800; 3.5 static bool fullscreen; 3.6 3.7 -static unsigned long start_time; 3.8 - 3.9 int main(int argc, char **argv) 3.10 { 3.11 glutInit(&argc, argv); 3.12 @@ -43,18 +41,15 @@ 3.13 } 3.14 atexit(fx_cleanup); 3.15 3.16 - start_time = glutGet(GLUT_ELAPSED_TIME); 3.17 glutMainLoop(); 3.18 return 0; 3.19 } 3.20 3.21 void display() 3.22 { 3.23 - unsigned long msec = glutGet(GLUT_ELAPSED_TIME) - start_time; 3.24 - 3.25 glClear(GL_COLOR_BUFFER_BIT); 3.26 3.27 - fx_draw(msec); 3.28 + fx_draw(); 3.29 3.30 glutSwapBuffers(); 3.31 assert(glGetError() == GL_NO_ERROR);