mirror of
https://github.com/zoriya/Bomberman.git
synced 2026-05-29 17:02:11 +00:00
Merge pull request #246 from AnonymusRaccoon/anim_tricks
it's better (animations optis)
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -5,6 +5,9 @@
|
||||
#include "AnimationsSystem.hpp"
|
||||
#include "Component/Animation/AnimationsComponent.hpp"
|
||||
#include "Model/Model.hpp"
|
||||
#include <iostream>
|
||||
#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<Drawable3DComponent, AnimationsComponent> &entity)
|
||||
void AnimationsSystem::onUpdate(WAL::ViewEntity<Drawable3DComponent, AnimationsComponent> &entity, std::chrono::nanoseconds)
|
||||
{
|
||||
auto &model = entity.get<Drawable3DComponent>();
|
||||
auto &anim = entity.get<AnimationsComponent>();
|
||||
|
||||
if (anim.isAnimDisabled())
|
||||
return;
|
||||
auto modelPtr = std::dynamic_pointer_cast<RAY::Drawables::Drawables3D::Model>(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<Drawable3DComponent>();
|
||||
auto modelPtr = std::dynamic_pointer_cast<RAY::Drawables::Drawables3D::Model>(model.drawable);
|
||||
if (modelPtr) {
|
||||
modelPtr->setAnimation(anim.getCurrentModelAnim());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void AnimationsSystem::onSelfUpdate(std::chrono::nanoseconds)
|
||||
{
|
||||
this->maxAnimsToSkip = this->_wal.getScene()->view<AnimationsComponent, TagComponent<Player>, PositionComponent>().size() - 1;
|
||||
if (this->animsToSkip <= 0) {
|
||||
this->animsToSkip = this->maxAnimsToSkip + 1;
|
||||
}
|
||||
this->animsToSkip--;
|
||||
}
|
||||
}
|
||||
@@ -12,9 +12,20 @@ namespace BBM
|
||||
{
|
||||
class AnimationsSystem : public WAL::System<Drawable3DComponent, AnimationsComponent>
|
||||
{
|
||||
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<Drawable3DComponent, AnimationsComponent> &entity) override;
|
||||
void onUpdate(WAL::ViewEntity<Drawable3DComponent, AnimationsComponent> &entity, std::chrono::nanoseconds dtime) override;
|
||||
|
||||
//! @inherit
|
||||
void onSelfUpdate(std::chrono::nanoseconds dtime) override;
|
||||
|
||||
//! @brief A default constructor
|
||||
explicit AnimationsSystem(WAL::Wal &wal);
|
||||
|
||||
Reference in New Issue
Block a user