diff --git a/sources/Component/Renderer/Drawable2DComponent.hpp b/sources/Component/Renderer/Drawable2DComponent.hpp index 0fc75f26..4bab9434 100644 --- a/sources/Component/Renderer/Drawable2DComponent.hpp +++ b/sources/Component/Renderer/Drawable2DComponent.hpp @@ -4,6 +4,7 @@ #pragma once +#include #include "Component/Component.hpp" #include "Drawables/ADrawable3D.hpp" #include "Model/Model.hpp" @@ -24,9 +25,9 @@ namespace BBM //! ctor template - explicit Drawable2DComponent(WAL::Entity &entity, Params &&...params) + explicit Drawable2DComponent(WAL::Entity &entity, WAL::TypeHolder, Params &&...params) : WAL::Component(entity), - drawable(std::move(T(std::forward(params)...))) + drawable(new T(std::forward(params)...)) {} //! @brief Clone a component for another or the same entity. diff --git a/sources/Runner/Runner.cpp b/sources/Runner/Runner.cpp index d45a9273..1341bc45 100644 --- a/sources/Runner/Runner.cpp +++ b/sources/Runner/Runner.cpp @@ -41,12 +41,10 @@ namespace BBM std::shared_ptr loadGameScene() { -// Drawable2DComponent cmp = Drawable2DComponent(Vector2f(), Vector2f(), RED); - auto scene = std::make_shared(); -// scene->addEntity("cube") -// .addComponent() -// .addComponent(Vector2f(), Vector2f(10, 10), RED); + scene->addEntity("cube") + .addComponent() + .addComponent(Vector2f(), Vector2f(10, 10), RED); scene->addEntity("player") .addComponent() .addComponent("assets/player/player.iqm", std::make_pair(MAP_DIFFUSE, "assets/player/blue.png")); diff --git a/sources/System/Renderer/RenderSystem.cpp b/sources/System/Renderer/RenderSystem.cpp index 590a9262..99a94f0e 100644 --- a/sources/System/Renderer/RenderSystem.cpp +++ b/sources/System/Renderer/RenderSystem.cpp @@ -4,10 +4,14 @@ #undef INTERNAL #define INTERNAL public -#include +#include +#include "Models/Vector2.hpp" #include "RenderSystem.hpp" #include "Component/Renderer/CameraComponent.hpp" #include "Component/Position/PositionComponent.hpp" +#include "Component/Renderer/Drawable2DComponent.hpp" +#include "Drawables/ADrawable2D.hpp" +#include "Drawables/ADrawable3D.hpp" namespace BBM { @@ -26,7 +30,21 @@ namespace BBM this->_camera.update(); BeginDrawing(); ClearBackground(BLACK); + BeginMode3D(this->_camera); + for (auto &entity : this->_wal.scene->getEntities()) { + if (!entity.hasComponent() + || !entity.hasComponent()) + continue; + auto &drawable = entity.getComponent(); + auto &pos = entity.getComponent(); + + drawable.drawable->setPosition(pos.position); + drawable.drawable->drawOn(this->_window); + } + EndMode3D(); + + // TODO sort entities based on the Z axis for (auto &entity : this->_wal.scene->getEntities()) { if (!entity.hasComponent() || !entity.hasComponent()) @@ -34,10 +52,9 @@ namespace BBM auto &drawable = entity.getComponent(); auto &pos = entity.getComponent(); -// drawable.drawable->setPosition(static_cast(pos.position)); -// drawable.drawable->drawOn(this->_window); + drawable.drawable->setPosition(Vector2f(pos.position.x, pos.position.y)); + drawable.drawable->drawOn(this->_window); } - EndMode3D(); EndDrawing(); }