Okay, it seems I finally understood how exactly waits system operates in StarCraft!There is a separate
timer I(P) for each player P. The timer is a system object of some kind. The only thing that matters for the external observer is that the timer can be found in three different states:
"raised",
"activated" and
"idle". When timer is raised it has it's
internal counter decreasing from some value downto 0. Decrease speed
does not affected by game speed and is done in realtime by system clock. When counter reaches 0 the timer automatically transfers into activated state. At start of the game all timers are idle.
I don't know how timer is implemented but imagine it as an integer variable which could take values from -2 to MAXINT. The value -2 represents the idle state, -1 represents the activated state and all other values represent the raised state. When timer is raised it's value constantly decreases downto -1 (included) and then stops.
1. When during execution of trigger T for player P StarCraft encounters a Wait(N) action W (T and W are not marked, see below) it looks at the state of the timer I(P) for that player.
1.1. If I(P) is idle or activated then SC assigns I(P)=N which transfers the timer into raised state. Then it
marks trigger T as
"incomplete" and wait action W in the trigger as
"executed". After this it continues with triggers starting with the trigger following T.
1.2. If I(P) is raised then SC marks trigger T as incomplete and the wait action W as
"delayed". After doing so it continues with triggers starting with the trigger following T.
2. When during execution of triggers for player P StarCraft encounters a trigger T which is marked as incomplete with the Wait(N) action W marked as incomplete or delayed the behavior depends on the state of the timer I(P).
2.1. If the timer I(P) is raised then SC simply ignores trigger T and continues with the execution of the next trigger for that player.
2.2. If the timer I(P) is idle or activated the behavior depends on the mark of the wait action W.
2.2.1. If action W is marked as executed SC transfers I(P) into idle state, clears marks on T and W and continues with the execution of actions with the action next to W.
2.2.2. If action W is marked as delayed SC assigns I(P)=N which transfers the timer into raised state. Then it retains trigger T mark incomplete and marks wait action W in the trigger as executed. After this it continues with triggers starting with the trigger following T.
And the last but not the least. Why the number of triggers executions per game second with hypers does not depend on the game speed?
We all know the game divides in frames. I believe frames rate is game speed dependent and there are always 16 frames in a game second
(please, someone correct me if I am wrong here!). Every second frame starcraft checks timers for all players, if
at least one timer is activated SC starts extra trigger loop. SC also starts the normal trigger loop every 16th frame regardless of whether timers are active or not.
This explains everything to me.
If anyone find any errors or inconsistencies with the actual SC behavior please let me know, I am still not 100% sure. Feel free to ask questions.
Post has been edited 8 time(s), last time on May 17 2009, 7:28 pm by Wormer.
Some.