HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Events are expiring simultaneously?

01-30-2009, 06:42 AM#1
Blackroot
Bleh, I'm not sure why this is happening. I have a periodic function which should alter units x/y/z but whenever 1 unit expires ALL units expire and callback.

Anyone see a reason for this?

Collapse JASS:
function interface MotionFunction takes nothing returns nothing

struct Motion
    unit rotating
    real x
    real y
    real z
    real xtheta
    real ytheta
    real ztheta
    real dur
    MotionFunction callback
endstruct

function TrigMotion takes nothing returns nothing
    local Motion m
    local integer I = NMotionObjects - 1
    
    loop
        set m = MotionObjects[i]
        set m.dur = m.dur - update
        
        call SetUnitX(m.rotating, GetUnitX(m.rotating) + m.xtheta)
        call SetUnitY(m.rotating, GetUnitY(m.rotating) + m.ytheta)
        set m.z = m.z+m.ztheta
        call SetUnitFlyHeight(m.rotating, m.z, .01)
        
        if(m.dur <= 0)then
            call m.callback.evaluate()
            call m.destroy()
            set NMotionObjects = NMotionObjects - 1
            set MotionObjects[i] = NMotionObjects
        endif
        exitwhen(I == 0)
        set I = I - 1
    endloop
    
    if(NMotionObjects == 0)then
        call PauseTimer(MotionTimer)
    endif
endfunction

While I'm on the subject I also have two slightly unrelated questions:
What happens if my callback is null?

Second question (involves math) I'm looking for a way to grant the most flexibility with the least number of reals. Assuming I have a function like:
F(x) = A(Bx+b)+a

In this case where A and B are fixed angles, I have essentialy maximum efficiency.

My question, however, is:

F(x) = Sin(A)c((Cos(B)dx+b)+a

Although it takes a large hit to efficiency it grants me the ability to strect and skew the x/y plane in addition to linear increments. However, is this plausable in a case of a large group of units (say 30) in this sytem?

Thanks :)
01-30-2009, 08:42 AM#2
Captain Griffen
You shouldn't set i = i - 1 if you destroy one.

Sin and Cos are lightning fast.
01-30-2009, 10:15 AM#3
Anitarf
Quote:
Originally Posted by Captain Griffen
You shouldn't set i = i - 1 if you destroy one.
Actually, he should. Since he's goin backwards, he's already gone over the last index. This actually quite a smart way to do it, less room for error.

The problem is that set MotionObjects[i] = NMotionObjects should be set MotionObjects[i] = set MotionObjects[NMotionObjects]
Also, you shouldn't use I as a variable because when posting the code on wc3c if it's used as an array index it becomes lowercase (because of italics, no idea how that works). I know, it's a very lame reason, but it's really hard to read code when it uses both I and i.
01-30-2009, 12:50 PM#4
Captain Griffen
Erm...what Anitarf said. I was thinking of looping up.