mirror of
https://github.com/zoriya/Bomberman.git
synced 2026-06-07 03:25:10 +00:00
starting to add RectangleDrawable2DSystem.cpp
This commit is contained in:
+1
-1
@@ -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)
|
||||
@@ -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<RectangleDrawableComponent>();
|
||||
auto &pos = entity.getComponent<PositionComponent>();
|
||||
RAY::Drawables::Drawables2D::Rectangle r({pos.getX(), pos.getY()},
|
||||
{static_cast<float>(rectDraw.width), static_cast<float>(rectDraw.length)},
|
||||
rectDraw.color);
|
||||
this->_w.draw(r);
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
}
|
||||
@@ -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)
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user