aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorladevieq <ladevie.quentin@gmail.com>2021-01-25 20:50:25 +0100
committerladevieq <ladevie.quentin@gmail.com>2021-01-25 20:50:25 +0100
commitfbe4f159bc4d9f801128fbb487e9e86d3786062c (patch)
tree7ff73ac21a4c4971cd2147421306344dc626faf9
parentc730c0214abfe851555df5793d4aca82782be1d0 (diff)
Setup delta time
-rw-r--r--src/main.cpp14
1 files changed, 11 insertions, 3 deletions
diff --git a/src/main.cpp b/src/main.cpp
index 17d7fb2..774429d 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -43,17 +43,25 @@ int main() {
// Image dimensions
const float aspect_ratio = 16.0 / 9.0;
- // const float aspect_ratio = 1;
const uint32_t width = 400;
const uint32_t height = width / aspect_ratio;
window wnd { width , height };
+ float delta_time = 0.f;
+ auto start = std::chrono::high_resolution_clock::now();
+ auto end = std::chrono::high_resolution_clock::now();
auto inputs = create_inputs(width, height);
auto canRender = true;
vkrenderer renderer { wnd, inputs };
while(wnd.isOpen) {
+ end = std::chrono::high_resolution_clock::now();
+
+ delta_time = std::chrono::duration<float, std::milli>(end - start).count();
+
+ start = std::chrono::high_resolution_clock::now();
+
wnd.poll_events();
for (auto event: wnd.events) {
@@ -72,9 +80,9 @@ int main() {
break;
}
case EVENT_TYPES::KEY_PRESS: {
- auto move_speed = 0.1f;
+ auto move_speed = 0.01f * delta_time;
if (wnd.keyboard[KEYS::SHIFT]) {
- move_speed *= 10.f;
+ move_speed *= 2.f;
}
vec3 move_vec {};