Jump to content
Posted 13 February 2014 - 02:53 PM
Posted 13 February 2014 - 03:38 PM
I know some turn-based games solve this by having a MovePhaseAtStartOfTurn followed by a AttackPhaseAtStartOfTurn. You can sometimes see this reflected by the animations in commercially available games. Basically, you just need a sync on starting the attack phase to completion of movement. Technically, you could even just add a wait equal to the maximum animation/movement time required if you don't have the ability to sync. That's hacky since it might break if you add a longer animation/movement later, so definitely better to sync if possible.
Posted 13 February 2014 - 08:13 PM
Game Developer, C++ Geek, Dragon Slayer - http://seanmiddleditch.com
C++ SG14 "Games & Low Latency" - Co-chair - public forums
Wargaming Seattle - Lead Server Engineer - We're hiring!
Posted 13 February 2014 - 10:26 PM
You need only a small modification to your Order class, most likely.
Just stop executing Orders if one returns a code that it is going to take time. Keep trying to drain the Order queue for the unit each frame until it's empty and the game state can advance. The Order object can then be in charge of knowing if it has to wait for an animation to complete or some wait timer to complete. There's not necessarily any reason to have one queue of Orders feed another queue.
There are a few limitations to keep in mind with this approach. In multi-threading execution of orders, "wait for me" status becomes a lock and that's an awful lot of locks. Order of execution becomes important (unit A moves and fires at B, unit B fires at A. What distance was B at when firing at A?). And you always cause a delay equal to the longest dependency chain's animations, which can be really bad if you allow move-fire-move orders.
None of this is to say the approach should be avoided as long as you understand the limitations. If you do not have actions interacting with one another and are single-threaded, it probably works fine. While I think having a move phase where you process movements and requeue other orders is easier, other programmers will certainly disagree. That's the art aspect of programming.