- Joined
- Dec 12, 2008
- Messages
- 7,385
Fine D:
I'll put them back
edit
In my defense:
You don't read the code, the code reads YOU
I'll put them back
edit
In my defense:
You don't read the code, the code reads YOU
//! zinc
library Test requires RegisterPlayerUnitEvent
{
function onInit()
{
RegisterPlayerUnitEvent(EVENT_PLAYER_UNIT_DEATH, function() -> boolean
{
BJDebugMsg("A " + GetUnitName(GetTriggerUnit()) + " has died!\nThe first response is being evaluated!");
return true;
});
RegisterPlayerUnitEvent(EVENT_PLAYER_UNIT_DEATH, function() -> boolean
{
BJDebugMsg("A " + GetUnitName(GetTriggerUnit()) + " has died!\nThe second response is being evaluated!");
return false;
});
KillUnit(CreateUnit(Player(0xF), 'hfoo', 0., 0., 0.));
}
}
//! endzinc
library RegisterPlayerUnitEvent // Special Thanks to Bribe
globals
private trigger array t
private boolexpr array b
endglobals
function RegisterPlayerUnitEvent takes playerunitevent p, code c returns nothing
local integer i = GetHandleId(p)
local integer j = 16
if null == t[i] then
set t[i] = CreateTrigger()
loop
set i = i - 1
call TriggerRegisterPlayerUnitEvent(t[i], Player(j), p, null)
exitwhen 0 == i
endloop
set b[i] = Filter(c)
else
call TriggerClearConditions(t[i])
set b[i] = Or(b[i], Filter(c)) // will leak once it will be the third time and more
endif
call TriggerAddCondition(t[i], b[i])
endfunction
endlibrary
You must return false or nothing
function F1 ...
// limit op nearly reached
function F2 ...
// limit op nearly reached
function F3 ...
// limit op nearly reached
TriggerAddCondition(trig, And ( And(F1,F2) , F3 ) // hopefully you get the idea, add function and filter yourself
Find code,
Reset op limit,
Start new thread so if this thread crashes the previous one can continue,
???
PROFIT!
I'll dew some benchmarks tonight.
function TestOp takes nothing returns boolean
local integer i = 10000
loop
set i = i - 1
exitwhen 0 == i
endloop
call BJDebugMsg(I2S(i))
return true
endfunction
function InitTrig_Test takes nothing returns nothing
call ForceEnumPlayersCounted(CreateForce(), And(Filter(function TestOp), And(Filter(function TestOp), And(Filter(function TestOp), And(Filter(function TestOp), Filter(function TestOp))))), 1)
endfunction
library Test initializer Init
globals
private integer AA = 0
endglobals
private function TestOp takes nothing returns boolean
local integer i = 10000
loop
set i = i - 1
exitwhen 0 == i
endloop
set AA=AA+1
return false
endfunction
private function Init takes nothing returns nothing
local boolexpr b = Filter(function TestOp)
local integer i = 104
loop
exitwhen 0==i
set b = Or(b,Filter(function TestOp))
set i=i-1
endloop
call ForceEnumPlayersCounted(CreateForce(),b,1)
call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,60,I2S(AA))
endfunction
endlibrary
globals
timer Tim = CreateTimer()
integer I = 10000 // ms
endglobals
function F1 takes nothing returns boolean
call DoNothing()
return false
endfunction
function F2 takes nothing returns boolean
call DoNothing()
call DoNothing()
return false
endfunction
function Test takes nothing returns nothing
set I = I-1
if I <= 0 then
call PauseTimer(GetExpiredTimer())
return
endif
call Or(null,null)
endfunction
function StartTest takes nothing returns boolean
call TimerStart(Tim,0.001,true,function Test)
return false
endfunction
//===========================================================================
function InitTrig_test takes nothing returns nothing
local trigger trig = CreateTrigger()
call TriggerRegisterPlayerEventEndCinematic(trig,GetLocalPlayer())
call TriggerAddCondition(trig,function StartTest)
call BJDebugMsg(I2S(GetHandleId(Or(null,null))))
call BJDebugMsg(I2S(GetHandleId(Or(null,null))))
call BJDebugMsg(I2S(GetHandleId(Or(function F1,function F2))))
call BJDebugMsg(I2S(GetHandleId(Or(function F1,function F2))))
endfunction
library RegisterPlayerUnitEvent // Special Thanks to Bribe
globals
private trigger array t
private boolexpr array b
endglobals
function RegisterPlayerUnitEvent takes playerunitevent p, code c returns nothing
local integer i = GetHandleId(p)
local integer j = 16
local boolexpr b
if null == t[i] then
set t[i] = CreateTrigger()
loop
set i = i - 1
call TriggerRegisterPlayerUnitEvent(t[i], Player(j), p, null)
exitwhen 0 == i
endloop
set b[i] = Filter(c)
else
call TriggerClearConditions(t[i])
set b = Or(b[i], Filter(c))
call DestroyBoolExpr(b[i]) // you can also check if b[i] != null before destroy it
set b[i] = b
set b = null
endif
call TriggerAddCondition(t[i], b[i])
endfunction
endlibrary
then struct allocators inlined
library ImplementThis requires FatalError
static if LIBRARY_GTrigger then
private struct AwesomeStruct extends array
private static method onInit takes nothing returns nothing
call ExitWarcraft()
endmethod
endstruct
endif
endlibrary
//! zinc
library RegisterPlayerUnitEvent
{
private
{
trigger eventTriggers [8190];
boolexpr eventResponses [8190];
triggercondition currentCondition [8190];
}
public function RegisterPlayerUnitEvent(playerunitevent whichEvent, code whichResponse)
{
integer eventId = GetHandleId(whichEvent), i;
boolexpr previousResponse;
if (eventTriggers[eventId] == null)
{
eventTriggers [eventId] = CreateTrigger();
eventResponses[eventId] = Filter(whichResponse);
for (i = 15; i >= 0; i -= 1)
TriggerRegisterPlayerUnitEvent(eventTriggers[eventId], Player(i), whichEvent, null);
}
else
{
TriggerRemoveCondition(eventTriggers[eventId], currentCondition[eventId]);
previousResponse = eventResponses[eventId];
eventResponses[eventId] = Or(previousResponse, Filter(whichResponse));
DestroyBoolExpr(previousResponse);
previousResponse = null;
}
currentCondition[eventId] = TriggerAddCondition(eventTriggers[eventId], eventResponses[eventId]);
}
}
//! endzinc
function Blah takes nothing returns boolean
set bj_forLoopAIndex = bj_forLoopAIndex + 1
return false
endfunction
function InitTrig_Untitled_Trigger_003 takes nothing returns nothing
local boolexpr b = Filter(function Blah)
local boolexpr be = Or(b, b)
local boolexpr be2 = Or(be, b)
call DestroyBoolExpr(be)
set bj_forLoopAIndex = 0
call ForceEnumPlayers(bj_FORCE_ALL_PLAYERS, be2)
call BJDebugMsg(I2S(bj_forLoopAIndex))
endfunction
function Blah takes nothing returns boolean
set bj_forLoopAIndex = bj_forLoopAIndex + 1
return false
endfunction
function InitWait takes nothing returns nothing
local boolexpr b = Filter(function Blah)
local boolexpr be = Or(b, b)
local boolexpr be2 = Or(be, b)
call DestroyBoolExpr(be)
call TriggerSleepAction(0)
set bj_forLoopAIndex = 0
call ForceEnumPlayers(bj_FORCE_ALL_PLAYERS, be2)
call BJDebugMsg(I2S(bj_forLoopAIndex))
endfunction
function InitTrig_Untitled_Trigger_003 takes nothing returns nothing
call ExecuteFunc("InitWait")
endfunction
//! zinc
library Test requires RegisterPlayerUnitEvent
{
function onInit()
{
unit u = CreateUnit(Player(0xF), 'hfoo', 0., 0., 0.);
RegisterPlayerUnitEvent(EVENT_PLAYER_UNIT_ISSUED_ORDER, function() { BJDebugMsg("a"); });
RegisterPlayerUnitEvent(EVENT_PLAYER_UNIT_ISSUED_ORDER, function() { BJDebugMsg("b"); });
RegisterPlayerUnitEvent(EVENT_PLAYER_UNIT_ISSUED_ORDER, function() { BJDebugMsg("c"); });
RegisterPlayerUnitEvent(EVENT_PLAYER_UNIT_ISSUED_ORDER, function() { BJDebugMsg("d"); });
RegisterPlayerUnitEvent(EVENT_PLAYER_UNIT_ISSUED_ORDER, function() { BJDebugMsg("f"); });
IssueImmediateOrder(u, "stop");
}
}
//! endzinc
Do realize that those anonymous functions you're creating through zinc do not return boolean false, that might be causing some issues.
Please keep the language G-rated (for those not familiar, that's a USA movie rating that doesn't allow any bad language or such).
I've heard that Filtering functions that doesn't return boolean causes errors on Mac
Or()
thingy to just adding plain conditions. As it turns out, multiple conditions end up being faster (or at least that's what my, again, very quick tests showed).Or()
is prone to leaking, I suggest that you revert everything back to "normal" (it wouldn't be bad if you ran some more tests though).Or() returns a new boolexpr the same as TriggerAddCondition returns a new triggercondition. They both leak the same.
TriggerClearConditions()
does not free up the memory that the trigger conditions use up, it only detaches them from the trigger. So both "versions" leak trigger conditions (if you could call that leaking...).