From 2015705f1104e82f70d02ddc0c2c118d7e440b66 Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Fri, 14 May 2021 17:46:14 +0200 Subject: [PATCH] Starting the game loop --- lib/wal/sources/Scene/SceneManager.cpp | 2 ++ lib/wal/sources/Wal.cpp | 8 ++++++++ lib/wal/sources/Wal.hpp | 2 ++ 3 files changed, 12 insertions(+) diff --git a/lib/wal/sources/Scene/SceneManager.cpp b/lib/wal/sources/Scene/SceneManager.cpp index 5ffbcc26..21c38221 100644 --- a/lib/wal/sources/Scene/SceneManager.cpp +++ b/lib/wal/sources/Scene/SceneManager.cpp @@ -20,6 +20,8 @@ namespace WAL Scene &SceneManager::getCurrent() { + if (this->_scenes.empty()) + throw NotFoundError("No scene exists."); return this->_scenes.front(); } diff --git a/lib/wal/sources/Wal.cpp b/lib/wal/sources/Wal.cpp index 2e8e18a8..b5f62458 100644 --- a/lib/wal/sources/Wal.cpp +++ b/lib/wal/sources/Wal.cpp @@ -2,6 +2,7 @@ // Created by Zoe Roux on 2021-05-14. // +#include #include "Wal.hpp" namespace WAL @@ -14,6 +15,13 @@ namespace WAL void WAL::run() { + auto lastTick = std::chrono::steady_clock::now(); + while (!this->_shouldClose) { + auto now = std::chrono::steady_clock::now(); + auto dtime = now - lastTick; + lastTick = now; + // see https://gist.github.com/mariobadr/673bbd5545242fcf9482 + } } } \ No newline at end of file diff --git a/lib/wal/sources/Wal.hpp b/lib/wal/sources/Wal.hpp index 4a8bec8a..19456fd6 100644 --- a/lib/wal/sources/Wal.hpp +++ b/lib/wal/sources/Wal.hpp @@ -29,6 +29,8 @@ namespace WAL std::vector> _systems = {}; //! @brief The renderer used to draw entities std::unique_ptr _renderer; + //! @brief True if the engine should close after the end of the current tick. + bool _shouldClose = false; public: //! @brief Create a new system in place. //! @return The wal instance used to call this function is returned. This allow method chaining.