From 4ef7f7543a811cb2e10ac447602c130065ffaa73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Le=20Bihan?= Date: Mon, 24 May 2021 10:06:25 +0200 Subject: [PATCH] renderer system is started --- lib/wal/CMakeLists.txt | 42 +++++++++---------- .../sources/System/Movable/RendererSystem.cpp | 32 ++++++++++++++ .../sources/System/Movable/RendererSystem.hpp | 33 +++++++++++++++ 3 files changed, 86 insertions(+), 21 deletions(-) create mode 100644 lib/wal/sources/System/Movable/RendererSystem.cpp create mode 100644 lib/wal/sources/System/Movable/RendererSystem.hpp diff --git a/lib/wal/CMakeLists.txt b/lib/wal/CMakeLists.txt index fcebfa75..5259a6e2 100644 --- a/lib/wal/CMakeLists.txt +++ b/lib/wal/CMakeLists.txt @@ -4,27 +4,27 @@ project(wal) set(CMAKE_CXX_STANDARD 20) add_library(wal - sources/Entity/Entity.hpp - sources/Component/Component.hpp - sources/System/System.hpp - sources/Wal.cpp - sources/Wal.hpp - sources/Scene/Scene.cpp - sources/Scene/Scene.hpp - sources/Exception/WalError.cpp - sources/Exception/WalError.hpp - sources/Entity/Entity.cpp - sources/Component/Component.cpp - sources/Component/Position/PositionComponent.cpp - sources/Component/Position/PositionComponent.hpp - sources/Models/Vector3.hpp - sources/Component/Movable/MovableComponent.cpp - sources/Component/Movable/MovableComponent.hpp - sources/System/Movable/MovableSystem.cpp - sources/System/Movable/MovableSystem.hpp - sources/System/System.cpp - sources/Models/Callback.hpp -) + sources/Entity/Entity.hpp + sources/Component/Component.hpp + sources/System/System.hpp + sources/Wal.cpp + sources/Wal.hpp + sources/Scene/Scene.cpp + sources/Scene/Scene.hpp + sources/Exception/WalError.cpp + sources/Exception/WalError.hpp + sources/Entity/Entity.cpp + sources/Component/Component.cpp + sources/Component/Position/PositionComponent.cpp + sources/Component/Position/PositionComponent.hpp + sources/Models/Vector3.hpp + sources/Component/Movable/MovableComponent.cpp + sources/Component/Movable/MovableComponent.hpp + sources/System/Movable/MovableSystem.cpp + sources/System/Movable/MovableSystem.hpp + sources/System/System.cpp + sources/Models/Callback.hpp + sources/System/Movable/RendererSystem.cpp sources/System/Movable/RendererSystem.hpp) target_include_directories(wal PUBLIC sources) diff --git a/lib/wal/sources/System/Movable/RendererSystem.cpp b/lib/wal/sources/System/Movable/RendererSystem.cpp new file mode 100644 index 00000000..b43abe2b --- /dev/null +++ b/lib/wal/sources/System/Movable/RendererSystem.cpp @@ -0,0 +1,32 @@ +// +// Created by cbihan on 24/05/2021. +// + +#include "RendererSystem.hpp" +#include "Component/Position/PositionComponent.hpp" + +namespace WAL +{ + + void RendererSystem::onUpdate(Entity &entity, std::chrono::nanoseconds dtime) + { + System::onUpdate(entity, dtime); + } + + void RendererSystem::onFixedUpdate(Entity &entity) + { + System::onFixedUpdate(entity); + } + + void RendererSystem::onSelfUpdate() + { + System::onSelfUpdate(); + } + + RendererSystem::RendererSystem() + : System({ + typeid(PositionComponent) + }) + { + } +} \ No newline at end of file diff --git a/lib/wal/sources/System/Movable/RendererSystem.hpp b/lib/wal/sources/System/Movable/RendererSystem.hpp new file mode 100644 index 00000000..695ac68b --- /dev/null +++ b/lib/wal/sources/System/Movable/RendererSystem.hpp @@ -0,0 +1,33 @@ +// +// Created by cbihan on 24/05/2021. +// + +#pragma once + +#include "System/System.hpp" + +namespace WAL +{ + class RendererSystem : public System + {; + + //! @brief Update the corresponding component of the given entity + //! @param entity The entity to update. + //! @param dtime The delta time. + void onUpdate(Entity &entity, std::chrono::nanoseconds dtime) override; + + //! @brief An alternative of onUpdate that is called every 8ms (120 times per seconds). If the system slow down, it will try to catch up. + //! @remark This should be used for Physics, AI and everything that could be imprecise due to float rounding. + //! @param entity The entity to update. + void onFixedUpdate(Entity &entity) override; + + //! @brief A method called after all entities that this system manage has been updated. + void onSelfUpdate() override; + + public: + RendererSystem(); + RendererSystem(const RendererSystem &) = default; + ~RendererSystem() override = default; + RendererSystem &operator=(const RendererSystem &) = default; + }; +} \ No newline at end of file