diff --git a/SHADE_Engine/src/Animation/SHAnimationSystem.cpp b/SHADE_Engine/src/Animation/SHAnimationSystem.cpp index 28b1a80e..8c514e7c 100644 --- a/SHADE_Engine/src/Animation/SHAnimationSystem.cpp +++ b/SHADE_Engine/src/Animation/SHAnimationSystem.cpp @@ -9,12 +9,28 @@ Copyright (C) 2022 DigiPen Institute of Technology. Reproduction or disclosure of this file or its contents without the prior written consent of DigiPen Institute of Technology is prohibited. *//*************************************************************************************/ -// Pre-compiled Header +// Precompiled Header #include "SHpch.h" // Primary Include #include "SHAnimationSystem.h" +// Project Includes +#include "ECS_Base/Managers/SHComponentManager.h" +#include "SHAnimatorComponent.h" namespace SHADE { - + /*-----------------------------------------------------------------------------------*/ + /* System Routine Functions - UpdateRoutine */ + /*-----------------------------------------------------------------------------------*/ + SHAnimationSystem::UpdateRoutine::UpdateRoutine() + : SHSystemRoutine("Animation System Update", false) + {} + void SHAnimationSystem::UpdateRoutine::Execute(double dt) noexcept + { + auto& animators = SHComponentManager::GetDense(); + for (auto& animator : animators) + { + animator.Update(dt); + } + } } diff --git a/SHADE_Engine/src/Animation/SHAnimationSystem.h b/SHADE_Engine/src/Animation/SHAnimationSystem.h index eac839ad..96cd9a71 100644 --- a/SHADE_Engine/src/Animation/SHAnimationSystem.h +++ b/SHADE_Engine/src/Animation/SHAnimationSystem.h @@ -25,8 +25,24 @@ namespace SHADE /*-----------------------------------------------------------------------------------*/ /* Type Definitions */ /*-----------------------------------------------------------------------------------*/ + /// + /// System that is responsible for updating all animations. + /// class SH_API SHAnimationSystem : public SHSystem { - + public: + /*---------------------------------------------------------------------------------*/ + /* Type Definitions */ + /*---------------------------------------------------------------------------------*/ + /// + /// Responsible for updating the playback of all animator components and computing + /// the required bone matrices. + /// + class SH_API UpdateRoutine final : public SHSystemRoutine + { + public: + UpdateRoutine(); + void Execute(double dt) noexcept override final; + }; }; } \ No newline at end of file diff --git a/SHADE_Engine/src/Animation/SHAnimatorComponent.cpp b/SHADE_Engine/src/Animation/SHAnimatorComponent.cpp index 3b4524e1..61c0e6af 100644 --- a/SHADE_Engine/src/Animation/SHAnimatorComponent.cpp +++ b/SHADE_Engine/src/Animation/SHAnimatorComponent.cpp @@ -9,7 +9,7 @@ Copyright (C) 2022 DigiPen Institute of Technology. Reproduction or disclosure of this file or its contents without the prior written consent of DigiPen Institute of Technology is prohibited. *//*************************************************************************************/ -// Pre-compiled Header +// Precompiled Header #include "SHpch.h" // Primary Include #include "SHAnimatorComponent.h" @@ -19,7 +19,13 @@ of DigiPen Institute of Technology is prohibited. namespace SHADE { - + /*-----------------------------------------------------------------------------------*/ + /* Update Functions */ + /*-----------------------------------------------------------------------------------*/ + void SHAnimatorComponent::Update(float dt) + { + // Set everything to identity + } } RTTR_REGISTRATION diff --git a/SHADE_Engine/src/Animation/SHAnimatorComponent.h b/SHADE_Engine/src/Animation/SHAnimatorComponent.h index be1bc742..dd71cc0e 100644 --- a/SHADE_Engine/src/Animation/SHAnimatorComponent.h +++ b/SHADE_Engine/src/Animation/SHAnimatorComponent.h @@ -37,10 +37,29 @@ namespace SHADE class SH_API SHAnimatorComponent final : public SHComponent { public: + /*---------------------------------------------------------------------------------*/ + /* Usage Functions */ + /*---------------------------------------------------------------------------------*/ + /*void Play(); + void PlayFromStart(); + void Pause(); + void Stop();*/ + /*---------------------------------------------------------------------------------*/ /* Getter Functions */ /*---------------------------------------------------------------------------------*/ const std::vector& GetBoneMatrices() const noexcept { return boneMatrices; } + bool IsPlaying() const { return isPlaying; } + + /*---------------------------------------------------------------------------------*/ + /* Update Functions */ + /*---------------------------------------------------------------------------------*/ + /// + /// Updates the current state of the animation if one is specified based on the + /// current animation clip and frames. This will update the bone matrices. + /// + /// Time passed since the last frame. + void Update(float dt); private: /*---------------------------------------------------------------------------------*/ @@ -49,6 +68,7 @@ namespace SHADE Handle rig; std::vector boneMatrices; float currPlaybackTime = 0.0f; + bool isPlaying = false; /*---------------------------------------------------------------------------------*/ /* RTTR */ diff --git a/SHADE_Engine/src/Animation/SHRig.cpp b/SHADE_Engine/src/Animation/SHRig.cpp index 0ef2a0e6..2214baa5 100644 --- a/SHADE_Engine/src/Animation/SHRig.cpp +++ b/SHADE_Engine/src/Animation/SHRig.cpp @@ -30,6 +30,7 @@ namespace SHADE return; // Do a recursive depth first traversal to populate the rig + nodeCount = 0; rootNode = recurseCreateNode(asset, asset.root); } @@ -54,6 +55,11 @@ namespace SHADE return {}; } + int SHRig::GetNodeCount() const noexcept + { + return nodeCount; + } + /*-----------------------------------------------------------------------------------*/ /* Helper Functions */ /*-----------------------------------------------------------------------------------*/ @@ -61,6 +67,7 @@ namespace SHADE { // Construct the node auto newNode = nodeStore.Create(); + ++nodeCount; // Fill the node with data const auto& NODE_DATA = asset.nodeDataCollection.at(sourceNode->idRef); diff --git a/SHADE_Engine/src/Animation/SHRig.h b/SHADE_Engine/src/Animation/SHRig.h index 39dbe1c4..af1b79ec 100644 --- a/SHADE_Engine/src/Animation/SHRig.h +++ b/SHADE_Engine/src/Animation/SHRig.h @@ -53,7 +53,7 @@ namespace SHADE explicit SHRig(const SHRigAsset& asset); /*---------------------------------------------------------------------------------*/ - /* Usage Functions */ + /* Getter Functions */ /*---------------------------------------------------------------------------------*/ /// /// Retrieves the name of a node. @@ -73,6 +73,11 @@ namespace SHADE /// handle will be provided. /// Handle GetNode(const std::string& name) const noexcept; + /// + /// Returns the number of nodes in the rig. This matches the number of bone matrices + /// needed. + /// + int GetNodeCount() const noexcept; private: /*---------------------------------------------------------------------------------*/ @@ -81,6 +86,7 @@ namespace SHADE Handle rootNode; std::unordered_map, std::string> nodeNames; std::unordered_map> nodesByName; + int nodeCount = 0; SHResourceLibrary nodeStore; /*---------------------------------------------------------------------------------*/