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
333
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
333
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
447
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
964
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.
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +2
  • V-SNES V-SNES:
    Happy Friday!
    +1
  • The Helper The Helper:
    New recipe is another summer dessert Berry and Peach Cheesecake - https://www.thehelper.net/threads/recipe-berry-and-peach-cheesecake.194169/

      The Helper Discord

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top