From afe4a26299fb50d03a2ad38275424b433f410dff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tam=C3=A1s=20B=C3=A1lint=20Misius?= Date: Wed, 1 Jan 2025 21:49:56 +0100 Subject: [PATCH] Make SRT work with event.AFTERSIMDRAW AFTERSIMDRAW can be composited on the main thread on top of the frame that got rendered in parallel, so there is no reason to have it hinder SRT. This cannot be done with BEFORESIMDRAW, which is applied to the frame before the rest of the sim is rendered. If we had proper associative compositing with pre-multiplied alpha, it could be, but this doesn't really work well with the colour space we're using right now (sRGB, with u8 components). --- src/gui/game/GameControllerEvents.h | 7 ++++++- src/gui/game/GameView.cpp | 13 +++++++++---- src/gui/game/GameView.h | 1 + src/gui/render/RenderView.cpp | 1 + src/lua/LuaScriptInterface.cpp | 2 +- 5 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/gui/game/GameControllerEvents.h b/src/gui/game/GameControllerEvents.h index 058437d16..0b4de6fca 100644 --- a/src/gui/game/GameControllerEvents.h +++ b/src/gui/game/GameControllerEvents.h @@ -8,7 +8,12 @@ enum EventTraits : uint32_t eventTraitNone = UINT32_C(0x00000000), eventTraitSimRng = UINT32_C(0x00000001), eventTraitSimGraphics = UINT32_C(0x00000002), + eventTraitHindersSrt = UINT32_C(0x00000004), }; +constexpr EventTraits operator |(EventTraits lhs, EventTraits rhs) +{ + return static_cast(static_cast(lhs) | static_cast(rhs)); +} struct TextInputEvent { @@ -104,7 +109,7 @@ struct AfterSimEvent struct BeforeSimDrawEvent { - static constexpr EventTraits traits = eventTraitSimGraphics; + static constexpr EventTraits traits = eventTraitSimGraphics | eventTraitHindersSrt; }; struct AfterSimDrawEvent diff --git a/src/gui/game/GameView.cpp b/src/gui/game/GameView.cpp index 94afdea55..244399af9 100644 --- a/src/gui/game/GameView.cpp +++ b/src/gui/game/GameView.cpp @@ -2143,10 +2143,13 @@ void GameView::RenderSimulation(const RenderableSimulation &sim, bool handleEven std::unique_lock lk(sd.elementGraphicsMx); ren->RenderSimulation(); } - if (handleEvents) - { - c->AfterSimDraw(); - } + ren->sim = nullptr; +} + +void GameView::AfterSimDraw(const RenderableSimulation &sim) +{ + ren->sim = ∼ + c->AfterSimDraw(); ren->sim = nullptr; } @@ -2159,6 +2162,7 @@ void GameView::OnDraw() { StartRendererThread(); WaitForRendererThread(); + AfterSimDraw(*sim); foundParticles = ren->GetFoundParticles(); *rendererThreadResult = ren->GetVideo(); rendererFrame = rendererThreadResult.get(); @@ -2169,6 +2173,7 @@ void GameView::OnDraw() PauseRendererThread(); ren->ApplySettings(*rendererSettings); RenderSimulation(*sim, true); + AfterSimDraw(*sim); foundParticles = ren->GetFoundParticles(); rendererFrame = &ren->GetVideo(); } diff --git a/src/gui/game/GameView.h b/src/gui/game/GameView.h index 6081ef696..7528d6187 100644 --- a/src/gui/game/GameView.h +++ b/src/gui/game/GameView.h @@ -275,4 +275,5 @@ public: void PauseRendererThread(); void RenderSimulation(const RenderableSimulation &sim, bool handleEvents); + void AfterSimDraw(const RenderableSimulation &sim); }; diff --git a/src/gui/render/RenderView.cpp b/src/gui/render/RenderView.cpp index 98ce999c2..eb27cece3 100644 --- a/src/gui/render/RenderView.cpp +++ b/src/gui/render/RenderView.cpp @@ -195,6 +195,7 @@ void RenderView::OnDraw() view->PauseRendererThread(); ren->ApplySettings(*rendererSettings); view->RenderSimulation(*sim, true); + view->AfterSimDraw(*sim); for (auto y = 0; y < YRES; ++y) { auto &video = ren->GetVideo(); diff --git a/src/lua/LuaScriptInterface.cpp b/src/lua/LuaScriptInterface.cpp index 78b55906a..5868ee99b 100644 --- a/src/lua/LuaScriptInterface.cpp +++ b/src/lua/LuaScriptInterface.cpp @@ -428,7 +428,7 @@ bool CommandInterface::HandleEvent(const GameControllerEvent &event) template std::enable_if_t, bool> HaveSimGraphicsEventHandlersHelper(lua_State *L, std::vector &gameControllerEventHandlers) { - if (std::variant_alternative_t::traits & eventTraitSimGraphics) + if (std::variant_alternative_t::traits & eventTraitHindersSrt) { gameControllerEventHandlers[Index].Push(L); auto have = lua_objlen(L, -1) > 0;