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 1/3] 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); From a5b794b1d1bc11a7e59655f3940b7e44abb103ea Mon Sep 17 00:00:00 2001 From: HENRY Benjamin Date: Sun, 20 Jun 2021 10:34:55 +0200 Subject: [PATCH 2/3] added ia to parser --- sources/Parser/ParserYaml.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/sources/Parser/ParserYaml.cpp b/sources/Parser/ParserYaml.cpp index b3a6ce82..24075fce 100644 --- a/sources/Parser/ParserYaml.cpp +++ b/sources/Parser/ParserYaml.cpp @@ -87,6 +87,7 @@ namespace BBM { auto *bombHolder = entity.tryGetComponent(); auto *model = entity.tryGetComponent(); auto *speed = entity.tryGetComponent(); + auto *controllable = entity.tryGetComponent(); auto name = entity.getName(); if (!position || !bombHolder || !model || !speed) @@ -97,6 +98,7 @@ namespace BBM { _player << "max_bomb: " << std::to_string(bombHolder->maxBombCount) << std::endl << " "; _player << "explosion_radius: " << std::to_string(bombHolder->explosionRadius) << std::endl << " "; _player << "speed: " << std::to_string(speed->speed) << std::endl << " "; + _player << "ia: " << (controllable->layout == ControllableComponent::AI ? "true" : "false") << std::endl << " "; _player << "position: [" << std::to_string(position->getX()) << "," << std::to_string(position->getY()) << "," << std::to_string(position->getZ()) << "]"; } @@ -177,8 +179,8 @@ namespace BBM { }); if ((tmpAssets.find("red.png") == std::string::npos && tmpAssets.find("blue.png") == std::string::npos && - tmpAssets.find("green.png") == std::string::npos && tmpAssets.find("yellow.png") == std::string::npos && - tmpAssets.find("ai.png") == std::string::npos) || !std::filesystem::exists(tmpAssets)) { + tmpAssets.find("green.png") == std::string::npos && tmpAssets.find("yellow.png") == std::string::npos) + || !std::filesystem::exists(tmpAssets)) { throw (ParserError("One asset is invalid.")); } auto start = tmpAssets.find_last_of('/') + 1; @@ -194,7 +196,14 @@ namespace BBM { auto &ready = resumeScene->addEntity("ready") .addComponent(224 * (countPlayer + 1) + 200 * countPlayer, 1080 / 3, 0) .addComponent(); - playerLogo.addComponent(countPlayer, ready, playerTile, colors.at(colorStr)); + auto *lobby = playerLogo.addComponent(countPlayer, ready, playerTile, colors.at(colorStr)).tryGetComponent(); + if (node.getProperty("ia") == "true") { + auto *texture = dynamic_cast(ready.getComponent().drawable.get()); + lobby->ready = true; + lobby->layout = ControllableComponent::AI; + if (texture) + texture->use("assets/player/icons/ai.png"); + } } void ParserYAML::_loadPlayers(std::shared_ptr scene, Node &node) From 0c167c86bc2b8566bfc5cb84331f4cf1075ddd93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Le=20Bihan?= Date: Sun, 20 Jun 2021 11:10:16 +0200 Subject: [PATCH 3/3] adding more checking --- sources/Parser/ParserYaml.cpp | 4 ++++ sources/System/Animation/AnimationsSystem.cpp | 1 - 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/sources/Parser/ParserYaml.cpp b/sources/Parser/ParserYaml.cpp index 24075fce..c927991c 100644 --- a/sources/Parser/ParserYaml.cpp +++ b/sources/Parser/ParserYaml.cpp @@ -197,6 +197,10 @@ namespace BBM { .addComponent(224 * (countPlayer + 1) + 200 * countPlayer, 1080 / 3, 0) .addComponent(); auto *lobby = playerLogo.addComponent(countPlayer, ready, playerTile, colors.at(colorStr)).tryGetComponent(); + std::string iaPropertyValue = node.getProperty("ia"); + if (iaPropertyValue != "false" && iaPropertyValue != "true") { + throw ParserError("Invalid value for ia property"); + } if (node.getProperty("ia") == "true") { auto *texture = dynamic_cast(ready.getComponent().drawable.get()); lobby->ready = true; diff --git a/sources/System/Animation/AnimationsSystem.cpp b/sources/System/Animation/AnimationsSystem.cpp index 5d52924b..822fa6b2 100644 --- a/sources/System/Animation/AnimationsSystem.cpp +++ b/sources/System/Animation/AnimationsSystem.cpp @@ -5,7 +5,6 @@ #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"