Skip to content

Commit a323add

Browse files
author
Floyd Huizinga
committed
belongs to previous commit, add deltatime to application
1 parent 0e8d34a commit a323add

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/Cpp/Framework/Application.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <GLFW/glfw3.h>
44

55
#include <iostream>
6+
#include <ratio>
67

78
Application::Application(const std::string& title)
89
: _title(title)
@@ -49,6 +50,8 @@ bool Application::Initialize()
4950

5051
glfwSetWindowUserPointer(_window, this);
5152
glfwSetFramebufferSizeCallback(_window, HandleResize);
53+
54+
_currentTime = std::chrono::high_resolution_clock::now();
5255
return true;
5356
}
5457

@@ -111,5 +114,10 @@ int32_t Application::GetWindowHeight() const
111114

112115
void Application::Update()
113116
{
117+
auto oldTime = _currentTime;
118+
_currentTime = std::chrono::high_resolution_clock::now();
119+
120+
std::chrono::duration<double, std::milli> timeSpan = (_currentTime - oldTime);
121+
_deltaTime = static_cast<float>(timeSpan.count() / 1000.0);
114122
glfwPollEvents();
115123
}

src/Cpp/Framework/Application.hpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include <cstdint>
44
#include <string>
5+
#include <chrono>
56

67
// ReSharper disable once CppInconsistentNaming
78
struct GLFWwindow;
@@ -33,9 +34,11 @@ class Application
3334
[[nodiscard]] int32_t GetWindowWidth() const;
3435
[[nodiscard]] int32_t GetWindowHeight() const;
3536

36-
private:
37-
GLFWwindow* _window = nullptr;
3837
int32_t _width = 0;
3938
int32_t _height = 0;
39+
float _deltaTime = 0.016f;
40+
private:
41+
std::chrono::high_resolution_clock::time_point _currentTime;
42+
GLFWwindow* _window = nullptr;
4043
std::string _title;
4144
};

0 commit comments

Comments
 (0)