diff --git a/code/Runtime/Engine/AudioLayer.cpp b/code/Runtime/Engine/AudioLayer.cpp index b9f9a8cf48..c9d52cf3f8 100644 --- a/code/Runtime/Engine/AudioLayer.cpp +++ b/code/Runtime/Engine/AudioLayer.cpp @@ -187,6 +187,10 @@ void AudioLayer::update(const UpdateInfo& info) } } +void AudioLayer::postUpdate(const UpdateInfo& info) +{ +} + void AudioLayer::preSetup(const UpdateInfo& info) { } diff --git a/code/Runtime/Engine/AudioLayer.h b/code/Runtime/Engine/AudioLayer.h index f51a1e7ede..967967f1e6 100644 --- a/code/Runtime/Engine/AudioLayer.h +++ b/code/Runtime/Engine/AudioLayer.h @@ -93,6 +93,8 @@ class T_DLLCLASS AudioLayer : public Layer virtual void update(const UpdateInfo& info) override final; + virtual void postUpdate(const UpdateInfo& info) override final; + virtual void preSetup(const UpdateInfo& info) override final; virtual void setup(const UpdateInfo& info, render::RenderGraph& renderGraph) override final; diff --git a/code/Runtime/Engine/Layer.h b/code/Runtime/Engine/Layer.h index 139cf5a029..be77dc082b 100644 --- a/code/Runtime/Engine/Layer.h +++ b/code/Runtime/Engine/Layer.h @@ -72,6 +72,12 @@ class T_DLLCLASS Layer : public Object */ virtual void update(const UpdateInfo& info) = 0; + /*! Update layer logic. + * + * info Engine update information. + */ + virtual void postUpdate(const UpdateInfo& info) = 0; + /*! Prepare layer for setup. * * \param info Engine update information. diff --git a/code/Runtime/Engine/ScreenLayer.cpp b/code/Runtime/Engine/ScreenLayer.cpp index 3d0d3cc98d..e930606416 100644 --- a/code/Runtime/Engine/ScreenLayer.cpp +++ b/code/Runtime/Engine/ScreenLayer.cpp @@ -65,6 +65,10 @@ void ScreenLayer::update(const UpdateInfo& info) { } +void ScreenLayer::postUpdate(const UpdateInfo& info) +{ +} + void ScreenLayer::preSetup(const UpdateInfo& info) { } diff --git a/code/Runtime/Engine/ScreenLayer.h b/code/Runtime/Engine/ScreenLayer.h index 70485b67ea..92b8940034 100644 --- a/code/Runtime/Engine/ScreenLayer.h +++ b/code/Runtime/Engine/ScreenLayer.h @@ -58,6 +58,8 @@ class T_DLLCLASS ScreenLayer : public Layer virtual void update(const UpdateInfo& info) override final; + virtual void postUpdate(const UpdateInfo& info) override final; + virtual void preSetup(const UpdateInfo& info) override final; virtual void setup(const UpdateInfo& info, render::RenderGraph& renderGraph) override final; diff --git a/code/Runtime/Engine/SplitWorldLayer.cpp b/code/Runtime/Engine/SplitWorldLayer.cpp index a39c61416c..f41c720b26 100644 --- a/code/Runtime/Engine/SplitWorldLayer.cpp +++ b/code/Runtime/Engine/SplitWorldLayer.cpp @@ -214,16 +214,16 @@ void SplitWorldLayer::update(const UpdateInfo& info) if (!m_worldRenderer) return; - // Update camera transform from entity. - for (int32_t i = 0; i < 2; ++i) - { - if (m_cameraEntities[i]) - { - const Transform cameraTransform = m_cameraEntities[i]->getTransform(); - m_cameraTransforms[i].step(); - m_cameraTransforms[i].set(cameraTransform); - } - } + // // Update camera transform from entity. + // for (int32_t i = 0; i < 2; ++i) + // { + // if (m_cameraEntities[i]) + // { + // const Transform cameraTransform = m_cameraEntities[i]->getTransform(); + // m_cameraTransforms[i].step(); + // m_cameraTransforms[i].set(cameraTransform); + // } + // } // Update scene controller. if (m_controllerEnable) @@ -261,6 +261,24 @@ void SplitWorldLayer::update(const UpdateInfo& info) m_alternateTime += info.getSimulationDeltaTime(); } +void SplitWorldLayer::postUpdate(const UpdateInfo& info) +{ + T_PROFILER_SCOPE(L"SplitWorldLayer post-update"); + if (!m_worldRenderer || !m_scene) + return; + + // Update camera transform from entity. + for (int32_t i = 0; i < 2; ++i) + { + if (m_cameraEntities[i]) + { + const Transform cameraTransform = m_cameraEntities[i]->getTransform(); + m_cameraTransforms[i].step(); + m_cameraTransforms[i].set(cameraTransform); + } + } +} + void SplitWorldLayer::preSetup(const UpdateInfo& info) { T_PROFILER_SCOPE(L"SplitWorldLayer pre-setup"); @@ -319,11 +337,11 @@ void SplitWorldLayer::setup(const UpdateInfo& info, render::RenderGraph& renderG render::RenderGraphTargetSetDesc rgtsd; rgtsd.count = 1; - rgtsd.width = width / 2; - rgtsd.height = height; + rgtsd.width = width / 4; + rgtsd.height = height / 2; rgtsd.createDepthStencil = true; rgtsd.ignoreStencil = true; - rgtsd.targets[0].colorFormat = render::TfR16G16B16A16F; + rgtsd.targets[0].colorFormat = render::TfR11G11B10F; auto leftTargetSetId = renderGraph.addTransientTargetSet( L"Split Left", diff --git a/code/Runtime/Engine/SplitWorldLayer.h b/code/Runtime/Engine/SplitWorldLayer.h index 4f32a64fe7..a80549b1b7 100644 --- a/code/Runtime/Engine/SplitWorldLayer.h +++ b/code/Runtime/Engine/SplitWorldLayer.h @@ -80,6 +80,8 @@ class T_DLLCLASS SplitWorldLayer virtual void update(const UpdateInfo& info) override final; + virtual void postUpdate(const UpdateInfo& info) override final; + virtual void preSetup(const UpdateInfo& info) override final; virtual void setup(const UpdateInfo& info, render::RenderGraph& renderGraph) override final; diff --git a/code/Runtime/Engine/Stage.cpp b/code/Runtime/Engine/Stage.cpp index 90fdcdd24e..9b232f720b 100644 --- a/code/Runtime/Engine/Stage.cpp +++ b/code/Runtime/Engine/Stage.cpp @@ -250,25 +250,37 @@ bool Stage::update(IStateManager* stateManager, const UpdateInfo& info) // Update each layer. for (auto layer : m_layers) layer->update(info); + } - // Issue script post update. - if (validateScriptContext()) + return true; +} + +bool Stage::postUpdate(IStateManager* stateManager, const UpdateInfo& info) +{ + if (m_pendingStage) + return true; + + // Issue script post update. + if (validateScriptContext()) + { + T_PROFILER_SCOPE(L"Script post update"); + if (m_object) { - T_PROFILER_SCOPE(L"Script post update"); - if (m_object) + const Any argv[] = { - const Any argv[] = - { - Any::fromObject(const_cast< UpdateInfo* >(&info)) - }; + Any::fromObject(const_cast< UpdateInfo* >(&info)) + }; - const IRuntimeDispatch* methodPostUpdate = findRuntimeClassMethod(m_class, "postUpdate"); - if (methodPostUpdate != nullptr) - methodPostUpdate->invoke(m_object, sizeof_array(argv), argv); - } + const IRuntimeDispatch* methodPostUpdate = findRuntimeClassMethod(m_class, "postUpdate"); + if (methodPostUpdate != nullptr) + methodPostUpdate->invoke(m_object, sizeof_array(argv), argv); } } + // Update each layer. + for (auto layer : m_layers) + layer->postUpdate(info); + return true; } diff --git a/code/Runtime/Engine/Stage.h b/code/Runtime/Engine/Stage.h index 15d87199d7..c2953d0c42 100644 --- a/code/Runtime/Engine/Stage.h +++ b/code/Runtime/Engine/Stage.h @@ -151,6 +151,14 @@ class T_DLLCLASS Stage : public Object */ bool update(IStateManager* stateManager, const UpdateInfo& info); + /*! Update, post physics, this stage. + * + * \param stateManager Engine state manager. + * \param info Engine update information. + * \return True if this update succeeded. + */ + bool postUpdate(IStateManager* stateManager, const UpdateInfo& info); + bool setup(const UpdateInfo& info, render::RenderGraph& renderGraph); void transition(); diff --git a/code/Runtime/Engine/StageState.cpp b/code/Runtime/Engine/StageState.cpp index f8cc11bfde..dbd8f70839 100644 --- a/code/Runtime/Engine/StageState.cpp +++ b/code/Runtime/Engine/StageState.cpp @@ -81,6 +81,14 @@ StageState::UpdateResult StageState::update(IStateManager* stateManager, const U return UrExit; } +StageState::UpdateResult StageState::postUpdate(IStateManager* stateManager, const UpdateInfo& info) +{ + if (m_stage->postUpdate(stateManager, info)) + return UrOk; + else + return UrExit; +} + StageState::BuildResult StageState::build(uint32_t frame, const UpdateInfo& info) { render::RenderContext* renderContext = m_frames[frame].renderContext; diff --git a/code/Runtime/Engine/StageState.h b/code/Runtime/Engine/StageState.h index fed099d4a1..c0ed9bd964 100644 --- a/code/Runtime/Engine/StageState.h +++ b/code/Runtime/Engine/StageState.h @@ -51,6 +51,8 @@ class T_DLLCLASS StageState : public IState virtual UpdateResult update(IStateManager* stateManager, const UpdateInfo& info) override final; + virtual UpdateResult postUpdate(IStateManager* stateManager, const UpdateInfo& info) override final; + virtual BuildResult build(uint32_t frame, const UpdateInfo& info) override final; virtual bool render(uint32_t frame, const UpdateInfo& info) override final; diff --git a/code/Runtime/Engine/VideoLayer.cpp b/code/Runtime/Engine/VideoLayer.cpp index fb5c35fd78..9951850e0a 100644 --- a/code/Runtime/Engine/VideoLayer.cpp +++ b/code/Runtime/Engine/VideoLayer.cpp @@ -138,6 +138,10 @@ void VideoLayer::update(const UpdateInfo& info) } } +void VideoLayer::postUpdate(const UpdateInfo& info) +{ +} + void VideoLayer::preSetup(const UpdateInfo& info) { } diff --git a/code/Runtime/Engine/VideoLayer.h b/code/Runtime/Engine/VideoLayer.h index cea74f0869..5ae77f0a3f 100644 --- a/code/Runtime/Engine/VideoLayer.h +++ b/code/Runtime/Engine/VideoLayer.h @@ -91,6 +91,8 @@ class T_DLLCLASS VideoLayer : public Layer virtual void update(const UpdateInfo& info) override final; + virtual void postUpdate(const UpdateInfo& info) override final; + virtual void preSetup(const UpdateInfo& info) override final; virtual void setup(const UpdateInfo& info, render::RenderGraph& renderGraph) override final; diff --git a/code/Runtime/Engine/WorldLayer.cpp b/code/Runtime/Engine/WorldLayer.cpp index a12e7cae51..cfca5d874b 100644 --- a/code/Runtime/Engine/WorldLayer.cpp +++ b/code/Runtime/Engine/WorldLayer.cpp @@ -212,14 +212,6 @@ void WorldLayer::update(const UpdateInfo& info) if (!m_worldRenderer) return; - // Update camera transform from entity. - if (m_cameraEntity) - { - const Transform cameraTransform = m_cameraEntity->getTransform(); - m_cameraTransform.step(); - m_cameraTransform.set(cameraTransform); - } - // Update scene controller. if (m_controllerEnable) { @@ -256,6 +248,21 @@ void WorldLayer::update(const UpdateInfo& info) m_alternateTime += info.getSimulationDeltaTime(); } +void WorldLayer::postUpdate(const UpdateInfo& info) +{ + T_PROFILER_SCOPE(L"WorldLayer post-update"); + if (!m_worldRenderer || !m_scene) + return; + + // Update camera transform from entity. + if (m_cameraEntity) + { + const Transform cameraTransform = m_cameraEntity->getTransform(); + m_cameraTransform.step(); + m_cameraTransform.set(cameraTransform); + } +} + void WorldLayer::preSetup(const UpdateInfo& info) { T_PROFILER_SCOPE(L"WorldLayer pre-setup"); diff --git a/code/Runtime/Engine/WorldLayer.h b/code/Runtime/Engine/WorldLayer.h index 262c306184..3fa77eeeb2 100644 --- a/code/Runtime/Engine/WorldLayer.h +++ b/code/Runtime/Engine/WorldLayer.h @@ -78,6 +78,8 @@ class T_DLLCLASS WorldLayer virtual void update(const UpdateInfo& info) override final; + virtual void postUpdate(const UpdateInfo& info) override final; + virtual void preSetup(const UpdateInfo& info) override final; virtual void setup(const UpdateInfo& info, render::RenderGraph& renderGraph) override final; diff --git a/code/Runtime/IState.h b/code/Runtime/IState.h index 98f8f7deed..de4e366049 100644 --- a/code/Runtime/IState.h +++ b/code/Runtime/IState.h @@ -69,6 +69,14 @@ class T_DLLCLASS IState : public Object */ virtual UpdateResult update(IStateManager* stateManager, const UpdateInfo& info) = 0; + /*! Post update state. + * + * \param stateManager State manager. + * \param info Update information. + * \return Update result. + */ + virtual UpdateResult postUpdate(IStateManager* stateManager, const UpdateInfo& info) = 0; + /*! Build frame. * * \param frame Build frame. diff --git a/code/Runtime/Impl/Application.cpp b/code/Runtime/Impl/Application.cpp index bb8f6949f8..1d5c1d7f01 100644 --- a/code/Runtime/Impl/Application.cpp +++ b/code/Runtime/Impl/Application.cpp @@ -667,10 +667,10 @@ bool Application::update() // Update current state for each simulation tick. const double updateTimeStart = m_timer.getElapsedTime(); - IState::UpdateResult result; + IState::UpdateResult updateResult; { T_PROFILER_SCOPE(L"Application update - State"); - result = currentState->update(m_stateManager, m_updateInfo); + updateResult = currentState->update(m_stateManager, m_updateInfo); } const double updateTimeEnd = m_timer.getElapsedTime(); updateDuration += updateTimeEnd - updateTimeStart; @@ -684,13 +684,20 @@ bool Application::update() const double physicsTimeEnd = m_timer.getElapsedTime(); physicsDuration += physicsTimeEnd - physicsTimeStart; + // Issue post update. + if (updateResult == IState::UrOk) + { + T_PROFILER_SCOPE(L"Application post update - State"); + updateResult = currentState->postUpdate(m_stateManager, m_updateInfo); + } + m_updateDuration = physicsTimeEnd - physicsTimeStart + inputTimeEnd - inputTimeStart + updateTimeEnd - updateTimeStart; m_updateInfo.m_simulationTime += dT; m_updateInfo.m_totalTime += (dFT / updateCount); m_updateInfo.m_stateTime += (dFT / updateCount); - if (result == IState::UrExit || result == IState::UrFailed) + if (updateResult == IState::UrExit || updateResult == IState::UrFailed) { // Ensure render thread is finished before we leave. if (m_threadRender) @@ -742,6 +749,13 @@ bool Application::update() updateDuration += updateTimeEnd - updateTimeStart; updateCount++; + // Issue post update. + if (updateResult == IState::UrOk) + { + T_PROFILER_SCOPE(L"Application post update - State"); + updateResult = currentState->postUpdate(m_stateManager, m_updateInfo); + } + m_updateInfo.m_simulationTime += m_updateInfo.m_simulationDeltaTime; m_updateInfo.m_totalTime += m_updateInfo.m_simulationDeltaTime; m_updateInfo.m_stateTime += m_updateInfo.m_simulationDeltaTime; diff --git a/code/Spark/Runtime/SparkLayer.cpp b/code/Spark/Runtime/SparkLayer.cpp index 9e2a37148e..c4a0c4a2f4 100644 --- a/code/Spark/Runtime/SparkLayer.cpp +++ b/code/Spark/Runtime/SparkLayer.cpp @@ -418,6 +418,10 @@ void SparkLayer::update(const runtime::UpdateInfo& info) m_moviePlayer->progress((float)info.getSimulationDeltaTime(), m_soundRenderer); } +void SparkLayer::postUpdate(const runtime::UpdateInfo& info) +{ +} + void SparkLayer::preSetup(const runtime::UpdateInfo& info) { if (m_movie.changed()) diff --git a/code/Spark/Runtime/SparkLayer.h b/code/Spark/Runtime/SparkLayer.h index b580814133..40944bc843 100644 --- a/code/Spark/Runtime/SparkLayer.h +++ b/code/Spark/Runtime/SparkLayer.h @@ -79,6 +79,8 @@ class T_DLLCLASS SparkLayer virtual void update(const runtime::UpdateInfo& info) override final; + virtual void postUpdate(const runtime::UpdateInfo& info) override final; + virtual void preSetup(const runtime::UpdateInfo& info) override final; virtual void setup(const runtime::UpdateInfo& info, render::RenderGraph& renderGraph) override final;