From c097575c683b6b12afacc2e9b3e8a2cb84986e61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Le=20Bihan?= Date: Mon, 24 May 2021 16:15:07 +0200 Subject: [PATCH] starting to add RectangleDrawable2DSystem.cpp --- CMakeLists.txt | 2 +- .../Renderer/RectangleDrawable2DSystem.cpp | 28 ++++++++++++++++++ .../Renderer/RectangleDrawable2DSystem.hpp | 29 +++++++++++++++++++ sources/System/Renderer/RendererSystem.cpp | 23 +++------------ sources/System/Renderer/RendererSystem.hpp | 22 ++++---------- 5 files changed, 68 insertions(+), 36 deletions(-) create mode 100644 sources/System/Renderer/RectangleDrawable2DSystem.cpp create mode 100644 sources/System/Renderer/RectangleDrawable2DSystem.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 14e5fa3e..08b5e0a6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,6 +24,6 @@ add_executable(bomberman sources/System/Movable/MovableSystem.hpp sources/System/Renderer/RendererSystem.cpp sources/System/Renderer/RendererSystem.hpp - ) + sources/System/Renderer/RectangleDrawable2DSystem.cpp sources/System/Renderer/RectangleDrawable2DSystem.hpp) target_link_libraries(bomberman wal ray) \ No newline at end of file diff --git a/sources/System/Renderer/RectangleDrawable2DSystem.cpp b/sources/System/Renderer/RectangleDrawable2DSystem.cpp new file mode 100644 index 00000000..159b6405 --- /dev/null +++ b/sources/System/Renderer/RectangleDrawable2DSystem.cpp @@ -0,0 +1,28 @@ +// +// Created by cbihan on 24/05/2021. +// + +#include "RectangleDrawable2DSystem.hpp" +#include "Component/Position/PositionComponent.hpp" +#include "Component/Drawable/RectangleDrawable2DComponent.hpp" +#include "Window.hpp" +#include "Drawables/2D/Rectangle.hpp" + +namespace BBM +{ + + RectangleDrawable2DSystem::RectangleDrawable2DSystem(RAY::Window &w) + : RendererSystem(w) + { + } + + void RectangleDrawable2DSystem::onUpdate(WAL::Entity &entity, std::chrono::nanoseconds) + { + auto &rectDraw = entity.getComponent(); + auto &pos = entity.getComponent(); + RAY::Drawables::Drawables2D::Rectangle r({pos.getX(), pos.getY()}, + {static_cast(rectDraw.width), static_cast(rectDraw.length)}, + rectDraw.color); + this->_w.draw(r); + } +} \ No newline at end of file diff --git a/sources/System/Renderer/RectangleDrawable2DSystem.hpp b/sources/System/Renderer/RectangleDrawable2DSystem.hpp new file mode 100644 index 00000000..e58021e4 --- /dev/null +++ b/sources/System/Renderer/RectangleDrawable2DSystem.hpp @@ -0,0 +1,29 @@ +// +// Created by cbihan on 24/05/2021. +// + +#pragma once + +#include "System/System.hpp" +#include "RendererSystem.hpp" +#include "Entity/Entity.hpp" +#include "Window.hpp" + +namespace BBM +{ + + class RectangleDrawable2DSystem : public RendererSystem + { + public: + //! @brief Update the corresponding component of the given entity + //! @param entity The entity to update. + //! @param dtime The delta time. + void onUpdate(WAL::Entity &entity, std::chrono::nanoseconds dtime) override; + + explicit RectangleDrawable2DSystem(RAY::Window &w); + RectangleDrawable2DSystem(const RectangleDrawable2DSystem &) = default; + ~RectangleDrawable2DSystem() override = default; + RectangleDrawable2DSystem &operator=(const RectangleDrawable2DSystem &) = default; + }; + +} diff --git a/sources/System/Renderer/RendererSystem.cpp b/sources/System/Renderer/RendererSystem.cpp index eb92d60d..502c3652 100644 --- a/sources/System/Renderer/RendererSystem.cpp +++ b/sources/System/Renderer/RendererSystem.cpp @@ -3,31 +3,16 @@ // #include "RendererSystem.hpp" -#include "Entity/Entity.hpp" #include "Component/Position/PositionComponent.hpp" +#include "Window.hpp" namespace BBM { - - void RendererSystem::onUpdate(WAL::Entity &entity, std::chrono::nanoseconds dtime) - { - WAL::System::onUpdate(entity, dtime); - } - - void RendererSystem::onFixedUpdate(WAL::Entity &entity) - { - WAL::System::onFixedUpdate(entity); - } - - void RendererSystem::onSelfUpdate() - { - WAL::System::onSelfUpdate(); - } - - RendererSystem::RendererSystem() + RendererSystem::RendererSystem(RAY::Window &window) : System({ typeid(PositionComponent) - }) + }), + _w(window) { } } \ No newline at end of file diff --git a/sources/System/Renderer/RendererSystem.hpp b/sources/System/Renderer/RendererSystem.hpp index 29b6c3e3..eb6df1cd 100644 --- a/sources/System/Renderer/RendererSystem.hpp +++ b/sources/System/Renderer/RendererSystem.hpp @@ -6,29 +6,19 @@ #include "System/System.hpp" #include "Entity/Entity.hpp" +#include "Window.hpp" namespace BBM { class RendererSystem : public WAL::System { - - //! @brief Update the corresponding component of the given entity - //! @param entity The entity to update. - //! @param dtime The delta time. - void onUpdate(WAL::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(WAL::Entity &entity) override; - - //! @brief A method called after all entities that this system manage has been updated. - void onSelfUpdate() override; - + protected: + //! @brief The window to render on + RAY::Window &_w; public: - RendererSystem(); + RendererSystem(RAY::Window &window); RendererSystem(const RendererSystem &) = default; ~RendererSystem() override = default; - RendererSystem &operator=(const RendererSystem &) = default; + RendererSystem &operator=(const RendererSystem &) = delete; }; } \ No newline at end of file