HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Global Timers using different Intervals

08-24-2008, 02:47 PM#1
Zerzax
Does this work? Normally, with structs, I've seen and used the method where the global has a constant interval and will only be started if the struct array count is equal to zero (same with pausing). I want to use at least 10 different intervals for one of my spell, but not really the 10 timers that it would require.
08-24-2008, 05:10 PM#2
Captain Griffen
If you don't make clear what you want, we cannot answer your question.

Yes, global timers can run at different intervals, although obviously one timer cannot run at multiple intervals at the same time.
08-24-2008, 05:25 PM#3
Vexorian
You probably want something like this or this Cause that 'global timers' stuff really is not worth it when the interval is higher than 0.04 seconds...
08-24-2008, 11:18 PM#4
Zerzax
What I'm planning to do is drag in units in a 750 aoe to a certain point in 1 second. Because these units will be located at varying coordinates, the distance = rate * time formula will change for each individual unit. Each unit must reach the target area in the same amount of time, 1 second. Lets say I want a particular unit to move 10 units per interval and it is 500 units away. Therefore, it will take 50 intervals per second, so the timer interval is 1 / 50. If the unit is 700 units away, its a different formula. Finding the right instance of a struct isn't really an issue. But now that I think of it I can probably make the interval constant and the distance per interval variable... that way some units will look choppier but 1 timer can still do it with a constant interval... The intervals will definitely be .04 or smaller than that Vex.
08-26-2008, 05:59 AM#5
Pyrogasm
No, you still only need one timer with an interval of, say, 0.04. I'll explain:
  • We can use the formula T/I*O = D (Or: O = DI/T, since we want to solve for O), where T is the total time over which you want to drag the units, I is the timer interval, O is the offset moved per interval, and D is the total distance to be moved.
  • If D = 500 and T = 2, then to calculate the offset moved per interval, O = 500*0.04/2 = 10
  • If D = 700 and T = 2, then O = 700*0.04/2 = 14
  • If D = 300 and T = 0.5, then O = 300*0.04/0.05 = 24

That formula works because in your case T and I are going to be constant.
08-27-2008, 01:28 AM#6
Zerzax
Quote:
Originally posted by Zerzax
But now that I think of it I can probably make the interval constant and the distance per interval variable... that way some units will look choppier but 1 timer can still do it with a constant interval

Thats what I meant Pyro, I've already chosen .04 to be the interval, the T and I are constant and the D differs for each unit :P

P.S. thank you for the offset part of the equation, that will help me a lot with movement, I always had to extend my calculations to figure that out. I also appreciate the examples :D
08-27-2008, 04:01 AM#7
Pyrogasm
Oh, wow, lulz. I misread your post and I thought you said you couldn't think of how to do that.

Whoooops.
08-29-2008, 03:34 AM#8
Zerzax
I have another question concerning timers / tracking struct instances. Is it better to track the instance number using gamecache or through a global struct array? As in:
Collapse JASS:
globals
    struct array struct_Ar
    integer struct_total=0
endglobals

function ReturnInstance takes timer t returns structname
    local integer i=0
        loop
            exitwhen i>=struct_total
            if t==struct_Ar[i].timer then
                return struct_Ar[i]
            endif
        endloop
    return 0
endfunction

That is my current method of detecting struct instances. Instead I could use gamecache natives to track the instance (as in Set/GetCSData or timer utils). I've heard its worse to use globals, but I wanted someone else's opinion
08-29-2008, 12:49 PM#9
Vexorian
I can't think of a way to use gamecache for that, please ellaborate.
08-29-2008, 03:12 PM#10
Zerzax
Let's say in a spell trigger your action func runs when your unit casts spell:

Collapse JASS:
function SpellEffect takes nothing returns nothing
    local struct s=s.create(GetTriggerUnit())
    call StoreInteger(cache, I2S(H2I(s.timer)), "instance", s) // s.timer assigned in create method
    call TimerStart(s.timer, INTERVAl, true, function Callback)
endfunction
Later on when interval is up:
Collapse JASS:
function Callback takes nothing returns nothing
    local struct s=GetStoredInteger(cache, I2S(H2I(GetExpiredTimer())), "instance")

endfunction
Essentially I'm debating which method is best for detecting a struct instance associated with a timer (or unit for that matter).
08-29-2008, 03:21 PM#11
Anitarf
If you use a proper timer system like TimerUtils you can just use SetTimerData/GetTimerData to accomplish that.
08-29-2008, 03:22 PM#12
Vexorian
Quote:
Essentially I'm debating which method is best for detecting a struct instance associated with a timer (or unit for that matter).

Neither.

There are links in the third post of this thread, take a look at them. Both methods you mentioned are terrible, one has O(n) time complexity which means it is not too good for multi instance, the other one requires a gamecache, though the speed doesn't matter matter that much , gamecache can get very heavy as a requirement, and it makes the code look very ugly. Also, if you had many instances of that timer it would be very slow.
08-29-2008, 07:31 PM#13
Zerzax
Alrighty, I think I'll try red timerUtils, since I doubt that in my testmap it will take more than the required limit (if it does I'll use blue). Out of curiosity, what is O(n) time complexity?

Also could someone please change the name of my OLY pastebin thread? It is currently [OLY] Doom Nova I'd just like it to be [OLY] Zerzax.
EDIT: Thanks for changing it.

I have a new question, is SetUnitUserData a good way to associate struct instances with a unit? I realized that a. there isn't a native (that I know of) that flushes this value and b. if there are multiple spells working on a unit that setting this value could conflict easily with other values set to the unit.