Fix game ticking in editor during cut-scene rendering at edit time
This commit is contained in:
@@ -276,7 +276,7 @@ namespace FlaxEditor.Windows.Assets
|
|||||||
private float _warmUpTimeLeft;
|
private float _warmUpTimeLeft;
|
||||||
private float _dt;
|
private float _dt;
|
||||||
private int _animationFrame;
|
private int _animationFrame;
|
||||||
private bool _wasGamePaused;
|
private bool _wasGamePaused, _wasTickEnabled;
|
||||||
private SceneAnimationPlayer _player;
|
private SceneAnimationPlayer _player;
|
||||||
private States _state;
|
private States _state;
|
||||||
private readonly StagingTexture[] _stagingTextures = new StagingTexture[FrameLatency + 1];
|
private readonly StagingTexture[] _stagingTextures = new StagingTexture[FrameLatency + 1];
|
||||||
@@ -365,11 +365,16 @@ namespace FlaxEditor.Windows.Assets
|
|||||||
};
|
};
|
||||||
FlaxEngine.Scripting.Update += Tick;
|
FlaxEngine.Scripting.Update += Tick;
|
||||||
_wasGamePaused = Time.GamePaused;
|
_wasGamePaused = Time.GamePaused;
|
||||||
|
_wasTickEnabled = Level.TickEnabled;
|
||||||
Time.GamePaused = false;
|
Time.GamePaused = false;
|
||||||
Time.SetFixedDeltaTime(true, _dt);
|
Time.SetFixedDeltaTime(true, _dt);
|
||||||
Time.UpdateFPS = Time.DrawFPS = _options.FrameRate;
|
Time.UpdateFPS = Time.DrawFPS = _options.FrameRate;
|
||||||
if (!Editor.IsPlayMode)
|
if (!Editor.IsPlayMode)
|
||||||
|
{
|
||||||
|
// Don't simulate physics and don't tick game when rendering at edit time
|
||||||
Time.PhysicsFPS = 0;
|
Time.PhysicsFPS = 0;
|
||||||
|
Level.TickEnabled = false;
|
||||||
|
}
|
||||||
Level.SpawnActor(_player);
|
Level.SpawnActor(_player);
|
||||||
var gameWin = editor.Windows.GameWin;
|
var gameWin = editor.Windows.GameWin;
|
||||||
var resolution = _options.GetResolution();
|
var resolution = _options.GetResolution();
|
||||||
@@ -441,6 +446,7 @@ namespace FlaxEditor.Windows.Assets
|
|||||||
FlaxEngine.Scripting.Update -= Tick;
|
FlaxEngine.Scripting.Update -= Tick;
|
||||||
Time.SetFixedDeltaTime(false, 0.0f);
|
Time.SetFixedDeltaTime(false, 0.0f);
|
||||||
Time.GamePaused = _wasGamePaused;
|
Time.GamePaused = _wasGamePaused;
|
||||||
|
Level.TickEnabled = _wasTickEnabled;
|
||||||
if (_player)
|
if (_player)
|
||||||
{
|
{
|
||||||
_player.Stop();
|
_player.Stop();
|
||||||
|
|||||||
@@ -145,6 +145,7 @@ LevelService LevelServiceInstanceService;
|
|||||||
|
|
||||||
CriticalSection Level::ScenesLock;
|
CriticalSection Level::ScenesLock;
|
||||||
Array<Scene*> Level::Scenes;
|
Array<Scene*> Level::Scenes;
|
||||||
|
bool Level::TickEnabled = true;
|
||||||
Delegate<Actor*> Level::ActorSpawned;
|
Delegate<Actor*> Level::ActorSpawned;
|
||||||
Delegate<Actor*> Level::ActorDeleted;
|
Delegate<Actor*> Level::ActorDeleted;
|
||||||
Delegate<Actor*, Actor*> Level::ActorParentChanged;
|
Delegate<Actor*, Actor*> Level::ActorParentChanged;
|
||||||
@@ -245,7 +246,7 @@ void LevelService::Update()
|
|||||||
auto& scenes = Level::Scenes;
|
auto& scenes = Level::Scenes;
|
||||||
|
|
||||||
// Update all actors
|
// Update all actors
|
||||||
if (!Time::GetGamePaused())
|
if (!Time::GetGamePaused() && Level::TickEnabled)
|
||||||
{
|
{
|
||||||
for (int32 i = 0; i < scenes.Count(); i++)
|
for (int32 i = 0; i < scenes.Count(); i++)
|
||||||
{
|
{
|
||||||
@@ -274,7 +275,7 @@ void LevelService::LateUpdate()
|
|||||||
auto& scenes = Level::Scenes;
|
auto& scenes = Level::Scenes;
|
||||||
|
|
||||||
// Update all actors
|
// Update all actors
|
||||||
if (!Time::GetGamePaused())
|
if (!Time::GetGamePaused() && Level::TickEnabled)
|
||||||
{
|
{
|
||||||
for (int32 i = 0; i < scenes.Count(); i++)
|
for (int32 i = 0; i < scenes.Count(); i++)
|
||||||
{
|
{
|
||||||
@@ -306,7 +307,7 @@ void LevelService::FixedUpdate()
|
|||||||
auto& scenes = Level::Scenes;
|
auto& scenes = Level::Scenes;
|
||||||
|
|
||||||
// Update all actors
|
// Update all actors
|
||||||
if (!Time::GetGamePaused())
|
if (!Time::GetGamePaused() && Level::TickEnabled)
|
||||||
{
|
{
|
||||||
for (int32 i = 0; i < scenes.Count(); i++)
|
for (int32 i = 0; i < scenes.Count(); i++)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -43,6 +43,11 @@ public:
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
API_FIELD(ReadOnly) static Array<Scene*> Scenes;
|
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:
|
public:
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Occurs when new actor gets spawned to the game.
|
/// Occurs when new actor gets spawned to the game.
|
||||||
@@ -104,7 +109,6 @@ public:
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the scenes count.
|
/// Gets the scenes count.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>The scenes count.</returns>
|
|
||||||
API_PROPERTY() static int32 GetScenesCount()
|
API_PROPERTY() static int32 GetScenesCount()
|
||||||
{
|
{
|
||||||
return Scenes.Count();
|
return Scenes.Count();
|
||||||
|
|||||||
Reference in New Issue
Block a user