mElite  1.0
An Elite clone based on TextElite by Jan-Philipp Kappmeier and Melanie Schmidt.
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
FrameCounter.cpp
Go to the documentation of this file.
1 
6 #include "GlobalGL.h"
7 #include "FrameCounter.h"
8 
10 
14  frames = 0;
15  //start = glutGet( GLUT_ELAPSED_TIME );
16  fps = 0;
17  m_frameStart = start = getTime();
18  m_lastFrameTime = 0;
19 }
20 
25 
26 }
27 
29 
33  return fps;
34 }
35 
37  return m_frameStart;
38 }
39 
41 
45  return 1000.0/getFrameRateAverage();
46 }
47 
52  long now = getTime();
53  long passed = getFrameStart();
54  return now - passed;
55 }
56 
61  return m_lastFrameTime;
62 }
63 
64 long FrameCounter::getTime( void ) {
65  return glutGet( GLUT_ELAPSED_TIME );
66 }
67 
69 
72 void FrameCounter::newFrame( void ) {
73  long now = getTime();
74  m_lastFrameTime = now - m_frameStart;
75  m_frameStart = now;
76  frames++;
77 }
78 
80 
84 void FrameCounter::update( void ) {
85  long now = getTime();
86  long dTime = now - start;
87 
88  if( dTime > 1000 ) {
89  start = now;
90  fps = (long)(1e3 * (double)frames/(double) dTime);
91  frames = 0;
92  }
93 }