diff --git a/CMakeLists.txt b/CMakeLists.txt index 1b4b1159..14e5fa3e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,12 +5,25 @@ set(CMAKE_CXX_STANDARD 20) include_directories(bomberman lib/Ray/sources) include_directories(bomberman lib/wal/sources) +include_directories(bomberman sources) add_subdirectory(${PROJECT_SOURCE_DIR}/lib/wal) add_subdirectory(${PROJECT_SOURCE_DIR}/lib/Ray) add_executable(bomberman sources/main.cpp - sources/Component/Drawable/RectangleDrawable2DComponent.cpp sources/Component/Drawable/RectangleDrawable2DComponent.hpp) + sources/Component/Drawable/RectangleDrawable2DComponent.cpp + sources/Component/Drawable/RectangleDrawable2DComponent.hpp + sources/Component/Drawable/Drawable2DComponent.hpp + sources/Component/Drawable/Drawable2DComponent.cpp + 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.cpp + sources/System/Renderer/RendererSystem.hpp + ) target_link_libraries(bomberman wal ray) \ No newline at end of file diff --git a/lib/wal/CMakeLists.txt b/lib/wal/CMakeLists.txt index 8d1c350e..b3cc8845 100644 --- a/lib/wal/CMakeLists.txt +++ b/lib/wal/CMakeLists.txt @@ -16,11 +16,9 @@ add_library(wal sources/Entity/Entity.cpp sources/Component/Component.cpp sources/Models/Vector3.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/sources/Component/Drawable/Drawable2DComponent.cpp b/sources/Component/Drawable/Drawable2DComponent.cpp index 3c72b23b..cdd07aa7 100644 --- a/sources/Component/Drawable/Drawable2DComponent.cpp +++ b/sources/Component/Drawable/Drawable2DComponent.cpp @@ -3,11 +3,13 @@ // #include "Drawable2DComponent.hpp" +#include "Component/Component.hpp" namespace BBM { Drawable2DComponent::Drawable2DComponent(WAL::Entity &entity) - : Component(entity) + : WAL::Component(entity), + color(0) { } } \ No newline at end of file diff --git a/sources/Component/Drawable/RectangleDrawable2DComponent.cpp b/sources/Component/Drawable/RectangleDrawable2DComponent.cpp index eb31cb68..477bcd26 100644 --- a/sources/Component/Drawable/RectangleDrawable2DComponent.cpp +++ b/sources/Component/Drawable/RectangleDrawable2DComponent.cpp @@ -11,6 +11,5 @@ namespace BBM RectangleDrawableComponent::RectangleDrawableComponent(WAL::Entity &entity) : Drawable2DComponent(entity) { - } } \ No newline at end of file diff --git a/sources/Component/Movable/MovableComponent.cpp b/sources/Component/Movable/MovableComponent.cpp index a86a69ab..dfdc8d5e 100644 --- a/sources/Component/Movable/MovableComponent.cpp +++ b/sources/Component/Movable/MovableComponent.cpp @@ -3,19 +3,20 @@ // #include "MovableComponent.hpp" +#include "Entity/Entity.hpp" -namespace WAL +namespace BBM { - MovableComponent::MovableComponent(Entity &entity) + MovableComponent::MovableComponent(WAL::Entity &entity) : Component(entity) {} - Component *MovableComponent::clone(Entity &entity) const + WAL::Component *MovableComponent::clone(WAL::Entity &entity) const { return new MovableComponent(entity); } - void MovableComponent::addForce(Vector3f force) + void MovableComponent::addForce(WAL::Vector3f force) { this->_acceleration += force; } diff --git a/sources/Component/Movable/MovableComponent.hpp b/sources/Component/Movable/MovableComponent.hpp index 0693121a..5131ff89 100644 --- a/sources/Component/Movable/MovableComponent.hpp +++ b/sources/Component/Movable/MovableComponent.hpp @@ -7,26 +7,26 @@ #include "Models/Vector3.hpp" #include "Entity/Entity.hpp" -namespace WAL +namespace BBM { //! @brief A component to place on entities that can move or be moved. - class MovableComponent : public Component + class MovableComponent : public WAL::Component { private: //! @brief The acceleration of this entity. - Vector3f _acceleration; + WAL::Vector3f _acceleration; //! @brief The velocity of the entity. - Vector3f _velocity; + WAL::Vector3f _velocity; public: //! @brief Add an instant force to this entity. //! @param force The force to add to this entity's acceleration. The force is added instantly and in one go. - void addForce(Vector3f force); + void addForce(WAL::Vector3f force); //! @inherit - Component *clone(Entity &entity) const override; + WAL::Component *clone(WAL::Entity &entity) const override; //! @brief Create a new movable component. - explicit MovableComponent(Entity &entity); + explicit MovableComponent(WAL::Entity &entity); //! @brief A movable component is copy constructable. MovableComponent(const MovableComponent &) = default; //! @brief A default destructor diff --git a/sources/Component/Position/PositionComponent.cpp b/sources/Component/Position/PositionComponent.cpp index 1e470254..0fcb7f70 100644 --- a/sources/Component/Position/PositionComponent.cpp +++ b/sources/Component/Position/PositionComponent.cpp @@ -3,25 +3,27 @@ // #include "PositionComponent.hpp" +#include "Entity/Entity.hpp" +#include "Component/Component.hpp" -namespace WAL +namespace BBM { - PositionComponent::PositionComponent(Entity &entity) - : Component(entity), + PositionComponent::PositionComponent(WAL::Entity &entity) + : WAL::Component(entity), position() {} - PositionComponent::PositionComponent(Entity &entity, Vector3f pos) - : Component(entity), + PositionComponent::PositionComponent(WAL::Entity &entity, WAL::Vector3f pos) + : WAL::Component(entity), position(pos) {} - PositionComponent::PositionComponent(Entity &entity, float x, float y, float z) - : Component(entity), + PositionComponent::PositionComponent(WAL::Entity &entity, float x, float y, float z) + : WAL::Component(entity), position(x, y, z) {} - Component *PositionComponent::clone(WAL::Entity &entity) const + WAL::Component *PositionComponent::clone(WAL::Entity &entity) const { return new PositionComponent(entity, this->position); } diff --git a/sources/Component/Position/PositionComponent.hpp b/sources/Component/Position/PositionComponent.hpp index 8e11a2e3..0d97099b 100644 --- a/sources/Component/Position/PositionComponent.hpp +++ b/sources/Component/Position/PositionComponent.hpp @@ -7,14 +7,14 @@ #include "Models/Vector3.hpp" #include "Component/Component.hpp" -namespace WAL +namespace BBM { //! @brief A basic position component - class PositionComponent : public Component + class PositionComponent : public WAL::Component { public: //! @brief Get the editable position of this entity - Vector3f position; + WAL::Vector3f position; //! @brief Get the X position of this entity. float getX() const; @@ -24,14 +24,14 @@ namespace WAL float getZ() const; //! @inherit - Component *clone(Entity &entity) const override; + WAL::Component *clone(WAL::Entity &entity) const override; //! @brief Create a new PositionComponent linked to a specific entity - explicit PositionComponent(Entity &entity); + explicit PositionComponent(WAL::Entity &entity); //! @brief Create a new PositionComponent at a certain position - PositionComponent(Entity &entity, Vector3f pos); + PositionComponent(WAL::Entity &entity, WAL::Vector3f pos); //! @brief Create a new PositionComponent at a certain position - PositionComponent(Entity &entity, float x, float y, float z); + PositionComponent(WAL::Entity &entity, float x, float y, float z); //! @brief A position component is copy constructable PositionComponent(const PositionComponent &) = default; //! @brief A default destructor diff --git a/sources/System/Movable/MovableSystem.cpp b/sources/System/Movable/MovableSystem.cpp index 7bd56fb0..1e7fd4b6 100644 --- a/sources/System/Movable/MovableSystem.cpp +++ b/sources/System/Movable/MovableSystem.cpp @@ -3,26 +3,26 @@ // #include "Component/Position/PositionComponent.hpp" -#include "System/Movable/MovableSystem.hpp" +#include "MovableSystem.hpp" #include "Component/Movable/MovableComponent.hpp" #include "Wal.hpp" -namespace WAL +namespace BBM { MovableSystem::MovableSystem() - : System({ + : WAL::System({ typeid(MovableComponent), typeid(PositionComponent) }) {} - void MovableSystem::onFixedUpdate(Entity &entity) + void MovableSystem::onFixedUpdate(WAL::Entity &entity) { auto &movable = entity.getComponent(); auto &position = entity.getComponent(); - position.position += movable._velocity * Wal::timestep.count(); - movable._velocity = movable._acceleration * Wal::timestep.count(); - movable._acceleration = Vector3f(); + position.position += movable._velocity * WAL::Wal::timestep.count(); + movable._velocity = movable._acceleration * WAL::Wal::timestep.count(); + movable._acceleration = WAL::Vector3f(); } } \ No newline at end of file diff --git a/sources/System/Movable/MovableSystem.hpp b/sources/System/Movable/MovableSystem.hpp index f7ec3c3c..2bfcd838 100644 --- a/sources/System/Movable/MovableSystem.hpp +++ b/sources/System/Movable/MovableSystem.hpp @@ -6,15 +6,16 @@ #pragma once #include "System/System.hpp" +#include "Entity/Entity.hpp" -namespace WAL +namespace BBM { //! @brief A system to handle movable entities. This system update velocity based on accelerations and positions based on velocity. - class MovableSystem : public System +class MovableSystem : public WAL::System { public: //! @inherit - void onFixedUpdate(Entity &entity) override; + void onFixedUpdate(WAL::Entity &entity) override; //! @brief A default constructor MovableSystem(); diff --git a/sources/System/Renderer/RendererSystem.cpp b/sources/System/Renderer/RendererSystem.cpp index b43abe2b..eb92d60d 100644 --- a/sources/System/Renderer/RendererSystem.cpp +++ b/sources/System/Renderer/RendererSystem.cpp @@ -3,24 +3,25 @@ // #include "RendererSystem.hpp" +#include "Entity/Entity.hpp" #include "Component/Position/PositionComponent.hpp" -namespace WAL +namespace BBM { - void RendererSystem::onUpdate(Entity &entity, std::chrono::nanoseconds dtime) + void RendererSystem::onUpdate(WAL::Entity &entity, std::chrono::nanoseconds dtime) { - System::onUpdate(entity, dtime); + WAL::System::onUpdate(entity, dtime); } - void RendererSystem::onFixedUpdate(Entity &entity) + void RendererSystem::onFixedUpdate(WAL::Entity &entity) { - System::onFixedUpdate(entity); + WAL::System::onFixedUpdate(entity); } void RendererSystem::onSelfUpdate() { - System::onSelfUpdate(); + WAL::System::onSelfUpdate(); } RendererSystem::RendererSystem() diff --git a/sources/System/Renderer/RendererSystem.hpp b/sources/System/Renderer/RendererSystem.hpp index 695ac68b..29b6c3e3 100644 --- a/sources/System/Renderer/RendererSystem.hpp +++ b/sources/System/Renderer/RendererSystem.hpp @@ -5,21 +5,22 @@ #pragma once #include "System/System.hpp" +#include "Entity/Entity.hpp" -namespace WAL +namespace BBM { - class RendererSystem : public System - {; + 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(Entity &entity, std::chrono::nanoseconds dtime) override; + 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(Entity &entity) override; + void onFixedUpdate(WAL::Entity &entity) override; //! @brief A method called after all entities that this system manage has been updated. void onSelfUpdate() override;