#How do I create a parallel sub‑app to compute game logic and send data to the render app from it?

17 messages · Page 1 of 1 (latest)

echo prism
#

You can basically copy what PipelinedRenderingPlugin does (go look at the source!). TL;DR, in Plugin::cleanup, they move the entire render world into a thread, and that thread then blocks on a channel. In the RenderApp's extract function, they move the main world to the channel, the thread extracts what it needs, and then it returns the main world through another channel back to the extract function, which puts the world back. Since the render world is not off in its own thread, they don't block each other.

#

All that said seriously consider whether this is what you want. This kinda muddies what frame you're actually rendering. Currently, it looks more like this:

First frame
main_app    [=====]|[========]     |[====]
render_app         |[=============]|[=========]
#

Namely, the render app runs after the first frame. But that means in your case, your rendering will actually render an unfinished physics state for the first frame.

#

The other thing to note, is that generally your bottleneck is rendering so it's not clear that pipelining physics will improve things

tame prairie
#

its not about improving performance

echo prism
tame prairie
#

im looking for better solution

echo prism
tame prairie
echo prism
#

There's no reason your physics world needs to be a SubApp. Instead it could be an App that you run in a separate thread

#

So your main world would send the main world to the physics world to do its "fake extract", then you just manually update the physics app. Then have a system in your RenderApp extract lock a Mutex on the results of that frame

#

The fundamental problem here though is that in order to render frame n you need the physics data for frame n which in turn needs the main world data for frame n

tame prairie
echo prism
#

Or how about, if the user presses the w key to move forward, you need to send that force to the physics system