GameState / Animation Skew

Started by
4 comments, last by way2lazy2care 12 years, 11 months ago
I have a game that features combat in a tactical, turn-based manner.

There is a GameState singleton and it has a list of Mobiles.

During a single turn in battle each Mobile can choose from a variety of actions including movement and attack. Each of these actions is animated. You can see smooth movement as Mobiles move from one tile to another and you can clearly see from where attacks originate from and who the victim is.

During the processing of a turn, several Mobiles will take their move e.g.:
Mobile 1 moves closer to its target Mobile 7
Mobile 2 attacks Mobile 1
Mobile 3 moves closer to its target Mobile 1
Mobile 4 attacks Mobile 1, killing it
etc...

The big design problem is that there is a skew between the existing GameState and what is displayed onscreen. Animations must be played before the display 'catches up' to the GameState.

In the above example, note how Mobile 1 is already dead after processing the turn but the player should see all the animations before seeing the corpse. I process several Mobiles at once because during a big battle of hundreds of Mobiles, no-one wants to wait while each and every Mobile takes its turn and is animated.

How would you design such a system at the programming level? Do you:
a) change your GameState singleton immediately but delegate the painting of the Mobile and corpses to the animations?
b) calculate the change but do not apply it to the GameState until after the animation is complete?
c) other?
Advertisement
why does it have to die before the animation finishes? Could you queue state changes, but only change to it when the previous state finishes... ie the death state won't finish until the animation finishes. Then it can go into the corpse state.
[ dev journal ]
[ current projects' videos ]
[ Zolo Project ]
I'm not mean, I just like to get to the point.

why does it have to die before the animation finishes? Could you queue state changes, but only change to it when the previous state finishes... ie the death state won't finish until the animation finishes. Then it can go into the corpse state.


The problem with this approach is this scenario:
1. Mobile X dies and an animation is spawned.
2. Immediately (i.e. before the animation is complete) Mobile Y takes its turn. Note that it was originally targeting Mobile X. If the GameState has not been updated for #1 then Mobile Y will incorrectly seek out Mobile X.

The reason I would like to process multiple Mobiles with one pass is that I want to parallelize the animations as much as possible. If 100 Mobiles are moving then instead of animating them all sequentially, animate all of them simultaneously assuming there are no collisions.

Your approach would work if I pause the GameState after #1 and wait until the animation is complete before letting Mobile Y take its turn (#2). The tricky part is determining what Mobile Y wants to do and correctly allow it to proceed or not (by inspecting running animations) without updating the GameState.
Perhaps you could speed up the animations? I like the one-at-a-time approach because it keeps things simple. As long as it doesn't take too long to complete them each turn, it should be fine. You can also include a 'skip' feature, if the players do not want to see them.

I also think the time during the animations might be good for the players to 'talk smack' or whatever to the other players. Might actually be good for the game to bring in some interaction.

Perhaps you could speed up the animations? I like the one-at-a-time approach because it keeps things simple. As long as it doesn't take too long to complete them each turn, it should be fine. You can also include a 'skip' feature, if the players do not want to see them.

I also think the time during the animations might be good for the players to 'talk smack' or whatever to the other players. Might actually be good for the game to bring in some interaction.


The game is a single-player RPG where one controls a party of characters. Think of it as a cross between old-style Ultima and Rogue. The controls are more RTS (mouse + keyboard) ala Starcraft although the game turn-based.

I'll include the options to speed up animations and also allow for explicit turn animation but I think that could be pretty tedious to the player.

The problem with this approach is this scenario:
1. Mobile X dies and an animation is spawned.
2. Immediately (i.e. before the animation is complete) Mobile Y takes its turn. Note that it was originally targeting Mobile X. If the GameState has not been updated for #1 then Mobile Y will incorrectly seek out Mobile X.

Why is MobileX's game state not updated when mobile X dies?

And you shouldn't use singletons if you want to parallelize anything.

This topic is closed to new replies.

Advertisement