Changeset 586

Show
Ignore:
Timestamp:
05/30/08 13:19:28 (7 months ago)
Author:
LeoD
Message:

less gc evilness

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/engine/list/BufferedArray.d

    r583 r586  
    188188        return result; 
    189189    } 
     190     
     191    int opApply(int delegate(ref uint, ref T) dg) 
     192    { 
     193        int result = 0; 
     194         
     195        for(uint i = 0; i < top; i++) 
     196        { 
     197            if(cast(bool)(result = dg(i, buffer[i]))) 
     198                break; 
     199        } 
     200         
     201        return result; 
     202    } 
    190203} 
    191204 
  • trunk/src/engine/sound/SoundSystem.d

    r585 r586  
    8686     */ 
    8787    void play(char[] file); 
    88     void play(SoundSource sound); 
     88    void play(SoundSource source); 
    8989} 
  • trunk/src/engine/sound/data/Ogg.d

    r585 r586  
    7272         
    7373        ov_pcm_seek(&oggFile, offset / (bits / 8) / _channels); 
    74         buffer.length = len; 
     74         
     75        if(buffer.length < len) 
     76            buffer.length = len; 
    7577         
    7678        uint progress; 
  • trunk/src/engine/sound/openal/SoundSystem.d

    r585 r586  
    88import engine.util.Log; 
    99import engine.util.Array; 
     10import engine.list.BufferedArray; 
    1011import engine.math.Vector; 
    1112import engine.sound.Buffer; 
     
    3536    } 
    3637 
    37     OALSoundSource[] sounds; 
     38    OALSoundSource.MemoryPool sourcePool; 
     39    BufferedArray!(OALSoundSource) sources; 
    3840 
    3941public: 
     
    7173        alcMakeContextCurrent(context); 
    7274        checkError(); 
     75         
     76        sourcePool.create(64); 
     77        sources.create(64); 
     78    } 
     79 
     80    ~this() 
     81    { 
     82        sourcePool.release(); 
     83        sources.release(); 
    7384    } 
    7485 
     
    98109        } 
    99110 
    100         return new OALSoundSource(cast(OALSoundBuffer)buffer); 
     111        return sourcePool.allocate(cast(OALSoundBuffer)buffer); 
    101112    } 
    102113 
     
    134145    override void update() 
    135146    { 
    136         loop: foreach(sound; sounds) 
     147        loop: foreach(i, source; sources) 
    137148        { 
    138             if(sound.finished) 
     149            if(source.finished) 
    139150            { 
    140                 sounds.removeElement(sound); 
    141                 delete sound
     151                sources.remove(i); 
     152                sourcePool.free(source)
    142153                 
    143154                goto loop; 
     
    151162            return; 
    152163             
    153         play(createSource(getBuffer(file))); // TODO: i r evul GC abuser! 
     164        play(createSource(getBuffer(file))); 
    154165    } 
    155166 
    156     override void play(SoundSource sound_) 
     167    override void play(SoundSource source_) 
    157168    { 
    158         if(!initialized || sound_ is null) 
     169        if(!initialized || source_ is null) 
    159170            return; 
    160171         
    161         auto sound = cast(OALSoundSource)sound_; 
    162         sounds ~= sound; 
    163         alSourcePlay(sound.id); 
     172        auto source = cast(OALSoundSource)source_; 
     173        sources.append(source); 
     174         
     175        alSourcePlay(source.id); 
    164176    } 
    165177} 
  • trunk/src/engine/sound/openal/Source.d

    r585 r586  
    11module engine.sound.openal.Source; 
     2 
     3import tango.io.Stdout; 
    24 
    35import derelict.openal.al; 
    46 
     7import engine.util.Memory; 
     8import engine.util.MemoryPool; 
    59import engine.sound.Source; 
    610import engine.sound.openal.Buffer; 
     
    2125     
    2226public: 
     27    mixin MMemoryPool!(OALSoundSource, false, true); 
     28     
    2329    this(OALSoundBuffer buffer) 
    2430    { 
  • trunk/src/engine/util/MemoryPool.d

    r583 r586  
    128128        } 
    129129         
    130         T allocate() 
    131         { 
     130        T allocate(U...)(U params) 
     131        { 
     132            //static assert(!initialize || !params.length, T.stringof); 
     133            static if(!initialize) static assert(!params.length); 
     134         
    132135            assert(mutex !is null); 
    133136             
     
    158161                    } 
    159162                     
    160                     auto result = new(stdlib.malloc(T.classinfo.init.length)) T
     163                    auto result = new(stdlib.malloc(T.classinfo.init.length)) T(params)
    161164                    Memory.memoryUsage += T.classinfo.init.length; 
    162165                     
     
    170173                 
    171174                static if(initialize) 
    172                     auto object = new(block) T
     175                    auto object = new(block) T(params)
    173176                else 
    174177                    auto object = cast(T)block;