Thanks for the input, there are some good suggestions.
Pathfinding is certainly something I’d like to do on another thread anyway - however, I don’t know if that lends itself well with Detour/Recast.
The only thing I did with it once was basically calling a function that would give a possible way from point A to B within the navigation mesh.
Now that, I think, would be safe to do on a WorkItem.
However, in a real game, these pathing calculations would have to be updated taking into account the positions of other agents. I’m not quite sure how that works in Detour or Urho, but I’ll look at the pathfinding example to see how it is done in the engine.
But pathfinding is something I’d mostly do in C++ anyway, I wouldn’t want that in gameplay scripts (not more than “actor:moveTowards(targetCoordinates, whenReachedCallback, whenBlockedCallback)” at least). Ideally, scripters shouldn’t worry about pathfinding at all.
I fully agree. However, how would that even be possible with gameplay data? You can’t have each WorkItem have its own copy of the game world
That’s the problem with worker queues. They are just not applicable in many situations. Not for gameplay logic, at least.
Imagine a forest where thousands of beings are just doing their business, the AI for each one calculating next steps based on information about the world, its surroundings, etc. You cannot have thousands of copies of relevant game data. Imagine the synching afterwards
But I think your suggestion to split everything into phases would solve the problem acceptably. It is really not important for gameplay calculations if they are based on 1 frame old logic. So the bird following its prey in the forest would be advancing by some space, even though the prey just got eaten by the wolf, which the bird would be noticed of only next frame. Perfectly acceptable.
So, a very simplified game frame could look like this (assuming that there is separate set for gameplay and Urho data, which is a good idea anyway):
- Object creation/deletion (including callbacks to Lua scripts to notify about object deletion so that Lua scripts can remove references, like the bird losing the prey reference)
- Game logic (threaded, step 3 happens before step 2 finishes), which changes gameplay data ONLY
- Urho engine loop, which changes Urho data ONLY
- Wait for step 2 to finish
- Apply gameplay data to Urho data*
*And vice versa! If physics says the bird is at X, but gameplay says the bird is at Y, that must be resolved somehow. Not an easy topic, I know.
Actually, I will look at the physics sample, maybe it is possible to do the physics calculations extra between step 1 and 2. Would be worth it just to avoid that synchronization nightmare - at least if not much is going on physics wise (and it isn’t in my ideas).
Bonus question: If I activated LuaJIT when building Urho3D, do I have to take any additional steps to make sure LuaJIT is used instead of the slower “normal” Lua?