-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.cpp
More file actions
52 lines (39 loc) · 849 Bytes
/
Copy pathApp.cpp
File metadata and controls
52 lines (39 loc) · 849 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include "App.h"
#include "Classes/ogldev_util.h"
#include <sys/time.h>
App::App()
{
frameCount = 0;
frameTime = 0;
fps = 0;
frameTime = startTime = GetCurrentTimeInMillis();
}
void App::CalcFPS()
{
frameCount++;
long long time = GetCurrentTimeInMillis();
if ( (time - frameTime) >= 1000)
{
frameTime = time;
fps = frameCount;
frameCount = 0;
}
}
void App::RenderFPS()
{
char text[32];
ZERO_MEM(text);
SNPRINTF(text, sizeof(text), "FPS: %d", fps);
}
float App::GetRunningTime()
{
float RunningTime = (float)( (double)GetCurrentTimeInMillis() - (double)startTime ) / 1000.0f;
return RunningTime;
}
long long App::GetCurrentTimeInMillis()
{
timeval t;
gettimeofday(&t, NULL);
long long ret = t.tv_sec * 1000 + t.tv_usec / 1000;
return ret;
}