-
Notifications
You must be signed in to change notification settings - Fork 0
/
runtime.cpp
43 lines (34 loc) · 1.1 KB
/
runtime.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
//
// Created by asuka on 13.03.2023.
//
# include <runtime.hpp>
#include <glad/glad.h>
namespace snake {
void Runtime::run() {
double last_time, curr_time = glfw_.get_time(),
upd_time_count = 0,
fps_time_count = 0;
bool should_redraw = true;
while (!window_.should_close()) {
last_time = curr_time;
curr_time = glfw_.get_time();
auto duration = curr_time - last_time;
upd_time_count += duration;
fps_time_count += duration;
if (should_redraw && fps_time_count >= fps_rate_) {
fps_time_count -= fps_rate_;
glClear(GL_COLOR_BUFFER_BIT);
renderer_.draw();
window_.swap_buffers();
should_redraw = false;
}
while (upd_time_count >= upd_rate_) {
upd_time_count -= upd_rate_;
if (!should_redraw) should_redraw = true;
glfw_.pool_events();
game_.input();
game_.update();
}
}
}
} // snake