From 573ab3fd924f1a6c9dee3a2462e6decee21b7fac Mon Sep 17 00:00:00 2001 From: "arthur.jamet" Date: Tue, 1 Jun 2021 13:40:43 +0200 Subject: [PATCH] add fps limit on window at construction --- lib/Ray/sources/Window.cpp | 5 +++++ lib/Ray/sources/Window.hpp | 3 +++ sources/System/Renderer/RenderScreenSystem.cpp | 5 ++++- sources/System/Renderer/RenderScreenSystem.hpp | 3 +++ 4 files changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/Ray/sources/Window.cpp b/lib/Ray/sources/Window.cpp index 11b14486..c705b47a 100644 --- a/lib/Ray/sources/Window.cpp +++ b/lib/Ray/sources/Window.cpp @@ -167,3 +167,8 @@ void RAY::Window::setIcon(RAY::Image &img) { SetWindowIcon(img); } + +void RAY::Window::drawFPS(const RAY::Vector2 &position) +{ + DrawFPS(position.x, position.y); +} \ No newline at end of file diff --git a/lib/Ray/sources/Window.hpp b/lib/Ray/sources/Window.hpp index b04f60d8..180b3d12 100644 --- a/lib/Ray/sources/Window.hpp +++ b/lib/Ray/sources/Window.hpp @@ -131,6 +131,9 @@ namespace RAY { //! @brief Draw a 3d mesh with material and transform void draw(const Mesh &mesh, const Material &material, const Matrix &transform); + //! @brief Draws current FPS on the frame + void drawFPS(const Vector2 &position); + private: //! @brief Creates window, and opens it if openNow is set to true diff --git a/sources/System/Renderer/RenderScreenSystem.cpp b/sources/System/Renderer/RenderScreenSystem.cpp index 8eba847a..f0a869d2 100644 --- a/sources/System/Renderer/RenderScreenSystem.cpp +++ b/sources/System/Renderer/RenderScreenSystem.cpp @@ -15,10 +15,13 @@ namespace BBM }), _window(window), _camera(Vector3f(), Vector3f(), Vector3f(0, 1, 0), 50, CAMERA_PERSPECTIVE) - {} + { + this->_window.setFPS(RenderScreenSystem::FPS); + } void RenderScreenSystem::onSelfUpdate() { + this->_window.drawFPS(RAY::Vector2(1, 1)); this->_window.draw(); this->_window.clear(); this->_window.useCamera(this->_camera); diff --git a/sources/System/Renderer/RenderScreenSystem.hpp b/sources/System/Renderer/RenderScreenSystem.hpp index e9b2ea85..7bb86039 100644 --- a/sources/System/Renderer/RenderScreenSystem.hpp +++ b/sources/System/Renderer/RenderScreenSystem.hpp @@ -17,6 +17,9 @@ namespace BBM //! @brief The camera used to render. RAY::Camera::Camera3D _camera; + + //! @brief Window framerate limit + static constexpr short FPS = 30; public: //! @brief A method called after all entities that this system manage has been updated. //! @note render on screen here