Add Engine::UpdateCount to sync gameplay logic updates with game loop rather than draw frames

This commit is contained in:
Wojtek Figat
2024-04-17 13:31:12 +02:00
parent 692a61c948
commit e53ab10145
4 changed files with 14 additions and 6 deletions

View File

@@ -60,6 +60,7 @@ namespace EngineImpl
DateTime Engine::StartupTime;
bool Engine::HasFocus = false;
uint64 Engine::UpdateCount = 0;
uint64 Engine::FrameCount = 0;
Action Engine::FixedUpdate;
Action Engine::Update;
@@ -296,6 +297,8 @@ void Engine::OnUpdate()
{
PROFILE_CPU_NAMED("Update");
UpdateCount++;
// Update application (will gather data and other platform related events)
{
PROFILE_CPU_NAMED("Platform.Tick");

View File

@@ -28,7 +28,12 @@ public:
API_FIELD(ReadOnly) static bool HasFocus;
/// <summary>
/// Gets the current frame count since the start of the game.
/// Gets the current update counter since the start of the game.
/// </summary>
API_FIELD(ReadOnly) static uint64 UpdateCount;
/// <summary>
/// Gets the current frame (drawing) count since the start of the game.
/// </summary>
API_FIELD(ReadOnly) static uint64 FrameCount;

View File

@@ -55,10 +55,10 @@ void AnimatedModel::UpdateAnimation()
|| !IsActiveInHierarchy()
|| SkinnedModel == nullptr
|| !SkinnedModel->IsLoaded()
|| _lastUpdateFrame == Engine::FrameCount
|| _lastUpdateFrame == Engine::UpdateCount
|| _masterPose)
return;
_lastUpdateFrame = Engine::FrameCount;
_lastUpdateFrame = Engine::UpdateCount;
if (AnimationGraph && AnimationGraph->IsLoaded() && AnimationGraph->Graph.IsReady())
{

View File

@@ -270,11 +270,11 @@ void ParticleEffect::UpdateSimulation(bool singleFrame)
if (!IsActiveInHierarchy()
|| ParticleSystem == nullptr
|| !ParticleSystem->IsLoaded()
|| _lastUpdateFrame == Engine::FrameCount)
|| _lastUpdateFrame == Engine::UpdateCount)
return;
// Request update
_lastUpdateFrame = Engine::FrameCount;
_lastUpdateFrame = Engine::UpdateCount;
_lastMinDstSqr = MAX_Real;
if (singleFrame)
Instance.LastUpdateTime = (UseTimeScale ? Time::Update.Time : Time::Update.UnscaledTime).GetTotalSeconds();
@@ -371,7 +371,7 @@ void ParticleEffect::Sync()
SceneRenderTask* ParticleEffect::GetRenderTask() const
{
const uint64 minFrame = Engine::FrameCount - 2;
const uint64 minFrame = Engine::UpdateCount - 2;
// Custom task
const auto customViewRenderTask = CustomViewRenderTask.Get();