Sharing an Idea - Periods as variables

Dr.Jack

That's Cap'n to you!
Reaction score
109
An exact piece of code? Not sure, I'm talking about hypothetic things here. There are many examples that getting a value off a timer before it is expired will help optimizing the code. The thing is getting a value of a timer even when it doesn't expire is always a good thing. Look at attaching system two years ago. Look at them now. Did they imporve in a 'Boom'? No. Every new system was slightly better than the previous one. Better speed, more comfortable, less limitation, etc.... Even if its not an important thing, it is still a good thing.
 

Troll-Brain

You can change this now in User CP.
Reaction score
85
I don't try to be annoying but simply try to understand why a such thing would be useful, i guess i won't believe it's useful while i don't see a piece of code, currently i still don't figure a such case.

Anyway like you said it's not the point of it, so i won't talk about it anymore.
 

Dr.Jack

That's Cap'n to you!
Reaction score
109
Bump!
Any chance someone tests the system? I really don't want to post it without knowing if its fast enough to be useful.
 

Troll-Brain

You can change this now in User CP.
Reaction score
85
I was trying to make one vs TU red and TU blue, but i'm wondering about the use of LocalGetData, shouldn't take it a timer in argument instead of real (and use TimerGet...) ?

Give an example of use.
 

Dr.Jack

That's Cap'n to you!
Reaction score
109
Thanks for that Troll-Brain! Did you test the lastest code (post #15)?

JASS:
function ccc takes nothing returns nothing
    local real r = TimerGetTimeout(GetExpiredTimer())
     call BJDebugMsg(I2S(GetData(r)))
endfunction

function Trig_Untitled_Trigger_002_Actions takes nothing returns nothing
    local real r = 0.1
    local integer i = 1
    call TimerStart(CreateTimer(),SetPeriod(r, i), true, function ccc)
endfunction


If I ever post the the system I'll probably add a function that returns data through timer.

I would love if you could post the results of TU red/blue against

JASS:
call SetPeriod(0.1,1)
call GetData(0.10000001)
// Or other numbers, doesn't matter
 

Troll-Brain

You can change this now in User CP.
Reaction score
85
After some tests it seems TimerGetTimeout can't handle a such precision (and if fact it's most likely timeout of timers by themselves), so your script should be fairly useless in the current state.
Or try to use also TimerGetRemaining and TimerGetTimeout.

If these 2 lasts can't handle a such precision, then i'm afraid that your script have no use :(
 

Dr.Jack

That's Cap'n to you!
Reaction score
109
After some tests it seems TimerGetTimeout can't handle a such precision (and if fact it's most likely timeout of timers by themselves), so your script should be fairly useless in the current state.
Or try to use also TimerGetRemaining and TimerGetTimeout.

If these 2 lasts can't handle a such precision, then i'm afraid that your script have no use :(

Are you sure? I tested the code again and again and again and have yet to see it fail. Can you post perhaps you tests and their results?
 

Troll-Brain

You can change this now in User CP.
Reaction score
85
Are you sure? I tested the code again and again and again and have yet to see it fail. Can you post perhaps you tests and their results?

It works to link an integer to a real, but not for a timer, here is the deal, try to use it in a timer callback.

EDIT : I will try it again, however even if it works i will post the benchmark tommorow.
 

Troll-Brain

You can change this now in User CP.
Reaction score
85
JASS:
library MP
function SetPeriod takes real p, integer i returns real
    return p + (i * 0.00000001) + 0.00000001
endfunction

function GetData takes real p returns integer
    set p = (p * 10000)
    return R2I(((p) - R2I(p)) * 10000)
endfunction
endlibrary


JASS:
scope Test initializer init

private function ccc takes nothing returns nothing
    local real r = TimerGetTimeout(GetExpiredTimer())
     call BJDebugMsg(I2S(GetData(r)))
endfunction

private function Actions takes nothing returns nothing
    local real r = 0.1
    local integer i = 1
    call TimerStart(CreateTimer(),SetPeriod(r, i), true, function ccc)
endfunction

private function init takes nothing returns nothing
    local trigger trig = CreateTrigger()
    call TriggerRegisterPlayerEventEndCinematic(trig,Player(0))
    call TriggerAddAction(trig, function Actions)
endfunction

endscope


Always display "0", as i said it seems a timer can't handle such many numbers under the digit.
Do more tests about it if you want.
 

Troll-Brain

You can change this now in User CP.
Reaction score
85
More tests :

JASS:
scope Test initializer init

globals
    private constant real LOWEST_PERIOD_POSSIBLE = 0.0001 // you can't use a period below this one
    private integer I = 0
    private integer J = 0
    private timer Tim1 = CreateTimer()
    private timer Tim2 = CreateTimer()
endglobals

private function Doloop1 takes nothing returns nothing
    set I = I+1
endfunction

private function Doloop2 takes nothing returns nothing
    set J = J+1
endfunction
private function Display takes nothing returns nothing
    call BJDebugMsg(" ")
    call BJDebugMsg("I == " + I2S(I))
    call BJDebugMsg("J == " + I2S(J))
    call BJDebugMsg("Timeout of Tim1 == " + R2SW(TimerGetTimeout(Tim1),15,15))
    call BJDebugMsg("Timeout of Tim2 == " + R2SW(TimerGetTimeout(Tim2),15,15))
    call BJDebugMsg("elapsed time of Tim1 == " + R2SW(TimerGetElapsed(Tim1),15,15))
    call BJDebugMsg("elapsed time of Tim2 == " + R2SW(TimerGetElapsed(Tim2),15,15))
    call BJDebugMsg("remaining time of Tim1 == " + R2SW(TimerGetRemaining(Tim1),15,15))
    call BJDebugMsg("remaining time of Tim2 == " + R2SW(TimerGetRemaining(Tim2),15,15))

    call DestroyTimer(GetExpiredTimer())
    
endfunction

private function Actions takes nothing returns nothing

    call DestroyTimer(Tim1)
    call DestroyTimer(Tim2)
    set I = 0
    set J = 0
    set Tim1 = CreateTimer()
    set Tim2 = CreateTimer()
    
    call TimerStart(Tim1,LOWEST_PERIOD_POSSIBLE,true,function Doloop1)
    call TimerStart(Tim2,0.,true,function Doloop2)
    call TimerStart(CreateTimer(),1.,false,function Display)
    
endfunction


private function init takes nothing returns nothing
    local trigger trig = CreateTrigger()
    
    call TriggerRegisterPlayerEventEndCinematic(trig,Player(0))
    call TriggerAddAction(trig,function Actions)
endfunction

endscope


As you can see time out display what argument was used with the function TimerStart, but not the real one.
time out + time elapsed seems to give the true period.

Anyway real are just floats, so even if there are no mistakes in your formulas, it wouldn't be reliable if you play with so many digits.

But in case you need the lowest period possible, it's pretty easy to link an integer to the timer, just use a negative integer period.
Sometimes these kind of timers are useful when an event fire.
 
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