• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!

To fuse or not to fuse.

Status
Not open for further replies.
Level 20
Joined
May 16, 2012
Messages
635
Lately I've been wondering if its better to code everything that has coincidental events, like "A unit Dies" in one big trigger or to split it into many simple ones. I know that smaller and simpler code is better to debug and improve, but since Warcraft run a trigger every time its events checked, having 50 triggers that runs when a unit dies or when is attacked do not sound good. At the end of the day, what really matters is performance, nobody likes when a map lags, specially if its because of bad/unnecessary coding. So with that in mind, from you guys, pros of the Hive, which one is better?

For example:

JASS:
scope PortalMagnataurs initializer Init

private function Conditions takes nothing returns boolean
    return ( GetUnitTypeId(GetTriggerUnit()) == 'unp2' )
endfunction

private function Actions takes nothing returns nothing
    //Magnataurs Part
    local location l
    local group g = CreateGroup()
   
    set l = GetUnitLoc(GetTriggerUnit())
   
    call SetPlayerTechResearched(Player(9), 'Rhan', GetPlayerTechCount(Player(9), 'Rhan', true) + udg_Difficult_Level)
    call SetPlayerTechResearched(Player(10), 'Rhan', GetPlayerTechCount(Player(10), 'Rhan', true) + udg_Difficult_Level)
    call SetPlayerTechResearched(Player(11), 'Rhan', GetPlayerTechCount(Player(11), 'Rhan', true) + udg_Difficult_Level)
    call SetPlayerTechResearched(Player(9), 'Rhme', GetPlayerTechCount(Player(9), 'Rhme', true) + udg_Difficult_Level)
    call SetPlayerTechResearched(Player(10), 'Rhme', GetPlayerTechCount(Player(10), 'Rhme', true) + udg_Difficult_Level)
    call SetPlayerTechResearched(Player(11), 'Rhme', GetPlayerTechCount(Player(11), 'Rhme', true) + udg_Difficult_Level)
    call SetPlayerTechResearched(Player(9), 'Rhpt', GetPlayerTechCount(Player(9), 'Rhpt', true) + udg_Difficult_Level)
    call SetPlayerTechResearched(Player(10), 'Rhpt', GetPlayerTechCount(Player(10), 'Rhpt', true) + udg_Difficult_Level)
    call SetPlayerTechResearched(Player(11), 'Rhpt', GetPlayerTechCount(Player(11), 'Rhpt', true) + udg_Difficult_Level)
    set g = CreateNUnitsLoc((1 * udg_Difficult_Level), 'n00D', Player(11), l, 0.0)
    call GroupPointOrderById(g, 851983, GetRectCenterX(gg_rct_Castle), GetRectCenterY(gg_rct_Castle))
    call DestroyGroup(g)
    call RemoveLocation(l)
   
    set g = null
    set l = null
    //Sideway System Part
    set udg_Sideway_Counter = ( udg_Sideway_Counter + 1 )
    if ( udg_Sideway_Counter == udg_NumberOfPlayers_Integer ) then
        set udg_Sideway_Flag = 1
        call SetUnitInvulnerable( gg_unit_ndt2_0054, false )
        call SetUnitInvulnerable( gg_unit_ndt2_0053, false )
        call EnableTrigger( gg_trg_SidewaySystem )
        call EnableTrigger( gg_trg_SidewayStopLeft )
        call EnableTrigger( gg_trg_SidewayStopRight )
        call DisableTrigger(gg_trg_OpenWay)
        call DisableTrigger(gg_trg_CloseWay)
        call DisableTrigger(gg_trg_UnitCleaning)
        call DisableTrigger(gg_trg_Spawn4)
        call DisableTrigger(gg_trg_SpawnStop1)
        call PauseTimer( udg_Active_Timer )
        call DestroyTimerDialog( udg_Active_Timer_Window )
    endif
endfunction

//===========================================================================
private function Init takes nothing returns nothing
    set gg_trg_PortalMagnataurs = CreateTrigger(  )
    call TriggerRegisterVariableEvent(gg_trg_PortalMagnataurs, "udg_DeathEvent", EQUAL, 1.00)
    call TriggerAddCondition( gg_trg_PortalMagnataurs, Condition( function Conditions ) )
    call TriggerAddAction( gg_trg_PortalMagnataurs, function Actions )
endfunction

endscope

Or

JASS:
scope SidewayChecker initializer Init

private function Conditions takes nothing returns boolean
    return GetUnitTypeId(GetTriggerUnit()) == 'unp2'
endfunction

private function Actions takes nothing returns nothing
    set udg_Sideway_Counter = ( udg_Sideway_Counter + 1 )
    if ( udg_Sideway_Counter == udg_NumberOfPlayers_Integer ) then
        set udg_Sideway_Flag = 1
        call SetUnitInvulnerable( gg_unit_ndt2_0054, false )
        call SetUnitInvulnerable( gg_unit_ndt2_0053, false )
        call EnableTrigger( gg_trg_SidewaySystem )
        call EnableTrigger( gg_trg_SidewayStopLeft )
        call EnableTrigger( gg_trg_SidewayStopRight )
        call DisableTrigger(gg_trg_OpenWay)
        call DisableTrigger(gg_trg_CloseWay)
        call DisableTrigger(gg_trg_UnitCleaning)
        call DisableTrigger(gg_trg_Spawn4)
        call PauseTimer( udg_Active_Timer )
        call DestroyTimerDialog( udg_Active_Timer_Window )
    endif
endfunction

//===========================================================================
private function Init takes nothing returns nothing
    set gg_trg_SidewayChecker = CreateTrigger(  )
    call TriggerRegisterVariableEvent(gg_trg_SidewayChecker, "udg_DeathEvent", EQUAL, 1.00)
    call TriggerAddCondition( gg_trg_SidewayChecker, Condition( function Conditions ) )
    call TriggerAddAction( gg_trg_SidewayChecker, function Actions )
endfunction

endscope
 
Level 20
Joined
May 16, 2012
Messages
635
It depends on how you wish to develop the map. If you wish to optimize everything, then a single trigger with a chain of events is the way to go, whereas if you wish to go for simplicity and comfort, the method you already have described is the way to go.


I think that, for the final user (the players), the only think that matters is smooth gameplay, without bugs or lag spikes. What i`m trying to understand is if its easier to accomplish that doing everything in one trigger with lots and lots of conditionals, or the game do it better with a lot of simpler triggers. If you had, lets say, 100 triggers with "A unit is attacked" event, would you keep them separate or fuse them?
 
Status
Not open for further replies.
Top