1. Updated Resource Submission Rules: All model & skin resource submissions must now include an in-game screenshot. This is to help speed up the moderation process and to show how the model and/or texture looks like from the in-game camera.
    Dismiss Notice
  2. DID YOU KNOW - That you can unlock new rank icons by posting on the forums or winning contests? Click here to customize your rank or read our User Rank Policy to see a list of ranks that you can unlock. Have you won a contest and still havn't received your rank award? Then please contact the administration.
    Dismiss Notice
  3. We have recently started the 16th edition of the Mini Mapping Contest. The theme is mini RPG. Do check it out and have fun.
    Dismiss Notice
  4. Dismiss Notice
  5. The Highway to Hell has been laid open. Come along and participate in the 5th Special Effect Contest.
    Dismiss Notice
  6. Check out the Staff job openings thread.
    Dismiss Notice
Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

[System] SoundTools

Discussion in 'JASS Resources' started by Magtheridon96, Nov 19, 2011.

  1. Magtheridon96

    Magtheridon96

    Joined:
    Dec 12, 2008
    Messages:
    6,006
    Resources:
    26
    Maps:
    1
    Spells:
    8
    Tutorials:
    7
    JASS:
    10
    Resources:
    26
    This system allows you to play a sound immediately after creating it (Which is impossible inside Warcraft III)

    Basically, all what it does is start a timer and play the sound.
    It also recycles these sounds to decrease the amount of RAM used up.

    Code (vJASS):
    /***********************************************
    *
    *   SoundTools
    *   v3.0.0.2
    *   By Magtheridon96
    *
    *   (Special Thanks to Rising_Dusk)
    *
    *   - Allows you to play sounds immediately after creating them.
    *   - Uses a sound recycler to increase efficiency and save RAM.
    *
    *   Requirements:
    *   -------------
    *
    *       - Table by Bribe
    *           - hiveworkshop.com/forums/jass-resources-412/snippet-new-table-188084/
    *       - TimerUtils by Vexorian
    *           - wc3c.net/showthread.php?t=101322
    *
    *   API:
    *   ----
    *
    *       constant boolean DEFAULT_SOUND_STOPS_ON_LEAVE_RANGE
    *       constant integer DEFAULT_SOUND_FADE_IN_RATE
    *       constant integer DEFAULT_SOUND_FADE_OUT_RATE
    *       constant string  DEFAULT_SOUND_EAX_SETTINGS
    *       constant integer DEFAULT_SOUND_VOLUME
    *       constant integer DEFAULT_SOUND_PITCH
    *
    *       struct Sound extends array
    *
    *           readonly string file
    *           readonly integer duration
    *           readonly boolean looping
    *           readonly boolean is3D
    *           readonly boolean stopOnLeaveRange
    *           readonly integer fadeIn
    *           readonly integer fadeOut
    *           readonly string eaxSetting
    *
    *           static method create takes string fileName, integer duration, boolean looping, boolean is3D returns thistype
    *               - Creates a sound struct given the filepath, the duration in milliseconds, whether it is looping or not, and whether it is 3D or not.
    *           static method createEx takes string fileName, integer duration, boolean looping, boolean is3D, boolean stopOnExitRange, integer fadeIn, integer fadeOut, string eaxSetting returns thistype
    *               - In addition to static method create, this allows you to specificy whether the sound stops when the player leaves range, the fadeIn/fadeOut rates and the EAX Setting.
    *           static method release takes sound s returns boolean
    *               - Releases a sound and throws it into the recycler. Also stops the sound.
    *
    *           method run takes nothing returns sound
    *               - Plays the sound.
    *           method runUnit takes unit whichUnit returns sound
    *               - Plays the sound on a unit.
    *           method runPoint takes real x, real y, real z returns sound
    *               - Plays the sound at a point.
    *           method runPlayer takes player whichPlayer returns sound
    *               - Plays the sound for a player.
    *
    *           method runEx takes integer volume, integer pitch returns sound
    *               - Plays the sound. This function allows you to pass in extra arguments.
    *           method runUnitEx takes unit whichUnit, integer volume, integer pitch returns sound
    *               - Plays the sound on a unit. This function allows you to pass in extra arguments.
    *           method runPointEx takes real x, real y, real z, integer volume, integer pitch returns sound
    *               - Plays the sound at a point. This function allows you to pass in extra arguments.
    *           method runPlayerEx takes player whichPlayer, integer volume, integer pitch returns sound
    *               - Plays the sound for a player. This function allows you to pass in extra arguments.
    *
    *       function NewSound takes string fileName, integer duration, boolean looping, boolean is3D returns Sound
    *           - Creates a sound struct given the filepath, the duration in milliseconds, whether it is looping or not, and whether it is 3D or not.
    *       function NewSoundEx takes string fileName, integer duration, boolean looping, boolean is3D, boolean stop, integer fadeInRate, integer fadeOutRate, string eax returns Sound
    *           - In addition to static method create, this allows you to specificy whether the sound stops when the player leaves range, the fadeIn/fadeOut rates and the EAX Setting.
    *       function ReleaseSound takes sound s returns boolean
    *           - Releases a sound and throws it into the recycler. Also stops the sound.
    *       function RunSound takes Sound this returns sound
    *           - Plays the sound.
    *       function RunSoundEx takes Sound this, integer volume, integer pitch returns sound
    *           - Plays the sound. This function allows you to pass in extra arguments.
    *       function RunSoundOnUnit takes Sound this, unit whichUnit returns sound
    *           - Plays the sound on a unit.
    *       function RunSoundAtPoint takes Sound this, real x, real y, real z returns sound
    *           - Plays the sound at a point.
    *       function RunSoundForPlayer takes Sound this, player p returns sound
    *           - Plays the sound for a player.
    *       function RunSoundOnUnitEx takes Sound this, unit whichUnit, integer volume, real pitch returns sound
    *           - Plays the sound on a unit. This function allows you to pass in extra arguments.
    *       function RunSoundAtPointEx takes Sound this, real x, real y, real z, integer volume, real pitch returns sound
    *           - Plays the sound at a point. This function allows you to pass in extra arguments.
    *       function RunSoundForPlayerEx takes Sound this, player p, integer volume, real pitch returns sound
    *           - Plays the sound for a player. This function allows you to pass in extra arguments.
    *
    *   Credits:
    *   --------
    *
    *       - Rising_Dusk (The original system)
    *       - Zwiebelchen (Research - He found a ton of Wc3 sound bugs and ways to fix them)
    *
    ***********************************************/

    library SoundTools requires Table, TimerUtils
       
        /*
        *   Configuration
        */

       
        globals
            constant boolean DEFAULT_SOUND_STOPS_ON_LEAVE_RANGE = true
            constant integer DEFAULT_SOUND_FADE_IN_RATE = 10
            constant integer DEFAULT_SOUND_FADE_OUT_RATE = 10
            constant string  DEFAULT_SOUND_EAX_SETTINGS = "CombatSoundsEAX"
            constant integer DEFAULT_SOUND_VOLUME = 127
            constant integer DEFAULT_SOUND_PITCH = 1
        endglobals
       
        globals
            private constant integer SOUND_CHANNEL = 5
            private constant integer SOUND_MIN_DIST = 600
            private constant integer SOUND_MAX_DIST = 10000
            private constant integer SOUND_DIST_CUT = 3000
        endglobals
       
        /*
        *   End of Configuration
        */

       
        struct Sound extends array
            private static key tk
            private static key pk
            private static Table tb = tk
            private static Table pt = pk
            private static integer index = 1
           
            private static Table array stack
            private static integer array count
           
            readonly string file
            readonly integer duration
            readonly boolean looping
            readonly boolean is3D
            readonly boolean stopOnLeaveRange
            readonly integer fadeIn
            readonly integer fadeOut
            readonly string eaxSetting
           
            private real pitch
           
            static method createEx takes string fileName, integer dur, boolean loopng, boolean isTD, boolean stop, integer fadeInRate, integer fadeOutRate, string eax returns thistype
                local thistype this = index
                set index = index + 1
               
                set this.file = fileName
                set this.duration = dur
                set this.looping = loopng
                set this.is3D = isTD
                set this.stopOnLeaveRange = stop
                set this.fadeIn = fadeInRate
                set this.fadeOut = fadeOutRate
                set this.eaxSetting = eax
                set this.pitch = 1
               
                set stack[this] = Table.create()
               
                return this
            endmethod
           
            static method create takes string fileName, integer dur, boolean loopng, boolean isTD returns thistype
                return createEx(fileName, dur, loopng, isTD, DEFAULT_SOUND_STOPS_ON_LEAVE_RANGE, DEFAULT_SOUND_FADE_IN_RATE, DEFAULT_SOUND_FADE_OUT_RATE, DEFAULT_SOUND_EAX_SETTINGS)
            endmethod
           
            // Credits to Zwiebelchen for this function
            // He discovered a bug with sound pitches and this function was written to fix that.
            method setSoundPitch takes sound s, real newPitch returns nothing
                if GetSoundIsPlaying(s) or GetSoundIsLoading(s) then
                    call SetSoundPitch(s, 1/this.pitch)
                    call SetSoundPitch(s, newPitch)
                    set this.pitch = newPitch
                elseif newPitch == 1 then
                    call SetSoundPitch(s, 1.0001)
                    set this.pitch = 1.0001
                else
                    call SetSoundPitch(s, newPitch)
                    set this.pitch = newPitch
                endif
            endmethod
           
            private static sound snd
           
            private method get takes nothing returns sound
                if count[this] == 0 then
               
                    /*
                    *   Create new sound and point it to
                    *   Sound struct instance.
                    */

                    set snd = CreateSound(this.file, this.looping, this.is3D, this.stopOnLeaveRange, this.fadeIn, this.fadeOut, this.eaxSetting)
                    set pt[GetHandleId(snd)] = this
                   
                    /*
                    *   Configure sound
                    */

                    call SetSoundDuration(snd, this.duration)
                    call SetSoundChannel(snd, SOUND_CHANNEL)
                    call SetSoundVolume(snd, DEFAULT_SOUND_VOLUME)
                    call this.setSoundPitch(snd, DEFAULT_SOUND_PITCH)
                   
                    /*
                    *   Proper 3D sound configuration
                    */

                    if this.is3D then
                        call SetSoundDistances(snd, SOUND_MIN_DIST, SOUND_MAX_DIST)
                        call SetSoundDistanceCutoff(snd, SOUND_DIST_CUT)
                        call SetSoundConeAngles(snd, 0, 0, DEFAULT_SOUND_VOLUME)
                        call SetSoundConeOrientation(snd, 0, 0, 0)
                    endif
                   
                    return snd
                endif
               
                /*
                *   Pop out of sound stack.
                */

                set count[this] = count[this] - 1
                return stack[this].sound[count[this]]
            endmethod
           
            private method push takes sound s returns nothing
                set stack[this].sound[count[this]] = s
                set count[this] = count[this] + 1
            endmethod
           
            private static method recycle takes nothing returns nothing
                local timer t = GetExpiredTimer()
                local sound s = tb.sound[GetHandleId(t)]
               
                /*
                *   Stop sound and push to the
                *   stack.
                */

                call StopSound(s, false, true)
                call thistype(GetTimerData(t)).push(s)
                call ReleaseTimer(t)
               
                set t = null
                set s = null
            endmethod
           
            private static integer array next
            private static sound array media
           
            private static method runSounds takes nothing returns nothing
                local thistype this = next[0]
                local timer t
               
                call ReleaseTimer(GetExpiredTimer())
               
                loop
                    exitwhen this == 0
                   
                    /*
                    *   Play the sound.
                    */

                    call StartSound(media[this])
                   
                    /*
                    *   If it is not looping,
                    *   we can recycle it when
                    *   it finishes playing.
                    */

                    if not this.looping then
                        set t = NewTimerEx(this)
                        set tb.sound[GetHandleId(t)] = media[this]
                        call TimerStart(t, this.duration * 0.001, false, function thistype.recycle)
                    endif
                   
                    set media[this] = null
                    set this = next[this]
                endloop
               
                set next[0] = 0
               
                set t = null
            endmethod
           
            method run takes nothing returns sound
                debug if this == 0 then
                    debug call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 60, "[SoundTools]Error: Attempted to play null sound.")
                    debug return null
                debug endif
               
                if next[0] == 0 then
                    call TimerStart(NewTimer(), 0, false, function thistype.runSounds)
                endif
               
                if media[this] == null then
                    set next[this] = next[0]
                    set next[0] = this
                    set media[this] = this.get()
                debug else
                    debug call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 60, "[SoundTools]Warning: Attempted to run the same sound twice.")
                endif
               
                return media[this]
            endmethod
           
            method runEx takes integer volume, integer newPitch returns sound
                set snd = this.run()
                call SetSoundVolume(snd, volume)
                call this.setSoundPitch(snd, newPitch)
                return snd
            endmethod
           
            static method release takes sound s returns boolean
                local integer id = GetHandleId(s)
               
                if s == null then
                    debug call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 60, "[SoundTools]Error: Attempted to release a null sound.")
                    return false
                elseif pt[id] == 0 then
                    debug call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 60, "[SoundTools]Error: Attempted to release a sound not allocated by RunSound.")
                    return false
                endif
               
                /*
                *   Stop the sound and push it
                *   to the stack.
                */

                call StopSound(s, false, true)
                call thistype(pt[id]).push(s)
               
                return true
            endmethod
           
            method runUnit takes unit whichUnit returns sound
                set snd = this.run()
                call AttachSoundToUnit(snd, whichUnit)
                return snd
            endmethod
           
            method runUnitEx takes unit whichUnit, integer volume, integer newPitch returns sound
                set snd = this.runUnit(whichUnit)
                call SetSoundVolume(snd, volume)
                call this.setSoundPitch(snd, newPitch)
                return snd
            endmethod
           
            method runPoint takes real x, real y, real z returns sound
                set snd = this.run()
                call SetSoundPosition(snd, x, y, z)
                return snd
            endmethod
           
            method runPointEx takes real x, real y, real z, integer volume, integer newPitch returns sound
                set snd = this.runPoint(x, y, z)
                call SetSoundVolume(snd, volume)
                call this.setSoundPitch(snd, newPitch)
                return snd
            endmethod
           
            method runPlayer takes player p returns sound
                set snd = this.run()
                if GetLocalPlayer() != p then
                    call SetSoundVolume(snd, 0)
                endif
                return snd
            endmethod
           
            method runPlayerEx takes player p, integer volume, integer newPitch returns sound
                set snd = this.runPlayer(p)
                call SetSoundVolume(snd, volume)
                call this.setSoundPitch(snd, newPitch)
                return snd
            endmethod
        endstruct
       
        function NewSoundEx takes string fileName, integer duration, boolean looping, boolean is3D, boolean stop, integer fadeInRate, integer fadeOutRate, string eax returns Sound
            return Sound.createEx(fileName, duration, looping, is3D, stop, fadeInRate, fadeOutRate, eax)
        endfunction
       
        function NewSound takes string fileName, integer duration, boolean looping, boolean is3D returns Sound
            return Sound.create(fileName, duration, looping, is3D)
        endfunction
       
        function RunSound takes Sound this returns sound
            return this.run()
        endfunction
       
        function RunSoundEx takes Sound this, integer volume, integer pitch returns sound
            return this.runEx(volume, pitch)
        endfunction
       
        function ReleaseSound takes sound s returns boolean
            return Sound.release(s)
        endfunction
       
        function RunSoundOnUnit takes Sound this, unit whichUnit returns sound
            return this.runUnit(whichUnit)
        endfunction
       
        function RunSoundOnUnitEx takes Sound this, unit whichUnit, integer volume, integer pitch returns sound
            return this.runUnitEx(whichUnit, volume, pitch)
        endfunction
       
        function RunSoundAtPoint takes Sound this, real x, real y, real z returns sound
            return this.runPoint(x, y, z)
        endfunction
       
        function RunSoundAtPointEx takes Sound this, real x, real y, real z, integer volume, integer pitch returns sound
            return this.runPointEx(x, y, z, volume, pitch)
        endfunction
       
        function RunSoundForPlayer takes Sound this, player p returns sound
            return this.runPlayer(p)
        endfunction
       
        function RunSoundForPlayerEx takes Sound this, player p, integer volume, integer pitch returns sound
            return this.runPlayerEx(p, volume, pitch)
        endfunction
       
    endlibrary


    Rising_Dusk's SoundUtils is the original version of this.
    This is a more optimal and cleaner version that's easier to read and understand, and it addresses the sound pitch bug C:

    Feel free to comment.
     
    Last edited: Apr 16, 2014
  2. Dirac

    Dirac

    Joined:
    Jun 20, 2011
    Messages:
    249
    Resources:
    3
    JASS:
    3
    Resources:
    3
    f1rst

    No rly, what's this?
    Code (vJASS):
    set tb.sound[GetHandleId(t)] = s
    call TimerStart(t, 0.001, false, function thistype.runProxy)

    Instead use a stack, pile up sounds being fired up in a stack and after the timer (which should be 0 and not 0.001) run all of them
    Code (vJASS):
    static method runProxy takes nothing returns nothing
        call DestroyTimer(GetExpiredTimer())
        loop
            exitwhen stack[0]==0
            //do stuff using stack[0] as this
            set stack[0]=stack[stack[0]]
        endloop
    endmethod

    method run takes nothing returns nothing
        if stack[0]==0 then
            call TimerStart(CreateTimer(),0,false,function thistype.runProxy)
        endif
        set stack[this]=stack[0]
        set stack[0]=this
    endmethod
     
  3. Laiev

    Laiev

    Joined:
    Oct 11, 2008
    Messages:
    273
    Resources:
    1
    Template:
    1
    Resources:
    1
    Finally you release it :D

    Code (vJASS):

           
            method runPoint takes real x, real y, real z returns sound
                local sound s = this.run() // leak?
                call SetSoundPosition(s, x, y, z)
                return s
            endmethod

    //>>

            method runPoint takes real x, real y, real z returns sound
                call SetSoundPosition(this.run(), x, y, z)
                return this.run() // will fail :/ another timer... ignore this example.
            endmethod

    // or >>

            private static sound TSound

            method runPoint takes real x, real y, real z returns sound
                set TSound = this.run()
                call SetSoundPosition(TSound, x, y, z)
                return TSound
            endmethod

    // or >>

            method position takes sound s, real x, real y, real z returns sound
                call SetSoundPosition(s, x, y, z)
                return s
            endmethod

            method runPoint takes real x, real y, real z returns sound
                return this.position(this.run(), x, y, z)
            endmethod
     
     
  4. Bribe

    Bribe

    Joined:
    Sep 26, 2009
    Messages:
    8,121
    Resources:
    25
    Maps:
    3
    Spells:
    10
    Tutorials:
    3
    JASS:
    9
    Resources:
    25
    Code (vJASS):
                  call SetSoundChannel(s, 5)
                    call SetSoundVolume(s, 127)
                    call SetSoundPitch(s, 1)
                   
                    // Proper 3D Sound Configuration
                    if is3D[this] then
                        call SetSoundDistances(s, 600, 10000)
                        call SetSoundDistanceCutoff(s, 3000)
                        call SetSoundConeAngles(s, 0, 0, 127)


    The 5, 127, 600, 10000, 3000, 127 should be configurable via constants.
     
  5. Luorax

    Luorax

    Joined:
    Aug 7, 2009
    Messages:
    1,301
    Resources:
    1
    Maps:
    1
    Resources:
    1
    Bye bye Stack, bye bye tons of unnecessary hashtables, hello struct syntax. Cool. If you fix/add those things that others said, I think I'm going to use this.
     
  6. Bribe

    Bribe

    Joined:
    Sep 26, 2009
    Messages:
    8,121
    Resources:
    25
    Maps:
    3
    Spells:
    10
    Tutorials:
    3
    JASS:
    9
    Resources:
    25
    Returning local handles also leaks the handle ID. You must use a "tempSound" global to return those sounds instead of using locals.
     
  7. Laiev

    Laiev

    Joined:
    Oct 11, 2008
    Messages:
    273
    Resources:
    1
    Template:
    1
    Resources:
    1
    :)
    Code (vJASS):

            private static sound TSound

            method runPoint takes real x, real y, real z returns sound
                set TSound = this.run()
                call SetSoundPosition(TSound, x, y, z)
                return TSound
            endmethod

    // or >>

            method position takes sound s, real x, real y, real z returns sound
                call SetSoundPosition(s, x, y, z)
                return s
            endmethod

            method runPoint takes real x, real y, real z returns sound
                return this.position(this.run(), x, y, z)
            endmethod
     
     
  8. WaterKnight

    WaterKnight

    Joined:
    Aug 18, 2009
    Messages:
    4,033
    Resources:
    5
    Maps:
    1
    Tutorials:
    4
    Resources:
    5
    Since you use it here, maybe you can tell what
    native SetSoundConeAngles takes sound soundHandle, real inside, real outside, integer outsideVolume returns nothing

    and
    native SetSoundConeOrientation takes sound soundHandle, real x, real y, real z returns nothing

    do exactly?
     
  9. Magtheridon96

    Magtheridon96

    Joined:
    Dec 12, 2008
    Messages:
    6,006
    Resources:
    26
    Maps:
    1
    Spells:
    8
    Tutorials:
    7
    JASS:
    10
    Resources:
    26
    I actually got the idea of how those natives work by playing some DotA :p
    The closer you are to the ground, the louder the 3D sound.
    Basically, those natives manipulate the 'cone' in which the sounds are played.
    By setting the cone angles to 0, I'm removing some wierd effects that occur while you move the camera around the position of the sound. By default, the x,y coordinates are 0. The first controls the angles of this cone.
    The second is pretty much like SetSoundPosition, but it actually does something to configure the cone.

    @Laiev:
    Yeah, but I don't want to increase code-size :eek:

    @Bribe:
    I'll fix that leak and I'll make most of those values configurable.

    @Luorax:

    :cgrin:

    @Dirac:

    It might not work with the 0-second timer, but I'll test that. (The
    GetSoundIsLoading
    native brings me to surmise that a sound can't play when it's created because it's loading)

    The stack is a good idea though :)
    Less timers, moar /win/ :D
     
    Last edited: Nov 20, 2011
  10. PurgeandFire

    PurgeandFire

    Code Moderator

    Joined:
    Nov 11, 2006
    Messages:
    7,426
    Resources:
    18
    Icons:
    1
    Spells:
    4
    Tutorials:
    9
    JASS:
    4
    Resources:
    18
  11. Magtheridon96

    Magtheridon96

    Joined:
    Dec 12, 2008
    Messages:
    6,006
    Resources:
    26
    Maps:
    1
    Spells:
    8
    Tutorials:
    7
    JASS:
    10
    Resources:
    26
    I just realized something about that stack. It will fail to play the same sound twice... Wait- what the hell am I talking about? That's a good thing :D
    More performance ^_^

    I LOVE YOU DIRAC ! :D

    edit
    Man, that thing is more epic than I thought. It's a stack that destroys itself DURING iteration :D
    Dude, you're awesome :D

    edit
    Updated. Good news:
    GetSoundIsLoading
    is useless.
     
    Last edited: Nov 20, 2011
  12. Laiev

    Laiev

    Joined:
    Oct 11, 2008
    Messages:
    273
    Resources:
    1
    Template:
    1
    Resources:
    1
    SoundUtils?

    The name is not SoundTools? [​IMG]
     
  13. Magtheridon96

    Magtheridon96

    Joined:
    Dec 12, 2008
    Messages:
    6,006
    Resources:
    26
    Maps:
    1
    Spells:
    8
    Tutorials:
    7
    JASS:
    10
    Resources:
    26
    It is SoundTools.
     
  14. Laiev

    Laiev

    Joined:
    Oct 11, 2008
    Messages:
    273
    Resources:
    1
    Template:
    1
    Resources:
    1
    So why the debugs message said: [SoundUtils]? :X
     
  15. Magtheridon96

    Magtheridon96

    Joined:
    Dec 12, 2008
    Messages:
    6,006
    Resources:
    26
    Maps:
    1
    Spells:
    8
    Tutorials:
    7
    JASS:
    10
    Resources:
    26
    >:O
    One sec.

    edit
    Updated and Detached Signature.
     
  16. Bribe

    Bribe

    Joined:
    Sep 26, 2009
    Messages:
    8,121
    Resources:
    25
    Maps:
    3
    Spells:
    10
    Tutorials:
    3
    JASS:
    9
    Resources:
    25
    You should store "next[0]" to a local. What was the thinking in not doing that?
     
  17. Magtheridon96

    Magtheridon96

    Joined:
    Dec 12, 2008
    Messages:
    6,006
    Resources:
    26
    Maps:
    1
    Spells:
    8
    Tutorials:
    7
    JASS:
    10
    Resources:
    26
    Resetting the list :p
     
  18. Bribe

    Bribe

    Joined:
    Sep 26, 2009
    Messages:
    8,121
    Resources:
    25
    Maps:
    3
    Spells:
    10
    Tutorials:
    3
    JASS:
    9
    Resources:
    25
    In any case you should use a local integer which gets set to next[0] once per wind, that way you avoid repeat-referencing the array. One local declaration is about the same speed as an array reference, so do that.
     
  19. Magtheridon96

    Magtheridon96

    Joined:
    Dec 12, 2008
    Messages:
    6,006
    Resources:
    26
    Maps:
    1
    Spells:
    8
    Tutorials:
    7
    JASS:
    10
    Resources:
    26
    So this is a speed thing. Well, sure I could do that. I'll just have to set next[0] to 0 at the end of the function. Everyone's happy :3
     
  20. Bribe

    Bribe

    Joined:
    Sep 26, 2009
    Messages:
    8,121
    Resources:
    25
    Maps:
    3
    Spells:
    10
    Tutorials:
    3
    JASS:
    9
    Resources:
    25
    It's not just speed it's also about logic (an array is meant for dynamic referencing and you're treating it as static referencing) and the fact that repeat-referencing an array will consume more file size than using a local (especially if the optimizer is not used for w/e reason).