List of 'Slow' function

hgkjfhfdsj

Active Member
Reaction score
55
SOLVED

hi, just looking for a list of functions that are generally slow in terms of execution time. im looking to spam these functions so that it is slow enough to be beaten by a TriggerExecute() or (if possible) a 0.0 timeout. basically want to control the order each events occur. my other question is: how are/ in what order are functions called. eg
if 2 different triggers call 'ForGroup', which trigger calls it first, and when does the other triggers ForGroup start?

and if it matters, im trying to create a GetEventDamage() that supports any form of blocking. ie, if a unit blocks off 50 damage, GetEventDamage will return the damage taken – 50; if 2 different triggers each block 50, it will return –100. methods ive come up with
- creating a damage event which fires appropriate trigger (TriggerExecute/Evaluate) (similiar to Jesus4lyf's 'Event' system)
- storing the event damage to a global array before the it fires the trigger
- custom block damage using unit attachment (subtracts from global array)
- GetEventDamageEx() <-- slows down so that every triggers that has BlockDamage is fired.

my triggers (note that it resembles GDD since i pretty much ripped it off that :p)
JASS:

//==============================================================
//   Damage
//==============================================================
globals
   (omitted udg_)  
     real array Damage_EventDamage // value that is set to eventdamage when event first fires
     integer array udg_Damage__I// [0] is total registered units, [1] is recycle indexer 
     integer array Damage__Trigger_I //registered triggers to the event
     trigger array Damage__Trigger_V//the trigger for the above
     unit array Damage__U //registered units
     trigger array Damage__V//actual trigger for damage event for (to be destroy when recycled)  
     real array Damage_EventDamage
endglobals
//==============================================================

function  TriggerRegisterAnyUnitDamagedEvent takes trigger trig, boolexpr userFunc returns nothing
    //function to register triggers
    if trig==null then
        call BJDebugMsg(&quot;|cFFFF0000Error|r Attempting to register a null trigger.&quot;)
        return
    endif
    set udg_Damage__Trigger_I = udg_Damage__Trigger_I+1
    set udg_Damage__Trigger_V[udg_Damage__Trigger_I] = trig
    call TriggerAddCondition(trig, userFunc)
endfunction
function Damage__Filter takes unit u returns boolean //same naming convention as GDD xD
    return not IsUnitType(u, UNIT_TYPE_STRUCTURE) and GetUnitAbilityLevel(u, &#039;Aloc&#039;) == 0
endfunction

function Damage__RecycleRate takes nothing returns real //same naming convention as GDD xD
    return 1.
endfunction

function Damage__FireEvent takes nothing returns boolean
    //fires triggers registered to event
    //ripped from &#039;event&#039; <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite7" alt=":p" title="Stick Out Tongue    :p" loading="lazy" data-shortname=":p" />
    local trigger currentTrigger
    local integer i = udg_Damage__Trigger_I
    loop
        exitwhen i&lt;0 
        set currentTrigger = udg_Damage__Trigger_V<i>
        if IsTriggerEnabled(currentTrigger) then   
            if TriggerEvaluate(currentTrigger) then
                 call TriggerExecute(currentTrigger)
            endif
        else
            //remove destroyed triggers
            call EnableTrigger(currentTrigger)
            if IsTriggerEnabled(currentTrigger) then
                call DisableTrigger(currentTrigger)
            else
              
                //
                set udg_Damage__Trigger_V<i> = udg_Damage__Trigger_V[udg_Damage__Trigger_I]
                set udg_Damage__Trigger_I = udg_Damage__Trigger_I-1
            endif
        endif
        set i=i-1
    endloop
    set currentTrigger = null
    return false
endfunction

function Damage__onDamageEvent takes nothing returns boolean
    set udg_Damage__EventDamage[GetUnitIndex(GetTriggerUnit())] = GetEventDamage()//save eventdamage before blockdamage    
    call Damage__FireEvent()   
    //blocking goes here
    
    return false
endfunction

//the rest pretty much functions like GDD..

function Damage__AddDetection takes nothing returns boolean
    if Damage__Filter(GetFilterUnit()) then
        set udg_Damage__I[0] = udg_Damage__I[0] + 1
        set udg_Damage__V[udg_Damage__I[0]] = CreateTrigger()
        set udg_Damage__U[udg_Damage__I[0]] = GetFilterUnit()
        call TriggerRegisterUnitEvent(udg_Damage__V[udg_Damage__I[0]], udg_Damage__U[udg_Damage__I[0]], EVENT_UNIT_DAMAGED)
        call TriggerAddCondition(udg_Damage__V[udg_Damage__I[0]], Condition(function Damage__onDamageEvent))
    endif
    return false
endfunction

function Damage__Recycle takes nothing returns nothing
    if udg_Damage__I[0] == 0 then
        return
    endif
    if udg_Damage__I[1] &lt; 0 then
        set udg_Damage__I[1] = udg_Damage__I[0]
    endif  
    if GetUnitTypeId(udg_Damage__U[udg_Damage__I[1]]) == 0 then
        call DestroyTrigger(udg_Damage__V[udg_Damage__I[1]])      
        set udg_Damage__V[udg_Damage__I[1]] = udg_Damage__V[udg_Damage__I[0]]
        set udg_Damage__U[udg_Damage__I[1]] = udg_Damage__U[udg_Damage__I[0]]
        set udg_Damage__U[udg_Damage__I[0]] = null
        set udg_Damage__V[udg_Damage__I[0]] = null
        set udg_Damage__I[0] = udg_Damage__I[0] - 1  
    endif
    set udg_Damage__I[1] = udg_Damage__I[1]-1
endfunction

function InitTrig_Damage takes nothing returns nothing
    local region r = CreateRegion()
    local region wb = GetWorldBounds()
    local integer i = 0
    call GroupClear(bj_lastCreatedGroup)
    loop
        call GroupEnumUnitsOfPlayer(bj_lastCreatedGroup, Player(i), Condition(function Damage__AddDetection))
        set i = i+1
        exitwhen i == bj_MAX_PLAYER_SLOTS
    endloop
    //call GroupClear(bj_lastCreatedGroup)
    call RegionAddRect(r, wb)
    call RemoveRect(wb)
    call TriggerRegisterEnterRegion(CreateTrigger(), r, Condition(function Damage__AddDetection))
    call TimerStart(CreateTimer(), Damage__RecycleRate(), true, function Damage__Recycle)
    
    set udg_Damage__I[0] = 0
    set wb = null
endfunction</i></i>

JASS:

//==============================================================
//   Shield
//==============================================================
globals
  real array ShieldLife
  unit array ShieldUnit
endglobals
//==============================================================
function GetEventDamageEx takes nothing returns nothing // &lt;------
    return udg_Damage_EventDamage[GetUnitIndex(GetTriggerUnit())]
endfunction

function ShieldDamage takes unit whichUnit, real amount, boolean priority returns nothing
    local integer index = GetUnitIndex(whichUnit)
    if amount &gt; 0 then
        set udg_ShieldLife[index] = udg_ShieldLife[index] + amount
    endif
endfunction

function GetShieldLife takes unit whichUnit returns real
    local real life
endfunction

function Shield__onDamage takes nothing returns boolean
    local unit u = GetTriggerUnit() 
    local real blockamount //etc  
    if udg_ShieldLife[index] &gt; 0.405 then
        //block/healing not completed
        set udg_Damage_EventDamage[GetUnitIndex(u)] = udg_Damage_EventDamage[GetUnitIndex(u)] - blockamount 
    endif 
    set u = null
endfunction

function InitTrig_Shield takes nothing returns nothing
    call TriggerRegisterAnyUnitDamagedEvent(CreateTrigger(), function Shield__onDamage)//from above system    
endfunction

//function UnitIndexLock takes unit whichUnit, integer data returns nothing
    //custom unit indexer that users custom value
    //<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite3" alt=":(" title="Frown    :(" loading="lazy" data-shortname=":(" /> cant use hook
//endfunction
//hook SetUnitUserData UnitIndexLock



any suggestions/optimization other than this method (i know this isnt the greatest..) ?
note that im a mac user so if you do come up with any suggestions/idea, in vanilla jass form would be much appreciated, though gui/vjass is tolerable..

ty
 

Bribe

vJass errors are legion
Reaction score
67
Why are you using CreateGroup() and DestroyGroup() for simple filtering? You can use bj_lastCreatedGroup, which needs no destroying, because it is created immediately in blizzard.j and never destroyed at any point in the game unless some freak does it intentionally.

[ljass]GetWorldBounds()[/ljass] is not like bj_mapInitialPlayableArea. Each time you use that native, you are generating a new rect.

Register it like this:

JASS:
local region reg = CreateRegion()
local rect rct = GetWorldBounds()
call RegionAddRect(reg, rct)
call RemoveRect(rct)
set rct = null
//&#039;reg&#039; needs no null, as you never remove that region at any point anyway.

The region remembers the rect, by the way. Most user-created rects never need to be used more than once.


InitTrig_Damage

You're assuming the user has to put this in a trigger, and assuming he'll want to name it "damage".

Scopes; they're there for a reason.
 

Bribe

vJass errors are legion
Reaction score
67
note that im a mac user

Huh. How can you get globals but not scopes? What's that about?

What's the big deal with mac users? What kind of crimps do those joshy systems put on the War3 interface?
 

hgkjfhfdsj

Active Member
Reaction score
55
the globals are just there to show the type ("omitted the udg_prefix") and commenting the block green is an eyesore..
scopes i thought of vjass, were you referring to something else? :/
 

Bribe

vJass errors are legion
Reaction score
67
No, I'm referring to JassHelper scopes. Sorry, I don't know much about the incapabilities of macs. Have you tried another JASS Editor? There are others that let you edit the war3map.j file straight away.
 

hgkjfhfdsj

Active Member
Reaction score
55
Have you tried another JASS Editor?
no, but not planning to yet..(and never knew it existed lol)

back to original q, list of slow functions (is there even such thing)?

EDIT
@bribe
ty ill test it out later
V V V V V V
 

Bribe

vJass errors are legion
Reaction score
67
JASS:
function foo takes nothing returns nothing
endfunction

function bar takes nothing returns nothing
    call ExecuteFunc(&quot;foo&quot;)
endfunction


That ExecuteFunc is slower than TriggerExecute, so it's probably your best bet.

TriggerEvaluate is faster than TriggerExecute.

call is faster than TriggerEvaluate.

Inlining is faster than calling.
 

hgkjfhfdsj

Active Member
Reaction score
55
another question
is it possible to change what a function returns? eg

JASS:
function returnreal takes nothing returns nothing
     //somehow this returns the value for the original GetEventDamageEx
     //perhaps globals?? but not sure if this will miss its timing..
endfunction

function GetEventDamageEx takes nothing returns real
     call ExecuteFunc(&quot;returnreal&quot;)
     //returns 0
endfunction


EDIT
just tested, executefunc is fast enough :D thankyou!!
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top