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.
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +2
  • V-SNES V-SNES:
    Happy Friday!
    +1
  • The Helper The Helper:
    New recipe is another summer dessert Berry and Peach Cheesecake - https://www.thehelper.net/threads/recipe-berry-and-peach-cheesecake.194169/

      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