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 )
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
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 )
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("|cFFFF0000Error|r Attempting to register a null trigger.")
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;Aloc039;) == 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 'event' <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<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] < 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 // <------
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 > 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] > 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