diff --git a/lib/wal/CMakeLists.txt b/lib/wal/CMakeLists.txt index 2e6dff87..81d730f2 100644 --- a/lib/wal/CMakeLists.txt +++ b/lib/wal/CMakeLists.txt @@ -13,8 +13,6 @@ add_library(wal sources/Scene/SceneManager.hpp sources/Scene/Scene.cpp sources/Scene/Scene.hpp - sources/Renderer/Renderer.cpp - sources/Renderer/Renderer.hpp sources/Events/EventManager.cpp sources/Events/EventManager.hpp sources/Exception/WalError.cpp diff --git a/lib/wal/sources/Renderer/Renderer.cpp b/lib/wal/sources/Renderer/Renderer.cpp deleted file mode 100644 index a77f2515..00000000 --- a/lib/wal/sources/Renderer/Renderer.cpp +++ /dev/null @@ -1,13 +0,0 @@ -// -// Created by Zoe Roux on 2021-05-14. -// - -#include "Renderer.hpp" - -namespace WAL -{ - void Renderer::render() - { - - } -} \ No newline at end of file diff --git a/lib/wal/sources/Renderer/Renderer.hpp b/lib/wal/sources/Renderer/Renderer.hpp deleted file mode 100644 index af6fbd27..00000000 --- a/lib/wal/sources/Renderer/Renderer.hpp +++ /dev/null @@ -1,16 +0,0 @@ -// -// Created by Zoe Roux on 2021-05-14. -// - - -#pragma once - -namespace WAL -{ - //! @brief The renderer class used to display things. - class Renderer - { - public: - void render(); - }; -} diff --git a/lib/wal/sources/System/System.cpp b/lib/wal/sources/System/System.cpp index e1cc2ec0..82f7fe11 100644 --- a/lib/wal/sources/System/System.cpp +++ b/lib/wal/sources/System/System.cpp @@ -12,4 +12,7 @@ namespace WAL void System::onFixedUpdate(Entity &entity) {} + + void System::onSelfUpdate() + {} } \ No newline at end of file diff --git a/lib/wal/sources/System/System.hpp b/lib/wal/sources/System/System.hpp index 76a609e8..3813e216 100644 --- a/lib/wal/sources/System/System.hpp +++ b/lib/wal/sources/System/System.hpp @@ -30,6 +30,9 @@ namespace WAL //! @remark This should be used for Physics, AI and everything that could be imprecise due to float rounding. //! @param entity The entity to update. virtual void onFixedUpdate(Entity &entity); + + //! @brief A method called after all entities that this system manage has been updated. + virtual void onSelfUpdate(); protected: //! @brief A system can't be instantiated, it should be derived. System() = default; diff --git a/lib/wal/sources/Wal.cpp b/lib/wal/sources/Wal.cpp index f1c84e72..569743aa 100644 --- a/lib/wal/sources/Wal.cpp +++ b/lib/wal/sources/Wal.cpp @@ -13,31 +13,31 @@ namespace WAL SceneManager &Wal::getSceneManager() { - return this->_scenes; + return this->_sceneManager; } void Wal::run() { auto lastTick = std::chrono::steady_clock::now(); - std::chrono::nanoseconds dtime(0); + std::chrono::nanoseconds fBehind(0); while (!this->_shouldClose) { auto now = std::chrono::steady_clock::now(); - dtime += now - lastTick; + std::chrono::nanoseconds dtime = now - lastTick; + fBehind += dtime; lastTick = now; - this->_update(dtime); - while (dtime > Wal::timestep) { - dtime -= Wal::timestep; + while (fBehind > Wal::timestep) { + fBehind -= Wal::timestep; this->_fixedUpdate(); } - this->_renderer->render(); + this->_update(dtime); } } void Wal::_update(std::chrono::nanoseconds dtime) { - auto &entities = this->_scenes.getCurrent().getEntities(); + auto &entities = this->_sceneManager.getCurrent().getEntities(); for (auto &system : this->_systems) { for (auto &entity : entities) { @@ -47,12 +47,13 @@ namespace WAL // TODO handle dependencies. system->onUpdate(entity, dtime); } + system->onSelfUpdate(); } } void Wal::_fixedUpdate() { - auto &entities = this->_scenes.getCurrent().getEntities(); + auto &entities = this->_sceneManager.getCurrent().getEntities(); for (auto &system : this->_systems) { for (auto &entity : entities) { diff --git a/lib/wal/sources/Wal.hpp b/lib/wal/sources/Wal.hpp index c8dd535c..ea72eb05 100644 --- a/lib/wal/sources/Wal.hpp +++ b/lib/wal/sources/Wal.hpp @@ -10,7 +10,6 @@ #include #include #include "Events/EventManager.hpp" -#include "Renderer/Renderer.hpp" #include "Scene/SceneManager.hpp" #include "Entity/Entity.hpp" #include "System/System.hpp" @@ -22,13 +21,11 @@ namespace WAL { private: //! @brief The scene manager that allow multiple scene to work together. - SceneManager _scenes; + SceneManager _sceneManager; //! @brief The event manager EventManager _eventManager; //! @brief The list of registered systems 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;