From: <wel...@us...> - 2010-04-23 12:22:52
|
Revision: 5826 http://planeshift.svn.sourceforge.net/planeshift/?rev=5826&view=rev Author: weltall2 Date: 2010-04-23 12:22:44 +0000 (Fri, 23 Apr 2010) Log Message: ----------- improvements to soundmanager patch by agy Modified Paths: -------------- trunk/src/client/cmdutil.cpp trunk/src/client/gui/chatwindow.cpp trunk/src/client/gui/pawsconfigsound.cpp trunk/src/client/psengine.cpp trunk/src/common/engine/psworld.cpp trunk/src/common/pssound/pssoundmngr.cpp trunk/src/common/pssound/pssoundmngr.h trunk/src/common/sound/control.cpp trunk/src/common/sound/control.h trunk/src/common/sound/data.cpp trunk/src/common/sound/data.h trunk/src/common/sound/handle.cpp trunk/src/common/sound/handle.h trunk/src/common/sound/manager.cpp trunk/src/common/sound/manager.h trunk/src/common/sound/queue.cpp trunk/src/common/sound/queue.h trunk/src/common/sound/system.cpp trunk/src/common/sound/system.h Added Paths: ----------- trunk/src/common/pssound/psemitter.cpp trunk/src/common/pssound/psemitter.h trunk/src/common/pssound/psentity.cpp trunk/src/common/pssound/psentity.h trunk/src/common/pssound/psmusic.cpp trunk/src/common/pssound/psmusic.h trunk/src/common/pssound/pssound.h trunk/src/common/pssound/pssoundsector.cpp trunk/src/common/pssound/pssoundsector.h trunk/src/common/util/pstoggle.cpp trunk/src/common/util/pstoggle.h Modified: trunk/src/client/cmdutil.cpp =================================================================== --- trunk/src/client/cmdutil.cpp 2010-04-22 17:21:44 UTC (rev 5825) +++ trunk/src/client/cmdutil.cpp 2010-04-23 12:22:44 UTC (rev 5826) @@ -68,6 +68,7 @@ cmdsource->Subscribe("/ping",this); cmdsource->Subscribe("/screenshot",this); cmdsource->Subscribe("/fps",this); + cmdsource->Subscribe("/reload",this); cmdsource->Subscribe("/graphicbug",this); cmdsource->Subscribe("/repaintlabels",this); //cmdsource->Subscribe("/dumpmovements",this); @@ -82,6 +83,7 @@ cmdsource->Unsubscribe("/ping",this); cmdsource->Unsubscribe("/screenshot",this); cmdsource->Unsubscribe("/fps",this); + cmdsource->Unsubscribe("/reload",this); cmdsource->Unsubscribe("/graphicbug",this); cmdsource->Unsubscribe("/repaintlabels",this); //cmdsource->Unsubscribe("/dumpmovements",this); @@ -193,6 +195,15 @@ HandleTestAnim(words, outputstring); return outputstring.GetData(); } + else if(words[0] == "/reload") + { + if (words[1] == "sound") + { + psengine->GetSoundManager()->Reload(); + return "Soundmanager reloaded"; + } + return "try /reload sound"; + } return "Unimplemented command received by psUtilityCommands."; } Modified: trunk/src/client/gui/chatwindow.cpp =================================================================== --- trunk/src/client/gui/chatwindow.cpp 2010-04-22 17:21:44 UTC (rev 5825) +++ trunk/src/client/gui/chatwindow.cpp 2010-04-23 12:22:44 UTC (rev 5826) @@ -1292,7 +1292,7 @@ case CHAT_SERVER_TELL: case CHAT_TELLSELF: case CHAT_TELL: - if (psengine->GetSoundManager()->GetChatToggle() == true) + if (psengine->GetSoundManager()->chatToggle.GetToggle() == true) { // Hardcoded Resource considered as FIXME psengine->GetSoundManager()->PlayGUISound("sound.standardButtonClick"); Modified: trunk/src/client/gui/pawsconfigsound.cpp =================================================================== --- trunk/src/client/gui/pawsconfigsound.cpp 2010-04-22 17:21:44 UTC (rev 5825) +++ trunk/src/client/gui/pawsconfigsound.cpp 2010-04-23 12:22:44 UTC (rev 5826) @@ -156,11 +156,11 @@ voices->SetState(psengine->GetSoundManager()->voiceSndCtrl->GetToggle()); muteOnFocusLoss->SetState(psengine->GetMuteSoundsOnFocusLoss()); - loopBGM->SetState(psengine->GetSoundManager()->GetLoopBGMToggle()); - combatMusic->SetState(psengine->GetSoundManager()->GetCombatToggle()); - chatSound->SetState(psengine->GetSoundManager()->GetChatToggle()); + loopBGM->SetState(psengine->GetSoundManager()->loopBGM.GetToggle()); + combatMusic->SetState(psengine->GetSoundManager()->combatMusic.GetToggle()); + chatSound->SetState(psengine->GetSoundManager()->chatToggle.GetToggle()); - if (psengine->GetSoundManager()->GetListenerOnCameraPos() == true) + if (psengine->GetSoundManager()->listenerOnCamera.GetToggle() == true) { soundLocation->Select("Camera"); } @@ -291,7 +291,7 @@ if(wdg == ambient) { - psengine->GetSoundManager()->SetAmbientToggle(ambient->GetState()); + psengine->GetSoundManager()->ambientSndCtrl->SetToggle(ambient->GetState()); } else if(wdg == actions) { @@ -299,7 +299,7 @@ } else if(wdg == music) { - psengine->GetSoundManager()->SetMusicToggle(music->GetState()); + psengine->GetSoundManager()->musicSndCtrl->SetToggle(music->GetState()); } else if(wdg == gui) { @@ -311,11 +311,11 @@ } else if(wdg == loopBGM) { - psengine->GetSoundManager()->SetLoopBGMToggle(loopBGM->GetState()); + psengine->GetSoundManager()->loopBGM.SetToggle(loopBGM->GetState()); } else if(wdg == combatMusic) { - psengine->GetSoundManager()->SetCombatToggle(combatMusic->GetState()); + psengine->GetSoundManager()->combatMusic.SetToggle(combatMusic->GetState()); } else if(wdg == muteOnFocusLoss) { @@ -323,7 +323,7 @@ } else if(wdg == chatSound) { - psengine->GetSoundManager()->SetChatToggle(chatSound->GetState()); + psengine->GetSoundManager()->chatToggle.SetToggle(chatSound->GetState()); } else { @@ -341,11 +341,11 @@ if (_selected.Compare("Camera")) { - psengine->GetSoundManager()->SetListenerOnCameraPos(true); + psengine->GetSoundManager()->listenerOnCamera.SetToggle(true); } else { - psengine->GetSoundManager()->SetListenerOnCameraPos(false); + psengine->GetSoundManager()->listenerOnCamera.SetToggle(false); } SaveConfig(); } @@ -358,8 +358,8 @@ oldactions = psengine->GetSoundManager()->actionSndCtrl->GetToggle(); oldgui = psengine->GetSoundManager()->guiSndCtrl->GetToggle(); oldvoices = psengine->GetSoundManager()->voiceSndCtrl->GetToggle(); - oldchatsound = psengine->GetSoundManager()->GetChatToggle(); - oldlisteneroncamerapos = psengine->GetSoundManager()->GetListenerOnCameraPos(); + oldchatsound = psengine->GetSoundManager()->chatToggle.GetToggle(); + oldlisteneroncamerapos = psengine->GetSoundManager()->listenerOnCamera.GetToggle(); oldvol = psengine->GetSoundManager()->mainSndCtrl->GetVolume(); oldmusicvol = psengine->GetSoundManager()->musicSndCtrl->GetVolume(); @@ -375,13 +375,13 @@ { if(dirty) { - psengine->GetSoundManager()->SetAmbientToggle(oldambient); + psengine->GetSoundManager()->ambientSndCtrl->SetToggle(oldambient); psengine->GetSoundManager()->actionSndCtrl->SetToggle(oldactions); - psengine->GetSoundManager()->SetMusicToggle(oldmusic); + psengine->GetSoundManager()->musicSndCtrl->SetToggle(oldmusic); psengine->GetSoundManager()->guiSndCtrl->SetToggle(oldgui); psengine->GetSoundManager()->SetVoiceToggle(oldvoices); - psengine->GetSoundManager()->SetChatToggle(oldchatsound); - psengine->GetSoundManager()->SetListenerOnCameraPos(oldlisteneroncamerapos); + psengine->GetSoundManager()->chatToggle.SetToggle(oldchatsound); + psengine->GetSoundManager()->listenerOnCamera.SetToggle(oldlisteneroncamerapos); psengine->GetSoundManager()->mainSndCtrl->SetVolume(oldvol); psengine->GetSoundManager()->musicSndCtrl->SetVolume(oldmusicvol); Modified: trunk/src/client/psengine.cpp =================================================================== --- trunk/src/client/psengine.cpp 2010-04-22 17:21:44 UTC (rev 5825) +++ trunk/src/client/psengine.cpp 2010-04-23 12:22:44 UTC (rev 5826) @@ -1148,8 +1148,8 @@ if (GetSoundStatus() && loadstate == LS_DONE) { - SoundManager->UpdateListener( camera->GetView() ); - SoundManager->playerposition = celclient->GetMainPlayer()->Pos(); + SoundManager->UpdateListener(camera->GetView()); + SoundManager->SetPosition(celclient->GetMainPlayer()->Pos()); } /* sound is updated EVERY FRAME, doesnt matter if 2D or 3D @@ -1641,7 +1641,7 @@ // load and apply the settings optionNode = mainNode->GetNode("ambient"); if (optionNode != NULL) - SoundManager->SetAmbientToggle(optionNode->GetAttributeValueAsBool("on",true)); + SoundManager->ambientSndCtrl->SetToggle(optionNode->GetAttributeValueAsBool("on",true)); optionNode = mainNode->GetNode("actions"); if (optionNode != NULL) @@ -1649,7 +1649,7 @@ optionNode = mainNode->GetNode("music"); if (optionNode != NULL) - SoundManager->SetMusicToggle(optionNode->GetAttributeValueAsBool("on",true)); + SoundManager->musicSndCtrl->SetToggle(optionNode->GetAttributeValueAsBool("on",true)); optionNode = mainNode->GetNode("gui"); if (optionNode != NULL) @@ -1749,23 +1749,19 @@ optionNode = mainNode->GetNode("loopbgm"); if (optionNode) - SoundManager->SetLoopBGMToggle(optionNode->GetAttributeValueAsBool("on", false)); + SoundManager->loopBGM.SetToggle(optionNode->GetAttributeValueAsBool("on", false)); optionNode = mainNode->GetNode("combatmusic"); if (optionNode) - SoundManager->SetCombatToggle(optionNode->GetAttributeValueAsBool("on", true)); + SoundManager->combatMusic.SetToggle(optionNode->GetAttributeValueAsBool("on", true)); - optionNode = mainNode->GetNode("combatmusic"); - if (optionNode) - SoundManager->SetCombatToggle(optionNode->GetAttributeValueAsBool("on", true)); - optionNode = mainNode->GetNode("chatsound"); if (optionNode) - SoundManager->SetCombatToggle(optionNode->GetAttributeValueAsBool("on", true)); + SoundManager->chatToggle.SetToggle(optionNode->GetAttributeValueAsBool("on", true)); optionNode = mainNode->GetNode("usecamerapos"); if (optionNode) - SoundManager->SetListenerOnCameraPos(optionNode->GetAttributeValueAsBool("on", true)); + SoundManager->listenerOnCamera.SetToggle(optionNode->GetAttributeValueAsBool("on", true)); return true; } Modified: trunk/src/common/engine/psworld.cpp =================================================================== --- trunk/src/common/engine/psworld.cpp 2010-04-22 17:21:44 UTC (rev 5825) +++ trunk/src/common/engine/psworld.cpp 2010-04-23 12:22:44 UTC (rev 5826) @@ -175,6 +175,9 @@ if (i == -1) return false; + if (transarray.GetSize() == 0) + return true; + csReversibleTransform* transform = transarray[i].Get((iSector*)to); if (transform) return true; Added: trunk/src/common/pssound/psemitter.cpp =================================================================== --- trunk/src/common/pssound/psemitter.cpp (rev 0) +++ trunk/src/common/pssound/psemitter.cpp 2010-04-23 12:22:44 UTC (rev 5826) @@ -0,0 +1,125 @@ +/* + * psemitter.cpp + * + * Copyright (C) 2001-2010 Atomic Blue (in...@pl..., http://www.planeshift.it) + * + * Credits : Saul Leite <le...@en...> + * Mathias 'AgY' Voeroes <ag...@op...> + * and all past and present planeshift coders + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation (version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ + +#include "pssound.h" + +extern SoundSystemManager *SndSysMgr; + +psEmitter::psEmitter () +{ + minvol = VOLUME_ZERO; + maxvol = VOLUME_ZERO; + fadedelay = 0; + minrange = 0.0f; + maxrange = 0.0f; + factory_prob = 0; + position = csVector3(0); + direction = csVector3(0); + active = false; + timeofday = -1; + timeofdayrange = -1; + handle = NULL; +} + +psEmitter::psEmitter (psEmitter* const &emitter) +{ + // FIXME, this copy constructor is incomplete + resource = csString(emitter->resource); + maxvol = emitter->maxvol; + minvol = emitter->minvol; + minrange = emitter->minrange; + maxrange = emitter->maxrange; + timeofday = emitter->timeofday; + timeofdayrange = emitter->timeofdayrange; +} + +psEmitter::~psEmitter () +{ + // stop deletes the handle + Stop(); +} + +bool psEmitter::CheckRange (csVector3 playerpos) +{ + csVector3 rangeVec; + float range; + + rangeVec = position - playerpos; + range = rangeVec.Norm(); + + if (!range) /* if range is NAN */ + { + return false; + } + else if (range <= maxrange) + { + return true; + } + + return false; +} + +bool psEmitter::CheckTimeOfDay (int time) +{ + if ((timeofday <= time) + && (timeofdayrange >= time)) + { + return true; + } + + return false; +} + +bool psEmitter::Play (SoundControl* &ctrl) +{ + if (SndSysMgr->Play3DSound (resource, LOOP, 0, 0, + maxvol, ctrl, + position, direction, + minrange, maxrange, + VOLUME_ZERO, CS_SND3D_ABSOLUTE, + handle)) + { + active = true; + handle->SetCallback(this, &StopCallback); + return true; + } + + return false; +} + +void psEmitter::Stop () +{ + active = false; + + if (handle != NULL) + { + SndSysMgr->StopSound(handle); + } +} + +void psEmitter::StopCallback(void* object) +{ + psEmitter *which = (psEmitter *) object; + which->active = false; + which->handle = NULL; +} \ No newline at end of file Property changes on: trunk/src/common/pssound/psemitter.cpp ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + native Added: trunk/src/common/pssound/psemitter.h =================================================================== --- trunk/src/common/pssound/psemitter.h (rev 0) +++ trunk/src/common/pssound/psemitter.h 2010-04-23 12:22:44 UTC (rev 5826) @@ -0,0 +1,102 @@ +/* + * psemitter.h + * + * Copyright (C) 2001-2010 Atomic Blue (in...@pl..., http://www.planeshift.it) + * + * Credits : Saul Leite <le...@en...> + * Mathias 'AgY' Voeroes <ag...@op...> + * and all past and present planeshift coders + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation (version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ + + +#ifndef PSEMITTER_H_ +#define PSEMITTER_H_ + +/** + * This object represents a planeshift soundEmitter. + * Everything is in this object public and you can modify it at any time. + * Make sure that you call Stop and Play after doing that. + * Keep in mind that you have to be carefull when changing the SoundHandle + * and its "active" status. + */ + +class psEmitter +{ + public: + csString resource; ///< name of the resource + float minvol; ///< vol at maxrange + float maxvol; ///< vol at minrange + int fadedelay; ///< how long fading should take in milliseconds + float minrange; ///< range when it should reach maxvol + float maxrange; ///< range when it should have minvol + csString factory; ///< name of the factory this emitter should attach to + float factory_prob; ///< probability that this emitter attaches to the factory + csVector3 position; ///< position of the emitter + csVector3 direction; ///< direction were emitting to + bool active; ///< is this emitter active? + int timeofday; ///< time when this emitter starts playing + int timeofdayrange; ///< time when this emitter stops + SoundHandle *handle; ///< @see SoundHandle if it is active + + /** + * Constructor + */ + psEmitter (); + /** + * Destructor + * Removes our Callback from the Handle if its still playing. + */ + ~psEmitter (); + /** + * Copy Constructor + * copies resource volume range and time parameters + * everything else remains uninitialized! + * @param emitter a existing emitter + */ + psEmitter (psEmitter* const &emitter); + /** + * Check range to the given position. + * Calculates the distance to the given position and returns + * true if this emitter is in range. + * @param playerpos position used for calculation + */ + bool CheckRange (csVector3 playerpos); + /** + * Check time of day. + * Checks if time is within this emitters timewindow. + * Returns true if it is. + * @param time <24 && >0 is resonable but can be any valid int + */ + bool CheckTimeOfDay (int time); + /** + * Play this emitter. + * Makes this emitter play - you need to provide a SoundControl. + * @param ctrl SoundControl for this emitter + */ + bool Play (SoundControl* &ctrl); + /** + * Stops this emitter. + */ + void Stop (); + /** + * Callback function for Stop. + * SoundHandles callback will point to this and inform us if it gets destroyed. + * It sets active to false and Handle to NULL + */ + static void StopCallback(void* object); +}; + +#endif /*PSEMITTER_H_*/ Property changes on: trunk/src/common/pssound/psemitter.h ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + native Added: trunk/src/common/pssound/psentity.cpp =================================================================== --- trunk/src/common/pssound/psentity.cpp (rev 0) +++ trunk/src/common/pssound/psentity.cpp 2010-04-23 12:22:44 UTC (rev 5826) @@ -0,0 +1,89 @@ +/* + * psentity.cpp + * + * Copyright (C) 2001-2010 Atomic Blue (in...@pl..., http://www.planeshift.it) + * + * Credits : Saul Leite <le...@en...> + * Mathias 'AgY' Voeroes <ag...@op...> + * and all past and present planeshift coders + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation (version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ + + +#include "pssound.h" + +extern SoundSystemManager *SndSysMgr; + +psEntity::psEntity () +{ + minvol = VOLUME_ZERO; + maxvol = VOLUME_ZERO; + minrange = 0.0f; + maxrange = 0.0f; + probability = 0; + active = false; + timeofday = -1; + timeofdayrange = -1; + handle = NULL; +} + +psEntity::psEntity (psEntity* const &entity) +{ +} + +psEntity::~psEntity () +{ + if (handle != NULL) + { + handle->RemoveCallback(); + } +} + +bool psEntity::CheckTimeOfDay (int time) +{ + if ((timeofday <= time) + && (timeofdayrange >= time)) + { + return true; + } + + return false; +} + +bool psEntity::Play (SoundControl* &ctrl, csVector3 entityposition) +{ + if (SndSysMgr->Play3DSound (resource, DONT_LOOP, 0, 0, + maxvol, ctrl, + entityposition, 0, + minrange, maxrange, + VOLUME_ZERO, CS_SND3D_ABSOLUTE, + handle)) + { + active = true; + when = (delay_after*1000); + handle->SetCallback(this, &StopCallback); + return true; + } + + return false; +} + +void psEntity::StopCallback(void* object) +{ + psEntity *which = (psEntity *) object; + which->active = false; + which->handle = NULL; +} + Property changes on: trunk/src/common/pssound/psentity.cpp ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + native Added: trunk/src/common/pssound/psentity.h =================================================================== --- trunk/src/common/pssound/psentity.h (rev 0) +++ trunk/src/common/pssound/psentity.h 2010-04-23 12:22:44 UTC (rev 5826) @@ -0,0 +1,85 @@ +/* + * psentity.h + * + * Copyright (C) 2001-2010 Atomic Blue (in...@pl..., http://www.planeshift.it) + * + * Credits : Saul Leite <le...@en...> + * Mathias 'AgY' Voeroes <ag...@op...> + * and all past and present planeshift coders + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation (version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ + + +#ifndef PSENTITY_H_ +#define PSENTITY_H_ + +/** + * This object represents a planeshift entity sound. + * this class is a thin class as this is work in progress + * and everything is subject to change. + */ + +class psEntity +{ + public: + csString name; ///< name of the entity + csString resource; ///< resource name of the sound + float minvol; ///< vol at maxrange + float maxvol; ///< vol at minrange + float minrange; ///< range when it should reach maxvol + float maxrange; ///< range when it should reach maxvol + int delay_before; ///< number of seconds till first time this sound is played + int delay_after; ///< number of seconds till played again + float probability; ///< how high is the probability that this entity makes this sound + int when; ///< counter to keep track when it has been played - zero means i may play at any time + bool active; ///< is the sound active? + SoundHandle *handle; ///< pointer to the SoundHandle if active + int timeofday; ///< time when this entity starts playing + int timeofdayrange; ///< time when this entity stops + + /** + * Constructer + */ + psEntity (); + /** + * Destructor + */ + ~psEntity (); + /** + * Copy Constructor - WARNING INCOMPLETE + */ + psEntity (psEntity* const &entity); + /** + * Check time of day. + * Checks if time is within this entitys timewindow. + * Returns true if it is. + * @param time <24 && >0 is resonable but can be any valid int + */ + bool CheckTimeOfDay (int time); + /** + * Play this entity sound. + * You need to supply a SoundControl and the position for this sound. + * @param ctrl SoundControl + * @param entityposition position of this entity + */ + bool Play (SoundControl* &ctrl, csVector3 entityposition); + /** + * The Callback gets called if the SoundHandle is destroyed. + * It sets active to false and handle to NULL + */ + static void StopCallback(void* object); +}; + +#endif /*PSENTITY_H_*/ Property changes on: trunk/src/common/pssound/psentity.h ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + native Added: trunk/src/common/pssound/psmusic.cpp =================================================================== --- trunk/src/common/pssound/psmusic.cpp (rev 0) +++ trunk/src/common/pssound/psmusic.cpp 2010-04-23 12:22:44 UTC (rev 5826) @@ -0,0 +1,140 @@ +/* + * psmusic.cpp + * + * Copyright (C) 2001-2010 Atomic Blue (in...@pl..., http://www.planeshift.it) + * + * Credits : Saul Leite <le...@en...> + * Mathias 'AgY' Voeroes <ag...@op...> + * and all past and present planeshift coders + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation (version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ + +#include "pssound.h" + +extern SoundSystemManager *SndSysMgr; + +psMusic::psMusic () +{ + active = false; + handle = NULL; +} + +psMusic::~psMusic () +{ + Stop(); +} + +bool psMusic::CheckTimeOfDay (int time) +{ + if ((timeofday <= time) + && (timeofdayrange >= time)) + { + return true; + } + + return false; +} + +bool psMusic::CheckType (const int _type) +{ + if (type == _type) + { + return true; + } + + return false; +} + +void psMusic::FadeUp () +{ + if (handle != NULL) + { + handle->Fade((maxvol - minvol), fadedelay, FADE_UP); + } +} + +void psMusic::FadeDown () +{ + if (handle != NULL) + { + handle->Fade(maxvol, fadedelay, FADE_DOWN); + } +} + +void psMusic::FadeDownAndStop () +{ + active = false; + + if (handle != NULL) + { + handle->RemoveCallback(); + handle->Fade(maxvol, fadedelay, FADE_STOP); + handle = NULL; + } +} + +bool psMusic::Play (bool loopToggle, SoundControl* &ctrl) +{ + if (SndSysMgr->Play2DSound (resource, loopToggle, + loopstart, loopend, + minvol, ctrl, + handle)) + { + active = true; + handle->preset_volume = maxvol; + handle->SetCallback(this, &StopCallback); + return true; + } + + return false; +} + +void psMusic::Stop () +{ + active = false; + + if (handle != NULL) + { + SndSysMgr->StopSound(handle); + } +} + +void psMusic::SetManaged () +{ + handle->SetAutoRemove(false); +} + +void psMusic::SetUnManaged () +{ + handle->SetAutoRemove(true); +} + +void psMusic::DontLoop () +{ + handle->sndstream->SetLoopState(DONT_LOOP); +} + +void psMusic::Loop () +{ + handle->sndstream->SetLoopState(LOOP); + handle->sndstream->Unpause(); +} + +void psMusic::StopCallback(void* object) +{ + psMusic *which = (psMusic *) object; + which->active = false; + which->handle = NULL; +} \ No newline at end of file Property changes on: trunk/src/common/pssound/psmusic.cpp ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + native Added: trunk/src/common/pssound/psmusic.h =================================================================== --- trunk/src/common/pssound/psmusic.h (rev 0) +++ trunk/src/common/pssound/psmusic.h 2010-04-23 12:22:44 UTC (rev 5826) @@ -0,0 +1,120 @@ +/* + * psmusic.h + * + * Copyright (C) 2001-2010 Atomic Blue (in...@pl..., http://www.planeshift.it) + * + * Credits : Saul Leite <le...@en...> + * Mathias 'AgY' Voeroes <ag...@op...> + * and all past and present planeshift coders + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation (version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ + +#ifndef PSMUSIC_H_ +#define PSMUSIC_H_ + +/** + * This object represents a planeshift Soundtrack. + * It maybe an ambient or a real soundtrack they are very similiar. + * it has methods to perform the most common operations. + */ + +class psMusic +{ + public: + csString resource; ///< sound resource + int type; ///< type can be anything i use it for weather checks and similar thhings + float minvol; ///< volume when fading in + float maxvol; ///< volume this track is playing at + int fadedelay; ///< number of milliseconds fading should use + int timeofday; ///< time when this music starts playing + int timeofdayrange; ///< time till this music is playing + size_t loopstart; ///< frame to start at when looping + size_t loopend; ///< frame when jumping back to loopstart (when looping) + bool active; ///< is this soundtrack active? + SoundHandle *handle; ///< handle if this soundtrack is active + + /** + * Constructor + * Sets active to false and handle to NULL + */ + psMusic (); + /** + * Destructor + * Removes Handle callback if theres one + */ + ~psMusic (); + /** + * Check time of day. + * Checks if time is within this soundtracks timewindow. + * Returns true if it is. + * @param time <24 && >0 is resonable but can be any valid int + */ + bool CheckTimeOfDay (int time); + /** + * Compares soundstracks type against a given type. + * Returns true if they are both equal + * @param _type type to compare against + */ + bool CheckType (const int _type); + /** + * Fades this Soundtrack down and stops it. + */ + void FadeDownAndStop (); + /** + * Fades this Soundtrack down. + */ + void FadeDown (); + /** + * Fades this Soundtrack up. + */ + void FadeUp (); + /** + * Play this SoundTrack + * @param loopToggle loop? maybe true or false + * @param ctrl SoundControl for this sound + */ + bool Play (bool loopToggle, SoundControl* &ctrl); + /** + * Stops this Soundtrack immediatly + */ + void Stop (); + /** + * Sets Autoremove to true. + * The SoundHandle will be removed when this sound has stopped playing. + * Warning: doesnt happen when looping! + */ + void SetUnManaged (); + /** + * Set Autoremove to false. + * The SoundHandle wont be removed even if paused. + */ + void SetManaged (); + /** + * Enable or resume looping. + */ + void Loop (); + /** + * Disable looping. + */ + void DontLoop (); + /** + * Callback function for Stop. + * SoundHandles callback will point to this and inform us if it gets destroyed. + * It sets active to false and Handle to NULL + */ + static void StopCallback(void* object); +}; + +#endif /*PSMUSIC_H_*/ Property changes on: trunk/src/common/pssound/psmusic.h ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + native Added: trunk/src/common/pssound/pssound.h =================================================================== --- trunk/src/common/pssound/pssound.h (rev 0) +++ trunk/src/common/pssound/pssound.h 2010-04-23 12:22:44 UTC (rev 5826) @@ -0,0 +1,35 @@ +/* + * pssound.h + * + * Copyright (C) 2001-2010 Atomic Blue (in...@pl..., http://www.planeshift.it) + * + * Credits : Saul Leite <le...@en...> + * Mathias 'AgY' Voeroes <ag...@op...> + * and all past and present planeshift coders + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation (version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ + +#ifndef PSSOUND_H_ +#define PSSOUND_H_ + +#include <crystalspace.h> +#include "sound/sound.h" +#include "util/pstoggle.h" +#include "psmusic.h" +#include "psentity.h" +#include "psemitter.h" +#include "pssoundsector.h" + +#endif /*PSSOUND_H_*/ Property changes on: trunk/src/common/pssound/pssound.h ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + native Modified: trunk/src/common/pssound/pssoundmngr.cpp =================================================================== --- trunk/src/common/pssound/pssoundmngr.cpp 2010-04-22 17:21:44 UTC (rev 5825) +++ trunk/src/common/pssound/pssoundmngr.cpp 2010-04-23 12:22:44 UTC (rev 5826) @@ -23,10 +23,13 @@ #include <psconfig.h> #include <crystalspace.h> -#include "util/psxmlparser.h" + +#include "sound/sound.h" +#include "pssound.h" #include "pssoundmngr.h" #include "pscelclient.h" #include "globals.h" +#include "util/psxmlparser.h" /* FIXME NAMESPACE */ // reminder: paws and effects need that thing (still) @@ -37,28 +40,35 @@ activesector = NULL; ///< combat = 0; ///< combat stance 0 peace 1 fighting 2 dead (TODO refactor me) weather = 1; ///< weather from weather.h 1 is sunshine - timeofday = 12; ///< timeofday initial is 12am / 12:00 SndSysMgr = new SoundSystemManager(objectReg); // load sector data - LoadData (objectReg, sectordata); + LoadSectors (); // request all needed soundcontrols mainSndCtrl = SndSysMgr->mainSndCtrl; + ambientSndCtrl = SndSysMgr->GetSoundControl(); + ambientSndCtrl->SetCallback(this, &UpdateAmbientCallback); + musicSndCtrl = SndSysMgr->GetSoundControl(); + musicSndCtrl->SetCallback(this, &UpdateMusicCallback); + voiceSndCtrl = SndSysMgr->GetSoundControl(); actionSndCtrl = SndSysMgr->effectSndCtrl; guiSndCtrl = SndSysMgr->guiSndCtrl; // request a new queue for playing voicefiles voicequeue = new SoundQueue(voiceSndCtrl, VOLUME_NORM); + + loopBGM.SetCallback(this, &UpdateMusicCallback); + combatMusic.SetCallback(this, &UpdateMusicCallback); + + LastUpdateTime = csGetTicks(); - chatToggle = false; - //TODO: NEED TO INITIALIZE ALL VARIABLES! } @@ -66,10 +76,8 @@ { delete voicequeue; delete SndSysMgr; + UnloadSectors(); // Note: SndSysMgr should take care of SoundControls .. we can ignore them - for(size_t i = 0; i < sectordata.GetSize(); i++) - delete sectordata[i]; - sectordata.DeleteAll(); } /* @@ -96,8 +104,8 @@ if (activesector != NULL && LastUpdateTime + 50 <= SndTime) { voicequeue->Work(); - UpdateEmitter(activesector); - UpdateEntity(activesector); + activesector->UpdateEmitter(ambientSndCtrl); + activesector->UpdateEntity(ambientSndCtrl); LastUpdateTime = csGetTicks(); } @@ -107,6 +115,38 @@ SndSysMgr->Update(); } +void psSoundManager::UpdateMusicCallback(void* object) +{ + psSoundManager *which = (psSoundManager *) object; + if (which->activesector != NULL) + { + which->activesector->UpdateMusic(which->loopBGM.GetToggle(), which->combat, which->musicSndCtrl); + } +} + +void psSoundManager::UpdateAmbientCallback(void* object) +{ + psSoundManager *which = (psSoundManager *) object; + if (which->activesector != NULL) + { + which->activesector->UpdateAmbient(which->weather, which->ambientSndCtrl); + } +} + +void psSoundManager::PlayActionSound (const char *name) +{ + SoundHandle *Handle; + SndSysMgr->Play2DSound(name, DONT_LOOP, 0, 0, VOLUME_NORM, + actionSndCtrl, Handle); +} + +void psSoundManager::PlayGUISound (const char *name) +{ + SoundHandle *Handle; + SndSysMgr->Play2DSound(name, DONT_LOOP, 0, 0, VOLUME_NORM, + guiSndCtrl, Handle); +} + /* * Transfer ambient/music Handles from oldsector to newsector if needed * if loopBGM is false then the handle might be invalid @@ -114,24 +154,24 @@ * all we do is copy the address */ -void psSoundManager::TransferHandles (sctdata* &oldsector, sctdata* &newsector) +void psSoundManager::TransferHandles (psSoundSector* &oldsector, + psSoundSector* &newsector) { - for (size_t j = 0; j< newsector->music.GetSize(); j++) + for (size_t j = 0; j< newsector->musicarray.GetSize(); j++) { if (oldsector->activemusic == NULL) { break; } - if (csStrCaseCmp(newsector->music[j]->resource, + if (csStrCaseCmp(newsector->musicarray[j]->resource, oldsector->activemusic->resource) == 0) { - csPrintf("About to steal a music handle\n"); /* yay active resource with the same name - steal the handle*/ - newsector->music[j]->handle = oldsector->activemusic->handle; - newsector->activemusic = newsector->music[j]; + newsector->musicarray[j]->handle = oldsector->activemusic->handle; + newsector->activemusic = newsector->musicarray[j]; /* set the sound to active */ - newsector->music[j]->active = true; + newsector->musicarray[j]->active = true; /* set it to inactive to prevent damage on the handle */ oldsector->activemusic->active = false; /* set it to NULL to avoid problems */ @@ -139,22 +179,21 @@ } } - for (size_t j = 0; j< activesector->ambient.GetSize(); j++) + for (size_t j = 0; j< activesector->ambientarray.GetSize(); j++) { if (oldsector->activeambient == NULL) { break; } - if (csStrCaseCmp(newsector->ambient[j]->resource, + if (csStrCaseCmp(newsector->ambientarray[j]->resource, oldsector->activeambient->resource) == 0) { - csPrintf("About to steal a ambient handle\n"); /* yay active resource with the same name - steal the handle*/ - newsector->ambient[j]->handle = oldsector->activeambient->handle; - newsector->activeambient = newsector->ambient[j]; + newsector->ambientarray[j]->handle = oldsector->activeambient->handle; + newsector->activeambient = newsector->ambientarray[j]; /* set the sound to active */ - newsector->ambient[j]->active = true; + newsector->ambientarray[j]->active = true; /* set it to inactive to prevent damage on the handle */ oldsector->activeambient->active = false; /* set it to NULL to avoid problems */ @@ -166,14 +205,14 @@ -void psSoundManager::ConvertFactoriesToEmitter (sctdata* §or) +void psSoundManager::ConvertFactoriesToEmitter (psSoundSector* §or) { iSector *searchSector; iMeshFactoryWrapper *factory; iMeshWrapper *mesh; iMeshList *meshes; iEngine *engine; - sct_emitter *emitter; + psEmitter *emitter; engine = psengine->GetEngine(); @@ -182,9 +221,9 @@ * positions are random but are only generated once */ - for (size_t j = 0; j< sector->emitter.GetSize(); j++) + for (size_t j = 0; j< sector->emitterarray.GetSize(); j++) { - if (!sector->emitter[j]->factory) + if (!sector->emitterarray[j]->factory) { continue; } @@ -196,9 +235,9 @@ } if (!(factory = engine->GetMeshFactories() - ->FindByName(sector->emitter[j]->factory))) + ->FindByName(sector->emitterarray[j]->factory))) { - Error2("Could not find factory name %s", (const char *) sector->emitter[j]->factory); + Error2("Could not find factory name %s", (const char *) sector->emitterarray[j]->factory); continue; } @@ -210,24 +249,24 @@ if (mesh->GetFactory() == factory) { - if (rng.Get() <= sector->emitter[j]->factory_prob) + if (rng.Get() <= sector->emitterarray[j]->factory_prob) { - emitter = new sct_emitter; + emitter = new psEmitter; - emitter->resource = csString(sector->emitter[j]->resource); - emitter->minvol = sector->emitter[j]->minvol; - emitter->maxvol = sector->emitter[j]->maxvol; - emitter->maxrange = sector->emitter[j]->maxrange; + emitter->resource = csString(sector->emitterarray[j]->resource); + emitter->minvol = sector->emitterarray[j]->minvol; + emitter->maxvol = sector->emitterarray[j]->maxvol; + emitter->maxrange = sector->emitterarray[j]->maxrange; emitter->position = mesh->GetMovable()->GetPosition(); emitter->active = false; - sector->emitter.Push(emitter); + sector->emitterarray.Push(emitter); } } } /* delete the factory node */ - sector->emitter.Delete(sector->emitter[j]); + sector->emitterarray.Delete(sector->emitterarray[j]); j--; } @@ -254,7 +293,8 @@ void psSoundManager::Load (const char* sector) { - sctdata *oldsector; + psSoundSector *oldsector; + psSoundSector *newsector; /* TODO wrong way todo this */ if (SndSysMgr->Initialised == false) @@ -276,13 +316,8 @@ * set the wanted sector to our active sector (if found) */ - for (size_t i = 0; i< sectordata.GetSize(); i++) + if (FindSector(sector, newsector) == true) { - if (strcmp(sector, sectordata[i]->name) != 0) - { - continue; - } - /* FIXME - hack for #4268 */ if (activesector != NULL) { @@ -293,7 +328,7 @@ } oldsector = activesector; - activesector = sectordata[i]; + activesector = newsector; activesector->active = true; /* works only on loaded sectors! */ @@ -323,421 +358,183 @@ } } -/* - * Update everything in the given sector - */ - -void psSoundManager::UpdateSector (sctdata* §or) +void psSoundManager::Reload() { - csPrintf("UpdateSector\n"); - UpdateEmitter(sector); - UpdateAmbient(sector); - UpdateMusic(sector); - UpdateEntity(sector); + csString currentsector = csString(activesector->name); + Unload(); + ReloadSectors(); + Load(currentsector); } -void psSoundManager::UpdateAmbient (sctdata* §or) +void psSoundManager::Unload() { - sct_ambient *ambient; + activesector->active = false; + UpdateSector(activesector); + activesector = NULL; +} - if (sector == NULL) +bool psSoundManager::FindSector (const char *name, psSoundSector* §or) +{ + for (size_t i = 0; i< sectordata.GetSize(); i++) { - return; - } - - csPrintf("update ambient\n"); - - /* - * Set Ambient Music and weather - * i pretend that xml-files are always correct - * there should be only ONE ambient playing - * - * ALL ambient and music sounds start at minvol and are faded in - */ - - for (size_t i = 0; i< sector->ambient.GetSize(); i++) - { - ambient = sector->ambient[i]; - - if (ambient->weather == weather - && sector->active == true - && GetAmbientToggle() == true - && (ambient->timeofday <= timeofday - && ambient->timeofdayrange >= timeofday)) + if (strcmp(name, sectordata[i]->name) != 0) { - if (ambient->active == true) - { - continue; - } - - csPrintf("adding a %s\n",(const char *) ambient->resource); - - ambient->active = true; - - if (SndSysMgr->Play2DSound (ambient->resource, LOOP, - ambient->loopstart, ambient->loopend, - ambient->minvol, ambientSndCtrl, - ambient->handle)) - { - - ambient->handle->Fade((ambient->maxvol - ambient->minvol), - ambient->fadedelay, FADE_UP); - - ambient->handle->preset_volume = ambient->maxvol; - sector->activeambient = ambient; - } - else // error occured .. get rid of this ambient - { - sector->ambient.Delete(ambient); - delete ambient; - break; - } - + continue; } - else if (ambient->active == true) + else { - csPrintf("removing a %s\n",(const char *) ambient->resource); - ambient->active = false; - ambient->handle->Fade(ambient->maxvol, ambient->fadedelay, FADE_STOP); - if (sector->activeambient == ambient) - { - sector->activeambient = NULL; - } + sector = sectordata[i]; + return true; } } + + sector = NULL; + return false; } -void psSoundManager::UpdateMusic (sctdata* §or) +/* + * Update everything in the given sector + */ + +void psSoundManager::UpdateSector (psSoundSector* §or) { - sct_music *music; + sector->UpdateMusic(loopBGM.GetToggle(), combat, musicSndCtrl); + sector->UpdateAmbient(weather, ambientSndCtrl); + sector->UpdateEmitter(ambientSndCtrl); + sector->UpdateEntity(ambientSndCtrl); +} - if (sector == NULL) - { - return; - } - csPrintf("update music\n"); +/* + * were always using camera height and rotation + * position can be players position or cameras position + * updated every frame? .. + */ - /* - * set music based on combat mode - * set combatmode to 0 if toggle is off - */ +void psSoundManager::UpdateListener ( iView* view ) +{ + csVector3 hearpoint; + csMatrix3 matrix; + csVector3 front; + csVector3 top; - if (GetCombatToggle() == false) + /* TODO wrong way todo this */ + if (SndSysMgr->Initialised == false) { - combat = 0; + return; } - for (size_t i = 0; i< sector->music.GetSize(); i++) + if (listenerOnCamera.GetToggle() == false) { - music = sector->music[i]; + hearpoint = playerposition; + } + else + { + // take position/direction from view->GetCamera () + hearpoint = view->GetPerspectiveCamera()->GetCamera() + ->GetTransform().GetOrigin(); + } - //csPrintf("%i %i %i\n", music->timeofday, music->timeofdayrange, timeofday); + matrix = view->GetPerspectiveCamera()->GetCamera() + ->GetTransform().GetT2O(); + front = matrix.Col3(); + top = matrix.Col2(); - if (music->type == combat - && sector->active == true - && GetMusicToggle() == true - && (music->timeofday <= timeofday - && music->timeofdayrange >= timeofday)) - { - if (music->active == true) - { - /* - * difficult logic. user doesnt want looping BGM - * therefor we keep the handle and leave it active - * so it wont be played again - * music continues if he enables loopBGM - */ - if (loopBGM == false) - { - /* set autoremove to false we want to keep the handle */ - music->handle->SetAutoRemove(false); - music->handle->sndstream->SetLoopState(DONT_LOOP); - continue; - } - else - { - /* enable looping because the toggle is true */ - music->handle->sndstream->SetLoopState(LOOP); - /* Unpause the stream because it might be paused */ - music->handle->sndstream->Unpause(); - /* set autoremove to true so it gets removed if someone pauses it */ - music->handle->SetAutoRemove(true); - continue; - } - } - - csPrintf("adding b %s\n", (const char *) music->resource); - music->active = true; - - if (SndSysMgr->Play2DSound (music->resource, loopBGM, - music->loopstart, music->loopend, - music->minvol, musicSndCtrl, - music->handle)) - { - music->handle->Fade((music->maxvol - music->minvol), - music->fadedelay, FADE_UP); - - music->handle->preset_volume = music->maxvol; - sector->activemusic = music; - } - else // error occured .. get rid of this music - { - sector->music.Delete(music); - delete music; - break; - } - } - else if (music->active == true) - { - csPrintf("removing b %s\n", (const char *) music->resource); - - /* - * remove a handle which have been paused because of loopBGM - * that means user is going to hear the BGM again if he enters - * a new sector and the previous sector didnt play this one - * or reenables music, leaves combatmode, if timeofday changes - * very complex - */ - if (loopBGM == false) - { - /* - * handle is there but maybe paused or whatever - * get rid of it - */ - music->handle->SetAutoRemove(true); - } - music->active = false; - music->handle->Fade(music->maxvol, music->fadedelay, FADE_STOP); - if (sector->activemusic == music) - { - sector->activemusic = NULL; - } - } - } + SndSysMgr->UpdateListener (hearpoint, front, top); } + /* -update on position change -*/ + * Set functions which trigger updates + */ - -void psSoundManager::UpdateEmitter (sctdata* §or) +void psSoundManager::SetTimeOfDay (int newTimeofday) { - sct_emitter *emitter; - csVector3 rangeVec; - float range; + activesector->timeofday = newTimeofday; + activesector->UpdateAmbient(weather, ambientSndCtrl); + activesector->UpdateMusic(loopBGM.GetToggle(), combat, musicSndCtrl); +} - if (sector == NULL) +void psSoundManager::SetPosition (csVector3 playerpos) +{ + playerposition = playerpos; + + if (activesector != NULL) { - return; + activesector->playerposition = playerpos; } - - /* - * start/stop all emitters in range - */ - - for (size_t i = 0; i< sector->emitter.GetSize(); i++) - { - emitter = sector->emitter[i]; - rangeVec = emitter->position - playerposition; - range = rangeVec.Norm(); - - if (!range) /* if range is NAN */ - { - break; - } - - if (range <= emitter->maxrange - && sector->active == true - && GetAmbientToggle() == true - && (emitter->timeofday <= timeofday - && emitter->timeofdayrange >= timeofday)) - { - if (emitter->active == true) - { - continue; - } - - csPrintf("adding e %s\n", (const char *) emitter->resource); - emitter->active = true; - - if (!SndSysMgr->Play3DSound (emitter->resource, LOOP, 0, 0, - emitter->maxvol, ambientSndCtrl, - emitter->position, emitter->direction, - emitter->minrange, emitter->maxrange, - VOLUME_ZERO, CS_SND3D_ABSOLUTE, - emitter->handle)) - { - // error occured .. emitter cant be played .. remove it - sector->emitter.Delete(emitter); - delete emitter; - break; - } - - } - else if (emitter->active != false) - { - csPrintf("removing e %s\n", (const char *) sector->emitter[i]->resource); - emitter->active = false; - emitter->handle->sndstream->Pause(); - } - } } /* - * this is the most powerfull part of the new soundmanager - * it can add sounds to any kind of entity - * e.g. items / actors (NPC/PC) and effects - * - * i hope it capable to replace PlayEffect / StopEffect - * - * tbh this function doesnt belong here - * the whole logic whould be in pscelclient.cpp - * - * not implementet yet: - * get real labals e.g. "Tefusangling" - * take animation into account (IDLE, PEACE ...) - * update position + * Engine calls SetWeather every frame or so + * update is only called if weather is changing */ -void psSoundManager::UpdateEntity (sctdata* §or) +void psSoundManager::SetWeather (int newWeather) { - sct_entity *entity; - iMeshWrapper* mesh; - csVector3 rangeVec; - float range; - - const csPDelArray<GEMClientObject>& entities = psengine->GetCelClient() - ->GetEntities(); - - if (sector == NULL) + if (weather != newWeather) { - return; + weather = newWeather; + activesector->UpdateAmbient(weather, ambientSndCtrl); } +} - for (size_t i = 0; i < sector->entity.GetSize(); i++) +void psSoundManager::SetCombatStance (int newCombatstance) +{ + if (combatMusic.GetToggle() == true) { - entity = sector->entity[i]; - - if (entity->active == true) - { - if (entity->when <= 0) - { - /* SndSysMgr will pick the dead sound up */ - entity->active = false; - } - else - { - entity->when = (entity->when - 50); - } - - continue; - } - - for (size_t a = 0; a < entities.GetSize(); a++) - { - if ((mesh = entities[a]->GetMesh()) == NULL) - { - continue; - } - - rangeVec = entities[a]->GetPosition() - playerposition; - range = rangeVec.Norm(); - - if (range <= entity->maxrange - && csStrCaseCmp(entity->name, mesh->QueryObject()->GetName()) == 0 - && rng.Get() <= entity->probability - && (entity->timeofday <= timeofday - && entity->timeofdayrange >= timeofday)) - { - csPrintf("iobject name %s %f %f\n", mesh->QueryObject()->GetName(), range, entity->maxrange); - /* play sound */ - entity->active = true; - entity->when = (entity->delay_after*1000); - - if (!SndSysMgr->Play3DSound (entity->resource, DONT_LOOP, 0, 0, - entity->maxvol, ambientSndCtrl, - entities[a]->GetPosition(), 0, - entity->minrange, entity->maxrange, - VOLUME_ZERO, CS_SND3D_ABSOLUTE, - entity->handle)) - { - sector->entity.Delete(entity); - delete entity; - break; - } - } - } + combat = newCombatstance; } + else + { + combat = 0; /* 0 is peace */ + } + + activesector->UpdateMusic(loopBGM.GetToggle(), combat, musicSndCtrl); } /* - * were always using camera height and rotation - * position can be players position or cameras position - * updated every frame? .. + * FIXME Remove GetCombatStance when you fix the victory effect */ -void psSoundManager::UpdateListener ( iView* view ) +int psSoundManager::GetCombatStance () { - /* TODO wrong way todo this */ - if (SndSysMgr->Initialised == false) - { - return; - } + return combat; +} - // take position/direction from view->GetCamera () - csVector3 v = view->GetPerspectiveCamera()->GetCamera() - ->GetTransform().GetOrigin(); - csMatrix3 m = view->GetPerspectiveCamera()->GetCamera() - ->GetTransform().GetT2O(); - csVector3 f = m.Col3(); - csVector3 t = m.Col2(); +void psSoundManager::SetVoiceToggle (bool toggle) +{ + voiceSndCtrl->SetToggle(toggle); - if (listenerOnCamera == false) + if (toggle == false) { - v = playerposition; + voicequeue->Purge(); } - - SndSysMgr->UpdateListener (v, f, t); } -void psSoundManager::PlayActionSound (const char *name) +bool psSoundManager::GetVoiceToggle () { - SoundHandle *Handle; - SndSysMgr->Play2DSound(name, DONT_LOOP, 0, 0, VOLUME_NORM, - actionSndCtrl, Handle); + return voiceSndCtrl->GetToggle(); } -void psSoundManager::PlayGUISound (const char *name) -{ - SoundHandle *Handle; - SndSysMgr->Play2DSound(name, DONT_LOOP, 0, 0, VOLUME_NORM, - ... [truncated message content] |