void CAI_Senses::Listen( void ) { m_iAudibleList = SOUNDLIST_EMPTY; int iSoundMask = GetOuter()->GetSoundInterests(); if ( iSoundMask != SOUND_NONE && !(GetOuter()->HasSpawnFlags(SF_NPC_WAIT_TILL_SEEN)) ) { int iSound = CSoundEnt::ActiveList(); while ( iSound != SOUNDLIST_EMPTY ) { CSound *pCurrentSound = CSoundEnt::SoundPointerForIndex( iSound ); if ( pCurrentSound && (iSoundMask & pCurrentSound->SoundType()) && CanHearSound( pCurrentSound ) ) { // the npc cares about this sound, and it's close enough to hear. pCurrentSound->m_iNextAudible = m_iAudibleList; m_iAudibleList = iSound; } iSound = pCurrentSound->NextSound(); } } GetOuter()->OnListened(); }
void CPowerUp::Respawn() { int x, y; CRenderer *pRenderer = CRenderer::Instance(); CUniverse* universe = CODEManager::Instance()->m_pUniverse; do { x = rand()%((int) universe->m_fWidth*2) - (int) universe->m_fWidth; y = rand()%((int) universe->m_fHeight*2) - (int) universe->m_fHeight; } while ( pRenderer->ObjectsInRange( x, y, 100 ) ); Vector v = Vector( (float)x, (float)y, 0.0f ); SetPosition( v ); Vector n; Vector vel((float) (rand() % 10), (float) (rand() % 10), 0); m_oPhysicsData.m_pOwner->SetLinVelocity(vel); SetForce(n); this->m_bIsGrabable = true; this->m_oPhysicsData.m_bHasCollision = true; CSound *pSound = (CSound *)CResourceManager::Instance()->GetResource("media/sounds/powerup_spawn.wav", RT_SOUND); if ( pSound ) pSound->Play(); }
//************************************************************************ void CNutDropScene::PlayClickWave (BOOL fSync/*=TRUE*/) //************************************************************************ { FNAME szFileName; // Play synchronously ? if (fSync) { CSound sound; if (m_pSound) { m_pSound->StopAndFree(); m_pSound->Activate (FALSE); } if (GetToon()->FindContent (CLICK_WAVE, TRUE, szFileName)) sound.StartFile (szFileName, NO/*bLoop*/, -1, TRUE); if (m_pSound) m_pSound->Activate (TRUE); } else if (m_pSound) { m_pSound->StopAndFree(); if (GetToon()->FindContent (CLICK_WAVE, TRUE, szFileName)) m_pSound->StartFile (szFileName, FALSE, HINT_CHANNEL, TRUE); } }
//************************************************************************ BOOL CGBScene::PlaySound(LPCTSTR lpWaveFile, BOOL fHint) //************************************************************************ { LPSOUND pSound = GetSound(); if ( !pSound ) return( FALSE ); BOOL fRet; if ( !pSound->IsMixing() ) fRet = pSound->StartFile((LPSTR)lpWaveFile, FALSE/*bLoop*/, -1, TRUE/*bWait*/); else { // this nonsense is here because in order to make buttons // in action strip play the click wave when they are clicked // on we need to synchronously play the sound so the click // happens while the button is down. WaveMix does not play // sounds synchronously, so we deactivate WaveMix and use // sndPlaySound stuff. CSound sound; pSound->Activate(FALSE); fRet = sound.StartFile((LPSTR)lpWaveFile, FALSE/*bLoop*/, -1, TRUE/*bWait*/); pSound->Activate(TRUE); } return(fRet); }
int CEasySound::Load(char *filename) { // find ID for sound std::list<CSound*>::iterator cs; int iSoundID = 0; bool bFoundID = true; while( bFoundID ) { // while loop until if there no ID match and set that ID for new sound's ID bFoundID = false; for (cs = m_listSound.begin(); cs != m_listSound.end(); ++cs) { if ((*cs)->GetSoundID() == iSoundID) { bFoundID = true; iSoundID++; break; } } } // load the sound with new ID CSound* sound = new CSound(filename,iSoundID); if (sound->GetLength() == CSoundTime(0,0,0)) { return -1; // fail to load } m_listSound.insert(m_listSound.end(),sound); return iSoundID; // fail to load }
//========================================================= // InsertSound - Allocates a free sound and fills it with // sound info. //========================================================= void CSoundEnt::InsertSound ( int iType, const Vector &vecOrigin, int iVolume, float flDuration, CBaseEntity *pOwner, int soundChannelIndex, CBaseEntity *pSoundTarget ) { int iThisSound; if ( !g_pSoundEnt ) return; if( soundChannelIndex == SOUNDENT_CHANNEL_UNSPECIFIED ) { // No sound channel specified. So just make a new sound. iThisSound = g_pSoundEnt->IAllocSound(); } else { // If this entity has already got a sound in the soundlist that's on this // channel, update that sound. Otherwise add a new one. iThisSound = g_pSoundEnt->FindOrAllocateSound( pOwner, soundChannelIndex ); } if ( iThisSound == SOUNDLIST_EMPTY ) { //DevMsg( "Could not AllocSound() for InsertSound() (Game DLL)\n" ); return; } CSound *pSound; pSound = &g_pSoundEnt->m_SoundPool[ iThisSound ]; pSound->SetSoundOrigin( vecOrigin ); pSound->m_iType = iType; pSound->m_iVolume = iVolume; pSound->m_flOcclusionScale = 0.5; pSound->m_flExpireTime = gpGlobals->curtime + flDuration; pSound->m_bNoExpirationTime = false; pSound->m_hOwner.Set( pOwner ); pSound->m_hTarget.Set( pSoundTarget ); pSound->m_ownerChannelIndex = soundChannelIndex; // Keep track of whether this sound had an owner when it was made. If the sound has a long duration, // the owner could disappear by the time someone hears this sound, so we have to look at this boolean // and throw out sounds who have a NULL owner but this field set to true. (sjb) 12/2/2005 if( pOwner ) { pSound->m_bHasOwner = true; } else { pSound->m_bHasOwner = false; } if( displaysoundlist.GetInt() == 1 ) { Msg(" Added Sound! Type:%d Duration:%f (Time:%f)\n", pSound->SoundType(), flDuration, gpGlobals->curtime ); } if( displaysoundlist.GetInt() == 2 && (iType & SOUND_DANGER) ) { Msg(" Added Danger Sound! Duration:%f (Time:%f)\n", flDuration, gpGlobals->curtime ); } }
/* =========== ClientDisconnect called when a player disconnects from a server GLOBALS ASSUMED SET: g_fGameOver ============ */ void ClientDisconnect( edict_t *pEntity ) { if (g_fGameOver) return; char text[256]; sprintf( text, "- %s has left the game\n", STRING(pEntity->v.netname) ); MESSAGE_BEGIN( MSG_ALL, gmsgSayText, NULL ); WRITE_BYTE( ENTINDEX(pEntity) ); WRITE_STRING( text ); MESSAGE_END(); CSound *pSound; pSound = CSoundEnt::SoundPointerForIndex( CSoundEnt::ClientSoundIndex( pEntity ) ); { // since this client isn't around to think anymore, reset their sound. if ( pSound ) { pSound->Reset(); } } // since the edict doesn't get deleted, fix it so it doesn't interfere. pEntity->v.takedamage = DAMAGE_NO;// don't attract autoaim pEntity->v.solid = SOLID_NOT;// nonsolid UTIL_SetOrigin ( &pEntity->v, pEntity->v.origin ); g_pGameRules->ClientDisconnected( pEntity ); }
void ManageAudio::stopSound(TypeAudio _type) { std::hash_map<int, CSound*>::iterator it = this->listAudio.find((int)_type); if (it != this->listAudio.end()) { CSound* sound = it->second; sound->Stop(); } }
void CResourceManager::MuteSound() { for (map<int, CSound*>::iterator it = CResourceManager::_instance->_lstSound.begin(); it != CResourceManager::_instance->_lstSound.end(); it++) if (it != CResourceManager::_instance->_lstSound.end()) { CSound* sound = it->second; sound->Stop(); } IsPlaySound = false; }
//----------------------------------------------------------------------------- // Purpose: Listens for sounds and updates the value of the SoundLevel output. //----------------------------------------------------------------------------- void CEnvMicrophone::Think(void) { int nSound = CSoundEnt::ActiveList(); bool fHearSound = false; float flMaxVolume = 0; // // Find the loudest sound that this microphone cares about. // while (nSound != SOUNDLIST_EMPTY) { CSound *pCurrentSound = CSoundEnt::SoundPointerForIndex(nSound); if (pCurrentSound) { if (m_nSoundMask & pCurrentSound->SoundType()) { float flVolume = 0; if (CanHearSound(pCurrentSound, flVolume) && (flVolume > flMaxVolume)) { flMaxVolume = flVolume; fHearSound = true; } } } nSound = pCurrentSound->NextSound(); } if( fHearSound ) { m_OnHeardSound.FireOutput( this, this ); } if (flMaxVolume != m_SoundLevel.Get()) { // // Don't smooth if we are within an epsilon. This allows the output to stop firing // much more quickly. // if (fabs(flMaxVolume - m_SoundLevel.Get()) < MICROPHONE_SETTLE_EPSILON) { m_SoundLevel.Set(flMaxVolume, this, this); } else { m_SoundLevel.Set(flMaxVolume * (1 - m_flSmoothFactor) + m_SoundLevel.Get() * m_flSmoothFactor, this, this); } } SetNextThink( gpGlobals->curtime + 0.1f ); }
void CGUISoundsManager::setSoundParameter(const std::string &sound, std::string ¶meter, float value) { CSound *s = findSound(sound); if(!s) { BaseSubsystems::Log::Warning("Estas accediendo a un sonido no registrado en GUISoundsManager"); } else { s->setParameter(parameter, value); } }//setSoundParameter
void CGUISoundsManager::stopSound(const std::string &sound) { CSound *s = findSound(sound); if(!s) { BaseSubsystems::Log::Warning("Estas accediendo a un sonido no registrado en GUISoundsManager"); } else { s->stop(); } }//stopSound
//============================================================================= // 終了 //============================================================================= void CStageSelect::Uninit(void) { //サウンド取得の作成 CSound *pSound; pSound = CManager::GetSound(); //サウンド再生の作成 pSound->Stop(); //シーンを全て終了 Cform::ReleaseAll(); }
void CResourceManager::StopSound(int soundID) { if (CResourceManager::IsPlaySound) { map<int, CSound*>::iterator it = CResourceManager::_instance->_lstSound.find(soundID); if (it != CResourceManager::_instance->_lstSound.end()) { CSound* sound = it->second; sound->Stop(); } } }
void CResourceManager::ReplaySound() { for (map<int, CSound*>::iterator it = CResourceManager::_instance->_lstSound.begin(); it != CResourceManager::_instance->_lstSound.end(); it++) { CSound* sound = it->second; if (it->first == CResourceManager::_instance->_idSoundBGDefault) { sound->Play(0, 1); IsPlaySound = true; break; } } }
void CEnemyBase::Damaged() { // 残り耐久度を1減らす hardness--; if(hardness == 0){ CSound *se = new CSound(*(CSound*)FindItemBox("explode1")); se->EnableDeleteByEnd(); se->Play(); // 爆発処理を追加 AppendObject(new CExplosion(x, y), EXPLOSION_PRIORITY, true); // 自身を削除 RemoveObject(this); } }
void CSoundManager::release() { if (m_soundVector.size() > 0) { std::vector<CSound*>::iterator i; for (i = m_soundVector.begin(); i != m_soundVector.end(); i++) { CSound* sound = (*i); sound->Stop(); sound->Reset(); SAFE_DELETE(sound); } m_soundVector.clear(); } SAFE_RELEASE( m_pDS ); }
BOOL cDxSound::playSound(char *filename) { if(!_pSoundManager) return FALSE; CSound *pSound = NULL; long hashValue = hash(filename); if(!_sounds.Lookup(hashValue, pSound)) { // A new sound, so we have to load it in first if(FAILED(_pSoundManager->Create(&pSound, filename, 0, GUID_NULL, 5))) { return FALSE; } _sounds.SetAt(hashValue, pSound); } pSound->Play(); return TRUE; }
float CBackgroundSound::getMaxDistance() const { CAudioMixerUser *mixer = CAudioMixerUser::instance(); float ret = 0.0f; std::vector<TSoundInfo>::const_iterator first(_Sounds.begin()), last(_Sounds.end()); for (; first != last; ++first) { CSound *sound = mixer->getSoundId(first->SoundName); if (sound != 0) { ret = max(ret, sound->getMaxDistance()); } } if (ret == 0) ret = 1; return ret; }
void CResourceManager::PlayASound(int soundID) { if (CResourceManager::IsPlaySound) { map<int, CSound*>::iterator it = CResourceManager::_instance->_lstSound.find(soundID); if (it != CResourceManager::_instance->_lstSound.end()) { CSound* sound = it->second; if (sound->loop) { sound->Play(0, 1); CResourceManager::_instance->_idSoundBGDefault = it->first; } else if (!sound->IsSoundPlaying()) sound->Play(); } } }
// Update beat times (and max length) if necessary void CLine::CheckBeatTimes(CSong& sSong,CSound& sSound,const int iTempo) { INTERNAL_SYNCHRONIZE; // Not necessary, stop if(iTempo == m_iValidTempo && sSound.GetFinalLength(iTempo) == m_iValidSoundLength) return; // Build times m_pbBeatContainer->SetTimeOffsets(0,CSong::GetBarLength(iTempo,m_ppParent->GetTimeSignature())); // Get sound length m_iValidSoundLength=sSound.GetFinalLength(iTempo); // Work out max length m_iMaxLength=m_pbBeatContainer->GetLastTime() + m_iValidSoundLength; // Set valid m_iValidTempo=iTempo; }
uint32 CBackgroundSound::getDuration() { if (_DurationValid) return _Duration; vector<sint32> durations; CAudioMixerUser *mixer = CAudioMixerUser::instance(); std::vector<TSoundInfo>::const_iterator first(_Sounds.begin()), last(_Sounds.end()); for (; first != last; ++first) { CSound *sound = mixer->getSoundId(first->SoundName); if (sound != NULL) durations.push_back(sound->getDuration()); } if (durations.empty()) return 0; _Duration = *(std::max_element(durations.begin(), durations.end())); _DurationValid = true; return _Duration; }
void CEnemy3::Damaged() { hardness--; if(hardness == 0){ // 10個の爆炎をランダムで拡散させる for(int i = 0; i < 10; i++){ float angle = d2r((float)(36 * i)); float size = 0.5f + 2.0f * (float)rand() / (float)(RAND_MAX + 1); float speed = 1.0f + 5.0f * (float)rand() / (float)(RAND_MAX + 1); AppendObject(new CExplosion(x, y, size, angle, speed), EXPLOSION_PRIORITY, true); } CSound *se = new CSound(*(CSound*)FindItemBox("explode2")); se->EnableDeleteByEnd(); se->Play(); AppendObject(new CPowerupItem(x, y), PLAYER_PRIORITY, true); RemoveObject(this); } }
void ManageAudio::playSound(TypeAudio _type) { this->stopSound(_type); std::hash_map<int, CSound*>::iterator it = this->listAudio.find((int)_type); if (it != this->listAudio.end()) { CSound* sound = it->second; if (sound->loop) { sound->Reset(); sound->Play(0, DSBPLAY_LOOPING); //sound->Play(0, DSSCL_PRIORITY); } else { sound->Reset(); sound->Play(); } } }
CSound *CAI_Senses::GetClosestSound( bool fScent, int validTypes, bool bUsePriority ) { float flBestDist = MAX_COORD_RANGE*MAX_COORD_RANGE;// so first nearby sound will become best so far. float flDist; int iBestPriority = SOUND_PRIORITY_VERY_LOW; AISoundIter_t iter; CSound *pResult = NULL; CSound *pCurrent = GetFirstHeardSound( &iter ); Vector earPosition = GetOuter()->EarPosition(); while ( pCurrent ) { if ( ( !fScent && pCurrent->FIsSound() ) || ( fScent && pCurrent->FIsScent() ) ) { if( pCurrent->IsSoundType( validTypes ) && !GetOuter()->ShouldIgnoreSound( pCurrent ) ) { if( !bUsePriority || GetOuter()->GetSoundPriority(pCurrent) >= iBestPriority ) { flDist = ( pCurrent->GetSoundOrigin() - earPosition ).LengthSqr(); if ( flDist < flBestDist ) { pResult = pCurrent; flBestDist = flDist; iBestPriority = GetOuter()->GetSoundPriority(pCurrent); } } } } pCurrent = GetNextHeardSound( &iter ); } return pResult; }
bool CBoss::ActionDestroy() { frame++; if(frame < 500){ // 500フレーム目まではボス周辺でランダムに爆炎を発生させる if(frame % 5 == 0){ float xx = x + (float)(rand() % 500 - 250); float yy = y + (float)(rand() % 300 - 150); float sz = 1.0f + 2.0f * (float)rand() / (float)RAND_MAX; AppendObject(new CExplosion(xx, yy, sz, 0.0f, 0.0f), EXPLOSION_PRIORITY, true); } y += 0.2f; if(frame % 15 == 0){ ((CSound*)FindItemBox("explode1"))->Play(); } return false; }else{ // 500フレーム目で大爆発を起こす float xx, yy, a, s, z; for(int i = 0; i < 50; i++){ xx = x + (float)(rand() % 100 - 50); yy = y + (float)(rand() % 100 - 50); a = atan2f(x - xx, yy - y); s = 5.0f + 10.0f * (float)rand() / (float)RAND_MAX; z = 3.0f + 8.0f * (float)rand() / (float)RAND_MAX; AppendObject(new CExplosion(xx, yy, 2.0f, a, s), EXPLOSION_PRIORITY, true); } CSound *se = new CSound(*(CSound*)FindItemBox("explode3")); se->EnableDeleteByEnd(); se->Play(); return true; } }
/* =========== ClientDisconnect called when a player disconnects from a server GLOBALS ASSUMED SET: g_fGameOver ============ */ void ClientDisconnect( edict_t *pEntity ) { // If they're in an arena, remove them CBasePlayer *pPlayer = (CBasePlayer *)GET_PRIVATE(pEntity); if ( pPlayer->m_pCurrentArena ) pPlayer->m_pCurrentArena->RemoveClient( pPlayer ); if (g_fGameOver) return; // char text[256]; // sprintf( text, "- %s has left the game\n", STRING(pEntity->v.netname) ); // MESSAGE_BEGIN( MSG_BROADCAST, gmsgSayText, NULL ); // WRITE_BYTE( ENTINDEX(pEntity) ); // WRITE_STRING( text ); // MESSAGE_END(); // notify other clients the player has left UTIL_ClientPrintAll( HUD_PRINTNOTIFY, "#Game_disconnected", STRING(pEntity->v.netname) ); CSound *pSound; pSound = CSoundEnt::SoundPointerForIndex( CSoundEnt::ClientSoundIndex( pEntity ) ); { // since this client isn't around to think anymore, reset their sound. if ( pSound ) { pSound->Reset(); } } // since the edict doesn't get deleted, fix it so it doesn't interfere. pEntity->v.takedamage = DAMAGE_NO;// don't attract autoaim pEntity->v.solid = SOLID_NOT;// nonsolid UTIL_SetOrigin ( &pEntity->v, pEntity->v.origin ); g_pGameRules->ClientDisconnected( pEntity ); pPlayer->m_bHasDisconnected = true; }
// Metoda dodajaca dzwiek do zbioru "sounds_" void CAudioSystem::addSound(const CSound & sound) { if ( sounds_.insert( std::make_pair( sound.GetNickname(), sound ) ).second ) { CLog::getInstance()->sss << "CAudioSystem::addSound:CAudioSystem::addSounds: dodano dzwiek do CAudioSystem" << endl; logs(CLog::getInstance()->sss.str(), INFO); } else { CLog::getInstance()->sss <<"CAudioSystem::addSound:CAudioSystem::addSounds: dzwiek juz istnieje \n"; logs(CLog::getInstance()->sss.str(), INFO); } }
//========================================================= // OnListened - monsters dig through the active sound list for // any sounds that may interest them. (smells, too!) //========================================================= void CNPC_Bullsquid::OnListened( void ) { AISoundIter_t iter; CSound *pCurrentSound; static int conditionsToClear[] = { COND_SQUID_SMELL_FOOD, }; ClearConditions( conditionsToClear, ARRAYSIZE( conditionsToClear ) ); pCurrentSound = GetSenses()->GetFirstHeardSound( &iter ); while ( pCurrentSound ) { // the npc cares about this sound, and it's close enough to hear. int condition = COND_NONE; if ( !pCurrentSound->FIsSound() ) { // if not a sound, must be a smell - determine if it's just a scent, or if it's a food scent if ( pCurrentSound->IsSoundType( SOUND_MEAT | SOUND_CARCASS ) ) { // the detected scent is a food item condition = COND_SQUID_SMELL_FOOD; } } if ( condition != COND_NONE ) SetCondition( condition ); pCurrentSound = GetSenses()->GetNextHeardSound( &iter ); } BaseClass::OnListened(); }
//----------------------------------------------------------------------------- // Purpose: Return the loudest sound of the specified type at "earposition" //----------------------------------------------------------------------------- CSound* CSoundEnt::GetLoudestSoundOfType( int iType, const Vector &vecEarPosition ) { CSound *pLoudestSound = NULL; int iThisSound; int iBestSound = SOUNDLIST_EMPTY; float flBestDist = MAX_COORD_RANGE*MAX_COORD_RANGE;// so first nearby sound will become best so far. float flDist; CSound *pSound; iThisSound = ActiveList(); while ( iThisSound != SOUNDLIST_EMPTY ) { pSound = SoundPointerForIndex( iThisSound ); if ( pSound && pSound->m_iType == iType && pSound->ValidateOwner() ) { flDist = ( pSound->GetSoundOrigin() - vecEarPosition ).Length(); //FIXME: This doesn't match what's in Listen() //flDist = UTIL_DistApprox( pSound->GetSoundOrigin(), vecEarPosition ); if ( flDist <= pSound->m_iVolume && flDist < flBestDist ) { pLoudestSound = pSound; iBestSound = iThisSound; flBestDist = flDist; } } iThisSound = pSound->m_iNext; } return pLoudestSound; }