-
Notifications
You must be signed in to change notification settings - Fork 0
Ticks
Ticks serve two purposes:
- Deterministic time source.
- Separate actions from reactions (our famous AoE damage + PoM example).
Time has to be generated by an outside entity and sent as packets to the
sandbox. We can not rely on setTimeout
or other javascript builtin functions
because they are not deterministic, and may fire at different times depending
on the server load etc. By using ticks we have complete control over how time
progresses inside the sandbox.
If executing an action involves updating multiple units, the reaction from the first unit should not have any influence on the updates performed to the other units. This is why reactions are queued and executed at the beginning of the next tick. Thus separating the actions from the reactions.
Tom: Actions and reactions can be also separated without the use of ticks. But the deeper problem here are reaction chains. That is when the reaction causes another reaction, which causes another reaction etc. which can cause an endless loop.
By using ticks we can prevent such reaction chain from blocking the server. But if an endless reaction chain is happening, we should detect it rather than hide it. It is clearly an error condition that shouldn't happen.
And if we assume a reaction chain which terminates after 10 charges (PoM). From the point of view of the user or the game mechanics, there is very little difference whether all reactions are executed within the same tick or within 0.1 seconds.
We should:
- Detect reaction chains and raise an exception if we detect one.
- Design the API so it's difficult to create these reaction chains.