-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
78 lines (69 loc) · 1.88 KB
/
main.cpp
File metadata and controls
78 lines (69 loc) · 1.88 KB
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
#include<iostream>
#include"program.h"
app _app = app();
double delta_time = 0;
uint16_t width = 1200, height = 800;
const float frame_delay = 1000.0 / 246;
uint32_t frame_start;
uint32_t frame_end;
float frame_time_ms;
float m_second_counter;
float m_temp_fps;
float fps;
void start_delta_calc() {
auto prev_now = std::chrono::system_clock::now();
auto prev_duration = prev_now.time_since_epoch();
auto prev_milliseconds
= std::chrono::duration_cast<std::chrono::milliseconds>(
prev_duration)
.count();
frame_start = prev_milliseconds;
}
void end_delta_calc(bool print_debug) {
auto crnt_now = std::chrono::system_clock::now();
auto crnt_duration = crnt_now.time_since_epoch();
auto crnt_milliseconds
= std::chrono::duration_cast<std::chrono::milliseconds>(
crnt_duration)
.count();
frame_end = crnt_milliseconds;
frame_time_ms = frame_end - frame_start;
delta_time = frame_time_ms / 1000.0f;
if (print_debug) std::cout << "DELTA::" << delta_time << "\n";
}
void start_fps_calc(bool print_debug, float delta) {
if (m_second_counter <= 1) {
m_second_counter += delta;
m_temp_fps++;
}
else {
fps = m_temp_fps;
m_second_counter = 0;
m_temp_fps = 0;
}
if (print_debug) std::cout << "FPS::" << fps << "\n";
}
int main() {
_app.delta_time = delta_time;
_app.window_width = width;
_app.window_height = height;
opengl::window::start_window(width, height, "WINDOW", false, glm::vec3(0.0f));
start(&_app);
while (!opengl::window::window_closed()) {
_app.delta_time = delta_time;
_app.window_width = width;
_app.window_height = height;
update(&_app);
start_delta_calc();
opengl::window::bind_window();
render(&_app);
opengl::window::unbind_window();
end_delta_calc(false);
start_fps_calc(false, (float)delta_time);
}
_app.delta_time = delta_time;
_app.window_width = width;
_app.window_height = height;
del(&_app);
opengl::window::end_window();
}