adding AnimationsSystem.cpp

This commit is contained in:
Clément Le Bihan
2021-06-01 17:26:01 +02:00
parent e298ce03eb
commit b4d783d6c2
9 changed files with 149 additions and 53 deletions
+6 -3
View File
@@ -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)
@@ -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)
{
}
}
@@ -1,31 +0,0 @@
//
// Created by cbihan on 01/06/2021.
//
#pragma once
#include <string>
#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;
};
}
@@ -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<int>(this->_animFrameCounter)];
}
void AnimationsComponent::setAnimFrameCounter(size_t animFrameCounter)
{
this->_animFrameCounter = animFrameCounter;
this->_animFrameCounter %= this->_modelAnimation.getAnimationsCount();
}
void AnimationsComponent::resetAnimFrameCounter()
{
this->_animFrameCounter = 0;
}
}
@@ -0,0 +1,47 @@
//
// Created by cbihan on 01/06/2021.
//
#pragma once
#include <string>
#include <Model/ModelAnimations.hpp>
#include <Component/Component.hpp>
#include <Entity/Entity.hpp>
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;
};
}
@@ -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<RAY::Drawables::Drawables3D::Model>)})
{
}
void AnimationsSystem::onFixedUpdate(WAL::Entity &entity)
{
auto &model = entity.getComponent<Drawable3DComponent<RAY::Drawables::Drawables3D::Model>>();
auto &anim = entity.getComponent<AnimationsComponent>();
model.member.setAnimation(anim.getCurrentModelAnim());
anim.setAnimFrameCounter(anim.getAnimFrameCounter() + 1);
}
}
@@ -0,0 +1,25 @@
//
// Created by cbihan on 01/06/2021.
//
#pragma once
#include <System/System.hpp>
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;
};
}
@@ -10,8 +10,6 @@
namespace BBM
{
float ControllableSystem::speed = .25f;
ControllableSystem::ControllableSystem()
: WAL::System({
typeid(ControllableComponent),
@@ -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;