-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProfiling.cpp
107 lines (89 loc) · 2.39 KB
/
Profiling.cpp
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/*
* File: Profiling.cpp
* Author: gabriel
*
* Created on May 18, 2011, 1:01 AM
*/
#include <GL/glew.h>
#include "externs.h"
#include "Profiling.h"
#include "ChangeMode.h"
Profiling::Profiling() {
old_count = new_count = glutGet(GLUT_ELAPSED_TIME);
frames = fps = 0;
if (conf.rint("window:fullscreen") == 1) {
start_coord_y = glutGameModeGet(GLUT_GAME_MODE_HEIGHT) - 50;
coords = new Vertex(glutGameModeGet(GLUT_GAME_MODE_WIDTH) - 100, start_coord_y, 0);
}
else {
start_coord_y = glutGet(GLUT_WINDOW_HEIGHT) - 50;
coords = new Vertex(glutGet(GLUT_WINDOW_WIDTH) - 100, start_coord_y, 0);
}
for (int i = 0; i < TIME_SIZE; i++) {
name[i] = NULL;
start[i] = end[i] = 0;
}
printed = false;
}
void Profiling::update() {
new_count = glutGet(GLUT_ELAPSED_TIME);
frames++;
if (new_count - old_count > 1000) {
fps = frames * 1000 / (new_count - old_count);
frames = 0;
old_count = new_count;
}
}
void Profiling::print(char* string) {
ChangeMode::setOrthographicProjection();
glPushMatrix();
glLoadIdentity();
int len, i;
glColor3f(1.0f, 1.0f, 1.0f);
glRasterPos2i(coords->x, coords->y);
len = strlen(string);
for (i = 0; i < len; i++) {
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_10, string[i]);
}
coords->y = coords->y - 15;
glPopMatrix();
ChangeMode::resetPerspectiveProjection();
}
void Profiling::reset_time() {
coords->y = start_coord_y;
//faz reset a todos excepto ao tempo de startup
// coords->y = 0;
// for (int i = 0; i < TIME_SIZE; i++)
// if (i != TIME_STARTUP)
// start[i] = end[i] = 0.0;
}
void Profiling::print_fps() {
char string[15];
sprintf(string, "FPS: %d", fps);
print(string);
}
void Profiling::print_time() {
char buff[50];
for (int i = 0; i < TIME_SIZE && start[i] != 0.0; i++) {
sprintf(buff, "%s: %d", name[i], end[i] - start[i]);
print(buff);
}
}
void Profiling::start_time(TIMES num, char* new_name) {
if (InputManager::getOpState(PROFILING_MODE) == KEY_OFF) {
start[num] = glutGet(GLUT_ELAPSED_TIME);
if (name[num] == NULL) {
name[num] = (char *) calloc(50, sizeof (char));
strcpy(this->name[num], new_name);
}
}
}
void Profiling::end_time(TIMES num) {
if (InputManager::getOpState(PROFILING_MODE) == KEY_OFF) {
end[num] = glutGet(GLUT_ELAPSED_TIME);
}
}
void Profiling::render() {
print_fps();
print_time();
}