diff --git a/CMakeLists.txt b/CMakeLists.txt index 81b3c154..b17dc1aa 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -54,13 +54,16 @@ set(SOURCES sources/Component/Renderer/CameraComponent.hpp sources/System/Renderer/Render2DScreenSystem.cpp sources/System/Renderer/Render2DScreenSystem.hpp - sources/Component/Animation/AnimationComponent.cpp - sources/Component/Animation/AnimationComponent.hpp + sources/Component/Animation/AnimationsComponent.cpp + sources/Component/Animation/AnimationsComponent.hpp + sources/System/Animation/AnimationsSystem.cpp + sources/System/Animation/AnimationsSystem.hpp ) add_executable(bomberman sources/main.cpp - ${SOURCES}) + ${SOURCES} + ) target_include_directories(bomberman PUBLIC sources) target_link_libraries(bomberman PUBLIC wal ray) diff --git a/sources/Component/Animation/AnimationComponent.cpp b/sources/Component/Animation/AnimationComponent.cpp deleted file mode 100644 index d1f8210b..00000000 --- a/sources/Component/Animation/AnimationComponent.cpp +++ /dev/null @@ -1,16 +0,0 @@ -// -// Created by cbihan on 01/06/2021. -// - -#include "AnimationComponent.hpp" -#include "Entity/Entity.hpp" - -namespace BBM -{ - AnimationComponent::AnimationComponent(WAL::Entity &entity, RAY::ModelAnimation &modelAnimation) - : WAL::Component(entity), - _modelAnimation(modelAnimation) - { - - } -} \ No newline at end of file diff --git a/sources/Component/Animation/AnimationComponent.hpp b/sources/Component/Animation/AnimationComponent.hpp deleted file mode 100644 index 36946c16..00000000 --- a/sources/Component/Animation/AnimationComponent.hpp +++ /dev/null @@ -1,31 +0,0 @@ -// -// Created by cbihan on 01/06/2021. -// - -#pragma once - -#include -#include "Component/Component.hpp" -#include "Entity/Entity.hpp" -#include "Model/Model.hpp" - -namespace BBM -{ - - class AnimationComponent : public WAL::Component - { - private: - //! @brief To get the animation data - RAY::ModelAnimation &_modelAnimation; - public: - //! @brief ctor entity and the path of the animation file - explicit AnimationComponent(WAL::Entity &entity, RAY::ModelAnimation &modelAnimation); - //! @brief copy ctor - AnimationComponent(const AnimationComponent &) = default; - //! @brief dtor - ~AnimationComponent() override = default; - //! @brief assignment operator - AnimationComponent &operator=(const AnimationComponent &) = delete; - }; - -} diff --git a/sources/Component/Animation/AnimationsComponent.cpp b/sources/Component/Animation/AnimationsComponent.cpp new file mode 100644 index 00000000..d32c6818 --- /dev/null +++ b/sources/Component/Animation/AnimationsComponent.cpp @@ -0,0 +1,43 @@ +// +// Created by cbihan on 01/06/2021. +// + +#include "AnimationsComponent.hpp" +#include "Entity/Entity.hpp" +#include "Model/ModelAnimations.hpp" + +namespace BBM +{ + AnimationsComponent::AnimationsComponent(WAL::Entity &entity, RAY::ModelAnimations &modelAnimation) + : WAL::Component(entity), + _modelAnimation(modelAnimation), + _animFrameCounter(0) + { + } + + WAL::Component *AnimationsComponent::clone(WAL::Entity &entity) const + { + return new AnimationsComponent(entity, this->_modelAnimation); + } + + size_t AnimationsComponent::getAnimFrameCounter() const + { + return this->_animFrameCounter; + } + + RAY::ModelAnimation AnimationsComponent::getCurrentModelAnim() const + { + return this->_modelAnimation[static_cast(this->_animFrameCounter)]; + } + + void AnimationsComponent::setAnimFrameCounter(size_t animFrameCounter) + { + this->_animFrameCounter = animFrameCounter; + this->_animFrameCounter %= this->_modelAnimation.getAnimationsCount(); + } + + void AnimationsComponent::resetAnimFrameCounter() + { + this->_animFrameCounter = 0; + } +} \ No newline at end of file diff --git a/sources/Component/Animation/AnimationsComponent.hpp b/sources/Component/Animation/AnimationsComponent.hpp new file mode 100644 index 00000000..a3d741a9 --- /dev/null +++ b/sources/Component/Animation/AnimationsComponent.hpp @@ -0,0 +1,47 @@ +// +// Created by cbihan on 01/06/2021. +// + +#pragma once + +#include +#include +#include +#include + +namespace BBM +{ + class AnimationsComponent : public WAL::Component + { + private: + //! @brief To get the animation data + RAY::ModelAnimations &_modelAnimation; + //! @brief the frame animation counter + size_t _animFrameCounter; + public: + //! @inherit + WAL::Component *clone(WAL::Entity &entity) const override; + + //! @brief get animation frame counter + size_t getAnimFrameCounter() const; + + //! @brief get the current + RAY::ModelAnimation getCurrentModelAnim() const; + + //! @brief + void setAnimFrameCounter(size_t animFrameCounter); + + //! @brief Set the internal anim counter to 0 + void resetAnimFrameCounter(); + + //! @brief ctor entity and the path of the animation file + explicit AnimationsComponent(WAL::Entity &entity, RAY::ModelAnimations &modelAnimation); + //! @brief copy ctor + AnimationsComponent(const AnimationsComponent &) = default; + //! @brief dtor + ~AnimationsComponent() override = default; + //! @brief assignment operator + AnimationsComponent &operator=(const AnimationsComponent &) = delete; + }; + +} diff --git a/sources/System/Animation/AnimationsSystem.cpp b/sources/System/Animation/AnimationsSystem.cpp new file mode 100644 index 00000000..42425acf --- /dev/null +++ b/sources/System/Animation/AnimationsSystem.cpp @@ -0,0 +1,27 @@ +// +// Created by cbihan on 01/06/2021. +// + +#include "AnimationsSystem.hpp" +#include "Component/Animation/AnimationsComponent.hpp" +#include "Model/Model.hpp" +#include "Component/Renderer/Drawable3DComponent.hpp" + +namespace BBM +{ + + AnimationsSystem::AnimationsSystem() + : WAL::System({typeid(AnimationsComponent), + typeid(Drawable3DComponent)}) + { + } + + void AnimationsSystem::onFixedUpdate(WAL::Entity &entity) + { + auto &model = entity.getComponent>(); + auto &anim = entity.getComponent(); + + model.member.setAnimation(anim.getCurrentModelAnim()); + anim.setAnimFrameCounter(anim.getAnimFrameCounter() + 1); + } +} \ No newline at end of file diff --git a/sources/System/Animation/AnimationsSystem.hpp b/sources/System/Animation/AnimationsSystem.hpp new file mode 100644 index 00000000..eb508b3e --- /dev/null +++ b/sources/System/Animation/AnimationsSystem.hpp @@ -0,0 +1,25 @@ +// +// Created by cbihan on 01/06/2021. +// + +#pragma once + +#include + +namespace BBM +{ + class AnimationsSystem : public WAL::System + { + //! @inherit + void onFixedUpdate(WAL::Entity &entity) override; + + //! @brief A default constructor + AnimationsSystem(); + //! @brief A Controllable system is copy constructable + AnimationsSystem(const AnimationsSystem &) = default; + //! @brief A default destructor + ~AnimationsSystem() override = default; + //! @brief A Controllable system is assignable. + AnimationsSystem &operator=(const AnimationsSystem &) = default; + }; +} \ No newline at end of file diff --git a/sources/System/Controllable/ControllableSystem.cpp b/sources/System/Controllable/ControllableSystem.cpp index 0a9c789c..41c54895 100644 --- a/sources/System/Controllable/ControllableSystem.cpp +++ b/sources/System/Controllable/ControllableSystem.cpp @@ -10,8 +10,6 @@ namespace BBM { - float ControllableSystem::speed = .25f; - ControllableSystem::ControllableSystem() : WAL::System({ typeid(ControllableComponent), diff --git a/sources/System/Controllable/ControllableSystem.hpp b/sources/System/Controllable/ControllableSystem.hpp index fac4db08..ec6eef9d 100644 --- a/sources/System/Controllable/ControllableSystem.hpp +++ b/sources/System/Controllable/ControllableSystem.hpp @@ -14,7 +14,7 @@ namespace BBM { public: //! @brief The speed applied to every controllable entities. - static float speed; + static constexpr const float speed = .25f; //! @inherit void onFixedUpdate(WAL::Entity &entity) override;