Added time scale for animation system #412

Merged
Pycorax merged 1 commits from SP3-22-AnimationController into main 2023-03-10 14:58:03 +08:00
6 changed files with 114 additions and 1 deletions
Showing only changes of commit 8c0ad47921 - Show all commits

View File

@ -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
pickUpClip: 0
controlAniSys: false

View File

@ -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
}

View File

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

View File

@ -42,6 +42,23 @@ namespace SHADE
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 */
/*---------------------------------------------------------------------------------*/

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);
}
};
}