adding Drawable2DComponent.hpp & Renderer2DSystem.hpp

This commit is contained in:
Clément Le Bihan
2021-05-25 12:03:17 +02:00
parent 8c3ef2a23c
commit 43f1f6ad1f
5 changed files with 79 additions and 13 deletions
+4 -2
View File
@@ -12,14 +12,16 @@ add_subdirectory(${PROJECT_SOURCE_DIR}/lib/Ray)
add_executable(bomberman
sources/main.cpp
sources/Component/Drawable/DrawableComponent.hpp
sources/Component/Drawable/Drawable3DComponent.hpp
sources/Component/Drawable/Drawable2DComponent.hpp
sources/Component/Movable/MovableComponent.cpp
sources/Component/Movable/MovableComponent.hpp
sources/Component/Position/PositionComponent.cpp
sources/Component/Position/PositionComponent.hpp
sources/System/Movable/MovableSystem.cpp
sources/System/Movable/MovableSystem.hpp
sources/System/Renderer/RendererSystem.hpp
sources/System/Renderer/Renderer3DSystem.hpp
sources/System/Renderer/Renderer2DSystem.hpp
)
target_link_libraries(bomberman wal ray)
@@ -6,17 +6,16 @@
#include "Component/Component.hpp"
#include "Drawables/ADrawable2D.hpp"
#include "Color.hpp"
namespace BBM
{
template <class T>
class DrawableComponent : public WAL::Component
class Drawable2DComponent : public WAL::Component
{
public:
T member;
explicit DrawableComponent(WAL::Entity &entity)
explicit Drawable2DComponent(WAL::Entity &entity)
: WAL::Component(entity)
{
}
@@ -0,0 +1,23 @@
//
// Created by cbihan on 24/05/2021.
//
#pragma once
#include "Component/Component.hpp"
#include "Drawables/ADrawable3D.hpp"
namespace BBM
{
template <class T>
class Drawable3DComponent : public WAL::Component
{
public:
T member;
explicit Drawable3DComponent(WAL::Entity &entity)
: WAL::Component(entity)
{
}
};
}
@@ -8,35 +8,35 @@
#include "System/System.hpp"
#include "Entity/Entity.hpp"
#include "Component/Position/PositionComponent.hpp"
#include "Component/Drawable/DrawableComponent.hpp"
#include "Component/Drawable/Drawable2DComponent.hpp"
#include "Window.hpp"
namespace BBM
{
template <class T>
class RendererSystem : public WAL::System
class Renderer2DSystem : public WAL::System
{
private:
//! @brief The class to render
RAY::Window &_window;
public:
explicit RendererSystem(RAY::Window &window)
: WAL::System({typeid(PositionComponent), typeid(DrawableComponent<T>)}),
explicit Renderer2DSystem(RAY::Window &window)
: WAL::System({typeid(PositionComponent), typeid(Drawable3DComponent<T>)}),
_window(window)
{
}
void onUpdate(WAL::Entity &entity, std::chrono::nanoseconds dtime) override
{
auto &comp = entity.getComponent<DrawableComponent<T>>();
auto &comp = entity.getComponent<Drawable3DComponent<T>>();
auto &pos = entity.getComponent<PositionComponent>();
// TODO update drawable pos with pos
comp.member.drawOn(this->_window);
}
RendererSystem(const RendererSystem &) = default;
~RendererSystem() override = default;
RendererSystem &operator=(const RendererSystem &) = delete;
Renderer2DSystem(const Renderer3DSystem &) = default;
~Renderer2DSystem() override = default;
Renderer2DSystem &operator=(const Renderer2DSystem &) = delete;
};
}
@@ -0,0 +1,42 @@
//
// Created by cbihan on 24/05/2021.
//
#pragma once
#include <type_traits>
#include "System/System.hpp"
#include "Entity/Entity.hpp"
#include "Component/Position/PositionComponent.hpp"
#include "Component/Drawable/Drawable3DComponent.hpp"
#include "Window.hpp"
namespace BBM
{
template <class T>
class Renderer3DSystem : public WAL::System
{
private:
//! @brief The class to render
RAY::Window &_window;
public:
explicit Renderer3DSystem(RAY::Window &window)
: WAL::System({typeid(PositionComponent), typeid(Drawable3DComponent<T>)}),
_window(window)
{
}
void onUpdate(WAL::Entity &entity, std::chrono::nanoseconds dtime) override
{
auto &comp = entity.getComponent<Drawable3DComponent<T>>();
auto &pos = entity.getComponent<PositionComponent>();
// TODO update drawable pos with pos
comp.member.drawOn(this->_window);
}
Renderer3DSystem(const Renderer3DSystem &) = default;
~Renderer3DSystem() override = default;
Renderer3DSystem &operator=(const Renderer3DSystem &) = delete;
};
}