Changeset 585

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

sounds (gc abusing for now)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/defend/game/Game.d

    r584 r585  
    303303        taskManager.addRepeatedTask(&hud.update, 30); 
    304304        taskManager.addRepeatedTask(&renderer.window.update, 60); 
     305        taskManager.addRepeatedTask(&soundSystem.update, 15); 
    305306        taskManager.addPostFrameTask(&render); 
    306307    } 
  • trunk/src/defend/sim/Core.d

    r584 r585  
    337337    OrderError checkOrder(GameObject[], OrderRemove*) { return OrderError.Ignored; } 
    338338    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*) { } 
    339347 
    340348    /* Callbacks for orders, called by the sync object manager 
     
    12851293                foreach(object; slice) 
    12861294                    ids[numIds++] = object.id; 
     1295                     
     1296                slice[0].typeInfo.localOrder(slice, &order); 
    12871297            } 
    12881298            else 
  • trunk/src/defend/sim/obj/Citizen.d

    r583 r585  
    2626        { 
    2727            // TODO: change citizen model and mini pic 
     28            moveSound = "data/sounds/sheep.ogg"; 
    2829            model = "sheep/low.obj"; 
    2930            miniPic = "minipics/sheep.png"; 
  • trunk/src/defend/sim/obj/Unit.d

    r583 r585  
    8080{ 
    8181    vec3 normRotation = vec3.zero; 
     82    char[] moveSound; 
    8283 
    8384    // Time needed for development (in simulation steps) 
     
    101102    } 
    102103     
     104    override void localOrder(GameObject[] objects, OrderMapRightClick* order) 
     105    { 
     106        if(moveSound) 
     107            soundSystem.play(moveSound); 
     108    } 
     109     
    103110    override void onOrder(GameObject[] objects, OrderMapRightClick* order) 
    104     {    
     111    { 
     112     
    105113        // TODO: Group pathfinding 
    106114        iterateObjects(objects, (Unit object) 
  • trunk/src/engine/sound/SoundSystem.d

    r583 r585  
    1616{ 
    1717    import engine.sound.data.Wav; 
     18    import engine.sound.data.Ogg; 
    1819     
    1920    private SoundBuffer[char[]] sounds; 
     
    2627        { 
    2728            logger.info("loading sound from `{}'", file); 
    28             SoundData data = new WAVSoundData(file); 
     29            //SoundData data = new WAVSoundData(file); 
     30            SoundData data = new OGGSoundData(file); 
    2931             
    3032            return (sounds[file] = createBuffer(data)); 
     
    7678     
    7779    /** 
     80     * Update sources etc. 
     81     */ 
     82    void update(); 
     83     
     84    /** 
    7885     * Play a sound. 
    7986     */ 
  • trunk/src/engine/sound/Source.d

    r583 r585  
    1212     */ 
    1313    void setVelocity(float x, float y, float z); 
    14      
    15     /** 
    16      * Play the sound in a loop? 
    17      */ 
    18     void loop(bool b); 
    1914} 
  • trunk/src/engine/sound/data/Data.d

    r583 r585  
    66     * Returns the data. 
    77     */ 
    8     ubyte[] data(); 
     8    ubyte[] data(uint offset, uint len); 
    99     
    1010    /** 
     
    1212     */ 
    1313    uint size(); 
     14     
     15    /** 
     16     * Frequency. 
     17     */ 
     18    uint frequency(); 
    1419} 
  • trunk/src/engine/sound/data/Wav.d

    r583 r585  
    33import tango.io.Stdout; 
    44import tango.io.FileConduit; 
    5 import tango.text.Ascii; 
    65 
    76import engine.util.Memory; 
     
    4241     
    4342public: 
    44     override ubyte[] data() { return _data; } 
     43    override ubyte[] data(uint offset, uint len) { return _data[offset .. len]; } 
    4544    override uint size() { return _size; } 
     45    override uint frequency() { return 11024; } 
    4646     
    4747    this(char[] name) 
    4848    { 
     49        assert(false, "gtfo"); 
     50     
    4951        scope file = new FileConduit(name); 
    5052        scope(exit) file.close(); 
     
    5456            file.input.read((cast(void*)&header)[0 .. header.sizeof]); 
    5557             
    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"); 
    5860             
    5961            _size = header.size; 
     
    6971                break; 
    7072 
    71             switch(toLower(header.type)
     73            switch(header.type
    7274            { 
    7375            case "fmt ": 
  • trunk/src/engine/sound/openal/Buffer.d

    r583 r585  
    1515    { 
    1616        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); 
    1921    } 
    2022} 
  • trunk/src/engine/sound/openal/SoundSystem.d

    r583 r585  
    77 
    88import engine.util.Log; 
     9import engine.util.Array; 
    910import engine.math.Vector; 
    1011import engine.sound.Buffer; 
     
    3334            logger.warn("error: {}", error); 
    3435    } 
     36 
     37    OALSoundSource[] sounds; 
    3538 
    3639public: 
     
    129132    } 
    130133 
     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 
    131148    override void play(char[] file) 
    132149    { 
     
    137154    } 
    138155 
    139     override void play(SoundSource sound
     156    override void play(SoundSource sound_
    140157    { 
    141         if(!initialized || sound is null) 
     158        if(!initialized || sound_ is null) 
    142159            return; 
    143  
    144         alSourcePlay((cast(OALSoundSource)sound).id); 
     160         
     161        auto sound = cast(OALSoundSource)sound_; 
     162        sounds ~= sound; 
     163        alSourcePlay(sound.id); 
    145164    } 
    146165} 
  • trunk/src/engine/sound/openal/Source.d

    r583 r585  
    1212    OALSoundBuffer buffer; 
    1313     
     14    bool finished() 
     15    { 
     16        int state; 
     17        alGetSourcei(id, AL_SOURCE_STATE, &state); 
     18         
     19        return state != AL_PLAYING; 
     20    } 
     21     
    1422public: 
    15     this(OALSoundBuffer b) 
    16     in 
     23    this(OALSoundBuffer buffer) 
    1724    { 
    18         assert(b !is null); 
    19     } 
    20     body 
    21     { 
    22         buffer = b; 
     25        this.buffer = buffer; 
    2326         
    2427        alGenSources(1, &id); 
    2528        alSourcei(id, AL_BUFFER, buffer.id); 
     29    } 
     30     
     31    ~this() 
     32    { 
     33        alDeleteSources(1, &id); 
    2634    } 
    2735     
     
    3543        alSource3f(id, AL_VELOCITY, x, y, z); 
    3644    } 
    37      
    38     override void loop(bool b) 
    39     { 
    40         alSourcei(id, AL_LOOPING, b); 
    41     } 
    4245} 
  • trunk/src/windefend.cbp

    r583 r585  
    9494            <Add library="tango-user-dmd.lib" /> 
    9595            <Add library="tango-base-dmd.lib" /> 
     96            <Add library="DerelictOGG.lib" /> 
     97            <Add library="DerelictVorbis.lib" /> 
    9698        </Linker> 
    9799        <Unit filename="defend\Camera.d" /> 
     
    210212        <Unit filename="engine\sound\Source.d" /> 
    211213        <Unit filename="engine\sound\data\Data.d" /> 
     214        <Unit filename="engine\sound\data\Ogg.d" /> 
    212215        <Unit filename="engine\sound\data\Wav.d" /> 
    213216        <Unit filename="engine\sound\openal\Buffer.d" />