Snippet Game Time

Nestharus

o-o
Reaction score
84
Game Time​

---------------------------------------------
It's time to get your game on


JASS:

/*Utility Information
//===================================================================
Name: GameTime
Version: 1.0
Author: Nestharus

Description: This will track the game time.

Requirements: None

Installation: NA

Usage:
------------------------------------------------------------------
-GetElapsedGameTime takes nothing returns real
 will return the current elapsed game time
 
 local real currentGameTime = GetElapsedGameTime()
------------------------------------------------------------------*/
//===================================================================

library GameTime initializer Initialization
    globals
        private timer gameTime = CreateTimer()
    endglobals
    
    function GetElapsedGameTime takes nothing returns real
        return TimerGetElapsed(gameTime)
    endfunction
    
    private function Initialization takes nothing returns nothing
        call TimerStart(gameTime, 1000000, false, null)
    endfunction
endlibrary
 

Sevion

The DIY Ninja
Reaction score
413
I don't know why anyone would want GameTime, but you used it in Timed ;o Then again, I guess some people would have usage in this. ;o Nice.
 

Nestharus

o-o
Reaction score
84
Submitted because a lot of my other stuff will require this.

People don't like the idea of these small snippets plugging into an arching framework, so I gotta split them : |.

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

Azlier

Old World Ghost
Reaction score
461
Hey, this looks like something that actually might work. I see no actual use, but still...

Make this one change, though:
JASS:

globals
    private integer gameTime = 0
endglobals

private function Initialization takes nothing returns nothing
    call TimerStart(CreateTimer(), 10000, true, function AddToGameTime)
endfunction
 

Nestharus

o-o
Reaction score
84
That'd be a bad thing to do =o. It'd make it slightly slower

JASS:
return gameTime + TimerGetElapsed(runGameTime)


Using a constant vrs using GetExpiredTimer() is better =).
 

Azlier

Old World Ghost
Reaction score
461
Ah, didn't see that. Unconstantize the timer, instead. Having a constant handle is a stupid idea.

Vex's optimizer tries to inline constants, you see? What happens when it inlines runGameTime with CreateTimer()?
 

Nestharus

o-o
Reaction score
84
It has a lot to do with it??

JASS:
return gameTime + TimerGetElapsed(runGameTime)


And if that's not enough

JASS:
function GameTime_Get takes nothing returns real
        return GameTime__gameTime + TimerGetElapsed(GameTime__runGameTime)
    endfunction
    
    function GameTime__AddToGameTime takes nothing returns nothing
        set GameTime__gameTime = GameTime__gameTime + 10000
    endfunction
    
    function GameTime__Initialization takes nothing returns nothing
        call TimerStart(GameTime__runGameTime , 10000 , true , function GameTime__AddToGameTime)
    endfunction


Is it inlined? no

Ok, performing another test using the Vex Optimizer Program. I apparently mis-understood ^_^. I thought you meant Vex's JH Optimizer, which does inline etc.

More proof
JASS:
function GameTime_Get takes nothing returns real
return E+TimerGetElapsed(V)
endfunction
function PV takes nothing returns nothing
call DisplayTextToPlayer(GetLocalPlayer(),0,0,I2S(GetHandleId(GetExpiredTimer())))
call DisplayTextToPlayer(GetLocalPlayer(),0,0,I2S(GetHandleId(V)))
set E=E+1
endfunction
function QV takes nothing returns nothing
call TimerStart(V,1,true,function PV)
endfunction
 

Jesus4Lyf

Good Idea™
Reaction score
397
This is a bit silly.

The reason you make the timer periodic and expire is because the game may last longer than the period.

But reals have a maximum value anyway - why not just use that for the period? Same effect, more efficient.

Anyway, a significantly better version of this (the version I use):
JASS:
library GameTime initializer OnInit
    globals
        private constant real FOREVER = &#039;ever&#039;
        
//=======================================================
        private timer GameTimer = CreateTimer()
    endglobals
    
    public function Get takes nothing returns real
        return TimerGetElapsed(GameTimer)
    endfunction
    
    private function OnInit takes nothing returns nothing
        call TimerStart(GameTimer, FOREVER, false, null)
    endfunction
endlibrary
 

Nestharus

o-o
Reaction score
84
Changed : )

Originally had it like what you showed Jesus, but changed because I had wanted to do it for infinity (kinda pointless I guess).

Now it's back to what it was : D.

Also, I don't know of a maximum value for reals?? If you know of one, please let me know ^_^.

As far as I know, reals can go up until your computer crashes o-o (pretty much infinite)
 

Igor_Z

You can change this now in User CP.
Reaction score
61
So this is for getting game time and using it in other triggers or what? Add some discription up there plz
 

Jesus4Lyf

Good Idea™
Reaction score
397
constant timer stays because it's faster
Prove it.
it's pointless to use one that's not constant
Wrong, some version of Optimizer will inline it screwing this system completely?
smaller numbers run faster than bigger numbers
Prove it.
if you have found a limit for reals I'd like to know it. I've yet to find a limit, and I've made some massive ones. They can be bigger than strings O_O.
How long is a piece of string?

Anyway, they're 32 bit. I have my doubts about how well Warcraft III does bounds checking, but I expect strange things happen when you pass a certain limit.
 

Nestharus

o-o
Reaction score
84
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 : ). Integers have nothing in them that allows them to get bigger tho : (.

For reals, you can't directly assign them big numbers : ). I do stuff like real = 10000000

set real = real * 10000000

or real .00000001
set real = real /10000000

you can just increase and decrease them to any limit (you are limited on the numbers you input, but if you use other reals then it's still any limit o-o).

etc : d.

Wrong, some version of Optimizer will inline it screwing this system completely?

Can you show me a version? I used Vexorian's latest without any probs and I posted the code up.

smaller numbers run faster than bigger numbers

I think this really only applies for when you pass the 32 bit limit on reals : ), which is why I changed it : P.

constant timer stays because it's faster

Constants always run faster? Constant functions are pure machine code and constant variables are static ;o. Then again, the optimization here would be for starting the timer and retrieving the timer (very slight, would probably have to run it mondo times to see a dif).

So this is for getting game time and using it in other triggers or what? Add some discription up there plz

There is a description =o.
 

Nestharus

o-o
Reaction score
84
Already made the timer non-constant since that's what everyone wanted =). This was made for the community, not me, so you guys get the final say. That's my new outlook on things ; D.
 

Nestharus

o-o
Reaction score
84
It'll do that on certain optimizers from what I heard. Vex's isn't one of them and I've yet to see a case of where it does that ; ).
 
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