|
情况是这样的,每0.01秒创建了100个计时器每个计时器创建一个trigger然后0.01秒后删除trigger 连同计时器,连条件和动作都没有加上去就已经卡了,难道是哈希表的问题吗?
[jass]globals
function C takes nothing returns nothing
call DestroyTrigger(LoadTriggerHandle(udg_HT,GetHandleId(GetExpiredTimer()),StringHash("trg")))
call FlushChildHashtable(udg_HT,GetHandleId(GetExpiredTimer()))
call DestroyTimer(GetExpiredTimer())
endfunction
//-------------------------------------------------------------------------------------------
function B takes nothing returns nothing
local trigger trg=CreateTrigger() //创建的trigger
local timer tm=GetExpiredTimer()
call TimerStart(tm,0.01,false,function C) //现在就去到函数C销毁trigger和timer
call SaveTriggerHandle(udg_HT,GetHandleId(tm),StringHash("trg"),trg)
set trg=null
set tm=null
endfunction
//-----------------------------------------------------------------------------------------------
function A takes nothing returns nothing
local timer tm=CreateTimer() //这是每0.01s创建100个计时器,每个计时器会创建一个trigger然后和计时器一起销毁
local integer t=LoadInteger(udg_HT,GetHandleId(GetExpiredTimer()),StringHash("t"))
call TimerStart(tm,0.01,true,function B) //每个计时器会创建一个trigger然后和计时器一起销毁
set t=t+1
call SaveInteger(udg_HT,GetHandleId(GetExpiredTimer()),StringHash("t"),t)
if t>100 then
call FlushChildHashtable(udg_HT,GetHandleId(GetExpiredTimer()))
call DestroyTimer(GetExpiredTimer())
endif
set tm=null
endfunction
function A1 takes nothing returns nothing
local timer tm=CreateTimer() //这个计时器会每0.01创建1个计时器 ,直到一百个为止就停止删除掉这个计时器,102个。。。
call TimerStart(tm,0.01,true,function A)
set tm=null
endfunction
function Actions takes nothing returns nothing
local timer tm=CreateTimer() //这个是主计时器就是每0.01s运行的不删除的那个
call TimerStart(tm,0.01,true,function A1)
set tm=null
endfunction
//===========================================================================
function InitTrig_aa takes nothing returns nothing
set gg_trg_aa = CreateTrigger( )
call TriggerRegisterPlayerChatEvent( gg_trg_aa, Player(0), "1", true )
call TriggerAddAction( gg_trg_aa, function Actions )
endfunction
endglobals[/jass] |
|