HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Laggy Trigger (Need To Obviously Reduce It)

06-29-2007, 01:14 AM#1
ClichesAreSt00pid
Yeah I got a trigger that has neutral passive attack barricades and such when they are near them, but I have like 11,000 destructables on the map (big map) and it lags like hell when this trigger runs. Any way to make it...not lag?

Collapse JASS:
function Trig_Attacking_Destructables_Condition1 takes nothing returns boolean
    if ( not ( IsUnitAliveBJ(GetEnumUnit()) == true ) ) then
        return false
    endif
    if ( not ( GetOwningPlayer(GetEnumUnit()) == Player(PLAYER_NEUTRAL_PASSIVE) ) ) then
        return false
    endif
    return true
endfunction

function Trig_Attacking_Destructables_GroupActions takes nothing returns nothing
    if ( Trig_Attacking_Destructables_Condition1() ) then
        call IssueTargetDestructableOrder( GetEnumUnit(), "attack", GetEnumDestructable() )
    else
    endif
endfunction

function Trig_Attacking_Destructables_Condition2 takes nothing returns boolean
    if ( not ( IsDestructableAliveBJ(GetFilterDestructable()) == true ) ) then
        return false
    endif
    if ( ( GetDestructableTypeId(GetFilterDestructable()) == 'XTmx' ) ) then
        return true
    endif
    if ( ( GetDestructableTypeId(GetFilterDestructable()) == 'XTx5' ) ) then
        return true
    endif
    if ( ( GetDestructableTypeId(GetFilterDestructable()) == 'LTba' ) ) then
        return true
    endif
    return false
endfunction

function Trig_Attacking_Destructables_DestructableActions takes nothing returns nothing
        set bj_wantDestroyGroup=true
        call ForGroupBJ(GetUnitsInRangeOfLocAll(200.00, GetDestructableLoc(GetEnumDestructable())), function Trig_Attacking_Destructables_GroupActions)
endfunction

function Trig_Attacking_Destructables_Actions takes nothing returns nothing
    local integer i = 1
    loop
        exitwhen i > 12
        call EnumDestructablesInRect( udg_DestructableRects[i], Condition(function Trig_Attacking_Destructables_Condition2), function Trig_Attacking_Destructables_DestructableActions)
        call PolledWait(.4)
        set i = i + 1
    endloop
endfunction

//===========================================================================
function InitTrig_Attacking_Destructables takes nothing returns nothing
    set gg_trg_Attacking_Destructables = CreateTrigger(  )
    call TriggerRegisterTimerEventPeriodic( gg_trg_Attacking_Destructables, 6.00 )
    call TriggerAddAction( gg_trg_Attacking_Destructables, function Trig_Attacking_Destructables_Actions )
endfunction

06-29-2007, 09:40 AM#2
Silvenon
First of all, this line leaks:

call EnumDestructablesInRect( udg_DestructableRects[i], Condition(function Trig_Attacking_Destructables_Condition2), function Trig_Attacking_Destructables_DestructableActions)
You have to put Condition(function Trig_Attacking_Destructables_Condition2) in a boolexpr variable then destroy it with DestroyBoolExpr.

Second, that Trig_Attacking_Destructables_Condition2 function can be narrowed a bit:

Collapse JASS:
function Trig_Attacking_Destructables_Condition2 takes nothing returns boolean
    return GetDestructableLife(GetFilterDestructable()) <= 0 and (GetDestructableTypeId(GetFilterDestructable()) == 'XTmx' or GetDestructableTypeId(GetFilterDestructable()) == 'XTx5' or GetDestructableTypeId(GetFilterDestructable()) == 'LTba')
endfunction

I hope I did this right :P. You can also narrow Trig_Attacking_Destructables_Condition1 function:

Collapse JASS:
function Trig_Attacking_Destructables_Condition1 takes nothing returns boolean
    return IsUnitType(GetEnumUnit(), UNIT_TYPE_DEAD) and GetOwningPlayer(GetEnumUnit()) == Player(PLAYER_NEUTRAL_PASSIVE)
endfunction

Oh, and remove else in Trig_Attacking_Destructables_GroupActions function, if you don't have anything in it, you might as well remove it (that's the good thing about JASS :))
06-29-2007, 05:49 PM#3
ClichesAreSt00pid
Thanks bud +rep. I'll test it out again.

I destroy the boolexpr after the loop not in it right?

Wee no lag!
06-30-2007, 04:09 PM#4
Silvenon
Yes, after loop. If you had different boolexpr in each loop
cycle, then you would have to put it in loop
06-30-2007, 04:12 PM#5
Captain Griffen
Learn real JASS, rather than converted GUI.
06-30-2007, 05:08 PM#6
grim001
Quote:
Originally Posted by ClichesAreSt00pid
I destroy the boolexpr

Boolexrs don't leak and don't need to be destroyed
06-30-2007, 06:01 PM#7
Silvenon
Quote:
Originally Posted by grim001
Boolexrs don't leak and don't need to be destroyed

Sure they do, from what I heard, they're based on strings, and strings leak. DestroyBoolExpr is a way to remove string leaks in a boolexpr I think...
06-30-2007, 07:59 PM#8
grim001
I don't know about them having anything to do with strings, but there's no way to remove a string leak...

creating a boolexpr with Condition() doesn't return a new handle, it just returns the same one over and over when you use the same code parameter, which is why it doesn't need to be destroyed.
06-30-2007, 08:21 PM#9
Ammorth
unless you use And() (I think this is what vex said).
06-30-2007, 08:25 PM#10
grim001
yeah, but there's no reason to force it to return different handles, that was just an experiment...
07-01-2007, 09:11 AM#11
Silvenon
Oh, yeah, sry grim001, you're right. My bad :)