Changeset 585
- Timestamp:
- 05/30/08 13:00:31 (7 months ago)
- Files:
-
- trunk/run/data/sounds/sheep.ogg (added)
- trunk/src/defend/game/Game.d (modified) (1 diff)
- trunk/src/defend/sim/Core.d (modified) (2 diffs)
- trunk/src/defend/sim/obj/Citizen.d (modified) (1 diff)
- trunk/src/defend/sim/obj/Unit.d (modified) (2 diffs)
- trunk/src/engine/sound/SoundSystem.d (modified) (3 diffs)
- trunk/src/engine/sound/Source.d (modified) (1 diff)
- trunk/src/engine/sound/data/Data.d (modified) (2 diffs)
- trunk/src/engine/sound/data/Ogg.d (added)
- trunk/src/engine/sound/data/Wav.d (modified) (4 diffs)
- trunk/src/engine/sound/openal/Buffer.d (modified) (1 diff)
- trunk/src/engine/sound/openal/SoundSystem.d (modified) (4 diffs)
- trunk/src/engine/sound/openal/Source.d (modified) (2 diffs)
- trunk/src/windefend.cbp (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/defend/game/Game.d
r584 r585 303 303 taskManager.addRepeatedTask(&hud.update, 30); 304 304 taskManager.addRepeatedTask(&renderer.window.update, 60); 305 taskManager.addRepeatedTask(&soundSystem.update, 15); 305 306 taskManager.addPostFrameTask(&render); 306 307 } trunk/src/defend/sim/Core.d
r584 r585 337 337 OrderError checkOrder(GameObject[], OrderRemove*) { return OrderError.Ignored; } 338 338 OrderError checkOrder(GameObject[], OrderPlaceObject*) { return OrderError.Ignored; } 339 340 // Locally do something before sending the order (like, play a sound) 341 void localOrder(GameObject[], OrderMapRightClick*) { } 342 void localOrder(GameObject[], OrderObjectRightClick*) { } 343 void localOrder(GameObject[], OrderButtonLeftClick*) { } 344 void localOrder(GameObject[], OrderButtonRightClick*) { } 345 void localOrder(GameObject[], OrderRemove*) { } 346 void localOrder(GameObject[], OrderPlaceObject*) { } 339 347 340 348 /* Callbacks for orders, called by the sync object manager … … 1285 1293 foreach(object; slice) 1286 1294 ids[numIds++] = object.id; 1295 1296 slice[0].typeInfo.localOrder(slice, &order); 1287 1297 } 1288 1298 else trunk/src/defend/sim/obj/Citizen.d
r583 r585 26 26 { 27 27 // TODO: change citizen model and mini pic 28 moveSound = "data/sounds/sheep.ogg"; 28 29 model = "sheep/low.obj"; 29 30 miniPic = "minipics/sheep.png"; trunk/src/defend/sim/obj/Unit.d
r583 r585 80 80 { 81 81 vec3 normRotation = vec3.zero; 82 char[] moveSound; 82 83 83 84 // Time needed for development (in simulation steps) … … 101 102 } 102 103 104 override void localOrder(GameObject[] objects, OrderMapRightClick* order) 105 { 106 if(moveSound) 107 soundSystem.play(moveSound); 108 } 109 103 110 override void onOrder(GameObject[] objects, OrderMapRightClick* order) 104 { 111 { 112 105 113 // TODO: Group pathfinding 106 114 iterateObjects(objects, (Unit object) trunk/src/engine/sound/SoundSystem.d
r583 r585 16 16 { 17 17 import engine.sound.data.Wav; 18 import engine.sound.data.Ogg; 18 19 19 20 private SoundBuffer[char[]] sounds; … … 26 27 { 27 28 logger.info("loading sound from `{}'", file); 28 SoundData data = new WAVSoundData(file); 29 //SoundData data = new WAVSoundData(file); 30 SoundData data = new OGGSoundData(file); 29 31 30 32 return (sounds[file] = createBuffer(data)); … … 76 78 77 79 /** 80 * Update sources etc. 81 */ 82 void update(); 83 84 /** 78 85 * Play a sound. 79 86 */ trunk/src/engine/sound/Source.d
r583 r585 12 12 */ 13 13 void setVelocity(float x, float y, float z); 14 15 /**16 * Play the sound in a loop?17 */18 void loop(bool b);19 14 } trunk/src/engine/sound/data/Data.d
r583 r585 6 6 * Returns the data. 7 7 */ 8 ubyte[] data( );8 ubyte[] data(uint offset, uint len); 9 9 10 10 /** … … 12 12 */ 13 13 uint size(); 14 15 /** 16 * Frequency. 17 */ 18 uint frequency(); 14 19 } trunk/src/engine/sound/data/Wav.d
r583 r585 3 3 import tango.io.Stdout; 4 4 import tango.io.FileConduit; 5 import tango.text.Ascii;6 5 7 6 import engine.util.Memory; … … 42 41 43 42 public: 44 override ubyte[] data( ) { return _data; }43 override ubyte[] data(uint offset, uint len) { return _data[offset .. len]; } 45 44 override uint size() { return _size; } 45 override uint frequency() { return 11024; } 46 46 47 47 this(char[] name) 48 48 { 49 assert(false, "gtfo"); 50 49 51 scope file = new FileConduit(name); 50 52 scope(exit) file.close(); … … 54 56 file.input.read((cast(void*)&header)[0 .. header.sizeof]); 55 57 56 assert(toLower(header.riff) == "riff");57 assert(toLower(header.format) == "wave");58 if(header.riff != "RIFF" || header.format != "WAVE") 59 throw new Exception("'" ~ name ~ "' is not anot a wav file"); 58 60 59 61 _size = header.size; … … 69 71 break; 70 72 71 switch( toLower(header.type))73 switch(header.type) 72 74 { 73 75 case "fmt ": trunk/src/engine/sound/openal/Buffer.d
r583 r585 15 15 { 16 16 alGenBuffers(1, &id); 17 alBufferData(id, AL_FORMAT_STEREO8, data.data.ptr, 18 data.size, 11024); 17 18 // TODO: multiple buffers (streaming) 19 alBufferData(id, AL_FORMAT_STEREO16, data.data(0, data.size).ptr, 20 data.size, data.frequency); 19 21 } 20 22 } trunk/src/engine/sound/openal/SoundSystem.d
r583 r585 7 7 8 8 import engine.util.Log; 9 import engine.util.Array; 9 10 import engine.math.Vector; 10 11 import engine.sound.Buffer; … … 33 34 logger.warn("error: {}", error); 34 35 } 36 37 OALSoundSource[] sounds; 35 38 36 39 public: … … 129 132 } 130 133 134 override void update() 135 { 136 loop: foreach(sound; sounds) 137 { 138 if(sound.finished) 139 { 140 sounds.removeElement(sound); 141 delete sound; 142 143 goto loop; 144 } 145 } 146 } 147 131 148 override void play(char[] file) 132 149 { … … 137 154 } 138 155 139 override void play(SoundSource sound )156 override void play(SoundSource sound_) 140 157 { 141 if(!initialized || sound is null)158 if(!initialized || sound_ is null) 142 159 return; 143 144 alSourcePlay((cast(OALSoundSource)sound).id); 160 161 auto sound = cast(OALSoundSource)sound_; 162 sounds ~= sound; 163 alSourcePlay(sound.id); 145 164 } 146 165 } trunk/src/engine/sound/openal/Source.d
r583 r585 12 12 OALSoundBuffer buffer; 13 13 14 bool finished() 15 { 16 int state; 17 alGetSourcei(id, AL_SOURCE_STATE, &state); 18 19 return state != AL_PLAYING; 20 } 21 14 22 public: 15 this(OALSoundBuffer b) 16 in 23 this(OALSoundBuffer buffer) 17 24 { 18 assert(b !is null); 19 } 20 body 21 { 22 buffer = b; 25 this.buffer = buffer; 23 26 24 27 alGenSources(1, &id); 25 28 alSourcei(id, AL_BUFFER, buffer.id); 29 } 30 31 ~this() 32 { 33 alDeleteSources(1, &id); 26 34 } 27 35 … … 35 43 alSource3f(id, AL_VELOCITY, x, y, z); 36 44 } 37 38 override void loop(bool b)39 {40 alSourcei(id, AL_LOOPING, b);41 }42 45 } trunk/src/windefend.cbp
r583 r585 94 94 <Add library="tango-user-dmd.lib" /> 95 95 <Add library="tango-base-dmd.lib" /> 96 <Add library="DerelictOGG.lib" /> 97 <Add library="DerelictVorbis.lib" /> 96 98 </Linker> 97 99 <Unit filename="defend\Camera.d" /> … … 210 212 <Unit filename="engine\sound\Source.d" /> 211 213 <Unit filename="engine\sound\data\Data.d" /> 214 <Unit filename="engine\sound\data\Ogg.d" /> 212 215 <Unit filename="engine\sound\data\Wav.d" /> 213 216 <Unit filename="engine\sound\openal\Buffer.d" />
