Revision: 2396 http://rigsofrods.svn.sourceforge.net/rigsofrods/?rev=2396&view=rev Author: rorthomas Date: 2012-01-31 00:08:45 +0000 (Tue, 31 Jan 2012) Log Message: ----------- sound: work++
Modified Paths: -------------- trunk/source/main/audio/Sound.cpp trunk/source/main/audio/SoundScriptManager.cpp trunk/source/main/audio/SoundScriptManager.h Modified: trunk/source/main/audio/Sound.cpp =================================================================== --- trunk/source/main/audio/Sound.cpp 2012-01-31 00:06:27 UTC (rev 2395) +++ trunk/source/main/audio/Sound.cpp 2012-01-31 00:08:45 UTC (rev 2396) @@ -103,43 +103,43 @@ void Sound::play() { - should_play=true; + should_play = true; sound_mgr->recomputeSource(source_index, REASON_PLAY, 0, NULL); } void Sound::stop() { - should_play=false; + should_play = false; sound_mgr->recomputeSource(source_index, REASON_STOP, 0, NULL); } void Sound::setGain(float gain) { - this->gain=gain; + this->gain = gain; sound_mgr->recomputeSource(source_index, REASON_GAIN, gain, NULL); } void Sound::setLoop(bool loop) { - this->loop=loop; + this->loop = loop; sound_mgr->recomputeSource(source_index, REASON_LOOP, (loop)?1.0:0.0, NULL); } void Sound::setPitch(float pitch) { - this->pitch=pitch; + this->pitch = pitch; sound_mgr->recomputeSource(source_index, REASON_PTCH, pitch, NULL); } void Sound::setPosition(Ogre::Vector3 pos) { - this->position=pos; + this->position = pos; sound_mgr->recomputeSource(source_index, REASON_POSN, 0, &pos); } void Sound::setVelocity(Ogre::Vector3 vel) { - this->velocity=vel; + this->velocity = vel; sound_mgr->recomputeSource(source_index, REASON_VLCT, 0, &vel); } Modified: trunk/source/main/audio/SoundScriptManager.cpp =================================================================== --- trunk/source/main/audio/SoundScriptManager.cpp 2012-01-31 00:06:27 UTC (rev 2395) +++ trunk/source/main/audio/SoundScriptManager.cpp 2012-01-31 00:08:45 UTC (rev 2396) @@ -30,11 +30,9 @@ using namespace Ogre; -static SoundScriptManager* singleton=NULL; - SoundScriptManager::SoundScriptManager() { - singleton=this; + // TODO: init variables in constr. instance_counter=0; maxDistance=500.0; loadingBase=false; @@ -160,13 +158,6 @@ sm->setCamera(position, direction, up, velocity); } -SoundScriptManager *SoundScriptManager::getSingleton() -{ - if (SSETTING("3D Sound renderer") == "No sound") return 0; - if (!singleton) singleton=new SoundScriptManager(); - return singleton; -} - const StringVector& SoundScriptManager::getScriptPatterns(void) const { return mScriptPatterns; Modified: trunk/source/main/audio/SoundScriptManager.h =================================================================== --- trunk/source/main/audio/SoundScriptManager.h 2012-01-31 00:06:27 UTC (rev 2395) +++ trunk/source/main/audio/SoundScriptManager.h 2012-01-31 00:08:45 UTC (rev 2396) @@ -29,7 +29,9 @@ #include "OgreResourceGroupManager.h" #include "Sound.h" #include "SoundManager.h" +#include "Singleton.h" +// TODO: fix this fugly defines into a proper enum #define MAX_SOUNDS_PER_SCRIPT 16 #define MAX_INSTANCES_PER_GROUP 256 @@ -131,38 +133,38 @@ #define SS_MOD_AOA 28 #define SS_MAX_MOD 29 -class SoundScriptTemplate +class SoundScriptTemplate { public: SoundScriptTemplate(Ogre::String name, Ogre::String groupname, Ogre::String filename, bool baseTemplate); bool setParameter(StringVector vec); ~SoundScriptTemplate(); -//private: +//protected: int parseModulation(Ogre::String str); Ogre::String name; Ogre::String groupname; Ogre::String filename; - int trigger_source; - int pitch_source; - float pitch_offset; - float pitch_multiplier; - float pitch_square; - int gain_source; - float gain_offset; - float gain_multiplier; - float gain_square; - bool has_start_sound; - float start_sound_pitch; + int trigger_source; + int pitch_source; + float pitch_offset; + float pitch_multiplier; + float pitch_square; + int gain_source; + float gain_offset; + float gain_multiplier; + float gain_square; + bool has_start_sound; + float start_sound_pitch; Ogre::String start_sound_name; - bool has_stop_sound; - float stop_sound_pitch; + bool has_stop_sound; + float stop_sound_pitch; Ogre::String stop_sound_name; - bool unpitchable; - int free_sound; - float sound_pitches[MAX_SOUNDS_PER_SCRIPT]; + bool unpitchable; + int free_sound; + float sound_pitches[MAX_SOUNDS_PER_SCRIPT]; Ogre::String sound_names[MAX_SOUNDS_PER_SCRIPT]; - bool baseTemplate; + bool baseTemplate; }; class SoundScriptInstance @@ -179,7 +181,7 @@ void setEnabled(bool e); SoundScriptTemplate* templ; -private: +protected: SoundManager* sm; Sound *startSound; Sound *stopSound; @@ -191,15 +193,14 @@ float pitchgain_cutoff(float sourcepitch, float targetpitch); }; -class SoundScriptManager: public ScriptLoader +class SoundScriptManager : public ScriptLoader , public Singleton2<SoundScriptManager> { public: const static int TERRAINSOUND = MAX_TRUCKS+1; SoundScriptManager(); - static SoundScriptManager *getSingleton(); - //ScriptLoader interface + // ScriptLoader interface const StringVector& getScriptPatterns(void) const; void parseScript(DataStreamPtr& stream, const Ogre::String& groupName); Real getLoadingOrder(void) const; @@ -208,19 +209,19 @@ void unloadResourceGroup(Ogre::String groupname); void clearNonBaseTemplates(); - //values update - void trigOnce(int truck, int trig); - void trigOnce(Beam *b, int trig); - void trigStart(int truck, int trig); - void trigStart(Beam *b, int trig); - void trigStop(int truck, int trig); - void trigStop(Beam *b, int trig); - void trigToggle(int truck, int trig); - void trigToggle(Beam *b, int trig); + // values update + void trigOnce (int truck, int trig); + void trigOnce (Beam *b, int trig); + void trigStart (int truck, int trig); + void trigStart (Beam *b, int trig); + void trigStop (int truck, int trig); + void trigStop (Beam *b, int trig); + void trigToggle (int truck, int trig); + void trigToggle (Beam *b, int trig); bool getTrigState(int truck, int trig); - bool getTrigState(Beam *b, int trig); - void modulate(int truck, int mod, float value); - void modulate(Beam *b, int mod, float value); + bool getTrigState(Beam *b, int trig); + void modulate (int truck, int mod, float value); + void modulate (Beam *b, int mod, float value); void soundEnable(bool state); @@ -230,7 +231,7 @@ float maxDistance; float rolloffFactor; float referenceDistance; -private: +protected: StringVector mScriptPatterns; int instance_counter; bool loadingBase; @@ -240,21 +241,24 @@ void skipToNextCloseBrace(DataStreamPtr& chunk); void skipToNextOpenBrace(DataStreamPtr& chunk); SoundScriptTemplate* createTemplate(Ogre::String name, Ogre::String groupname, Ogre::String filename); + //instances lookup tables int free_trigs[SS_MAX_TRIG]; - SoundScriptInstance* trigs[SS_MAX_TRIG*MAX_INSTANCES_PER_GROUP]; + SoundScriptInstance *trigs[SS_MAX_TRIG * MAX_INSTANCES_PER_GROUP]; + int free_pitches[SS_MAX_MOD]; - SoundScriptInstance* pitches[SS_MAX_MOD*MAX_INSTANCES_PER_GROUP]; + SoundScriptInstance *pitches[SS_MAX_MOD * MAX_INSTANCES_PER_GROUP]; + int free_gains[SS_MAX_MOD]; - SoundScriptInstance* gains[SS_MAX_MOD*MAX_INSTANCES_PER_GROUP]; + SoundScriptInstance *gains[SS_MAX_MOD * MAX_INSTANCES_PER_GROUP]; + //state map - bool statemap[SS_MAX_TRIG*(MAX_TRUCKS+2)]; + bool statemap[SS_MAX_TRIG * (MAX_TRUCKS + 2)]; SoundManager* sm; - }; -#endif +#endif // __SoundScriptManager_H__ -#endif //OPENAL +#endif // USE_OPENAL This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------------ Keep Your Developer Skills Current with LearnDevNow! The most comprehensive online learning library for Microsoft developers is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3, Metro Style Apps, more. Free future releases when you subscribe now! http://p.sf.net/sfu/learndevnow-d2d _______________________________________________ Rigsofrods-devel mailing list Rigsofrods-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/rigsofrods-devel