[Gcblue-commits] gcb_wx/src/common tcOptionsView.cpp,1.13,1.14 tcSound.cpp,1.19,1.20 tcSoundConsole.
Status: Alpha
Brought to you by:
ddcforge
|
From: Dewitt C. <ddc...@us...> - 2005-01-27 01:02:29
|
Update of /cvsroot/gcblue/gcb_wx/src/common In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11058/src/common Modified Files: tcOptionsView.cpp tcSound.cpp tcSoundConsole.cpp Log Message: Multiple smoke trail fixes Animation tweaks Index: tcSoundConsole.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/common/tcSoundConsole.cpp,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** tcSoundConsole.cpp 7 Dec 2004 04:00:28 -0000 1.11 --- tcSoundConsole.cpp 27 Jan 2005 01:01:48 -0000 1.12 *************** *** 53,57 **** if (counter - lastEffect > 4) { ! tcSound::Get()->PlayEffect(mnSoundEffect); lastEffect = counter; } --- 53,57 ---- if (counter - lastEffect > 4) { ! tcSound::Get()->PlayEffect(soundEffect); lastEffect = counter; } *************** *** 79,83 **** void tcSoundConsole::Print(const char* line) { ! tcSound::Get()->PlayEffect(mnSoundEffect); textBox->Print(line); --- 79,83 ---- void tcSoundConsole::Print(const char* line) { ! tcSound::Get()->PlayEffect(soundEffect); textBox->Print(line); *************** *** 112,116 **** const wxString& name) : tcXmlWindow(parent, pos, size, configFile, name), ! mnSoundEffect(SEFFECT_CONSOLE), lastEffect(0) { --- 112,116 ---- const wxString& name) : tcXmlWindow(parent, pos, size, configFile, name), ! soundEffect("consolebeep"), lastEffect(0) { Index: tcOptionsView.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/common/tcOptionsView.cpp,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** tcOptionsView.cpp 1 Nov 2004 03:17:17 -0000 1.13 --- tcOptionsView.cpp 27 Jan 2005 01:01:47 -0000 1.14 *************** *** 178,182 **** mpOptions->Serialize(false); // create new options file ! tcSound::Get()->PlayEffect(SEFFECT_BEEP2); } else --- 178,182 ---- mpOptions->Serialize(false); // create new options file ! tcSound::Get()->PlayEffect("Beep2"); } else Index: tcSound.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/common/tcSound.cpp,v retrieving revision 1.19 retrieving revision 1.20 diff -C2 -d -r1.19 -r1.20 *** tcSound.cpp 10 Jan 2005 00:30:46 -0000 1.19 --- tcSound.cpp 27 Jan 2005 01:01:48 -0000 1.20 *************** *** 46,140 **** ! bool tcSound::GetMusicPause() const { ! wxASSERT(oggStreamer); ! return oggStreamer->GetPause(); ! } ! bool tcSound::Init() ! { ! int i; ! // ALuint moving_source = 0; ! ALfloat zeroes[] = { 0.0f, 0.0f, 0.0f }; ! // ALfloat back[] = { 0.0f, 0.0f, -1.0f, 0.0f, 1.0f, 0.0f }; ! ALfloat front[] = { 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f }; ! // ALfloat position[] = { 0.0f, 0.0f, -4.0f }; ! alutInit(NULL,0); ! // Clear Error Code ! if (alGetError() != AL_NO_ERROR) ! { ! wxMessageBox("Error during OpenAL init. " ! "Sound driver may not support OpenAL.", "Warning", wxICON_WARNING); ! } ! alListenerfv(AL_POSITION, zeroes ); ! alListenerfv(AL_VELOCITY, zeroes ); ! alListenerfv(AL_ORIENTATION, front ); ! for(i=0;i<N_SEFFECT;i++) ! { ! alGenBuffers( 1, &BufferEffect[i]); ! if((alGetError())!=AL_NO_ERROR) ! { ! printf("error creating buffer %i",i); ! } ! } ! LoadWavDataFromFile("Explosion.wav",SEFFECT_EXPLOSION); ! LoadWavDataFromFile("Implosion.wav",SEFFECT_IMPLOSION); ! LoadWavDataFromFile("ShortBeep.wav",SEFFECT_SHORTBEEP); ! LoadWavDataFromFile("MissileLaunch.wav",SEFFECT_MISSILELAUNCH); ! LoadWavDataFromFile("TwoBeeps.wav",SEFFECT_TWOBEEPS); ! LoadWavDataFromFile("consolebeep.wav",SEFFECT_CONSOLE); ! LoadWavDataFromFile("Beep2.wav",SEFFECT_BEEP2); ! LoadWavDataFromFile("RejectBeep.wav",SEFFECT_REJECTBEEP); ! LoadWavDataFromFile("Ping.wav",SEFFECT_LIGHTSABER); ! LoadWavDataFromFile("Ping.wav",SEFFECT_PING); ! LoadWavDataFromFile("Ping2.wav",SEFFECT_PING2); ! LoadWavDataFromFile("radarping.wav",SEFFECT_PING3); ! LoadWavDataFromFile("LowBeep.wav",SEFFECT_LOWBEEP); ! LoadWavDataFromFile("Bloop.wav",SEFFECT_BLOOP); ! LoadWavDataFromFile("NoisyBeepLow.wav",SEFFECT_NOISYBEEP); ! LoadWavDataFromFile("Thuck.wav",SEFFECT_THUCK); ! LoadWavDataFromFile("Explosion2.wav",SEFFECT_EXPLOSION2); ! LoadWavDataFromFile("Welcome.wav",SEFFECT_WELCOME); ! LoadWavDataFromFile("jetlaunch.wav",SEFFECT_JETLAUNCH); ! LoadWavDataFromFile("MutedBeep.wav",SEFFECT_MUTEDBEEP); ! LoadWavDataFromFile("intercom.wav",SEFFECT_INTERCOM); ! LoadWavDataFromFile("fslide.wav",SEFFECT_FSLIDE); ! LoadWavDataFromFile("NavalGun1.wav", SEFFECT_NAVALGUN); ! LoadWavDataFromFile("helolaunch.wav", SEFFECT_HELOLAUNCH); ! LoadWavDataFromFile("radar_on.wav", SEFFECT_RADARON); ! LoadWavDataFromFile("radar_off.wav", SEFFECT_RADAROFF); ! LoadWavDataFromFile("torpedo_launch.wav", SEFFECT_TORPEDOLAUNCH); ! LoadWavDataFromFile("shishding.wav", SEFFECT_SONARDETECT); ! if((alGetError())!=AL_NO_ERROR) ! { ! fprintf(stderr, "Error loading wav files.\n"); ! } - for(i=0;i<N_EFFECT_BUFFERS;i++) - { - alGenSources( 1, &SourceEffect[i]); - // alGenBuffers( 1, &BufferEffect[i]); - alSourcei( SourceEffect[i], AL_LOOPING, AL_FALSE); - // alSourcefv( SourceEffect[i], AL_POSITION, position ); - // alSourcefv( SourceEffect[i], AL_VELOCITY, zeroes ); - // alSourcefv( SourceEffect[i], AL_ORIENTATION, back ); - // alSourcef( SourceEffect[i], AL_PITCH, 1.0f ); ! if((alGetError())!=AL_NO_ERROR) ! { ! printf("error creating source %i\n",i); - } - } oggStreamer->Init(); SetMusicVolume(0.5f); --- 46,139 ---- ! /** ! * Based on osgAL example osgal.cpp from ! * http://www.vrlab.umu.se/research/osgAL/osgal.cpp ! */ ! osg::ref_ptr<osgAL::SoundNode> tcSound::CreateSound(const std::string& file) { ! // Create a sample, load a .wav file. ! openalpp::Sample *sample = osgAL::SoundManager::instance()->getSample(file.c_str()); + // Create a named sound state. + std::string stateName = "state_"; + stateName += file; + osgAL::SoundState* sound_state = new osgAL::SoundState(stateName); ! // Let the soundstate use the sample we just created ! sound_state->setSample(sample); ! // Set its gain (volume) to 0.9 ! sound_state->setGain(0.4f); ! // Set its pitch to 1 (normal speed) ! sound_state->setPitch(1); ! // Make it play ! sound_state->setPlay(true); ! // The sound should loop over and over again ! sound_state->setLooping(true); ! // Allocate a hardware soundsource to this soundstate (priority 10) ! // ! sound_state->allocateSource(10, false); + // At 40 the gain will be half of full! + sound_state->setReferenceDistance(10); + sound_state->apply(); ! // Add the soundstate to the sound manager, so we can find it later on if we want to ! osgAL::SoundManager::instance()->addSoundState(sound_state); ! // Create a sound node and attach the soundstate to it. ! osg::ref_ptr<osgAL::SoundNode> sound = new osgAL::SoundNode; ! sound->setSoundState(sound_state); + return sound; + } ! bool tcSound::GetMusicPause() const ! { ! wxASSERT(oggStreamer); ! return oggStreamer->GetPause(); ! } ! ! ! bool tcSound::Init() ! { ! ! InitOsgAL(); ! ! effectMap["Explosion"] = osgAL::SoundManager::instance()->getSample("Explosion.wav"); ! effectMap["Implosion"] = osgAL::SoundManager::instance()->getSample("Implosion.wav"); ! effectMap["ShortBeep"] = osgAL::SoundManager::instance()->getSample("ShortBeep.wav"); ! effectMap["MissileLaunch"] = osgAL::SoundManager::instance()->getSample("MissileLaunch.wav"); ! effectMap["TwoBeeps"] = osgAL::SoundManager::instance()->getSample("TwoBeeps.wav"); ! effectMap["consolebeep"] = osgAL::SoundManager::instance()->getSample("consolebeep.wav"); ! effectMap["Beep2"] = osgAL::SoundManager::instance()->getSample("Beep2.wav"); ! effectMap["RejectBeep"] = osgAL::SoundManager::instance()->getSample("RejectBeep.wav"); ! effectMap["Ping"] = osgAL::SoundManager::instance()->getSample("Ping.wav"); ! effectMap["Ping"] = osgAL::SoundManager::instance()->getSample("Ping.wav"); ! effectMap["Ping2"] = osgAL::SoundManager::instance()->getSample("Ping2.wav"); ! effectMap["radarping"] = osgAL::SoundManager::instance()->getSample("radarping.wav"); ! effectMap["LowBeep"] = osgAL::SoundManager::instance()->getSample("LowBeep.wav"); ! effectMap["Bloop"] = osgAL::SoundManager::instance()->getSample("Bloop.wav"); ! effectMap["NoisyBeepLow"] = osgAL::SoundManager::instance()->getSample("NoisyBeepLow.wav"); ! effectMap["Thuck"] = osgAL::SoundManager::instance()->getSample("Thuck.wav"); ! effectMap["Explosion2"] = osgAL::SoundManager::instance()->getSample("Explosion2.wav"); ! effectMap["Welcome"] = osgAL::SoundManager::instance()->getSample("Welcome.wav"); ! effectMap["jetlaunch"] = osgAL::SoundManager::instance()->getSample("jetlaunch.wav"); ! effectMap["MutedBeep"] = osgAL::SoundManager::instance()->getSample("MutedBeep.wav"); ! effectMap["intercom"] = osgAL::SoundManager::instance()->getSample("intercom.wav"); ! effectMap["fslide"] = osgAL::SoundManager::instance()->getSample("fslide.wav"); ! effectMap["NavalGun1"] = osgAL::SoundManager::instance()->getSample("NavalGun1.wav"); ! effectMap["helolaunch"] = osgAL::SoundManager::instance()->getSample("helolaunch.wav"); ! effectMap["radar_on"] = osgAL::SoundManager::instance()->getSample("radar_on.wav"); ! effectMap["radar_off"] = osgAL::SoundManager::instance()->getSample("radar_off.wav"); ! effectMap["torpedo_launch"] = osgAL::SoundManager::instance()->getSample("torpedo_launch.wav"); ! effectMap["shishding"] = osgAL::SoundManager::instance()->getSample("shishding.wav"); ! oggStreamer->Init(); SetMusicVolume(0.5f); *************** *** 144,224 **** } ! bool tcSound::LoadWavDataFromFile(char *azFileName, unsigned anEffectID) { ! ALboolean err; ! ALsizei size; ! ALsizei freq; ! ALenum format; ! ALvoid *wave; ! ALboolean loop; ! char zFilePath[256]; ! if (anEffectID >= N_SEFFECT) {return false;} // error, out of range ! strcpy(zFilePath,WAV_PATH); // prepend WAV_PATH ! strcat(zFilePath,azFileName); ! alutLoadWAVFile((ALbyte*)zFilePath,&format,&wave,&size,&freq,&loop); ! if (wave == NULL) ! { ! fprintf(stderr,"File not found, wav file %s\n",azFileName); ! return false; ! } ! if((err=alGetError())!=AL_NO_ERROR) { ! fprintf(stderr,"Error loading wav file %s\n",azFileName); ! return false; } - alBufferData( BufferEffect[anEffectID], format, wave, size ,freq ); - alutUnloadWAV(format,wave,size,freq); ! if((err=alGetError())!=AL_NO_ERROR) { ! fprintf(stderr,"Error buffering wav file %s\n",azFileName); ! return false; ! } ! // add to effect map to lookup by name ! wxString fileName(azFileName); ! wxString nameRoot = fileName.BeforeFirst('.'); ! effectMap[std::string(nameRoot.c_str())] = anEffectID; ! return true; ! } ! void tcSound::FillBufferFromFile(char *azFileName,ALuint* buffer) ! { ! ALboolean err; ! ALsizei size; ! ALsizei freq; ! ALenum format; ! ALvoid *wave; ! ALboolean loop; ! char zFilePath[256]; - strcpy(zFilePath,WAV_PATH); // prepend WAV_PATH - strcat(zFilePath,azFileName); - alutLoadWAVFile((ALbyte*)zFilePath,&format,&wave,&size,&freq,&loop); - if((err=alGetError())!=AL_NO_ERROR) - { - fprintf(stderr,"Error loading wav file %s\n",azFileName); - return; - } - alBufferData( *buffer, format, wave, size ,freq ); - alutUnloadWAV(format,wave,size,freq); - } void tcSound::Test() { ! // int nTestEffect = SEFFECT_SHORTBEEP; ! /* int nTestEffect = SEFFECT_REJECTBEEP; if (!mbInitialized) return; PlayEffect(nTestEffect); --- 143,229 ---- } + /** + * @return osgAL::SoundRoot to add to scene graph + */ + osgAL::SoundRoot* tcSound::GetSoundRoot() + { + wxASSERT(soundRoot.valid()); + + return soundRoot.get(); + } ! /** ! * Initialization associated with osgAL. Should be called once at ! * startup. ! */ ! void tcSound::InitOsgAL() { ! osgAL::SoundManager::instance()->init(16); ! osgAL::SoundManager::instance()->getEnvironment()->setDistanceModel(openalpp::InverseDistance); ! osgAL::SoundManager::instance()->getEnvironment()->setDopplerFactor(1); ! osgAL::SoundManager::instance()->addFilePath("sound\\wav"); ! // Create ONE (only one, otherwise the transformation of the listener and update for SoundManager will be ! // called several times, which is not catastrophic, but unnecessary) ! // SoundRoot that will make sure the listener is updated and ! // to keep the internal state of the SoundManager updated ! // This could also be done manually, this is just a handy way of doing it. ! if (!soundRoot.valid()) { ! soundRoot = new osgAL::SoundRoot; } ! // create SoundState's to use as buffers ! for (size_t n=0; n<N_EFFECT_BUFFERS; n++) { ! wxString stateName = wxString::Format("state%d", n); ! osgAL::SoundState* soundState = new osgAL::SoundState(stateName.c_str()); ! soundState->setAmbient(true); ! soundState->setGain(0.5f); // Set its gain (volume) ! soundState->setPitch(1); // Set its pitch to 1 (normal speed) ! soundState->setRelative(true); ! soundState->setPosition(osg::Vec3(0,0,0)); ! soundState->setLooping(false); ! soundState->setStopMethod(openalpp::Stopped); + // Allocate a hardware soundsource to this soundstate (priority 10) + // soundState->allocateSource(10, false); + // Add the soundstate to the sound manager, so we can find it later on if we want to + osgAL::SoundManager::instance()->addSoundState(soundState); ! effectBuffer.push_back(soundState); ! available.push_back(n); ! } ! } ! /** ! * ! */ ! void tcSound::SetListenerDirection(const osg::Vec3& dir) ! { ! osgAL::SoundManager::instance()->setListenerDirection(dir); ! } ! /** ! * Set the transformation matrix for the listener ! */ ! void tcSound::SetListenerMatrix(const osg::Matrix& matrix) ! { ! osgAL::SoundManager::instance()->setListenerMatrix(matrix); ! } void tcSound::Test() { ! // int nTestEffect = "ShortBeep"; ! /* int nTestEffect = "RejectBeep"; if (!mbInitialized) return; PlayEffect(nTestEffect); *************** *** 407,425 **** ! void tcSound::ReleaseStoppedBuffers() { ! ! ALint play; ! for(int i=0;i<N_EFFECT_BUFFERS;i++) { ! if (AL_TRUE==alIsSource(SourceEffect[i])) { ! alGetSourcei(SourceEffect[i],AL_SOURCE_STATE,&play); ! //printf(" buffer %d: %d\n",i,play==AL_PLAYING); ! if (play!=AL_PLAYING) ! { ! ReleaseEffectBuffer(i); ! } } } --- 412,425 ---- ! /** ! * ! */ void tcSound::ReleaseStoppedBuffers() { ! for(size_t i=0; i<effectBuffer.size(); i++) { ! if (!effectBuffer[i]->isPlaying()) { ! ReleaseEffectBuffer(i); } } *************** *** 427,446 **** ! // returns -1 if none available int tcSound::GetEffectBuffer() { ! if (msEffectBufferInfo.mnAvailable <= 0) {ReleaseStoppedBuffers();} ! if (msEffectBufferInfo.mnAvailable <= 0) {return -1;} ! return msEffectBufferInfo.maAvailableBuffers[--msEffectBufferInfo.mnAvailable]; } ! void tcSound::ReleaseEffectBuffer(int anBuffer) { ! if ((anBuffer < 0)||(anBuffer >= N_EFFECT_BUFFERS)) {return;} // error, out of range ! if (msEffectBufferInfo.mnAvailable >= N_EFFECT_BUFFERS) {return;} // error, already full ! msEffectBufferInfo.maAvailableBuffers[msEffectBufferInfo.mnAvailable++] = anBuffer; ! alSourceStop(SourceEffect[anBuffer]); } --- 427,458 ---- ! /** ! * @returns -1 if none available, otherwise returns index to use ! */ int tcSound::GetEffectBuffer() { ! if (available.size() < 4) ! { ! ReleaseStoppedBuffers(); ! } ! ! if (available.size() == 0) {return -1;} ! ! // take index from front of queue ! size_t idx = (size_t)available.front(); ! available.pop_front(); ! ! return idx; } ! void tcSound::ReleaseEffectBuffer(int bufferIdx) { ! if ((bufferIdx < 0)||(bufferIdx >= (int)effectBuffer.size())) {return;} // error, out of range + wxASSERT(effectBuffer[bufferIdx].valid()); + effectBuffer[bufferIdx]->setPlay(false); + if (effectBuffer[bufferIdx]->getSource()) effectBuffer[bufferIdx]->releaseSource(); + available.push_back((size_t)bufferIdx); } *************** *** 448,479 **** void tcSound::PlayEffect(std::string effectName) { ! std::map<std::string, int>::const_iterator mapIter; mapIter = effectMap.find(effectName); if (mapIter == effectMap.end()) { ! std::cerr << "Error - tcSound::PlayEffect - effectName not found in map." ! << std::endl; return; } ! int effectIdx = effectMap[effectName]; ! PlayEffect(effectIdx); ! } - void tcSound::PlayEffect(int anEffect) - { - if (!mbInitialized) return; - if ((anEffect<0)||(anEffect>=N_SEFFECT)) return; // out of range int nFreeBufferIdx = GetEffectBuffer(); // returns -1 if none available ! if ((nFreeBufferIdx < 0)||(nFreeBufferIdx >= N_EFFECT_BUFFERS)) { return; } ! alSourcei( SourceEffect[nFreeBufferIdx], AL_BUFFER, BufferEffect[anEffect] ); - alSourcePlay(SourceEffect[nFreeBufferIdx] ); } --- 460,501 ---- void tcSound::PlayEffect(std::string effectName) { ! if (!mbInitialized) return; ! ! ReleaseStoppedBuffers(); ! ! std::map<std::string, openalpp::Sample*>::const_iterator mapIter; mapIter = effectMap.find(effectName); if (mapIter == effectMap.end()) { ! fprintf(stderr, "Error - tcSound::PlayEffect - effectName (%s) not found in map.\n", ! effectName.c_str()); return; } ! openalpp::Sample* sample = mapIter->second; int nFreeBufferIdx = GetEffectBuffer(); // returns -1 if none available ! if ((nFreeBufferIdx < 0)||(nFreeBufferIdx >= (int)effectBuffer.size())) { return; } + osgAL::SoundState* soundState = effectBuffer[nFreeBufferIdx].get(); + soundState->setSample(sample); + if (!soundState->getSource()) + { + soundState->allocateSource(10, false); + } + soundState->setPlay(true); + } ! /** ! * DEPRECATED ! */ ! void tcSound::PlayEffect(int anEffect) ! { ! wxASSERT(false); } *************** *** 483,504 **** void tcSound::UnInit() { - int i; - if (!mbInitialized) return; ! oggStreamer->Release(); ! for(i=0;i<N_EFFECT_BUFFERS;i++) ! { ! alSourceStop(SourceEffect[i]); ! alDeleteSources(1,&SourceEffect[i]); ! } ! for(i=0;i<N_SEFFECT;i++) ! { ! alDeleteBuffers(1,&BufferEffect[i]); } - alutExit(); mbInitialized = false; --- 505,527 ---- void tcSound::UnInit() { if (!mbInitialized) return; ! effectBuffer.clear(); ! std::map<std::string, openalpp::Sample*>::iterator iter; ! /** mem leak? ! for (iter = effectMap.begin(); iter != effectMap.end(); ++iter) ! { ! delete iter->second; } + */ + + effectMap.clear(); + + oggStreamer->Release(); + + osgAL::SoundManager::instance()->shutdown(); mbInitialized = false; *************** *** 517,529 **** tcSound::tcSound() { - int i; mbInitialized = false; ! for(i=0;i<N_EFFECT_BUFFERS;i++) ! { ! BufferEffect[i] = 0; ! SourceEffect[i] = 0; ! msEffectBufferInfo.maAvailableBuffers[i] = i; ! } ! msEffectBufferInfo.mnAvailable = N_EFFECT_BUFFERS; // all available at start mnCurrentTrack = -1; --- 540,545 ---- tcSound::tcSound() { mbInitialized = false; ! mnCurrentTrack = -1; |