File tree Expand file tree Collapse file tree 2 files changed +13
-2
lines changed
Expand file tree Collapse file tree 2 files changed +13
-2
lines changed Original file line number Diff line number Diff line change 33#include < GLFW/glfw3.h>
44
55#include < iostream>
6+ #include < ratio>
67
78Application::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
112115void 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}
Original file line number Diff line number Diff line change 22
33#include < cstdint>
44#include < string>
5+ #include < chrono>
56
67// ReSharper disable once CppInconsistentNaming
78struct 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};
You can’t perform that action at this time.
0 commit comments