Changeset 1045

Show
Ignore:
Timestamp:
06/04/07 15:32:11 (1 year ago)
Author:
ChristianK
Message:

added arc.sound.process

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/arc/sound.d

    r995 r1045  
    5858    std.c.stdio, 
    5959    std.c.stdlib, 
     60    std.gc, 
    6061    std.string; 
    6162 
     
    6566    arc.math.routines, 
    6667    arc.math.point; 
     68     
     69static import arc.templates.array; 
     70import std.stdio; 
    6771 
    6872public  
     
    109113        unloadDerelict();  
    110114    } 
     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    } 
    111125     
    112126    /// turn sound on  
     
    195209        alGetListener3f(AL_ORIENTATION, &x, &y, null);  
    196210        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); 
    197228    } 
    198229} 
     
    203234    ALCdevice   *al_device; 
    204235    ALCcontext  *al_context; 
     236     
     237    // sound list of all created sounds 
     238    Sound[] soundList; 
    205239} 
    206240 
     
    241275            setLoop(looping);  
    242276            setVolume(volume);  
    243             setRadius(radius);  
     277            setRadius(radius); 
    244278        } 
    245279    } 
     
    247281    /// Destructor 
    248282    ~this() 
    249     {   
     283    { 
    250284        if (soundInitialized) 
    251285        { 
     
    257291        } 
    258292    } 
    259  
     293     
    260294    /// Return the Sound Resource that this SoundNode plays. 
    261295    SoundFile getSound()  
     
    549583            }  
    550584     
    551             if (!(filename in soundList)) 
     585            if (!(filename in soundFileList)) 
    552586            { 
    553587                // Get first four bytes of sound file to determine type 
     
    577611                buffers.length = buffers_ref.length = buffer_num;   // allocate empty buffers 
    578612                 
    579                 soundList[filename] = this;  
    580                 soundList.rehash;  
     613                soundFileList[filename] = this;  
     614                soundFileList.rehash;  
    581615            } 
    582616            else 
    583617            { 
    584618                // set to one already loaded  
    585                 this = soundList[filename];  
     619                this = soundFileList[filename];  
    586620            } 
    587621        } 
     
    908942{ 
    909943    // list of soundfiles that are already loaded  
    910     SoundFile[char[]] soundList; 
     944    SoundFile[char[]] soundFileList; 
    911945     
    912946    // whether sound is 'on' or not 
  • trunk/examples/asteroids/asteroids.d

    r1023 r1045  
    8383            playerShip.process(); 
    8484             
     85            arc.sound.process(); 
     86             
    8587            // Goes through the scenegraph, calling the advance method on every 
    8688            // node that's derived from IAdvancable. 
  • trunk/examples/asteroids/ship.d

    r1003 r1045  
    4848        // sound effects  
    4949        explodeSnd = new Sound(new SoundFile("astbin/explosion.wav")); 
     50        registerAutoProcessSound(explodeSnd); 
    5051        laserSnd = new Sound(new SoundFile("astbin/ship/laser.wav")); 
     52        registerAutoProcessSound(laserSnd); 
    5153         
    5254        // Circle is a physics class: radius is 16 and mass 100 
     
    5860         
    5961        super(physics, stillFrame); 
     62    } 
     63     
     64    ~this() 
     65    { 
     66        unregisterAutoProcessSound(laserSnd); 
     67        unregisterAutoProcessSound(explodeSnd); 
    6068    } 
    6169 
     
    103111    { 
    104112        processControls(); 
    105         processSounds(); 
    106     } 
    107      
    108     void processSounds() 
    109     { 
    110         explodeSnd.process(); 
    111         laserSnd.process(); 
    112113    } 
    113114     
     
    168169    } 
    169170 
    170     Sound explodeSnd, laserSnd;  
     171   Sound explodeSnd, laserSnd;  
    171172 
    172173private: