sc2c.org

Go Back   Sc2C.org > Resources > Tutorials
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Search this Thread Display Modes
Old 10-11-2010, 05:07 AM   #1
grim001
Junior Member
 
Join Date: Oct 2010
Posts: 1
Default Guide: Ticks per second, waits, timers, real time, game time...

I've spent all day researching exactly how time works in SC2, and I'm here to document the results of my findings.

Ticks Per Second vs Game Speed

The scripting engine runs with a certain number of ticks per second depending on the current game speed setting. To calculate this, you can simply take the base number of updates per second in normal speed (32) and multiply it by the current game speed modifier (retrievable by using the GameGetSpeed() native). Yes, it actually does use non-integer values for the number of updates per second, so do not round to the nearest integer or your timing calculations will become inaccurate.

Code:
Game Speed | Slower, Slow, Normal, Fast, Faster Speed Modifier | 0.6, 0.8, 1.0, 1.2, 1.4 Ticks Per Second | 19.2, 25.6, 32, 38.4, 44.8 Tick Duration | ~0.052083, 0.0390625, 0.03125, ~0.0260416, ~0.0223214

Wait 0

Now, about the Wait function. Using either Wait(0, c_timeReal) or Wait(0, c_timeGame) has precisely the same effect: the function will resume during the very next tick. This means that a 0.0 Wait loop will iterate during every single tick of the scripting engine. ANY other value than 0.0 will cause the next tick to be skipped. The number of iterations per second will be decided by your current game speed as shown in the chart above. The actual duration of a Wait 0.0 is equal to the Tick Duration on the chart above. In other words, the speed at which 0.0 loops iterate scales directly with the adjustment of the game speed.

Timers and Wait >0

Timers and the Wait function when used with non-0 values both share something in common, and that is that they are incapable of expiring on every tick of the scripting engine. They will only expire every OTHER tick. This means that a Wait 0.00001 loop will expire half as quickly as a Wait 0 loop! The minimal expiration time of timers and non-0 wait loops for each game speed is listed in the chart below. If your wait or timer duration isn't a multiple of those values, it may cause a rather large amount of inaccuracy which has the potential to compound in itself if you repeatedly restart the wait or timer.

Code:
Game Speed | Slower, Slow, Normal, Fast, Faster Maximum Expirations Per Second | 9.5, 12.8, 16, 19.2, 22.4 Minimal Expiration Time | ~0.10526, 0.078125, 0.0625, ~0.052083, ~0.04464

Real Time

Here's the first thing you should know: StarCraft 2's perception of real time does not match match your clock's perception of real time. The game engine is meant to pretend that time is not elapsing during any lag or slowdown. If you watch SC2's real time (viewable in the debug menu with an option), it will never progress quite as quickly as a clock, and the more stuff that's going on in your map, the larger the gap will become. If you have large amounts of slowdown, SC2 may believe that time is passing much more slowly than it really is. Also, time does not advance while a player is lagging. During optimal conditions, SC2's real time may fall behind a clock by about 1 second each minute.

Tracking Real Time

Starcraft 2 lacks a native to return the current amount of elapsed real time. You can use this simple function to do so:
Code:
fixed GameGetElapsedTime () { return GameGetMissionTime() / GameGetSpeed() ; }

Game Time

It is possible to view the current elapsed game time by using the native GameGetMissionTime(). However, you can expect 3 strange behaviors out of this native: first, it only updates the time it will return on every other tick of the scripting engine. Second, its time output is directly scaled by the game speed modifier, i.e. in fastest mode, time will pass 40% more quickly. Third, the passage of time will also be influenced by SC2's perception of real time, as described above.

Real Time vs Game Time

With Waits and Timers, you have the option to use either c_realTime or c_gameTime. As we mentioned before, this distinction has no effect on 0.0 wait timers. It is simply up to you whether you would prefer to have your waits and timers speed up or slow down based on the game speed modifier, or whether you would like for them to expire in the same amount of real time regardless of game speed. There should be different times that each is appropriate.

I will update this guide to contain any new information discovered about the topics addressed above, so feel free to contribute anything else you discover.

Last edited by grim001 : 10-11-2010 at 06:03 AM.
grim001 is offline   Reply With Quote
Old 10-12-2010, 11:57 AM   #2
TKF
Cruiser Commander
 
TKF's Avatar
 
Join Date: Jul 2010
Posts: 32
Default

Thanks, this is really useful info you have shared with us.
__________________
Cruiser Command for WC3 - Never coming to SC2...
TKF is offline   Reply With Quote
Old 11-03-2010, 05:45 PM   #3
Toadcop
Member
 
Toadcop's Avatar
 
Join Date: Apr 2010
Posts: 36
Default

Quote:
The scripting engine runs with a certain number of ticks per second depending on the current game speed setting.
the game* not just scripting engine now it's fully a part of game (no* idea how exactly it was in wc3) as one step of logic processing.

when you plan to release your physic engine ? =O

Last edited by Toadcop : 11-03-2010 at 11:51 PM.
Toadcop is offline   Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT. The time now is 08:08 PM.


Powered by vBulletin
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.