Merge branch 'main' into PlayerController

This commit is contained in:
Glence 2023-03-10 14:59:47 +08:00
commit 2cf67a1378
12 changed files with 190 additions and 67 deletions

View File

@ -38,6 +38,7 @@
idleClip: 227450439 idleClip: 227450439
runClip: 229125027 runClip: 229125027
pickUpClip: 219605278 pickUpClip: 219605278
controlAniSys: true
- EID: 1 - EID: 1
Name: Default Name: Default
IsActive: true IsActive: true
@ -80,3 +81,4 @@
idleClip: 0 idleClip: 0
runClip: 0 runClip: 0
pickUpClip: 0 pickUpClip: 0
controlAniSys: false

View File

@ -13,6 +13,8 @@ namespace SHADE.Test
private AnimationClipAsset runClip; private AnimationClipAsset runClip;
[SerializeField] [SerializeField]
private AnimationClipAsset pickUpClip; private AnimationClipAsset pickUpClip;
[SerializeField]
private bool controlAniSys = false;
#endregion #endregion
#region Components #region Components
@ -34,20 +36,31 @@ namespace SHADE.Test
// Play animations // Play animations
if (Input.GetKeyUp(Input.KeyCode.Equals)) if (Input.GetKeyUp(Input.KeyCode.Equals))
{ {
if (fullClip)
playFunc(fullClip); playFunc(fullClip);
} }
else if (Input.GetKeyUp(Input.KeyCode.Alpha1)) else if (Input.GetKeyUp(Input.KeyCode.Alpha1))
{ {
if (idleClip)
playFunc(idleClip); playFunc(idleClip);
} }
else if (Input.GetKeyUp(Input.KeyCode.Alpha2)) else if (Input.GetKeyUp(Input.KeyCode.Alpha2))
{ {
if (runClip)
playFunc(runClip); playFunc(runClip);
} }
else if (Input.GetKeyUp(Input.KeyCode.Alpha3)) else if (Input.GetKeyUp(Input.KeyCode.Alpha3))
{ {
if (pickUpClip)
playFunc(pickUpClip); playFunc(pickUpClip);
} }
// Play and pause
if (controlAniSys && Input.GetKeyUp(Input.KeyCode.Space))
{
AnimationSystem.TimeScale = AnimationSystem.TimeScale > 0.0f ? 0.0f
: AnimationSystem.DefaultTimeScale;
}
} }
#endregion #endregion
} }

View File

@ -32,6 +32,7 @@ namespace SHADE
void SHAnimationSystem::UpdateRoutine::Execute(double dt) noexcept void SHAnimationSystem::UpdateRoutine::Execute(double dt) noexcept
{ {
auto& animators = SHComponentManager::GetDense<SHAnimatorComponent>(); auto& animators = SHComponentManager::GetDense<SHAnimatorComponent>();
dt *= reinterpret_cast<SHAnimationSystem*>(system)->TimeScale;
for (auto& animator : animators) for (auto& animator : animators)
{ {
animator.Update(dt); animator.Update(dt);

View File

@ -42,6 +42,23 @@ namespace SHADE
void Execute(double dt) noexcept override final; void Execute(double dt) noexcept override final;
}; };
/*---------------------------------------------------------------------------------*/
/* Constants */
/*---------------------------------------------------------------------------------*/
/// <summary>
/// Default time scale used by the system.
/// </summary>
static constexpr double DEFAULT_TIME_SCALE = 1.0;
/*---------------------------------------------------------------------------------*/
/* Public Data Members */
/*---------------------------------------------------------------------------------*/
/// <summary>
/// Used by the system to multiply the given delta time to scale the animation
/// speed.
/// </summary>
double TimeScale = DEFAULT_TIME_SCALE;
/*---------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------*/
/* Constructors */ /* Constructors */
/*---------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------*/

View File

@ -29,6 +29,17 @@ namespace SHADE
/// </summary> /// </summary>
public value struct AnimationClipAsset public value struct AnimationClipAsset
{ {
public:
/*-----------------------------------------------------------------------------*/
/* Operator Overloads */
/*-----------------------------------------------------------------------------*/
/// <summary>
/// Implicit conversion operator to enable checking if a AnimationClip is valid.
/// </summary>
/// <param name="gameObj">Asset to check.</param>
/// <returns>True if the Asset is valid.</returns>
static operator bool(AnimationClipAsset asset);
internal: internal:
/*-----------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------*/
/* Properties */ /* Properties */
@ -57,16 +68,6 @@ namespace SHADE
/// <param name="AnimationClipId">AssetID to the AnimationClip asset.</param> /// <param name="AnimationClipId">AssetID to the AnimationClip asset.</param>
AnimationClipAsset(AssetID AnimationClipId); AnimationClipAsset(AssetID AnimationClipId);
/*-----------------------------------------------------------------------------*/
/* Operator Overloads */
/*-----------------------------------------------------------------------------*/
/// <summary>
/// Implicit conversion operator to enable checking if a AnimationClip is valid.
/// </summary>
/// <param name="gameObj">Asset to check.</param>
/// <returns>True if the Asset is valid.</returns>
static operator bool(AnimationClipAsset asset);
/*-----------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------*/
/* Conversion Operators */ /* Conversion Operators */
/*-----------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------*/

View File

@ -28,6 +28,17 @@ namespace SHADE
/// </summary> /// </summary>
public value struct AnimationControllerAsset public value struct AnimationControllerAsset
{ {
public:
/*-----------------------------------------------------------------------------*/
/* Operator Overloads */
/*-----------------------------------------------------------------------------*/
/// <summary>
/// Implicit conversion operator to enable checking if a AnimationController is valid.
/// </summary>
/// <param name="gameObj">Asset to check.</param>
/// <returns>True if the Asset is valid.</returns>
static operator bool(AnimationControllerAsset asset);
internal: internal:
/*-----------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------*/
/* Properties */ /* Properties */
@ -56,16 +67,6 @@ namespace SHADE
/// <param name="AnimationControllerId">AssetID to the AnimationController asset.</param> /// <param name="AnimationControllerId">AssetID to the AnimationController asset.</param>
AnimationControllerAsset(AssetID AnimationControllerId); AnimationControllerAsset(AssetID AnimationControllerId);
/*-----------------------------------------------------------------------------*/
/* Operator Overloads */
/*-----------------------------------------------------------------------------*/
/// <summary>
/// Implicit conversion operator to enable checking if a AnimationController is valid.
/// </summary>
/// <param name="gameObj">Asset to check.</param>
/// <returns>True if the Asset is valid.</returns>
static operator bool(AnimationControllerAsset asset);
/*-----------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------*/
/* Conversion Operators */ /* Conversion Operators */
/*-----------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------*/

View File

@ -28,6 +28,17 @@ namespace SHADE
/// </summary> /// </summary>
public value struct AnimationRigAsset public value struct AnimationRigAsset
{ {
public:
/*-----------------------------------------------------------------------------*/
/* Operator Overloads */
/*-----------------------------------------------------------------------------*/
/// <summary>
/// Implicit conversion operator to enable checking if a AnimationRig is valid.
/// </summary>
/// <param name="gameObj">Asset to check.</param>
/// <returns>True if the Asset is valid.</returns>
static operator bool(AnimationRigAsset asset);
internal: internal:
/*-----------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------*/
/* Properties */ /* Properties */
@ -56,16 +67,6 @@ namespace SHADE
/// <param name="AnimationRigId">AssetID to the AnimationRig asset.</param> /// <param name="AnimationRigId">AssetID to the AnimationRig asset.</param>
AnimationRigAsset(AssetID AnimationRigId); AnimationRigAsset(AssetID AnimationRigId);
/*-----------------------------------------------------------------------------*/
/* Operator Overloads */
/*-----------------------------------------------------------------------------*/
/// <summary>
/// Implicit conversion operator to enable checking if a AnimationRig is valid.
/// </summary>
/// <param name="gameObj">Asset to check.</param>
/// <returns>True if the Asset is valid.</returns>
static operator bool(AnimationRigAsset asset);
/*-----------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------*/
/* Conversion Operators */ /* Conversion Operators */
/*-----------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------*/

View File

@ -28,6 +28,17 @@ namespace SHADE
/// </summary> /// </summary>
public value struct FontAsset public value struct FontAsset
{ {
public:
/*-----------------------------------------------------------------------------*/
/* Operator Overloads */
/*-----------------------------------------------------------------------------*/
/// <summary>
/// Implicit conversion operator to enable checking if a Font is valid.
/// </summary>
/// <param name="gameObj">Asset to check.</param>
/// <returns>True if the Asset is valid.</returns>
static operator bool(FontAsset asset);
internal: internal:
/*-----------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------*/
/* Properties */ /* Properties */
@ -56,16 +67,6 @@ namespace SHADE
/// <param name="fontId">AssetID to the font asset.</param> /// <param name="fontId">AssetID to the font asset.</param>
FontAsset(AssetID fontId); FontAsset(AssetID fontId);
/*-----------------------------------------------------------------------------*/
/* Operator Overloads */
/*-----------------------------------------------------------------------------*/
/// <summary>
/// Implicit conversion operator to enable checking if a Font is valid.
/// </summary>
/// <param name="gameObj">Asset to check.</param>
/// <returns>True if the Asset is valid.</returns>
static operator bool(FontAsset asset);
/*-----------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------*/
/* Conversion Operators */ /* Conversion Operators */
/*-----------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------*/

View File

@ -28,6 +28,17 @@ namespace SHADE
/// </summary> /// </summary>
public value struct MaterialAsset public value struct MaterialAsset
{ {
public:
/*-----------------------------------------------------------------------------*/
/* Operator Overloads */
/*-----------------------------------------------------------------------------*/
/// <summary>
/// Implicit conversion operator to enable checking if a Material is valid.
/// </summary>
/// <param name="gameObj">Asset to check.</param>
/// <returns>True if the Asset is valid.</returns>
static operator bool(MaterialAsset asset);
internal: internal:
/*-----------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------*/
/* Properties */ /* Properties */
@ -56,16 +67,6 @@ namespace SHADE
/// <param name="MaterialId">AssetID to the Material asset.</param> /// <param name="MaterialId">AssetID to the Material asset.</param>
MaterialAsset(AssetID MaterialId); MaterialAsset(AssetID MaterialId);
/*-----------------------------------------------------------------------------*/
/* Operator Overloads */
/*-----------------------------------------------------------------------------*/
/// <summary>
/// Implicit conversion operator to enable checking if a Material is valid.
/// </summary>
/// <param name="gameObj">Asset to check.</param>
/// <returns>True if the Asset is valid.</returns>
static operator bool(MaterialAsset asset);
/*-----------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------*/
/* Conversion Operators */ /* Conversion Operators */
/*-----------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------*/

View File

@ -28,6 +28,17 @@ namespace SHADE
/// </summary> /// </summary>
public value struct MeshAsset public value struct MeshAsset
{ {
public:
/*-----------------------------------------------------------------------------*/
/* Operator Overloads */
/*-----------------------------------------------------------------------------*/
/// <summary>
/// Implicit conversion operator to enable checking if a Mesh is valid.
/// </summary>
/// <param name="gameObj">Asset to check.</param>
/// <returns>True if the Asset is valid.</returns>
static operator bool(MeshAsset asset);
internal: internal:
/*-----------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------*/
/* Properties */ /* Properties */
@ -56,16 +67,6 @@ namespace SHADE
/// <param name="meshId">AssetID to the Mesh asset.</param> /// <param name="meshId">AssetID to the Mesh asset.</param>
MeshAsset(AssetID meshId); MeshAsset(AssetID meshId);
/*-----------------------------------------------------------------------------*/
/* Operator Overloads */
/*-----------------------------------------------------------------------------*/
/// <summary>
/// Implicit conversion operator to enable checking if a Mesh is valid.
/// </summary>
/// <param name="gameObj">Asset to check.</param>
/// <returns>True if the Asset is valid.</returns>
static operator bool(MeshAsset asset);
/*-----------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------*/
/* Conversion Operators */ /* Conversion Operators */
/*-----------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------*/

View File

@ -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<SHAnimationSystem>();
return sys->TimeScale;
}
void AnimationSystem::TimeScale::set(double value)
{
auto sys = SHSystemManager::GetSystem<SHAnimationSystem>();
sys->TimeScale = value;
}
}

View File

@ -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
{
/// <summary>
/// Static class for interfacing with the animation system.
/// </summary>
public ref class AnimationSystem abstract sealed
{
public:
/*-----------------------------------------------------------------------------*/
/* Constants */
/*-----------------------------------------------------------------------------*/
/// <summary>
/// Default time scale used by the system.
/// </summary>
literal double DefaultTimeScale = SHAnimationSystem::DEFAULT_TIME_SCALE;
/*-----------------------------------------------------------------------------*/
/* Properties */
/*-----------------------------------------------------------------------------*/
/// <summary>
/// Used by the system to multiply the given delta time to scale the animation
/// speed.
/// </summary>
static property double TimeScale
{
double get();
void set(double value);
}
};
}