From 614b5af580ab92f03a243a777eacd2442d9994f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Le=20Bihan?= Date: Sat, 19 Jun 2021 23:30:07 +0200 Subject: [PATCH] it's better --- .../Animation/AnimationsComponent.hpp | 2 -- sources/System/Animation/AnimationsSystem.cpp | 30 +++++++++++++------ sources/System/Animation/AnimationsSystem.hpp | 13 +++++++- 3 files changed, 33 insertions(+), 12 deletions(-) diff --git a/sources/Component/Animation/AnimationsComponent.hpp b/sources/Component/Animation/AnimationsComponent.hpp index 41d9c10e..7d921932 100644 --- a/sources/Component/Animation/AnimationsComponent.hpp +++ b/sources/Component/Animation/AnimationsComponent.hpp @@ -22,8 +22,6 @@ namespace BBM bool _animDisabled; public: - //! @brief Should the next update call be skipped? - bool skipNext = false; //! @inherit WAL::Component *clone(WAL::Entity &entity) const override; diff --git a/sources/System/Animation/AnimationsSystem.cpp b/sources/System/Animation/AnimationsSystem.cpp index 9d37658b..5d52924b 100644 --- a/sources/System/Animation/AnimationsSystem.cpp +++ b/sources/System/Animation/AnimationsSystem.cpp @@ -5,6 +5,9 @@ #include "AnimationsSystem.hpp" #include "Component/Animation/AnimationsComponent.hpp" #include "Model/Model.hpp" +#include +#include "Component/Tag/TagComponent.hpp" +#include "Component/Position/PositionComponent.hpp" #include "Component/Renderer/Drawable3DComponent.hpp" namespace BBM @@ -14,20 +17,29 @@ namespace BBM : System(wal) {} - void AnimationsSystem::onFixedUpdate(WAL::ViewEntity &entity) + void AnimationsSystem::onUpdate(WAL::ViewEntity &entity, std::chrono::nanoseconds) { - auto &model = entity.get(); auto &anim = entity.get(); if (anim.isAnimDisabled()) return; - auto modelPtr = std::dynamic_pointer_cast(model.drawable); - if (modelPtr) { - modelPtr->setAnimation(anim.getCurrentModelAnim()); - anim.incCurrentAnimFrameCounter(); - anim.incCurrentAnimFrameCounter(); - anim.incCurrentAnimFrameCounter(); - anim.incCurrentAnimFrameCounter(); + anim.incCurrentAnimFrameCounter(); + anim.incCurrentAnimFrameCounter(); + if (this->animsToSkip <= 0) { + auto &model = entity.get(); + auto modelPtr = std::dynamic_pointer_cast(model.drawable); + if (modelPtr) { + modelPtr->setAnimation(anim.getCurrentModelAnim()); + } } } + + void AnimationsSystem::onSelfUpdate(std::chrono::nanoseconds) + { + this->maxAnimsToSkip = this->_wal.getScene()->view, PositionComponent>().size() - 1; + if (this->animsToSkip <= 0) { + this->animsToSkip = this->maxAnimsToSkip + 1; + } + this->animsToSkip--; + } } \ No newline at end of file diff --git a/sources/System/Animation/AnimationsSystem.hpp b/sources/System/Animation/AnimationsSystem.hpp index bf71460e..d9b7aacd 100644 --- a/sources/System/Animation/AnimationsSystem.hpp +++ b/sources/System/Animation/AnimationsSystem.hpp @@ -12,9 +12,20 @@ namespace BBM { class AnimationsSystem : public WAL::System { + private: + + //! @brief used to reset animsToskip + long maxAnimsToSkip = 4; + + //! @brief Should the next update call be skipped? + long animsToSkip = maxAnimsToSkip; + public: //! @inherit - void onFixedUpdate(WAL::ViewEntity &entity) override; + void onUpdate(WAL::ViewEntity &entity, std::chrono::nanoseconds dtime) override; + + //! @inherit + void onSelfUpdate(std::chrono::nanoseconds dtime) override; //! @brief A default constructor explicit AnimationsSystem(WAL::Wal &wal);