Planeshift
|
00001 /* 00002 * handle.h 00003 * 00004 * Copyright (C) 2001-2010 Atomic Blue ([email protected], http://www.planeshift.it) 00005 * 00006 * Credits : Saul Leite <[email protected]> 00007 * Mathias 'AgY' Voeroes <[email protected]> 00008 * and all past and present planeshift coders 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 (version 2 of the License. 00013 * 00014 * This program is distributed in the hope that it will be useful, 00015 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00017 * GNU General Public License for more details. 00018 * You should have received a copy of the GNU General Public License 00019 * along with this program; if not, write to the Free Software 00020 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00021 * 00022 */ 00023 00024 #ifndef _SOUND_HANDLE_H_ 00025 #define _SOUND_HANDLE_H_ 00026 00027 00028 //==================================================================================== 00029 // Crystal Space Includes 00030 //==================================================================================== 00031 #include <crystalspace.h> 00032 00033 //==================================================================================== 00034 // Local Includes 00035 //==================================================================================== 00036 #include "soundctrl.h" 00037 00038 //------------------------------------------------------------------------------------ 00039 // Forward Declarations 00040 //------------------------------------------------------------------------------------ 00041 class SoundSystemManager; 00042 00043 00044 enum 00045 { 00046 FADE_DOWN = 0, 00047 FADE_UP = 1, 00048 FADE_STOP = -1 00049 }; 00050 00051 class SoundHandle: public scfImplementation1<SoundHandle, iTimerEvent>, public iSoundControlListener 00052 { 00053 public: 00054 csString name; 00055 SoundControl* sndCtrl; 00056 00057 csRef<iSndSysData> snddata; 00058 csRef<iSndSysStream> sndstream; 00059 csRef<iSndSysSource> sndsource; 00060 csRef<iSndSysSource3D> sndsource3d; 00061 csRef<iSndSysSource3DDirectionalSimple> sndsourcedir; 00062 00063 SoundHandle(); 00064 virtual ~SoundHandle(); 00065 00072 void Fade(float volume, int time, int direction); 00073 00077 void FadeStep(); 00078 00089 virtual bool Init(const char* resname, bool loop, 00090 float volume_preset, int type, 00091 SoundControl* &ctrl, bool dopplerEffect); 00092 00096 virtual bool Perform(iTimerEvent* /*ev*/); 00097 00108 void ConvertTo3D(float mindist, float maxdist, 00109 csVector3 pos, csVector3 dir, 00110 float rad); 00111 00116 bool Is3D(); 00117 00122 bool IsDopplerEffectEnabled(); 00123 00129 bool IsWithinMaximumDistance(csVector3 listenerPos) const; 00130 00135 uint GetID() const { return id; } 00136 00141 void SetID(uint identifier) { id = identifier; } 00142 00149 csVector3 GetSourcePosition(); 00150 00157 void SetAutoRemove(bool toggle); 00158 00162 bool GetAutoRemove(); 00163 00168 void UnpauseAfterDelay(unsigned int delay); 00169 00175 void SetCallback(void (*object), void (*function) (void *)); 00179 void RemoveCallback(); 00180 00181 // From iSoundControlListener 00182 //---------------------------- 00183 virtual void OnSoundChange(SoundControl* sndCtrl); 00184 00185 protected: 00186 bool dopplerEffect; 00187 float currentVolume; 00188 00189 private: 00190 uint id; 00191 int fadeSteps; 00192 bool fadeStop; 00193 float maxDistance; 00194 bool hasCallback; 00195 void (*callbackobject); 00196 void (*callbackfunction) (void *); 00197 00198 bool autoremove; 00199 bool delayActive; 00200 00205 void Callback(); 00206 00207 }; 00208 00209 #endif /*_SOUND_HANDLE_H_*/