Changeset 1045
- Timestamp:
- 06/04/07 15:32:11 (1 year ago)
- Files:
-
- trunk/arc/sound.d (modified) (11 diffs)
- trunk/examples/asteroids/asteroids.d (modified) (1 diff)
- trunk/examples/asteroids/ship.d (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/arc/sound.d
r995 r1045 58 58 std.c.stdio, 59 59 std.c.stdlib, 60 std.gc, 60 61 std.string; 61 62 … … 65 66 arc.math.routines, 66 67 arc.math.point; 68 69 static import arc.templates.array; 70 import std.stdio; 67 71 68 72 public … … 109 113 unloadDerelict(); 110 114 } 115 116 /// calls process on all sounds 117 void process() 118 { 119 foreach(sound; soundList) 120 { 121 if(!sound.paused) 122 sound.process(); 123 } 124 } 111 125 112 126 /// turn sound on … … 195 209 alGetListener3f(AL_ORIENTATION, &x, &y, null); 196 210 return Point(x,y); 211 } 212 213 /** 214 Makes a sound get processed when arc.sound.process is called. 215 You must call unregisterAutoProcessSound (preferably in the destructor 216 of the owning object): otherwise the sound can't get garbage collected 217 and the sound might continue playing. 218 **/ 219 void registerAutoProcessSound(Sound s) 220 { 221 soundList ~= s; 222 } 223 224 /// ditto 225 void unregisterAutoProcessSound(Sound s) 226 { 227 arc.templates.array.remove(soundList, s); 197 228 } 198 229 } … … 203 234 ALCdevice *al_device; 204 235 ALCcontext *al_context; 236 237 // sound list of all created sounds 238 Sound[] soundList; 205 239 } 206 240 … … 241 275 setLoop(looping); 242 276 setVolume(volume); 243 setRadius(radius); 277 setRadius(radius); 244 278 } 245 279 } … … 247 281 /// Destructor 248 282 ~this() 249 { 283 { 250 284 if (soundInitialized) 251 285 { … … 257 291 } 258 292 } 259 293 260 294 /// Return the Sound Resource that this SoundNode plays. 261 295 SoundFile getSound() … … 549 583 } 550 584 551 if (!(filename in sound List))585 if (!(filename in soundFileList)) 552 586 { 553 587 // Get first four bytes of sound file to determine type … … 577 611 buffers.length = buffers_ref.length = buffer_num; // allocate empty buffers 578 612 579 sound List[filename] = this;580 sound List.rehash;613 soundFileList[filename] = this; 614 soundFileList.rehash; 581 615 } 582 616 else 583 617 { 584 618 // set to one already loaded 585 this = sound List[filename];619 this = soundFileList[filename]; 586 620 } 587 621 } … … 908 942 { 909 943 // list of soundfiles that are already loaded 910 SoundFile[char[]] sound List;944 SoundFile[char[]] soundFileList; 911 945 912 946 // whether sound is 'on' or not trunk/examples/asteroids/asteroids.d
r1023 r1045 83 83 playerShip.process(); 84 84 85 arc.sound.process(); 86 85 87 // Goes through the scenegraph, calling the advance method on every 86 88 // node that's derived from IAdvancable. trunk/examples/asteroids/ship.d
r1003 r1045 48 48 // sound effects 49 49 explodeSnd = new Sound(new SoundFile("astbin/explosion.wav")); 50 registerAutoProcessSound(explodeSnd); 50 51 laserSnd = new Sound(new SoundFile("astbin/ship/laser.wav")); 52 registerAutoProcessSound(laserSnd); 51 53 52 54 // Circle is a physics class: radius is 16 and mass 100 … … 58 60 59 61 super(physics, stillFrame); 62 } 63 64 ~this() 65 { 66 unregisterAutoProcessSound(laserSnd); 67 unregisterAutoProcessSound(explodeSnd); 60 68 } 61 69 … … 103 111 { 104 112 processControls(); 105 processSounds();106 }107 108 void processSounds()109 {110 explodeSnd.process();111 laserSnd.process();112 113 } 113 114 … … 168 169 } 169 170 170 Sound explodeSnd, laserSnd;171 Sound explodeSnd, laserSnd; 171 172 172 173 private:
