• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[JASS] Mysterious Lag Spike

Status
Not open for further replies.
JASS:
//************************************************************************************
//*
//*
//*                             TIMED LIGHTNING
//*
//*                                BY: ALMIA
//*
//*
//************************************************************************************
//*
//*    Attaches timer to lightnings, with fading and auto-destroy
//*    Also, locks lightning to unit or locations
//*
//************************************************************************************
//*
//*    Requires:
//*
//*    Linked List Table
//*    - [url]http://www.hiveworkshop.com/forums/spells-569/linked-list-table-v1-3-a-230076/[/url]
//*
//************************************************************************************
//*
//*    Code API
//*
//*    constant function TimedLightningFadeTime takes nothing returns real
//*
//*    - Fading time delay
//*
//*    function GetLightningLocZ takes real x, real y returns real
//*
//*    - Gets the location height
//*
//*    function TimedLightningPeriodic takes nothing returns nothing
//*
//*    - System core
//*
//*    function AddTimedLightningByU2U takes lightning l, unit s, real z, unit t, real z2, real duration returns nothing
//*
//*    - Locks the lightning to 2 units
//*
//*    function AddTimedLightningByU2P takes lightning l, unit s, real z, real x, real y, real z2, real duration returns nothing
//*
//*    - Locks the lightning to 1 unit and 1 location(via coords)
//*    - Location height is taken into account
//*
//*    function AddTimedLightningByP2U takes lightning l, real x, real y, real z, unit t, real z2, real duration returns nothing
//*
//*    - Same with U2P, but the location is the source and the unit is the target
//*    - Created because of lightning waves(direction)
//*    - Location height is taken into account
//*
//*    function AddTimedLightningByP2P takes lightning l, real x, real y, real z, real x2, real y2, real z2, real duration returns nothing
//*
//*    - Locks the lightning to 2 locations(via coords)
//*    - Location height is taken into account
//*
//************************************************************************************
//*
//*    Variables
//*
//*    TL_List            = integer
//*    TL_Lightning       = lightning array
//*    TL_Duration        = real      array
//*    TL_X               = real      array
//*    TL_Y               = real      array
//*    TL_Z               = real      array
//*    TL_X2              = real      array
//*    TL_Y2              = real      array
//*    TL_Z2              = real      array
//*    TL_Count           = integer
//*    TL_Timer           = timer
//*    TL_Source          = unit      array
//*    TL_Target          = unit      array
//*    TL_ZLoc            = point     array
//*
//************************************************************************************
//*
//*                              SETTINGS
//*
//************************************************************************************

constant function TimedLightningFadeTime takes nothing returns real
    return 1.0
endfunction

//************************************************************************************
//*
//*                               TOOL
//*
//************************************************************************************

function GetLightningLocZ takes real x, real y returns real
    call MoveLocation(udg_TL_ZLoc, x, y)
    return GetLocationZ(udg_TL_ZLoc)
endfunction

//************************************************************************************
//*
//*                       PERIODIC SYSTEM CORE
//*
//************************************************************************************

function TimedLightningPeriodic takes nothing returns nothing
    local integer i = GetFirstIndexFromLinkedList(udg_TL_List)
    local real z = 0
    local real z2 = 0

    //For readability variables
    local real red = 0
    local real green = 0
    local real blue = 0
    local real alpha = 0
    loop
        exitwhen 0 == i
        if 0 < udg_TL_Duration[i] then
            set udg_TL_Duration[i] = udg_TL_Duration[i] - 0.03125

            //Set Lightning Coords
          
            if null != udg_TL_Source[i] then
                set udg_TL_X[i] = GetUnitX(udg_TL_Source[i])
                set udg_TL_Y[i] = GetUnitY(udg_TL_Source[i])
                set z = GetUnitFlyHeight(udg_TL_Source[i]) + udg_TL_Z[i] + GetLightningLocZ(udg_TL_X[i],udg_TL_Y[i])
            else
                set z = udg_TL_Z[i]
            endif
            if null != udg_TL_Target[i] then
                set udg_TL_X2[i] = GetUnitX(udg_TL_Target[i])
                set udg_TL_Y2[i] = GetUnitY(udg_TL_Target[i]) 
                set z2 = GetUnitFlyHeight(udg_TL_Target[i]) + udg_TL_Z2[i] + GetLightningLocZ(udg_TL_X2[i],udg_TL_Y2[i])
            else
                set z2 = udg_TL_Z2[i]
            endif

            //Moving Lightning
            call MoveLightningEx(udg_TL_Lightning[i], true, udg_TL_X[i], udg_TL_Y[i], z, udg_TL_X2[i], udg_TL_Y2[i], z2)
            
            call BJDebugMsg(R2S(udg_TL_X[i]) + "," + R2S(udg_TL_Y[i]))
            call BJDebugMsg(R2S(udg_TL_X2[i]) + "," + R2S(udg_TL_Y2[i]))
            //Applying ARGB of Lightning, mainly for vertex alpha

            if TimedLightningFadeTime() > udg_TL_Duration[i] then
                set red = GetLightningColorR(udg_TL_Lightning[i])
                set green = GetLightningColorG(udg_TL_Lightning[i])
                set blue = GetLightningColorB(udg_TL_Lightning[i])
                set alpha = udg_TL_Duration[i] / TimedLightningFadeTime()
                call SetLightningColor(udg_TL_Lightning[i], red, green, blue, alpha)
            endif
        else
            call DestroyLightning(udg_TL_Lightning[i])
            call RecycleIndexFromLinkedList(udg_TL_List, i)

            //Nulling variables
            set udg_TL_Lightning[i] = null
            set udg_TL_Source[i] = null
            set udg_TL_Target[i] = null
            set udg_TL_Duration[i] = 0
            set udg_TL_X[i] = 0
            set udg_TL_Y[i] = 0
            set udg_TL_Z[i] = 0
            set udg_TL_X2[i] = 0
            set udg_TL_Y2[i] = 0
            set udg_TL_Z2[i] = 0
 
            //Decrement count
            set udg_TL_Count = udg_TL_Count - 1
            if 0 == udg_TL_Count then
                call PauseTimer(udg_TL_Timer)
            endif
        endif

        set i = GetNextIndexFromLinkedList(udg_TL_List, i)
    endloop
endfunction

//************************************************************************************
//*
//*                          TIMED LIGHTNING CREATORS
//*
//************************************************************************************

//************************************************************************************
//*
//*                          UNIT TO UNIT TIMED LIGHTNING
//*
//************************************************************************************

function AddTimedLightningByU2U takes lightning l, unit s, real z, unit t, real z2, real duration returns nothing
    local integer this = GetNewIndexFromLinkedList(udg_TL_List)
    set udg_TL_Lightning[this] = l
    set udg_TL_Source[this] = s
    set udg_TL_Z[this] = z
    set udg_TL_Target[this] = t
    set udg_TL_Z2[this] = z2
    set udg_TL_Duration[this] = duration

    //Incremeting count
    set udg_TL_Count = udg_TL_Count + 1
    if 1 == udg_TL_Count then
        call TimerStart(udg_TL_Timer, 0.03125, true, function TimedLightningPeriodic)
    endif
endfunction

//************************************************************************************
//*
//*                          UNIT TO POINT TIMED LIGHTNING
//*
//************************************************************************************

function AddTimedLightningByU2P takes lightning l, unit s, real z, real x2, real y2, real z2, real duration returns nothing
    local integer this = GetNewIndexFromLinkedList(udg_TL_List)
    set udg_TL_Lightning[this] = l
    set udg_TL_Source[this] = s
    set udg_TL_Z[this] = z
    set udg_TL_X2[this] = x2
    set udg_TL_Y2[this] = y2
    set udg_TL_Z2[this] = z2 - GetLightningLocZ(x2,y2)
    set udg_TL_Duration[this] = duration

    //Incremeting count
    set udg_TL_Count = udg_TL_Count + 1
    if 1 == udg_TL_Count then
        call TimerStart(udg_TL_Timer, 0.03125, true, function TimedLightningPeriodic)
    endif
endfunction

//************************************************************************************
//*
//*                          POINT TO UNIT TIMED LIGHTNING
//*
//************************************************************************************

function AddTimedLightningByP2U takes lightning l, real x, real y, real z, unit t, real z2, real duration returns nothing
    local integer this = GetNewIndexFromLinkedList(udg_TL_List)
    set udg_TL_Lightning[this] = l
    set udg_TL_X[this] = x
    set udg_TL_Y[this] = y
    set udg_TL_Z[this] = z - GetLightningLocZ(x,y)
    set udg_TL_Target[this] = t
    set udg_TL_Z2[this] = z2
    set udg_TL_Duration[this] = duration

    //Incremeting count
    set udg_TL_Count = udg_TL_Count + 1
    if 1 == udg_TL_Count then
        call TimerStart(udg_TL_Timer, 0.03125, true, function TimedLightningPeriodic)
    endif
endfunction

//************************************************************************************
//*
//*                           POINT TO POINT TIMED LIGHTNING
//*
//************************************************************************************

function AddTimedLightningByP2P takes lightning l, real x, real y, real z, real x2, real y2, real z2, real duration returns nothing
    local integer this = GetNewIndexFromLinkedList(udg_TL_List)
    set udg_TL_Lightning[this] = l
    set udg_TL_X[this] = x
    set udg_TL_Y[this] = y
    set udg_TL_Z[this] = z - GetLightningLocZ(x,y)
    set udg_TL_X2[this] = x2
    set udg_TL_Y2[this] = y2
    set udg_TL_Z2[this] = z2 - GetLightningLocZ(x2,y2)
    set udg_TL_Duration[this] = duration

    //Incremeting count
    set udg_TL_Count = udg_TL_Count + 1
    if 1 == udg_TL_Count then
        call TimerStart(udg_TL_Timer, 0.03125, true, function TimedLightningPeriodic)
    endif
endfunction

//************************************************************************************

function InitTrig_Timed_Lightning takes nothing returns nothing
    set udg_TL_List = CreateLinkedList()
    set udg_TL_ZLoc = Location(0,0)
endfunction

I don't know what's wrong here. The code is good.But when i test this thing:
  • Example
    • Events
      • Time - Every 5.00 seconds of game time
    • Conditions
    • Actions
      • Custom script: set bj_wantDestroyGroup = true
      • Unit Group - Pick every unit in (Units in (Playable map area)) and do (Actions)
        • Loop - Actions
          • Set Unit[1] = (Picked unit)
          • Custom script: set bj_wantDestroyGroup = true
          • Unit Group - Pick every unit in (Units in (Playable map area)) and do (Actions)
            • Loop - Actions
              • Custom script: local real x
              • Custom script: local real y
              • Set Unit[2] = (Picked unit)
              • -------- - --------
              • -------- Create Lightning --------
              • -------- - --------
              • Custom script: set bj_lastCreatedLightning = AddLightningEx("DRAM",true, 0, 0 ,0, 0, 0, 0)
              • Lightning - Change color of (Last created lightning effect) to (1.00 1.00 1.00) with 1.00 alpha
              • -------- - --------
              • -------- Add Lightning to system --------
              • -------- - --------
              • Custom script: call AddTimedLightningByU2U(bj_lastCreatedLightning,udg_Unit[1],75,udg_Unit[2],75,5)
              • -------- - --------
              • -------- Create Lightning --------
              • -------- - --------
              • Custom script: set bj_lastCreatedLightning = AddLightningEx("CLPB",true, 0, 0 ,0, 0, 0, 0)
              • Lightning - Change color of (Last created lightning effect) to (1.00 0.00 1.00) with 1.00 alpha
              • Custom script: set x = GetUnitX(udg_Unit[2])
              • Custom script: set y = GetUnitY(udg_Unit[2])
              • -------- - --------
              • -------- Add Lightning to system --------
              • -------- - --------
              • Custom script: call AddTimedLightningByU2P(bj_lastCreatedLightning,udg_Unit[1],75,x,y,GetLightningLocZ(x,y),4)
and

  • Untitled Trigger 001
    • Events
      • Time - Every 5.00 seconds of game time
    • Conditions
    • Actions
      • Set Unit[1] = Mountain King 0001 <gen>
      • Set Unit[2] = Mountain King 0002 <gen>
      • -------- - --------
      • -------- Create Lightning --------
      • -------- - --------
      • Custom script: set bj_lastCreatedLightning = AddLightningEx("DRAM",true, 0, 0 ,0, 0, 0, 0)
      • Lightning - Change color of (Last created lightning effect) to (1.00 1.00 1.00) with 1.00 alpha
      • -------- - --------
      • -------- Add Lightning to system --------
      • -------- - --------
      • Custom script: call AddTimedLightningByU2U(bj_lastCreatedLightning,udg_Unit[1],75,udg_Unit[2],75,5)

It seems that it con't create the lightnings outside this mysterious invisible square.
I tested the units inside the square and the system works perfectly.
But when i put units outside the square,they don't create lightnings.
The most scary thing is that when the units with attached leash moves outside the square,FPS drops to 20 fps below.

Anyone help please.Here is the test map:
 

Attachments

  • Timed Lightning v1.0.w3x
    21.4 KB · Views: 43
Status
Not open for further replies.
Top