Leviathan  0.8.0.0
Leviathan game engine
Leviathan::RenderingStatistics Class Reference

Mainly a FPS limiter. More...

#include <RenderingStatistics.h>

Public Member Functions

DLLEXPORT RenderingStatistics ()
 
DLLEXPORT ~RenderingStatistics ()
 
DLLEXPORT void RenderingStart ()
 
DLLEXPORT void RenderingEnd ()
 
DLLEXPORT bool CanRenderNow (int maxfps, int &TimeSinceLastFrame)
 
DLLEXPORT void ReportStats (DataStore *dstore)
 

Detailed Description

Mainly a FPS limiter.

Definition at line 11 of file RenderingStatistics.h.

Constructor & Destructor Documentation

◆ RenderingStatistics()

Leviathan::RenderingStatistics::RenderingStatistics ( )

Definition at line 8 of file RenderingStatistics.cpp.

8  : LastMinuteFPS(80), LastMinuteRenderTimes(320){
9 
10  Frames = 0;
11 
12  FPS = 0;
13  RenderMCRSeconds = 0;
14 
15  MinFPS = 9999;
16  MaxFPS = 0;
17  AverageFps = 0;
18 
19  MaxFrameTime = 0;
20  MinFrameTime = 9999;
21  AverageRenderTime = 0;
22 
23  HalfMinuteStartTime = 0;
24  SecondStartTime = 0;
25  RenderingStartTime = 0;
26  RenderingEndTime = 0;
27 
28  DoubtfulCancel = 0;
29 
30  LastMinuteFPSPos = 0;
31  LastMinuteRenderTimesPos = 0;
32 
33 
34 
35  IsFirstFrame = true;
36  EraseOld = true;
37 }

◆ ~RenderingStatistics()

Leviathan::RenderingStatistics::~RenderingStatistics ( )

Definition at line 39 of file RenderingStatistics.cpp.

39  {
40 
41 }

Member Function Documentation

◆ CanRenderNow()

bool Leviathan::RenderingStatistics::CanRenderNow ( int  maxfps,
int &  TimeSinceLastFrame 
)

Definition at line 152 of file RenderingStatistics.cpp.

152  {
153 
154 
155  // calculate can a frame be rendered now without going over max fps //
156  auto CurrentTime = Time::GetTimeMicro64();
157 
158  // check first frame //
159  if(IsFirstFrame){
160  // set values to current time //
161  HalfMinuteStartTime = CurrentTime;
162  SecondStartTime = CurrentTime;
163  RenderingStartTime = CurrentTime;
164  RenderingEndTime = CurrentTime;
165  // on first frame always can render //
166  return true;
167  }
168 
169  int TimePassed = (int)(CurrentTime-RenderingStartTime);
170  int TimeFromLastSecond = (int)(CurrentTime-SecondStartTime);
171 
172  if(TimeFromLastSecond < -1){
173  // second passed //
174  SecondStartTime = CurrentTime;
175  //DEBUG_OUTPUT(L"second pass\n");
176  TimeFromLastSecond = 0;
177 
178  SecondMark();
179  return true;
180  }
181 
182 
183  // Check has a second passed //
184  bool Set = false;
185  while(TimeFromLastSecond > 1000000){
186  TimeFromLastSecond -= 1000000;
187  Set = true;
188 
189  }
190 
191  if(Set){
192 
193  // second passed //
194  SecondStartTime = CurrentTime;
195  SecondMark();
196  }
197 
198  // send back time before last frame in microseconds //
199  TimeSinceLastFrame = TimePassed;
200 
201 
202  // calculate how many frames should have been rendered //
203  // divide current passed by 1 second and multiply frame rate to see how many should be at this time //
204  float Percentage = (TimeFromLastSecond/1000000.f);
205  int FramesShouldBe = (int)((Percentage*maxfps)+0.5f);
206 
207  // check do we have enough frames, if we don't we can render 1 //
208  // or if a second has passed render then //
209  if(Frames <= FramesShouldBe){
210 
211 
212  return true;
213  }
214 
215 
216  return false;
217 }
static DLLEXPORT int64_t GetTimeMicro64()

◆ RenderingEnd()

void Leviathan::RenderingStatistics::RenderingEnd ( )

Definition at line 49 of file RenderingStatistics.cpp.

49  {
50  RenderingEndTime = Time::GetTimeMicro64();
51 
52  RenderMCRSeconds = (int)(RenderingEndTime-RenderingStartTime);
53 
54 
55  MakeSureHasEnoughRoom(LastMinuteRenderTimes, LastMinuteRenderTimesPos);
56 
57  LastMinuteRenderTimes[LastMinuteRenderTimesPos] = RenderMCRSeconds;
58  ++LastMinuteRenderTimesPos;
59 
60  // half minute check //
61  if(RenderingEndTime > HalfMinuteStartTime+(1000000*30)){
62 
63  HalfMinuteStartTime = RenderingEndTime;
64  HalfMinuteMark();
65  }
66 
67  if(IsFirstFrame)
68  IsFirstFrame = false;
69 
70 }
static DLLEXPORT int64_t GetTimeMicro64()

◆ RenderingStart()

void Leviathan::RenderingStatistics::RenderingStart ( )

Definition at line 43 of file RenderingStatistics.cpp.

43  {
44  RenderingStartTime = Time::GetTimeMicro64();
45 
46  Frames++;
47 }
static DLLEXPORT int64_t GetTimeMicro64()

◆ ReportStats()

void Leviathan::RenderingStatistics::ReportStats ( DataStore dstore)

Definition at line 72 of file RenderingStatistics.cpp.

72  {
73  dstore->SetFPS(FPS);
74  dstore->SetFPSAverage(AverageFps);
75  dstore->SetFPSMax(MaxFPS);
76  dstore->SetFPSMin(MinFPS);
77 
78  dstore->SetFrameTime(RenderMCRSeconds);
79  dstore->SetFrameTimeAverage(AverageRenderTime);
80  dstore->SetFrameTimeMax(MaxFrameTime);
81  dstore->SetFrameTimeMin(MinFrameTime);
82 }
DLLEXPORT void SetFPS(int newval)
Definition: DataStore.cpp:354
DLLEXPORT void SetFPSAverage(int newval)
Definition: DataStore.cpp:501
DLLEXPORT void SetFPSMax(int newval)
Definition: DataStore.cpp:496
DLLEXPORT void SetFrameTimeAverage(int newval)
Definition: DataStore.cpp:486
DLLEXPORT void SetFPSMin(int newval)
Definition: DataStore.cpp:491
DLLEXPORT void SetFrameTimeMax(int newval)
Definition: DataStore.cpp:481
DLLEXPORT void SetFrameTimeMin(int newval)
Definition: DataStore.cpp:476
DLLEXPORT void SetFrameTime(int newval)
Definition: DataStore.cpp:359

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