Sharing an Idea - Periods as variables

Dr.Jack

That's Cap'n to you!
Reaction score
109
Well this was supposed to be a data to timer attachment system. However after testing (Thanks Artificial for testing!!) it appears as this system's speed is no match to TU,KT2,T32 (damn J4L you are good :p) etc.... I think however that the concept behind has never been tried before so I thought about sharing it, perhaps a better Jasser could use this. Presenting Manipulated Periods (after some massive cleaning) to anyone remotely interested. Anyway while working on this I learned a bit of small reals, can't be a bad thing. ;)

Basically this attaches data to a timer by using periods. It take's the timer period and slightly increase it by converting the data to a real small real and adding it. Than when retrieving data it uses the period.

JASS:
function SetPeriod takes real p, integer i returns real
    if i < 10 then
        return p + S2R("0.0000000" + I2S(i)) + 0.00000001
    elseif i < 100 then
        return p + S2R("0.000000" + I2S(i)) + 0.00000001
    elseif i < 1000 then
        return p + S2R("0.00000" + I2S(i)) + 0.00000001
    else
        return p + S2R("0.0000" + I2S(i)) + 0.00000001
    endif
    
    return 0.
endfunction

function LocalGetData takes real p returns integer
    local integer i = R2I(p * 100000000)
    local string s = I2S(i)

    set i = StringLength(s)
    set s = SubString(s,i-4,i)
    
    return S2I(s)
endfunction


Edit: Untested, removed strings from the attach function.. Don't know why I didn't do it this way in the first place. :p
Now if there was anyway to remove string use from the LocalGetData func...

JASS:
function SetPeriod takes real p, integer i returns real
    return p + (R2I(i) * 0.00000001) + 0.00000001
endfunction
 

Azlier

Old World Ghost
Reaction score
461
Playing with strings is very slow.
 

Dr.Jack

That's Cap'n to you!
Reaction score
109
Yup, seems so. In SetPeriod I guess there is a way to manage without strings, but there is no way to do LocalGetData without strings.
 

Dr.Jack

That's Cap'n to you!
Reaction score
109
I just realized that there is a much simpler way to do this... And to think the current code required 2 days of testing to get full understanding...

JASS:
library MP
function SetPeriod takes real p, integer i returns real
    return p + (i * 0.00000001) + 0.00000001
endfunction

function LocalGetData takes real p returns integer
    local real tp = (p * 100000)
    local integer ip = R2I(tp)
    set tp = tp - ip
    return R2I(tp * 1000)
endfunction
endlibrary


That should be fast enough, no?
 

Troll-Brain

You can change this now in User CP.
Reaction score
85
As far as I understand this statement only if a timer finished running you can use this. Or did I misinterpret the term expired?

Hmm yes, but why you would need it when the timer is running anyway ?
Maybe i miss something.

Also :

JASS:
function LocalGetData takes real p returns integer
    return R2I((p * 100000. - R2I(p * 100000.)) * 1000.)
endfunction


I wonder it it would be faster, even if it won't be inlined (p used many times and not only one)
At least i would use "." for reals, even if it doesn't matter it clearly show that is a real and not an integer, for sake readability.
 

Troll-Brain

You can change this now in User CP.
Reaction score
85
myself said:
Hmm yes, but why you would need it when the timer is running anyway ?
Maybe i miss something.
Some words, coz the quote doesn't count in the length of a message.
 

Dr.Jack

That's Cap'n to you!
Reaction score
109
My SW fails.
Is anyone willing to test

JASS:
library MP
public function SetPeriod takes real p, integer i returns real
    return p + (i * 0.00000001) + 0.00000001
endfunction

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


Versus TU (Red)? Also testing along the way TU(Blue) and KT2 probably won't hurt (not optimistic about KT2 but what the heck).

Thanks a lot to anyone willing to do this and post the results!
 

Troll-Brain

You can change this now in User CP.
Reaction score
85
The current functions should be faster than his at a quick glance.
Then it's fine if it's true.

Anyway what's wrong with working on something new?
Nothing, i was simply wondering about which case you need to get a value attached to a timer outside his expiration.
And it seems you can't figure one, like i thought.
 

Dr.Jack

That's Cap'n to you!
Reaction score
109
Then it's fine if it's true.


Nothing, i was simply wondering about which case you need to get a value attached to a timer outside his expiration.
And it seems you can't figure one, like i thought.

I'm still not 100% what you mean by expired. If you mean expired as when the callback function is called, true there are few cases you would want to get a value from a timer before its expirimanation. Yet, there will be times that you need to that, and a proper answer needs to be found.

Want an example? Just off the top of my head -Timer recycling with high periods. You could use the attached value to determine accurately when to recycle and by that optimizing the code to the max.
 

Troll-Brain

You can change this now in User CP.
Reaction score
85
Yes that is what i wanted to say.

Want an example? Just off the top of my head -Timer recycling with high periods. You could use the attached value to determine accurately when to recycle and by that optimizing the code to the max.
I'm lost.
Could you give a piece of code plz ?
 
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