I'm currently trying to figure out a way where I can achieve the following;

Pre-Calculate the game - This will predetermine any event / interaction between the players.

Simulate the calculation - Over a 2 minute period it will show what happens at the pre calculated time.

The interactions will be determined by a class for position. Where certain positions are able to interact with other positions and randomised/calculated evens occur. However, my main problem is trying to think of where to start. I'm pretty good when it comes to programming. However, I've never designed an engine that is capable of doing this.

So I'm sat here wondering what the first step is, how do I determine a logical outcome i.e every player interacting in the first 10 seconds is a no go, how do I even determine a timeframe for their interaction when it's pre-calculated? I would probably have an easier time just running the functions for 2 minutes and relying on methods to determine the outcomes. However, I want to pre calculate it.

Can anyone give me a few pointers so I can actually get my teeth stuck into this?



Are you looking to build something like Frozen Synapse http://www.frozensynapse.com/ ? The game queues the player movements and actions, in the precalc phase the game 'plays' these actions. And finally shows the results where the player can manipulate time to see the action.

There are two strategies I can currently think of. It depends on the scale and complexity your game needs which one suits best.

Option one: In the simplest way one could accelerate time (1s passes in 1ms). The results of each 'tick' is stored in a frame-snapshot. The queue for a gameobject could be cleared if the gameobject is destroyed or prevented from continuing (for example another object locks a door the player planned to pass). The snapshot could then include particles for bullet impacts or grenade explosions where random shrapnel may destroy objects or cause near misses.

The result is a series of frames that can be played out in the 'result phase'. One could also do interpolations for slowmotion or other effects. Since you have frames the player can analyse by replaying or slide the time back and forth. The 'frames' can be optimised to only include deltas.

Option two: Depending on your game idea, you may queue player actions and calculate outcomes based on timing. For example, if a player moves towards a point, calculate the distance and speed and determine the point in time the player will arrive. This may be harder to do, but it may help depending on what you're planning to do.

Compare this to a simulation of a solar system, where everything happens on a larger timescale so accelerated time would still cause the simulation to run for quite some time.

In this case only store a list of events that happen at timestamps so you can replay the simulation using the calculations and spawn the events at the given timestamps so the replay is always the same.

  • \$\begingroup\$ Option two seems like the most logical approach for me as I'm writing it in objective-c and don't have a great deal of libraries at my disposal for this task. However, calculating time by movements would make perfect sense.. i.e, a loop for 120 'units' which are then converted into seconds for the replay. So players move to a new 'spot' and that takes 'x' units, calculate each loop to see if there's any possible interactions and continue. Thanks for your answer, it's been of great help. \$\endgroup\$
    – Daniel
    Nov 19 '15 at 13:45

Not the answer you're looking for? Browse other questions tagged or ask your own question.