mirror of
https://github.com/The-Powder-Toy/The-Powder-Toy.git
synced 2025-01-16 22:08:28 +01:00
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).
This commit is contained in:
parent
87cf63dbcc
commit
afe4a26299
@ -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<EventTraits>(static_cast<uint32_t>(lhs) | static_cast<uint32_t>(rhs));
|
||||
}
|
||||
|
||||
struct TextInputEvent
|
||||
{
|
||||
@ -104,7 +109,7 @@ struct AfterSimEvent
|
||||
|
||||
struct BeforeSimDrawEvent
|
||||
{
|
||||
static constexpr EventTraits traits = eventTraitSimGraphics;
|
||||
static constexpr EventTraits traits = eventTraitSimGraphics | eventTraitHindersSrt;
|
||||
};
|
||||
|
||||
struct AfterSimDrawEvent
|
||||
|
@ -2143,10 +2143,13 @@ void GameView::RenderSimulation(const RenderableSimulation &sim, bool handleEven
|
||||
std::unique_lock lk(sd.elementGraphicsMx);
|
||||
ren->RenderSimulation();
|
||||
}
|
||||
if (handleEvents)
|
||||
{
|
||||
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();
|
||||
}
|
||||
|
@ -275,4 +275,5 @@ public:
|
||||
void PauseRendererThread();
|
||||
|
||||
void RenderSimulation(const RenderableSimulation &sim, bool handleEvents);
|
||||
void AfterSimDraw(const RenderableSimulation &sim);
|
||||
};
|
||||
|
@ -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();
|
||||
|
@ -428,7 +428,7 @@ bool CommandInterface::HandleEvent(const GameControllerEvent &event)
|
||||
template<size_t Index>
|
||||
std::enable_if_t<Index != std::variant_size_v<GameControllerEvent>, bool> HaveSimGraphicsEventHandlersHelper(lua_State *L, std::vector<LuaSmartRef> &gameControllerEventHandlers)
|
||||
{
|
||||
if (std::variant_alternative_t<Index, GameControllerEvent>::traits & eventTraitSimGraphics)
|
||||
if (std::variant_alternative_t<Index, GameControllerEvent>::traits & eventTraitHindersSrt)
|
||||
{
|
||||
gameControllerEventHandlers[Index].Push(L);
|
||||
auto have = lua_objlen(L, -1) > 0;
|
||||
|
Loading…
x
Reference in New Issue
Block a user