- Joined
- Apr 27, 2011
- Messages
- 272
Will registering a lot of events into a single trigger slow it down? :O
Your triggering EVERY UNIT INTO A DAMAGE DETECTION SYSTEM? *cough*soinefficientandtimewasting*cough*
With a CreateUnit call, *testing* it froze and crashed T_T (with 7820 registerations)
With 1300: 2 second lag spike.
Mag said:The final test involved no unit creation
Only 2 of my tests involved unit creation :>
struct Test extends array
private static trigger onDamageTrig = CreateTrigger()
private static trigger damageUnitsTrig = CreateTrigger()
private static integer requiredOperations = 8200
private static Table u
private static integer count = 0
private static integer index = 0
private static method causeDamage takes nothing returns boolean
local integer op = 200
loop
call UnitDamageTarget(u.unit[requiredOperations], u.unit[requiredOperations], 60, false, false, null, null, null)
set op = op - 1
set requiredOperations = requiredOperations - 1
exitwhen op == 0 or requiredOperations <= 0
endloop
return requiredOperations <= 0
endmethod
private static method onDamage takes nothing returns boolean
set count = count + 1
return false
endmethod
private static method createUnits takes nothing returns nothing
call CreateUnit(Player(0), 'hpea', 0, 0, 0)
if index == 8200 then
call BJDebugMsg("dealing damage")
call PauseTimer(GetExpiredTimer())
call DestroyTimer(GetExpiredTimer())
loop
exitwhen TriggerEvaluate(damageUnitsTrig)
endloop
call BJDebugMsg("dealt damage")
endif
endmethod
private static method display takes nothing returns boolean
call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 60, I2S(count))
return false
endmethod
private static method onEnter takes nothing returns boolean
set index = index + 1
set u.unit[index] = GetTriggerUnit()
call TriggerRegisterUnitEvent(onDamageTrig, u.unit[index], EVENT_UNIT_DAMAGED)
return false
endmethod
private static method onInit takes nothing returns nothing
local trigger t = CreateTrigger()
local region r = CreateRegion()
set u = Table.create()
call RegionAddRect(r, GetWorldBounds())
call TriggerRegisterEnterRegion(t, r, null)
call TriggerAddCondition(t, Condition(function thistype.onEnter))
call TriggerAddCondition(onDamageTrig, Condition(function thistype.onDamage))
call TriggerAddCondition(damageUnitsTrig, Condition(function thistype.causeDamage))
set t = CreateTrigger()
call TriggerRegisterPlayerChatEvent(t, Player(0), "-", true)
call TriggerAddCondition(t, Condition(function thistype.display))
call TimerStart(CreateTimer(), 0.001, true, function thistype.createUnits)
set r = null
set t = null
endmethod
endstruct
Triggers aren't even touched by the event if there are no triggeractions or triggerconditions (I know because I registered 30000 events to the same trigger, fired the event and no lag spike or tiny FPS drop occured (not even 1 FPS)
fyi, conditions don't open new threads. That's why you're supposed to use if blocks in conditions instead of actions if you can.
scope crashThread initializer i
private function c takes nothing returns boolean
call TriggerSleepAction(0.)
call DisplayTextToPlayer(GetLocalPlayer(),0,0,"This won't display because TSA crashed the thread!")
return false
endfunction
private function i takes nothing returns nothing
local trigger t=CreateTrigger()
call TriggerRegisterTimerEvent(t,1.,false)
call TriggerAddCondition(t,Condition(function c))
set t=null
endfunction
endscope
library ConditionsTest initializer init
globals
private constant integer ITERATIONS = 23000 // limit op reached with 24000 ( "ok" not displayed )
endglobals
private function Cond0 takes nothing returns boolean
call BJDebugMsg("the thread will crash")
loop
exitwhen false
endloop
call BJDebugMsg("this message will never be displayed")
return false
endfunction
private function Cond1 takes nothing returns boolean
local integer i = 0
call BJDebugMsg("1")
loop
exitwhen i == ITERATIONS
set i = i+1
endloop
call BJDebugMsg("end 1")
return false
endfunction
private function Cond2 takes nothing returns boolean
local integer i = 0
call BJDebugMsg("2")
loop
exitwhen i == ITERATIONS
set i = i+1
endloop
call BJDebugMsg("end 2")
return false
endfunction
private function init takes nothing returns nothing
local integer i = 0
local trigger trig = CreateTrigger()
call TriggerAddCondition(trig,function Cond0)
call TriggerAddCondition(trig,function Cond1)
call TriggerAddCondition(trig,function Cond2)
call TriggerSleepAction(0)
loop
exitwhen i == ITERATIONS
set i = i+1
endloop
call BJDebugMsg("ok")
call TriggerEvaluate(trig)
endfunction
endlibrary
myself said:Btw, each time code or boolexpr is involved in a native "function", the op limit is reset.
Like ForForce, GroupEnum...