Leviathan  0.8.0.0
Leviathan game engine
Leviathan::FpsCounter Class Reference

#include <FpsCounter.h>

Public Member Functions

 FpsCounter ()
 
void FakeFrame (int mspassed)
 
void Frame (int timepassed)
 
int GetFps ()
 
bool ShouldRender (int passed, int maxfps)
 

Detailed Description

Definition at line 6 of file FpsCounter.h.

Constructor & Destructor Documentation

◆ FpsCounter()

FpsCounter::FpsCounter ( )

Definition at line 5 of file FpsCounter.cpp.

5  :
6  passedtime(0), MaxFps(0), MinFps(0), Fps(0), Framecount(0), SinceLast(0)
7 {
8 
9 }

Member Function Documentation

◆ FakeFrame()

void FpsCounter::FakeFrame ( int  mspassed)

Definition at line 80 of file FpsCounter.cpp.

80  {
81 
82  if(SinceLast < 0)
83  SinceLast = 0;
84 
85  SinceLast += mspassed;
86 
87 
88  if(passedtime < 0)
89  passedtime = 0;
90 
91  passedtime += mspassed;
92 
93  if(passedtime > 6000){
94 
95  passedtime = passedtime-((passedtime/1000)*1000);
96 
97  Fps = Framecount;
98 
99  if(Fps > MaxFps)
100  MaxFps = Fps;
101 
102  if(Fps < MinFps)
103  MinFps = Fps;
104 
105  Framecount = 0;
106  return;
107  }
108 
109  if(passedtime > 1000){
110 
111  passedtime -= 1000;
112 
113  Fps = Framecount;
114 
115  if(Fps > MaxFps)
116  MaxFps = Fps;
117 
118  if(Fps < MinFps)
119  MinFps = Fps;
120 
121  Framecount = 0;
122  }
123 }

◆ Frame()

void FpsCounter::Frame ( int  timepassed)

Definition at line 11 of file FpsCounter.cpp.

11  {
12 
13  Framecount++;
14  SinceLast = 0;
15 
16  if(passedtime < 0)
17  passedtime = 0;
18 
19  passedtime += timepassed;
20 
21  if(passedtime > 6000){
22  passedtime = passedtime-((passedtime/1000)*1000);
23 
24  Fps = Framecount;
25  if(Fps > MaxFps)
26  MaxFps = Fps;
27  if(Fps < MinFps)
28  MinFps = Fps;
29 
30 
31  Framecount = 0;
32  return;
33  }
34 
35  if(passedtime > 1000){
36  passedtime -= 1000;
37 
38  Fps = Framecount;
39  if(Fps > MaxFps)
40  MaxFps = Fps;
41  if(Fps < MinFps)
42  MinFps = Fps;
43 
44 
45  Framecount = 0;
46  }
47 }

◆ GetFps()

int FpsCounter::GetFps ( )

Definition at line 49 of file FpsCounter.cpp.

49  {
50  return Fps;
51 }

◆ ShouldRender()

bool FpsCounter::ShouldRender ( int  passed,
int  maxfps 
)

Definition at line 53 of file FpsCounter.cpp.

53  {
54  // calculate how many frames should be rendered
55  int timeperframe = (int)((1000.f/maxfps)+0.5f);
56 
57  // how many frames should have been rendered
58  int nowrend = (int)((passedtime/1000.f)*maxfps+0.5f);
59 
60 
61  if(nowrend > Framecount){
62  // falling behind //
63 
64  SinceLast += nowrend-(Framecount);
65 
66  } else if(nowrend < Framecount){
67  // getting ahead //
68 
69  SinceLast += nowrend-(Framecount+1);
70 
71  }
72 
73 
74  if(SinceLast >= timeperframe)
75  return true;
76 
77  return false;
78 }

The documentation for this class was generated from the following files: