HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

How to make functions faster?

08-15-2006, 04:40 AM#1
DioD
Collapse JASS:
function SFX_Timed_Loc_Child takes nothing returns nothing
    local integer Slot = H2I(GetExpiredTimer())-1048675
    call DestroyEffect(udg_LH_Effect[Slot])
    call DestroyTimer(udg_LH_Timer[Slot])
    set udg_LH_Effect[Slot]=null
    set udg_LH_Timer[Slot]=null
endfunction

function SFX_Timed_Loc takes string Effect, real X,real Y,real Time returns nothing
    local timer Timer = CreateTimer()
    local integer Slot = H2I(Timer)-1048675
    set udg_LH_Timer[Slot] = Timer
    set udg_LH_Effect[Slot] = AddSpecialEffect(Effect,X,Y)
    call TimerStart(udg_LH_Timer[Slot],Time,false,function SFX_Timed_Loc_Child)
    set Timer = null
endfunction

I dont know how to test functions speed.

Is this faster then cache?
Can this be faster?
Is this leak?
08-15-2006, 11:00 AM#2
blu_da_noob
It will almost certainly be faster than cache, but that doesn't mean it's better than using cache. It has other problems.
08-15-2006, 11:14 AM#3
Captain Griffen
Collapse JASS:
function TimerAttach takes timer t, real time, real value, code func returns nothing
    call TimerStart(t, value, false, null)
    call PauseTimer(t)
    call TimerStart(t, time, false, func)
endfunction

// ONLY call on an expired timer.
function GetTimerInt takes timer t returns integer
    return R2I(TimerGetRemaining(t) + 0.5)
endfunction

function SFX_Timed_Loc_Child takes nothing returns nothing
    call DestroyEffect(I2E(GetTimerInt(GetExpiredTimer())))
    call DestroyTimer(GetExpiredTimer())
endfunction

function SFX_Timed_Loc takes string Effect, real X,real Y,real Time returns nothing
    call TimerAttach(CreateTimer(),Time,H2I(AddSpecialEffect(Effect,X,Y)),function SFX_Timed_Loc_Child)
endfunction
08-15-2006, 11:26 AM#4
DioD
Is this faster then arrays?
08-15-2006, 12:25 PM#5
Captain Griffen
Probably faster than your method, yes. If you want to know for certain benchmark the two against each other.
08-15-2006, 03:02 PM#6
Toadcop
Quote:
Probably faster than your method
- if Timers a faster then ARRAYS ! then JASS is shit.... no comments more...
the code is good...
08-15-2006, 03:22 PM#7
Captain Griffen
Read, understand, post. He has to use a timer, and we are discussing the ways to attach things to a timer. His method requires the creation, setting and destruction of multiple variables, extra usage of H2I, subtraction and usage of globals, while my method requires only a couple of extra function calls. My method is probably faster, though they are both fast methods.

Both methods use a timer, however.