Skip to content

Commit

Permalink
Traktor: Added "postUpdate" call to stages, esp layers, which allows …
Browse files Browse the repository at this point in the history
…WorldLayer to update camera transforms always after simulation.
  • Loading branch information
apistol78 committed Jan 1, 2024
1 parent 4b2c4f1 commit 4e6d471
Show file tree
Hide file tree
Showing 19 changed files with 147 additions and 36 deletions.
4 changes: 4 additions & 0 deletions code/Runtime/Engine/AudioLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,10 @@ void AudioLayer::update(const UpdateInfo& info)
}
}

void AudioLayer::postUpdate(const UpdateInfo& info)
{
}

void AudioLayer::preSetup(const UpdateInfo& info)
{
}
Expand Down
2 changes: 2 additions & 0 deletions code/Runtime/Engine/AudioLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 6 additions & 0 deletions code/Runtime/Engine/Layer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 4 additions & 0 deletions code/Runtime/Engine/ScreenLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ void ScreenLayer::update(const UpdateInfo& info)
{
}

void ScreenLayer::postUpdate(const UpdateInfo& info)
{
}

void ScreenLayer::preSetup(const UpdateInfo& info)
{
}
Expand Down
2 changes: 2 additions & 0 deletions code/Runtime/Engine/ScreenLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
44 changes: 31 additions & 13 deletions code/Runtime/Engine/SplitWorldLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions code/Runtime/Engine/SplitWorldLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
36 changes: 24 additions & 12 deletions code/Runtime/Engine/Stage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
8 changes: 8 additions & 0 deletions code/Runtime/Engine/Stage.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
8 changes: 8 additions & 0 deletions code/Runtime/Engine/StageState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions code/Runtime/Engine/StageState.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions code/Runtime/Engine/VideoLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@ void VideoLayer::update(const UpdateInfo& info)
}
}

void VideoLayer::postUpdate(const UpdateInfo& info)
{
}

void VideoLayer::preSetup(const UpdateInfo& info)
{
}
Expand Down
2 changes: 2 additions & 0 deletions code/Runtime/Engine/VideoLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
23 changes: 15 additions & 8 deletions code/Runtime/Engine/WorldLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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");
Expand Down
2 changes: 2 additions & 0 deletions code/Runtime/Engine/WorldLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 8 additions & 0 deletions code/Runtime/IState.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
20 changes: 17 additions & 3 deletions code/Runtime/Impl/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions code/Spark/Runtime/SparkLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
2 changes: 2 additions & 0 deletions code/Spark/Runtime/SparkLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 4e6d471

Please sign in to comment.