Fix game ticking in editor during cut-scene rendering at edit time

This commit is contained in:
Wojtek Figat
2022-08-19 15:35:34 +02:00
parent a545520d6b
commit 20ebe3ac85
3 changed files with 16 additions and 5 deletions

View File

@@ -276,7 +276,7 @@ namespace FlaxEditor.Windows.Assets
private float _warmUpTimeLeft;
private float _dt;
private int _animationFrame;
private bool _wasGamePaused;
private bool _wasGamePaused, _wasTickEnabled;
private SceneAnimationPlayer _player;
private States _state;
private readonly StagingTexture[] _stagingTextures = new StagingTexture[FrameLatency + 1];
@@ -365,11 +365,16 @@ namespace FlaxEditor.Windows.Assets
};
FlaxEngine.Scripting.Update += Tick;
_wasGamePaused = Time.GamePaused;
_wasTickEnabled = Level.TickEnabled;
Time.GamePaused = false;
Time.SetFixedDeltaTime(true, _dt);
Time.UpdateFPS = Time.DrawFPS = _options.FrameRate;
if (!Editor.IsPlayMode)
{
// Don't simulate physics and don't tick game when rendering at edit time
Time.PhysicsFPS = 0;
Level.TickEnabled = false;
}
Level.SpawnActor(_player);
var gameWin = editor.Windows.GameWin;
var resolution = _options.GetResolution();
@@ -441,6 +446,7 @@ namespace FlaxEditor.Windows.Assets
FlaxEngine.Scripting.Update -= Tick;
Time.SetFixedDeltaTime(false, 0.0f);
Time.GamePaused = _wasGamePaused;
Level.TickEnabled = _wasTickEnabled;
if (_player)
{
_player.Stop();

View File

@@ -145,6 +145,7 @@ LevelService LevelServiceInstanceService;
CriticalSection Level::ScenesLock;
Array<Scene*> Level::Scenes;
bool Level::TickEnabled = true;
Delegate<Actor*> Level::ActorSpawned;
Delegate<Actor*> Level::ActorDeleted;
Delegate<Actor*, Actor*> Level::ActorParentChanged;
@@ -245,7 +246,7 @@ void LevelService::Update()
auto& scenes = Level::Scenes;
// Update all actors
if (!Time::GetGamePaused())
if (!Time::GetGamePaused() && Level::TickEnabled)
{
for (int32 i = 0; i < scenes.Count(); i++)
{
@@ -274,7 +275,7 @@ void LevelService::LateUpdate()
auto& scenes = Level::Scenes;
// Update all actors
if (!Time::GetGamePaused())
if (!Time::GetGamePaused() && Level::TickEnabled)
{
for (int32 i = 0; i < scenes.Count(); i++)
{
@@ -306,7 +307,7 @@ void LevelService::FixedUpdate()
auto& scenes = Level::Scenes;
// Update all actors
if (!Time::GetGamePaused())
if (!Time::GetGamePaused() && Level::TickEnabled)
{
for (int32 i = 0; i < scenes.Count(); i++)
{

View File

@@ -43,6 +43,11 @@ public:
/// </summary>
API_FIELD(ReadOnly) static Array<Scene*> Scenes;
/// <summary>
/// True if game objects (actors and scripts) can receive a tick during engine Update/LateUpdate/FixedUpdate events. Can be used to temporarily disable gameplay logic updating.
/// </summary>
API_FIELD() static bool TickEnabled;
public:
/// <summary>
/// Occurs when new actor gets spawned to the game.
@@ -104,7 +109,6 @@ public:
/// <summary>
/// Gets the scenes count.
/// </summary>
/// <returns>The scenes count.</returns>
API_PROPERTY() static int32 GetScenesCount()
{
return Scenes.Count();