• 🏆 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!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[JASS] System lags at 1.29

Status
Not open for further replies.
When working on our map, we noticed that when casting spells that affect whole squad using our system it causes a lag, which didn't happen under older version. Here is a trigger that manages those spells:

JASS:
//TESH.scrollpos=0
//TESH.alwaysfold=0

function Trig_Battalion_spells_Conditions takes nothing returns boolean
    local integer battallionIndex
    if ( LoadInteger(udg_hashtable, GetHandleId(GetSpellTargetUnit()), 0) > 0 and GetBatalionAbility(GetSpellAbilityId()) > 0) then
        return true
    else
        return false
    endif
endfunction

function CastSpell takes nothing returns nothing
    local unit dummy
    local integer abilityIndex = GetBatalionAbility(udg_Tempint)
    //call BJDebugMsg(I2S(GetSpellAbilityId()))   
    set dummy = CreateUnit( GetOwningPlayer(GetTriggerUnit()), 'h60H', GetUnitX(GetEnumUnit()), GetUnitY(GetEnumUnit()), bj_UNIT_FACING)
    call IssueTargetOrderById( dummy, udg_BattalionSpellOrderID[abilityIndex], GetEnumUnit() )
    call UnitApplyTimedLife( dummy, 'BTLF', 1.00 )
    set dummy = null
endfunction

function Trig_Battalion_spells_Actions takes nothing returns nothing
    local integer battallionIndexTarget = LoadInteger(udg_hashtable, GetHandleId(GetSpellTargetUnit()), 0)
    local integer battallionIndexCaster = LoadInteger(udg_hashtable, GetHandleId(GetTriggerUnit()), 0)
    set udg_Tempint = GetSpellAbilityId()
   
    call GroupRemoveUnit( udg_Battallion[battallionIndexCaster], GetTriggerUnit() )
    call GroupTargetOrder( udg_Battallion[battallionIndexCaster], "smart", GetTriggerUnit() )
    call GroupAddUnit( udg_Battallion[battallionIndexCaster], GetTriggerUnit() )
    call DisableTrigger( GetTriggeringTrigger() )
    call ForGroup( udg_Battallion[battallionIndexTarget], function CastSpell )
    call EnableTrigger( GetTriggeringTrigger() )
endfunction

//===========================================================================
function InitTrig_Battalion_spells takes nothing returns nothing
    set gg_trg_Battalion_spells = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Battalion_spells, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_Battalion_spells, Condition( function Trig_Battalion_spells_Conditions ) )
    call TriggerAddAction( gg_trg_Battalion_spells, function Trig_Battalion_spells_Actions )
endfunction

It may be that some commands cause lag in the new version for some reason? Maybe could be another trigger, but the lag occurs when casting spells.
 

Jampion

Code Reviewer
Level 15
Joined
Mar 25, 2016
Messages
1,327
Simply create the unit when the map is started and remove it immediatly after that:
call RemoveUnit(CreateUnit(...))

This makes sure the game loads the unit during the loading screen. If a lot of data (abilities for example) is attached to a unit, you want it to be loaded during the loading screen. Otherwise you will get a lag spike when the unit appears for the first time on the map.
 

Jampion

Code Reviewer
Level 15
Joined
Mar 25, 2016
Messages
1,327
The unit type is loaded, when a unit of that type is created for the first time.
Loading the unit type can take a long time, especially if it has a lot of abilities with a lot of levels.
If the unit type is loaded during the game you get a lag spike, if it is loaded during the loading screen it just takes a bit longer to load.
By creating the unit during the loading screen you force the game to load the unit type. This means the unit type does not have to be loaded during the game and you won't get a lag spike.
You remove the unit immediatly, because you don't actually want to create the unit. You just want the game to load the unit type.
 

Jampion

Code Reviewer
Level 15
Joined
Mar 25, 2016
Messages
1,327
They added a function to cancel timed life. Maybe because of that the native become slower? I don't know.

You could use negative health regeneration. Since it is a dummy, it most likely has the locust ability, so there should be no way for the unit to be healed.
If your dummy always needs the same duration that is easy. If you need varaible durations, you could set max hp to 60, regenration to -1 and when you create it, you set the current hp to the number of second you need the dummy.

You could also use a timer to remove the dummy, but the regeneration thing is easier and a lot more efficient.
 
Status
Not open for further replies.
Top