Changeset 586
- Timestamp:
- 05/30/08 13:19:28 (7 months ago)
- Files:
-
- trunk/src/engine/list/BufferedArray.d (modified) (1 diff)
- trunk/src/engine/sound/SoundSystem.d (modified) (1 diff)
- trunk/src/engine/sound/data/Ogg.d (modified) (1 diff)
- trunk/src/engine/sound/openal/SoundSystem.d (modified) (6 diffs)
- trunk/src/engine/sound/openal/Source.d (modified) (2 diffs)
- trunk/src/engine/util/MemoryPool.d (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/engine/list/BufferedArray.d
r583 r586 188 188 return result; 189 189 } 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 } 190 203 } 191 204 trunk/src/engine/sound/SoundSystem.d
r585 r586 86 86 */ 87 87 void play(char[] file); 88 void play(SoundSource sou nd);88 void play(SoundSource source); 89 89 } trunk/src/engine/sound/data/Ogg.d
r585 r586 72 72 73 73 ov_pcm_seek(&oggFile, offset / (bits / 8) / _channels); 74 buffer.length = len; 74 75 if(buffer.length < len) 76 buffer.length = len; 75 77 76 78 uint progress; trunk/src/engine/sound/openal/SoundSystem.d
r585 r586 8 8 import engine.util.Log; 9 9 import engine.util.Array; 10 import engine.list.BufferedArray; 10 11 import engine.math.Vector; 11 12 import engine.sound.Buffer; … … 35 36 } 36 37 37 OALSoundSource[] sounds; 38 OALSoundSource.MemoryPool sourcePool; 39 BufferedArray!(OALSoundSource) sources; 38 40 39 41 public: … … 71 73 alcMakeContextCurrent(context); 72 74 checkError(); 75 76 sourcePool.create(64); 77 sources.create(64); 78 } 79 80 ~this() 81 { 82 sourcePool.release(); 83 sources.release(); 73 84 } 74 85 … … 98 109 } 99 110 100 return new OALSoundSource(cast(OALSoundBuffer)buffer);111 return sourcePool.allocate(cast(OALSoundBuffer)buffer); 101 112 } 102 113 … … 134 145 override void update() 135 146 { 136 loop: foreach( sound; sounds)147 loop: foreach(i, source; sources) 137 148 { 138 if(sou nd.finished)149 if(source.finished) 139 150 { 140 sou nds.removeElement(sound);141 delete sound;151 sources.remove(i); 152 sourcePool.free(source); 142 153 143 154 goto loop; … … 151 162 return; 152 163 153 play(createSource(getBuffer(file))); // TODO: i r evul GC abuser!164 play(createSource(getBuffer(file))); 154 165 } 155 166 156 override void play(SoundSource sou nd_)167 override void play(SoundSource source_) 157 168 { 158 if(!initialized || sou nd_ is null)169 if(!initialized || source_ is null) 159 170 return; 160 171 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); 164 176 } 165 177 } trunk/src/engine/sound/openal/Source.d
r585 r586 1 1 module engine.sound.openal.Source; 2 3 import tango.io.Stdout; 2 4 3 5 import derelict.openal.al; 4 6 7 import engine.util.Memory; 8 import engine.util.MemoryPool; 5 9 import engine.sound.Source; 6 10 import engine.sound.openal.Buffer; … … 21 25 22 26 public: 27 mixin MMemoryPool!(OALSoundSource, false, true); 28 23 29 this(OALSoundBuffer buffer) 24 30 { trunk/src/engine/util/MemoryPool.d
r583 r586 128 128 } 129 129 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 132 135 assert(mutex !is null); 133 136 … … 158 161 } 159 162 160 auto result = new(stdlib.malloc(T.classinfo.init.length)) T ;163 auto result = new(stdlib.malloc(T.classinfo.init.length)) T(params); 161 164 Memory.memoryUsage += T.classinfo.init.length; 162 165 … … 170 173 171 174 static if(initialize) 172 auto object = new(block) T ;175 auto object = new(block) T(params); 173 176 else 174 177 auto object = cast(T)block;
