From 089eb9de261eaca1d8aba027fcbccfaf8bf20798 Mon Sep 17 00:00:00 2001 From: Kah Wei Date: Fri, 10 Mar 2023 14:11:59 +0800 Subject: [PATCH 1/2] Fixed bug where C# Asset implicit bool conversion operators were internal --- Assets/Scripts/AnimTest.cs | 12 ++++++---- .../src/Assets/AnimationClipAsset.hxx | 21 +++++++++-------- .../src/Assets/AnimationControllerAsset.hxx | 23 ++++++++++--------- .../src/Assets/AnimationRigAsset.hxx | 21 +++++++++-------- SHADE_Managed/src/Assets/FontAsset.hxx | 21 +++++++++-------- SHADE_Managed/src/Assets/MaterialAsset.hxx | 21 +++++++++-------- SHADE_Managed/src/Assets/MeshAsset.hxx | 23 ++++++++++--------- 7 files changed, 76 insertions(+), 66 deletions(-) diff --git a/Assets/Scripts/AnimTest.cs b/Assets/Scripts/AnimTest.cs index 4ceccbe6..584d046f 100644 --- a/Assets/Scripts/AnimTest.cs +++ b/Assets/Scripts/AnimTest.cs @@ -34,19 +34,23 @@ namespace SHADE.Test // Play animations if (Input.GetKeyUp(Input.KeyCode.Equals)) { - playFunc(fullClip); + if (fullClip) + playFunc(fullClip); } else if (Input.GetKeyUp(Input.KeyCode.Alpha1)) { - playFunc(idleClip); + if (idleClip) + playFunc(idleClip); } else if (Input.GetKeyUp(Input.KeyCode.Alpha2)) { - playFunc(runClip); + if (runClip) + playFunc(runClip); } else if (Input.GetKeyUp(Input.KeyCode.Alpha3)) { - playFunc(pickUpClip); + if (pickUpClip) + playFunc(pickUpClip); } } #endregion diff --git a/SHADE_Managed/src/Assets/AnimationClipAsset.hxx b/SHADE_Managed/src/Assets/AnimationClipAsset.hxx index 5a8c7845..2a4e52b3 100644 --- a/SHADE_Managed/src/Assets/AnimationClipAsset.hxx +++ b/SHADE_Managed/src/Assets/AnimationClipAsset.hxx @@ -29,6 +29,17 @@ namespace SHADE /// public value struct AnimationClipAsset { + public: + /*-----------------------------------------------------------------------------*/ + /* Operator Overloads */ + /*-----------------------------------------------------------------------------*/ + /// + /// Implicit conversion operator to enable checking if a AnimationClip is valid. + /// + /// Asset to check. + /// True if the Asset is valid. + static operator bool(AnimationClipAsset asset); + internal: /*-----------------------------------------------------------------------------*/ /* Properties */ @@ -57,16 +68,6 @@ namespace SHADE /// AssetID to the AnimationClip asset. AnimationClipAsset(AssetID AnimationClipId); - /*-----------------------------------------------------------------------------*/ - /* Operator Overloads */ - /*-----------------------------------------------------------------------------*/ - /// - /// Implicit conversion operator to enable checking if a AnimationClip is valid. - /// - /// Asset to check. - /// True if the Asset is valid. - static operator bool(AnimationClipAsset asset); - /*-----------------------------------------------------------------------------*/ /* Conversion Operators */ /*-----------------------------------------------------------------------------*/ diff --git a/SHADE_Managed/src/Assets/AnimationControllerAsset.hxx b/SHADE_Managed/src/Assets/AnimationControllerAsset.hxx index 1be74fb9..7dc3d3d7 100644 --- a/SHADE_Managed/src/Assets/AnimationControllerAsset.hxx +++ b/SHADE_Managed/src/Assets/AnimationControllerAsset.hxx @@ -28,7 +28,18 @@ namespace SHADE /// public value struct AnimationControllerAsset { - internal: + public: + /*-----------------------------------------------------------------------------*/ + /* Operator Overloads */ + /*-----------------------------------------------------------------------------*/ + /// + /// Implicit conversion operator to enable checking if a AnimationController is valid. + /// + /// Asset to check. + /// True if the Asset is valid. + static operator bool(AnimationControllerAsset asset); + + internal: /*-----------------------------------------------------------------------------*/ /* Properties */ /*-----------------------------------------------------------------------------*/ @@ -56,16 +67,6 @@ namespace SHADE /// AssetID to the AnimationController asset. AnimationControllerAsset(AssetID AnimationControllerId); - /*-----------------------------------------------------------------------------*/ - /* Operator Overloads */ - /*-----------------------------------------------------------------------------*/ - /// - /// Implicit conversion operator to enable checking if a AnimationController is valid. - /// - /// Asset to check. - /// True if the Asset is valid. - static operator bool(AnimationControllerAsset asset); - /*-----------------------------------------------------------------------------*/ /* Conversion Operators */ /*-----------------------------------------------------------------------------*/ diff --git a/SHADE_Managed/src/Assets/AnimationRigAsset.hxx b/SHADE_Managed/src/Assets/AnimationRigAsset.hxx index be43b7f0..09964d31 100644 --- a/SHADE_Managed/src/Assets/AnimationRigAsset.hxx +++ b/SHADE_Managed/src/Assets/AnimationRigAsset.hxx @@ -28,6 +28,17 @@ namespace SHADE /// public value struct AnimationRigAsset { + public: + /*-----------------------------------------------------------------------------*/ + /* Operator Overloads */ + /*-----------------------------------------------------------------------------*/ + /// + /// Implicit conversion operator to enable checking if a AnimationRig is valid. + /// + /// Asset to check. + /// True if the Asset is valid. + static operator bool(AnimationRigAsset asset); + internal: /*-----------------------------------------------------------------------------*/ /* Properties */ @@ -56,16 +67,6 @@ namespace SHADE /// AssetID to the AnimationRig asset. AnimationRigAsset(AssetID AnimationRigId); - /*-----------------------------------------------------------------------------*/ - /* Operator Overloads */ - /*-----------------------------------------------------------------------------*/ - /// - /// Implicit conversion operator to enable checking if a AnimationRig is valid. - /// - /// Asset to check. - /// True if the Asset is valid. - static operator bool(AnimationRigAsset asset); - /*-----------------------------------------------------------------------------*/ /* Conversion Operators */ /*-----------------------------------------------------------------------------*/ diff --git a/SHADE_Managed/src/Assets/FontAsset.hxx b/SHADE_Managed/src/Assets/FontAsset.hxx index 89239224..5c3b4e11 100644 --- a/SHADE_Managed/src/Assets/FontAsset.hxx +++ b/SHADE_Managed/src/Assets/FontAsset.hxx @@ -28,6 +28,17 @@ namespace SHADE /// public value struct FontAsset { + public: + /*-----------------------------------------------------------------------------*/ + /* Operator Overloads */ + /*-----------------------------------------------------------------------------*/ + /// + /// Implicit conversion operator to enable checking if a Font is valid. + /// + /// Asset to check. + /// True if the Asset is valid. + static operator bool(FontAsset asset); + internal: /*-----------------------------------------------------------------------------*/ /* Properties */ @@ -56,16 +67,6 @@ namespace SHADE /// AssetID to the font asset. FontAsset(AssetID fontId); - /*-----------------------------------------------------------------------------*/ - /* Operator Overloads */ - /*-----------------------------------------------------------------------------*/ - /// - /// Implicit conversion operator to enable checking if a Font is valid. - /// - /// Asset to check. - /// True if the Asset is valid. - static operator bool(FontAsset asset); - /*-----------------------------------------------------------------------------*/ /* Conversion Operators */ /*-----------------------------------------------------------------------------*/ diff --git a/SHADE_Managed/src/Assets/MaterialAsset.hxx b/SHADE_Managed/src/Assets/MaterialAsset.hxx index 5380b286..a5a0909b 100644 --- a/SHADE_Managed/src/Assets/MaterialAsset.hxx +++ b/SHADE_Managed/src/Assets/MaterialAsset.hxx @@ -28,6 +28,17 @@ namespace SHADE /// public value struct MaterialAsset { + public: + /*-----------------------------------------------------------------------------*/ + /* Operator Overloads */ + /*-----------------------------------------------------------------------------*/ + /// + /// Implicit conversion operator to enable checking if a Material is valid. + /// + /// Asset to check. + /// True if the Asset is valid. + static operator bool(MaterialAsset asset); + internal: /*-----------------------------------------------------------------------------*/ /* Properties */ @@ -56,16 +67,6 @@ namespace SHADE /// AssetID to the Material asset. MaterialAsset(AssetID MaterialId); - /*-----------------------------------------------------------------------------*/ - /* Operator Overloads */ - /*-----------------------------------------------------------------------------*/ - /// - /// Implicit conversion operator to enable checking if a Material is valid. - /// - /// Asset to check. - /// True if the Asset is valid. - static operator bool(MaterialAsset asset); - /*-----------------------------------------------------------------------------*/ /* Conversion Operators */ /*-----------------------------------------------------------------------------*/ diff --git a/SHADE_Managed/src/Assets/MeshAsset.hxx b/SHADE_Managed/src/Assets/MeshAsset.hxx index 26625c1a..63922d65 100644 --- a/SHADE_Managed/src/Assets/MeshAsset.hxx +++ b/SHADE_Managed/src/Assets/MeshAsset.hxx @@ -28,7 +28,18 @@ namespace SHADE /// public value struct MeshAsset { - internal: + public: + /*-----------------------------------------------------------------------------*/ + /* Operator Overloads */ + /*-----------------------------------------------------------------------------*/ + /// + /// Implicit conversion operator to enable checking if a Mesh is valid. + /// + /// Asset to check. + /// True if the Asset is valid. + static operator bool(MeshAsset asset); + + internal: /*-----------------------------------------------------------------------------*/ /* Properties */ /*-----------------------------------------------------------------------------*/ @@ -56,16 +67,6 @@ namespace SHADE /// AssetID to the Mesh asset. MeshAsset(AssetID meshId); - /*-----------------------------------------------------------------------------*/ - /* Operator Overloads */ - /*-----------------------------------------------------------------------------*/ - /// - /// Implicit conversion operator to enable checking if a Mesh is valid. - /// - /// Asset to check. - /// True if the Asset is valid. - static operator bool(MeshAsset asset); - /*-----------------------------------------------------------------------------*/ /* Conversion Operators */ /*-----------------------------------------------------------------------------*/ From 8c0ad47921354512826977e677f38047054d7d7f Mon Sep 17 00:00:00 2001 From: Kah Wei Date: Fri, 10 Mar 2023 14:55:49 +0800 Subject: [PATCH 2/2] Added timescale for animation system --- Assets/Scenes/anim.shade | 4 +- Assets/Scripts/AnimTest.cs | 9 ++++ .../src/Animation/SHAnimationSystem.cpp | 1 + .../src/Animation/SHAnimationSystem.h | 17 +++++++ .../src/Graphics/AnimationSystem.cxx | 37 +++++++++++++++ .../src/Graphics/AnimationSystem.hxx | 47 +++++++++++++++++++ 6 files changed, 114 insertions(+), 1 deletion(-) create mode 100644 SHADE_Managed/src/Graphics/AnimationSystem.cxx create mode 100644 SHADE_Managed/src/Graphics/AnimationSystem.hxx diff --git a/Assets/Scenes/anim.shade b/Assets/Scenes/anim.shade index 986195f6..5c9c7163 100644 --- a/Assets/Scenes/anim.shade +++ b/Assets/Scenes/anim.shade @@ -38,6 +38,7 @@ idleClip: 227450439 runClip: 229125027 pickUpClip: 219605278 + controlAniSys: true - EID: 1 Name: Default IsActive: true @@ -79,4 +80,5 @@ fullClip: 231416496 idleClip: 0 runClip: 0 - pickUpClip: 0 \ No newline at end of file + pickUpClip: 0 + controlAniSys: false \ No newline at end of file diff --git a/Assets/Scripts/AnimTest.cs b/Assets/Scripts/AnimTest.cs index 584d046f..b0761476 100644 --- a/Assets/Scripts/AnimTest.cs +++ b/Assets/Scripts/AnimTest.cs @@ -13,6 +13,8 @@ namespace SHADE.Test private AnimationClipAsset runClip; [SerializeField] private AnimationClipAsset pickUpClip; + [SerializeField] + private bool controlAniSys = false; #endregion #region Components @@ -52,6 +54,13 @@ namespace SHADE.Test if (pickUpClip) playFunc(pickUpClip); } + + // Play and pause + if (controlAniSys && Input.GetKeyUp(Input.KeyCode.Space)) + { + AnimationSystem.TimeScale = AnimationSystem.TimeScale > 0.0f ? 0.0f + : AnimationSystem.DefaultTimeScale; + } } #endregion } diff --git a/SHADE_Engine/src/Animation/SHAnimationSystem.cpp b/SHADE_Engine/src/Animation/SHAnimationSystem.cpp index 6f41e2aa..e38d2287 100644 --- a/SHADE_Engine/src/Animation/SHAnimationSystem.cpp +++ b/SHADE_Engine/src/Animation/SHAnimationSystem.cpp @@ -32,6 +32,7 @@ namespace SHADE void SHAnimationSystem::UpdateRoutine::Execute(double dt) noexcept { auto& animators = SHComponentManager::GetDense(); + dt *= reinterpret_cast(system)->TimeScale; for (auto& animator : animators) { animator.Update(dt); diff --git a/SHADE_Engine/src/Animation/SHAnimationSystem.h b/SHADE_Engine/src/Animation/SHAnimationSystem.h index 9c2cd073..fd972e47 100644 --- a/SHADE_Engine/src/Animation/SHAnimationSystem.h +++ b/SHADE_Engine/src/Animation/SHAnimationSystem.h @@ -42,6 +42,23 @@ namespace SHADE void Execute(double dt) noexcept override final; }; + /*---------------------------------------------------------------------------------*/ + /* Constants */ + /*---------------------------------------------------------------------------------*/ + /// + /// Default time scale used by the system. + /// + static constexpr double DEFAULT_TIME_SCALE = 1.0; + + /*---------------------------------------------------------------------------------*/ + /* Public Data Members */ + /*---------------------------------------------------------------------------------*/ + /// + /// Used by the system to multiply the given delta time to scale the animation + /// speed. + /// + double TimeScale = DEFAULT_TIME_SCALE; + /*---------------------------------------------------------------------------------*/ /* Constructors */ /*---------------------------------------------------------------------------------*/ diff --git a/SHADE_Managed/src/Graphics/AnimationSystem.cxx b/SHADE_Managed/src/Graphics/AnimationSystem.cxx new file mode 100644 index 00000000..8ed11c28 --- /dev/null +++ b/SHADE_Managed/src/Graphics/AnimationSystem.cxx @@ -0,0 +1,37 @@ +/************************************************************************************//*! +\file AnimationSystem.cxx +\author Tng Kah Wei, kahwei.tng, 390009620 +\par email: kahwei.tng\@digipen.edu +\date Mar 10, 2023 +\brief Contains the definition of the functions of the managed AnimationSystem + static class. + + Note: This file is written in C++17/CLI. + +Copyright (C) 2023 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. +*//*************************************************************************************/ +// Precompiled Headers +#include "SHpch.h" +// Primary Header +#include "AnimationSystem.hxx" +// External Dependencies +#include "ECS_Base/Managers/SHSystemManager.h" + +namespace SHADE +{ + /*---------------------------------------------------------------------------------*/ + /* Properties */ + /*---------------------------------------------------------------------------------*/ + double AnimationSystem::TimeScale::get() + { + auto sys = SHSystemManager::GetSystem(); + return sys->TimeScale; + } + void AnimationSystem::TimeScale::set(double value) + { + auto sys = SHSystemManager::GetSystem(); + sys->TimeScale = value; + } +} diff --git a/SHADE_Managed/src/Graphics/AnimationSystem.hxx b/SHADE_Managed/src/Graphics/AnimationSystem.hxx new file mode 100644 index 00000000..fe3bcd59 --- /dev/null +++ b/SHADE_Managed/src/Graphics/AnimationSystem.hxx @@ -0,0 +1,47 @@ +/************************************************************************************//*! +\file AnimationSystem.hxx +\author Tng Kah Wei, kahwei.tng, 390009620 +\par email: kahwei.tng\@digipen.edu +\date Mar 10, 2023 +\brief Contains the definition of the managed AnimationSystem static class. + + Note: This file is written in C++17/CLI. + +Copyright (C) 2023 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. +*//*************************************************************************************/ +#pragma once + +#include "Animation/SHAnimationSystem.h" + +namespace SHADE +{ + /// + /// Static class for interfacing with the animation system. + /// + public ref class AnimationSystem abstract sealed + { + public: + /*-----------------------------------------------------------------------------*/ + /* Constants */ + /*-----------------------------------------------------------------------------*/ + /// + /// Default time scale used by the system. + /// + literal double DefaultTimeScale = SHAnimationSystem::DEFAULT_TIME_SCALE; + + /*-----------------------------------------------------------------------------*/ + /* Properties */ + /*-----------------------------------------------------------------------------*/ + /// + /// Used by the system to multiply the given delta time to scale the animation + /// speed. + /// + static property double TimeScale + { + double get(); + void set(double value); + } + }; +}