src/engine/sound/base/eChannel.h

Go to the documentation of this file.
00001 /*
00002 
00003 *************************************************************************
00004 
00005 ArmageTron -- Just another Tron Lightcycle Game in 3D.
00006 Copyright (C) 2000  Manuel Moos (manuel@moosnet.de)
00007 
00008 **************************************************************************
00009 
00010 This program is free software; you can redistribute it and/or
00011 modify it under the terms of the GNU General Public License
00012 as published by the Free Software Foundation; either version 2
00013 of the License, or (at your option) any later version.
00014 
00015 This program is distributed in the hope that it will be useful,
00016 but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018 GNU General Public License for more details.
00019 
00020 You should have received a copy of the GNU General Public License
00021 along with this program; if not, write to the Free Software
00022 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00023 
00024 ***************************************************************************
00025 
00026 
00027 */
00028 
00029 #include "rSDL.h"
00030 #ifndef DEDICATED
00031 #include <SDL_mixer.h>
00032 #else
00033 // dummy types
00034 typedef int Mix_Chunk;
00035 typedef int Mix_Music;
00036 #endif
00037 #include "tPlayList.h"
00038 #include "eCoord.h"
00039 
00040 #ifndef ECHANNEL_H
00041 #define ECHANNEL_H
00042 
00043 // Forward declarations from other files
00044 class eGameObject;
00045 class eCoord;
00046 
00047 // Forward declarations from this file
00048 class eWavData;
00049 class eMusicTrack;
00050 class eChannel;
00051 
00052 /*******************************************************************************
00053  *
00054  * eWavData
00055  *
00056  *******************************************************************************/
00057 
00058 class eWavData {
00059 public:
00060     eWavData();
00061     ~eWavData();
00062     eWavData(const char* filename);
00063     void LoadWavFile(const char* filename);
00064 
00065     Mix_Chunk* GetWavData() { return m_WavData; };
00066 
00067     void SetVolume(int newVolume) { m_Volume = newVolume; };
00068     int GetVolume() { return m_Volume; };
00069 
00070 private:
00071     Mix_Chunk* m_WavData;
00072     int m_Volume;
00073     bool m_Playable;
00074 };
00075 
00076 /*******************************************************************************
00077  *
00078  * eChannel
00079  *      Description of a mixer channel, corresponds to an SDL_mixer channel
00080  *
00081  *******************************************************************************/
00082 
00083 class eChannel {
00084 public:
00085     eChannel();
00086     void SetVolume(int volume);
00087     int GetId() { return m_ChannelID; };
00088     void SetId(int newID) { m_ChannelID = newID; };
00089 
00090     void Set3d(eCoord home, eCoord soundPos, eCoord homeDirection);
00091     void PlaySound(eWavData& sound);
00092     void LoopSound(eWavData& sound);
00093     void StopSound() {
00094 #ifndef DEDICATED
00095         m_isDirty = true; m_isPlaying = false; Mix_HaltChannel(m_ChannelID);
00096 #endif
00097     };
00098 
00099     // Removes any effects on the channel, should it get picked more or less at random
00100     // to play a sample.  Intended to be called from an SDL_mixer callback.
00101     void UnplaySound();
00102 
00103     Uint32 StartTime() { return m_StartTime; };
00104     bool IsContinuous() { return m_continuous; };
00105 
00106     // Call this whenever the object needs to be updated.
00107     void Update();
00108 
00109     // Call to see if the object needs to be updated
00110     bool isDirty() { return m_isDirty; };
00111 
00112     // Call to see if it's busy right now
00113     bool isBusy() { return m_isPlaying; };
00114 
00115     void SetOwner(eGameObject* owner);
00116     void DelayStarting() { m_Delayed = true; m_StartNow = false; };
00117     bool IsDelayed() { return m_Delayed; };
00118     void Undelay() { m_StartNow = true; };
00119     void SetHome(eGameObject* home) { m_Home = home; };
00120     eGameObject* GetOwner() { return m_Owner; };
00121 
00122     // A cop out, I should just iterate through all the channels and initialize it
00123     // properly, so they're guaranteed to be in sync, but this should work, as long
00124     // as the list of channels only gets built once.
00125     static int numChannels;
00126 
00127 private:
00128     eWavData m_Sound;
00129     bool m_Delayed;
00130     bool m_StartNow;
00131     int m_Volume;
00132     int m_ChannelID;
00133     Uint32 m_StartTime;
00134     bool m_isDirty;
00135     bool m_isPlaying;
00136     eGameObject* m_Owner;
00137     eGameObject* m_Home;
00138     bool m_continuous;
00139 };
00140 
00141 #endif

Generated on Sat Mar 15 22:55:48 2008 for Armagetron Advanced by  doxygen 1.5.4