Snippet Game Time

Flare

Stops copies me!
Reaction score
662
Strictly speaking, shouldn't you be starting the timer at 0 seconds of game-time? If someone put the time on display in their game, it'd appear to be a few seconds ahead of the actual start time (e.g. displayed value at 0 seconds of game-time could be 5) since the timer would be started while the loading screen was still present

Just did a quick test on a new map. Event was 'Elapsed game time is 0.00 seconds', and GameTime_Get () returned 0.063 and, for what it's worth, the code
Code:
Zero Sec
    Events
        Time - Elapsed game time is 0.00 seconds
    Conditions
    Actions
        Custom script:   call BJDebugMsg ("Event is Elapsed game time is 0.00 seconds, supposed elapsed time is " + R2S (GameTime_Get ()))
:p

Doesn't seem like a big thing there, but if you put the system into an existing map with alot of content, the discrepancy could be much bigger
 
Reaction score
332
Jesus4Lyf, you are right that they are 32 bit, but wc3 has stuff in the background "for reals only" that allows them to go up to mega sizes, and I have yet to find a limit : ).

Maximum value for reals is somewhere between 10^38 and 10^39. You won't be able to get any finite value larger than 10^39.
 

Nestharus

o-o
Reaction score
84
That's good to know damien. I think I went up to 10^30 and 10^-30 and just assumed that at that point it could go wildly high ;P.

It's too bad that the performance hit is so massive as you go up tho, and it's also too bad that you can't directly assign those values to the variable =|.
 
Reaction score
332
That's good to know damien. I think I went up to 10^30 and 10^-30 and just assumed that at that point it could go wildly high ;P.

It's too bad that the performance hit is so massive as you go up tho, and it's also too bad that you can't directly assign those values to the variable =|.

What performance hit is this? I'm no expert in floating point math but I assumed the performance would be more or less consistent. Do we have benchmarks for this?
 

Troll-Brain

You can change this now in User CP.
Reaction score
85
Why the hell a dynamic trigger is needed here ?

You can just increment a global integer each time the timer expire.

Also according to Vexorian a such period will be horribly inaccurate :
http://www.wc3c.net/showpost.php?p=1085942&postcount=10

EDIT :
Aha got it more "efficient" when you read the elapsed time, like a such one does matter xD

Anyway if you want to be accurate you don't have really the choice.
 

Troll-Brain

You can change this now in User CP.
Reaction score
85
A dynamic trigger is needed to start the timer at 0 seconds instead of map init.
Ok, but you still don't need a global variable, you can use GetTriggeringTrigger() instead and a local one inside the init function.

>Also according to Vexorian a such period will be horribly inaccurate
The timeout on this simply doesn't matter. Furthermore, how is being "0.007" out horribly inaccurate?
Yes you're right it isn't "horribly".
 

Azlier

Old World Ghost
Reaction score
461
Am I missing something, or will
JASS:
private function StartGameTime takes nothing returns nothing
    call TimerStart(runGameTime, gameTime, false, null)
endfunction
    
private function Initialization takes nothing returns nothing
    call TimerStart(runGameTime, 0, false, function StartGameTime)
endfunction

not work the same, if not better, than the dynamic trigger solution?
 

Jesus4Lyf

Good Idea™
Reaction score
397
Am I missing something, or will
JASS:
private function StartGameTime takes nothing returns nothing
    call TimerStart(runGameTime, gameTime, false, null)
endfunction
    
private function Initialization takes nothing returns nothing
    call TimerStart(runGameTime, 0, false, function StartGameTime)
endfunction

not work the same, if not better, than the dynamic trigger solution?
Genius. I was thinking of using a dynamic timer instead of trigger but that didn't make sense. Lol...
 

Troll-Brain

You can change this now in User CP.
Reaction score
85
It seems this solution is pointless, test this code :

JASS:
library Test initializer init

globals
    private timer Tim
    private timer T2
endglobals

private function Actions takes nothing returns nothing
    call TimerStart(T2,10.,false,null)
endfunction

private function init takes nothing returns nothing
    local trigger trig = CreateTrigger()
    call TriggerAddAction(trig, function Actions)
    call TriggerRegisterTimerEvent(trig,0.,false)
    
    set Tim = CreateTimer()
    set T2 = CreateTimer()
    call TimerStart(T2,0.,false,function Actions)
    call TimerStart(Tim,10.,false,null)
    
    call TriggerSleepAction(5.)
    call BJDebugMsg(R2S(TimerGetElapsed(Tim) * 100000.))
    call BJDebugMsg(R2S(TimerGetElapsed(T2) * 100000.))
endfunction

endlibrary


Simply start the timer one time should be enough.

Tested on an other-random-aos-that-fuck-up-your-mouse with a 9-10 seconds of loading and the difference between the two elapsed is irrelevant and probably just because 0. is not truly instant and also calling BJDebugMsg takes a few time to be done.
It seems timers start by themselves only when the loading is finished, and that makes sense.

In fact that's why i said a dynamic trigger is useless, and now i'm sure of that, blame you to make me doubtful :p
 

Sim

Forum Administrator
Staff member
Reaction score
534
Well, first of all this is a snippet, not really a system.

> MFN had like... 15 plugins... so get ready for a torrent of submissions ><

Why not find something they have in common and try to unite them?
 

UndeadDragon

Super Moderator
Reaction score
448
Any reason why the function is called GameTime_Get(), rather than GetGameTime(). To me it seems more logical to call it GetGameTime().
 

Vexorian

Why no custom sig?
Reaction score
187
The constant keyword makes no difference after compiled to bytecode, it does not exist in the bytecode, it does nothing speed-wise.

It is more of a language feature, like setting the global as read-only, and in the case of functions, it means the function will always return the same thing after you give it the same arguments, unfortunately, this has been implemented very poorly, because you can do things like set inside constant functions, and there are many natives that are DEFINITELY not constant, yet they have that keyword.

The only use for the constant keyword is when the optimizer tries to inline them. As for constant functions, they used to be useful only when you wanted the optimizer to inline them. Nowadays they aren't that much as jasshelper can inline even non-constant functions, and it turns out "constant" gives little to no guarantee about a function being inline friendly.
 

Nestharus

o-o
Reaction score
84
JASS:
private function StartGameTime takes nothing returns nothing
    call TimerStart(runGameTime, gameTime, false, null)
endfunction
    
private function Initialization takes nothing returns nothing
    call TimerStart(runGameTime, 0, false, function StartGameTime)
endfunction

I remember a long time ago that when I'd start a timer, it wouldn't start properly unless started after loading. I used this while making it and didn't think to do a quick test on starting a timer before loading : ).

I'll be updating it to use this format right now : ).

Finally, everyone prefers the normal JASS style of things like GetElapsedGameTime, so the function name changed to that : ). I normally work in a more OO environment, so it's more natural for me to do things like GameTime.GetElapsed(), =).
 

Romek

Super Moderator
Reaction score
963
Changed from [System] to [Snippet]

The naming of the global timer does bug me, though it's private anyway, so meh. Nobody will know about it.

Anyway, approved.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top