Posts: 220
Threads: 37
Joined: May 2010
Reputation:
0
21.09.2012, 05:03
(
Последний раз редактировалось Audiophr3ak; 21.09.2012 в 10:52.
)
Suggest the most efficient (for performance) global timing system:
1) A timer gets server time (GetTime) each second, compares it with custom server variables (hh, mm ,ss), if they not same - makes them same, updates time (SetPlayerTime) for all players using a loop every next minute.
2)Same system, but "GetTime" replaced with a counter (ss++, mm++ and so on).
I know 1st variant would work more sharp, but 2nd variant gives an ability to set time directly in game.
EDIT: seems like noone have a clue, nevermind then.
Posts: 1,781
Threads: 13
Joined: Sep 2009
Reputation:
0
timers tend to run not very precise - if you use a SetTimer() with exactly 1000ms, then it sometimes needs 1001 ms, sometimes 1010 ms.
the method at increasing a variable in a non-presice timer +=1, will cause the time-delays to sum up:
a timer (1000 ms) repeated 60 times, can need 61 or 62 seconds, while the variable got incresed 60 times "only".
your first method will give better results, since it compares the non-precise timer with a fixed amount, which i assume its set in ms: as soon the timer exceeds that amount, your function gets called.
since the "trigger"call will always happen delayed, the difference between each delayed triggered call is almost the same amount: 0 to 10 ms (caused by the timer itself), BUT it will NOT be off like 2000 ms, which is often the case if you let the timer "decide" how long to run.
Posts: 220
Threads: 37
Joined: May 2010
Reputation:
0
Thanks for reply, but actually i was wondering which method is better for script performance (like less memory usage etc). Is that normal if i use "GetTime" too much, like every second?
Posts: 448
Threads: 19
Joined: Jan 2012
Reputation:
0
I am currently running a system like what you said, I use GetTickCount() for each of my different systems that checks the time every 500ms. I noticed a drop in CPU usage, mainly cause i went from 8+ timers down to one main player timer and one main server timer, memory didn't change from what i seen.
But performance wise i guess it is better in a way, it would help with less timers and things would be executed with better accuracy. Like players time online would be more accurate, game-time, or any other time related thing since its going off at a certain time.