Merge remote-tracking branch 'origin/master' into 1.9

# Conflicts:
#	Content/Editor/Camera/M_Camera.flax
#	Content/Editor/CubeTexturePreviewMaterial.flax
#	Content/Editor/DebugMaterials/DDGIDebugProbes.flax
#	Content/Editor/DebugMaterials/SingleColor/Decal.flax
#	Content/Editor/DebugMaterials/SingleColor/Particle.flax
#	Content/Editor/DebugMaterials/SingleColor/Surface.flax
#	Content/Editor/DebugMaterials/SingleColor/SurfaceAdditive.flax
#	Content/Editor/DebugMaterials/SingleColor/Terrain.flax
#	Content/Editor/DefaultFontMaterial.flax
#	Content/Editor/Gizmo/FoliageBrushMaterial.flax
#	Content/Editor/Gizmo/Material.flax
#	Content/Editor/Gizmo/MaterialWire.flax
#	Content/Editor/Gizmo/SelectionOutlineMaterial.flax
#	Content/Editor/Gizmo/VertexColorsPreviewMaterial.flax
#	Content/Editor/Highlight Material.flax
#	Content/Editor/Icons/IconsMaterial.flax
#	Content/Editor/IesProfilePreviewMaterial.flax
#	Content/Editor/Particles/Particle Material Color.flax
#	Content/Editor/Particles/Smoke Material.flax
#	Content/Editor/SpriteMaterial.flax
#	Content/Editor/Terrain/Circle Brush Material.flax
#	Content/Editor/Terrain/Highlight Terrain Material.flax
#	Content/Editor/TexturePreviewMaterial.flax
#	Content/Editor/Wires Debug Material.flax
#	Content/Engine/DefaultDeformableMaterial.flax
#	Content/Engine/DefaultMaterial.flax
#	Content/Engine/DefaultTerrainMaterial.flax
#	Content/Engine/SingleColorMaterial.flax
#	Content/Engine/SkyboxMaterial.flax
#	Source/Engine/Graphics/Materials/MaterialShader.h
This commit is contained in:
Wojtek Figat
2024-04-23 10:30:01 +02:00
91 changed files with 1107 additions and 830 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;
@@ -156,7 +157,7 @@ int32 Engine::Main(const Char* cmdLine)
#endif
Log::Logger::WriteFloor();
LOG_FLUSH();
Time::OnBeforeRun();
Time::Synchronize();
EngineImpl::IsReady = true;
// Main engine loop
@@ -191,8 +192,11 @@ int32 Engine::Main(const Char* cmdLine)
OnUnpause();
}
// Use the same time for all ticks to improve synchronization
const double time = Platform::GetTimeSeconds();
// Update game logic
if (Time::OnBeginUpdate())
if (Time::OnBeginUpdate(time))
{
OnUpdate();
OnLateUpdate();
@@ -200,7 +204,7 @@ int32 Engine::Main(const Char* cmdLine)
}
// Start physics simulation
if (Time::OnBeginPhysics())
if (Time::OnBeginPhysics(time))
{
OnFixedUpdate();
OnLateFixedUpdate();
@@ -208,7 +212,7 @@ int32 Engine::Main(const Char* cmdLine)
}
// Draw frame
if (Time::OnBeginDraw())
if (Time::OnBeginDraw(time))
{
OnDraw();
Time::OnEndDraw();
@@ -296,6 +300,8 @@ void Engine::OnUpdate()
{
PROFILE_CPU_NAMED("Update");
UpdateCount++;
// Update application (will gather data and other platform related events)
{
PROFILE_CPU_NAMED("Platform.Tick");
@@ -465,7 +471,7 @@ void Engine::OnUnpause()
LOG(Info, "App unpaused");
Unpause();
Time::OnBeforeRun();
Time::Synchronize();
}
void Engine::OnExit()

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

@@ -54,7 +54,7 @@ void TimeSettings::Apply()
::MaxUpdateDeltaTime = MaxUpdateDeltaTime;
}
void Time::TickData::OnBeforeRun(float targetFps, double currentTime)
void Time::TickData::Synchronize(float targetFps, double currentTime)
{
Time = UnscaledTime = TimeSpan::Zero();
DeltaTime = UnscaledDeltaTime = targetFps > ZeroTolerance ? TimeSpan::FromSeconds(1.0f / targetFps) : TimeSpan::Zero();
@@ -72,10 +72,9 @@ void Time::TickData::OnReset(float targetFps, double currentTime)
LastEnd = currentTime;
}
bool Time::TickData::OnTickBegin(float targetFps, float maxDeltaTime)
bool Time::TickData::OnTickBegin(double time, float targetFps, float maxDeltaTime)
{
// Check if can perform a tick
const double time = Platform::GetTimeSeconds();
double deltaTime;
if (FixedDeltaTimeEnable)
{
@@ -126,10 +125,9 @@ void Time::TickData::Advance(double time, double deltaTime)
TicksCount++;
}
bool Time::FixedStepTickData::OnTickBegin(float targetFps, float maxDeltaTime)
bool Time::FixedStepTickData::OnTickBegin(double time, float targetFps, float maxDeltaTime)
{
// Check if can perform a tick
double time = Platform::GetTimeSeconds();
double deltaTime, minDeltaTime;
if (FixedDeltaTimeEnable)
{
@@ -240,18 +238,18 @@ void Time::SetFixedDeltaTime(bool enable, float value)
FixedDeltaTimeValue = value;
}
void Time::OnBeforeRun()
void Time::Synchronize()
{
// Initialize tick data (based on a time settings)
const double time = Platform::GetTimeSeconds();
Update.OnBeforeRun(UpdateFPS, time);
Physics.OnBeforeRun(PhysicsFPS, time);
Draw.OnBeforeRun(DrawFPS, time);
Update.Synchronize(UpdateFPS, time);
Physics.Synchronize(PhysicsFPS, time);
Draw.Synchronize(DrawFPS, time);
}
bool Time::OnBeginUpdate()
bool Time::OnBeginUpdate(double time)
{
if (Update.OnTickBegin(UpdateFPS, MaxUpdateDeltaTime))
if (Update.OnTickBegin(time, UpdateFPS, MaxUpdateDeltaTime))
{
Current = &Update;
return true;
@@ -259,9 +257,9 @@ bool Time::OnBeginUpdate()
return false;
}
bool Time::OnBeginPhysics()
bool Time::OnBeginPhysics(double time)
{
if (Physics.OnTickBegin(PhysicsFPS, _physicsMaxDeltaTime))
if (Physics.OnTickBegin(time, PhysicsFPS, _physicsMaxDeltaTime))
{
Current = &Physics;
return true;
@@ -269,9 +267,9 @@ bool Time::OnBeginPhysics()
return false;
}
bool Time::OnBeginDraw()
bool Time::OnBeginDraw(double time)
{
if (Draw.OnTickBegin(DrawFPS, 1.0f))
if (Draw.OnTickBegin(time, DrawFPS, 1.0f))
{
Current = &Draw;
return true;

View File

@@ -12,12 +12,12 @@
/// </summary>
API_CLASS(Static) class FLAXENGINE_API Time
{
DECLARE_SCRIPTING_TYPE_NO_SPAWN(Time);
DECLARE_SCRIPTING_TYPE_NO_SPAWN(Time);
friend class Engine;
friend class TimeService;
friend class PhysicsSettings;
public:
public:
/// <summary>
/// Engine subsystem updating data.
/// Used to invoke game logic updates, physics updates and rendering with possibly different frequencies.
@@ -25,7 +25,6 @@ public:
class FLAXENGINE_API TickData
{
public:
virtual ~TickData() = default;
/// <summary>
@@ -75,14 +74,12 @@ public:
TimeSpan UnscaledTime;
public:
virtual void OnBeforeRun(float targetFps, double currentTime);
virtual void Synchronize(float targetFps, double currentTime);
virtual void OnReset(float targetFps, double currentTime);
virtual bool OnTickBegin(float targetFps, float maxDeltaTime);
virtual bool OnTickBegin(double time, float targetFps, float maxDeltaTime);
virtual void OnTickEnd();
protected:
void Advance(double time, double deltaTime);
};
@@ -92,25 +89,21 @@ public:
class FixedStepTickData : public TickData
{
public:
/// <summary>
/// The last few ticks delta times. Used to check if can use fixed steps or whenever is running slowly so should use normal stepping.
/// </summary>
SamplesBuffer<double, 4> Samples;
public:
// [TickData]
bool OnTickBegin(float targetFps, float maxDeltaTime) override;
bool OnTickBegin(double time, float targetFps, float maxDeltaTime) override;
};
private:
static bool _gamePaused;
static float _physicsMaxDeltaTime;
public:
/// <summary>
/// The time at which the game started (UTC local).
/// </summary>
@@ -140,7 +133,6 @@ public:
API_FIELD() static float TimeScale;
public:
/// <summary>
/// The game logic updating data.
/// </summary>
@@ -162,7 +154,6 @@ public:
static TickData* Current;
public:
/// <summary>
/// Gets the current tick data (safety so returns Update tick data if no active).
/// </summary>
@@ -225,15 +216,17 @@ public:
/// <param name="value">The fixed draw/update rate for the time.</param>
API_FUNCTION() static void SetFixedDeltaTime(bool enable, float value);
private:
/// <summary>
/// Synchronizes update, fixed update and draw. Resets any pending deltas for fresh ticking in sync.
/// </summary>
API_FUNCTION() static void Synchronize();
private:
// Methods used by the Engine class
static void OnBeforeRun();
static bool OnBeginUpdate();
static bool OnBeginPhysics();
static bool OnBeginDraw();
static bool OnBeginUpdate(double time);
static bool OnBeginPhysics(double time);
static bool OnBeginDraw(double time);
static void OnEndUpdate();
static void OnEndPhysics();