Files
UnrealEngineUWP/Engine/Source/Runtime/TimeManagement/Private/FixedFrameRateCustomTimeStep.cpp
Ryan Vance 7c51ff94af Merging //UE4/Dev-Main to Dev-VR (//UE4/Dev-VR)
CL 1 of 8
#rb integration

[CL 4748712 by Ryan Vance in Dev-VR branch]
2019-01-17 18:54:05 -05:00

60 lines
1.6 KiB
C++

// Copyright 1998-2019 Epic Games, Inc. All Rights Reserved.
#include "FixedFrameRateCustomTimeStep.h"
#include "Misc/App.h"
#include "Stats/StatsMisc.h"
#include "HAL/PlatformProcess.h"
PRAGMA_DISABLE_DEPRECATION_WARNINGS
UFixedFrameRateCustomTimeStep::UFixedFrameRateCustomTimeStep(const FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer)
, FixedFrameRate(30, 1)
{
}
PRAGMA_ENABLE_DEPRECATION_WARNINGS
void UFixedFrameRateCustomTimeStep::WaitForFixedFrameRate() const
{
UpdateApplicationLastTime();
const double CurrentTime = FPlatformTime::Seconds();
const FFrameRate FrameRate = GetFixedFrameRate();
// Calculate delta time
const float DeltaRealTime = CurrentTime - FApp::GetLastTime();
const float WaitTime = FMath::Max(FrameRate.AsInterval() - DeltaRealTime, 0.0);
double ActualWaitTime = 0.0;
{
FSimpleScopeSecondsCounter ActualWaitTimeCounter(ActualWaitTime);
if (WaitTime > 5.f / 1000.f)
{
FPlatformProcess::SleepNoStats(WaitTime - 0.002f);
}
// Give up timeslice for remainder of wait time.
const double WaitEndTime = FApp::GetLastTime() + FApp::GetDeltaTime();
while (FPlatformTime::Seconds() < WaitEndTime)
{
FPlatformProcess::SleepNoStats(0.f);
}
}
// Use fixed delta time and update time.
FApp::SetDeltaTime(FrameRate.AsInterval());
FApp::SetIdleTime(ActualWaitTime);
FApp::SetCurrentTime(FApp::GetLastTime() + FApp::GetDeltaTime());
}
FFrameRate UFixedFrameRateCustomTimeStep::GetFixedFrameRate_PureVirtual() const
{
PRAGMA_DISABLE_DEPRECATION_WARNINGS
return FixedFrameRate;
PRAGMA_ENABLE_DEPRECATION_WARNINGS
}