void StopSoundByHandle( int entindex, const char *soundname, HSOUNDSCRIPTHANDLE& handle )
	{
		if ( handle == SOUNDEMITTER_INVALID_HANDLE )
		{
			handle = (HSOUNDSCRIPTHANDLE)soundemitterbase->GetSoundIndex( soundname );
		}

		if ( handle == SOUNDEMITTER_INVALID_HANDLE )
			return;

		CSoundParametersInternal *params;

		params = soundemitterbase->InternalGetParametersForSound( (int)handle );
		if ( !params )
		{
			return;
		}

		// HACK:  we have to stop all sounds if there are > 1 in the rndwave section...
		int c = params->NumSoundNames();
		for ( int i = 0; i < c; ++i )
		{
			char const *wavename = soundemitterbase->GetWaveName( params->GetSoundNames()[ i ].symbol );
			Assert( wavename );

			enginesound->StopSound( 
				entindex, 
				params->GetChannel(), 
				wavename );

			TraceEmitSound( "StopSound:  '%s' stopped as '%s' (ent %i)\n",
				soundname, wavename, entindex );
		}
	}
Example #2
0
bool InternalPrecacheScriptSound(const char *soundname)
{
	int soundIndex = soundemitterbase->GetSoundIndex(soundname);
	if (!soundemitterbase->IsValidIndex(soundIndex))
	{
		return false;
	}

	CSoundParametersInternal *internal = soundemitterbase->InternalGetParametersForSound(soundIndex);

	if (!internal)
		return false;

	int waveCount = internal->NumSoundNames();

	if (!waveCount)
	{
		return false;
	}

	for (int wave = 0; wave < waveCount; wave++)
	{
		const char* waveName = soundemitterbase->GetWaveName(internal->GetSoundNames()[wave].symbol);
		// return true even if we precache no new wavs
		if (!engsound->IsSoundPrecached(waveName))
		{
			engsound->PrecacheSound(waveName);
		}
	}

	return true;
}
	// Precache all wave files referenced in wave or rndwave keys
	virtual void LevelInitPreEntity()
	{
		char mapname[ 256 ];
#if !defined( CLIENT_DLL )
		StartLog();
		Q_snprintf( mapname, sizeof( mapname ), "maps/%s", STRING( gpGlobals->mapname ) );
#else
		Q_strncpy( mapname, engine->GetLevelName(), sizeof( mapname ) );
#endif

		Q_FixSlashes( mapname );
		Q_strlower( mapname );

		// Load in any map specific overrides
		char scriptfile[ 512 ];
		Q_StripExtension( mapname, scriptfile, sizeof( scriptfile ) );
		Q_strncat( scriptfile, "_level_sounds.txt", sizeof( scriptfile ), COPY_ALL_CHARACTERS );

		if ( filesystem->FileExists( scriptfile, "GAME" ) )
		{
			soundemitterbase->AddSoundOverrides( scriptfile );
		}

#if !defined( CLIENT_DLL )
		for ( int i=soundemitterbase->First(); i != soundemitterbase->InvalidIndex(); i=soundemitterbase->Next( i ) )
		{
			CSoundParametersInternal *pParams = soundemitterbase->InternalGetParametersForSound( i );
			if ( pParams->ShouldPreload() )
			{
				InternalPrecacheWaves( i );
			}
		}
#endif
	}
bool CSoundParametersInternal::operator == ( const CSoundParametersInternal& other ) const
{
	if ( this == &other )
		return true;

	if ( channel != other.channel )
		return false;
	if ( !CompareInterval( volume, other.volume ) )
		return false;
	if ( !CompareInterval( pitch, other.pitch ) )
		return false;
	if ( !CompareInterval( soundlevel, other.soundlevel ) )
		return false;
	if ( delay_msec != other.delay_msec )
		return false;
	if ( play_to_owner_only != other.play_to_owner_only )
		return false;

	if ( m_nSoundNames != other.m_nSoundNames )
		return false;

	// Compare items
	int c = m_nSoundNames;
	for ( int i = 0; i < c; i++ )
	{
		if ( GetSoundNames()[ i ].symbol != other.GetSoundNames()[ i ].symbol )
			return false;
	}

	return true;
}
//-----------------------------------------------------------------------------
// Purpose: 
// Input  : hwndDlg - 
//			uMsg - 
//			wParam - 
//			lParam - 
// Output : static BOOL CALLBACK
//-----------------------------------------------------------------------------
static BOOL CALLBACK SoundProperties_MultipleDialogProc( HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam )
{
	switch(uMsg)
	{
    case WM_INITDIALOG:
		{
			g_Params.PositionSelf( hwndDlg );

			CSoundEntry *entry = g_Params.items[ 0 ];
			Assert( entry );

			CSoundParametersInternal *p = entry->GetSoundParameters();
			Assert( p );

			SendMessage( GetDlgItem( hwndDlg, IDC_OWNERONLY ), BM_SETCHECK, 
				( WPARAM ) p->OnlyPlayToOwner() ? BST_CHECKED : BST_UNCHECKED,
				( LPARAM )0 );

			PopulateChannelList( hwndDlg, p );
			PopulateVolumeList( hwndDlg, p );
			PopulateSoundlevelList( hwndDlg, p );
			PopulatePitchList( hwndDlg, p );

			SetWindowText( hwndDlg, g_Params.m_szDialogTitle );

			SetFocus( GetDlgItem( hwndDlg, IDC_CHANNEL ) );
		}
		return FALSE;  
		
    case WM_COMMAND:
		switch (LOWORD(wParam))
		{
		case IDOK:
			{
				SoundProperties_Multiple_OnOK( hwndDlg );

				EndDialog( hwndDlg, 1 );
			}
			break;
        case IDCANCEL:
			EndDialog( hwndDlg, 0 );
			break;
		}
		return FALSE;
	}
	return FALSE;
}
Example #6
0
//-----------------------------------------------------------------------------
// Precaches all game UI sounds
//-----------------------------------------------------------------------------
void CGameUIGameSystem::PrecacheGameUISounds()
{
	// Precache all UI sounds. These must exist in the game_sounds_ui.txt script file
	KeyValues *pUIGameSounds = new KeyValues( "Game Instructor Counts" );
	if ( !pUIGameSounds->LoadFromFile( g_pFullFileSystem, "scripts/game_sounds_ui.txt", "GAME" ) )
	{
		pUIGameSounds->deleteThis();
		return;
	}

	for ( KeyValues *pKey = pUIGameSounds; pKey; pKey = pKey->GetNextKey() )
	{
		const char *pSoundName = pKey->GetName();
		int nSoundIndex = soundemitterbase->GetSoundIndex( pSoundName );
		if ( !soundemitterbase->IsValidIndex( nSoundIndex ) )
		{
			Log_Warning( LOG_GameUI, "GameUI: Unable to precache gamesound \"%s\"\n", pSoundName );
			continue;
		}

		CSoundParametersInternal *pInternal = soundemitterbase->InternalGetParametersForSound( nSoundIndex );
		if ( !pInternal )
		{
			Log_Warning( LOG_GameUI, "GameUI: Unable to precache gamesound \"%s\"\n", pSoundName );
			continue;
		}

		int nWaveCount = pInternal->NumSoundNames();
		if ( !nWaveCount )
		{
			Log_Warning( LOG_GameUI, "GameUI: game_sounds_ui.txt entry '%s' has no waves listed under 'wave' or 'rndwave' key!!!\n", pSoundName );
			continue;
		}

		for( int nWave = 0; nWave < nWaveCount; ++nWave )
		{
			const char *pWavName = soundemitterbase->GetWaveName( pInternal->GetSoundNames()[ nWave ].symbol );
			enginesound->PrecacheSound( pWavName, true, true );
		}
	}
	pUIGameSounds->deleteThis();
}
	void InternalPrefetchWaves( int soundIndex )
	{
		CSoundParametersInternal *internal = soundemitterbase->InternalGetParametersForSound( soundIndex );
		if ( !internal )
			return;

		int waveCount = internal->NumSoundNames();
		if ( !waveCount )
		{
			DevMsg( "CSoundEmitterSystem:  sounds.txt entry '%s' has no waves listed under 'wave' or 'rndwave' key!!!\n",
				soundemitterbase->GetSoundName( soundIndex ) );
		}
		else
		{
			for( int wave = 0; wave < waveCount; wave++ )
			{
				CBaseEntity::PrefetchSound( soundemitterbase->GetWaveName( internal->GetSoundNames()[ wave ].symbol ) );
			}
		}
	}
static void SoundProperties_Multiple_OnOK( HWND hwndDlg )
{
	int c = g_Params.items.Count();
	for ( int i = 0; i < c; i++ )
	{
		// Gather info and make changes
		CSoundEntry *item = g_Params.items[ i ];
		Assert( item );
		if ( !item )
			continue;

		int idx = g_pSoundEmitterSystem->GetSoundIndex( item->GetName() );
		if ( !g_pSoundEmitterSystem->IsValidIndex( idx ) )
		{
			continue;
		}


		CSoundParametersInternal *baseparams = g_pSoundEmitterSystem->InternalGetParametersForSound( idx );
		if ( !baseparams )
			return;

		// Start with old settings
		CSoundParametersInternal outparams;
		outparams.CopyFrom( *baseparams );

		char sz[ 128 ];
		GetDlgItemText( hwndDlg, IDC_CHANNEL, sz, sizeof( sz ) );
		outparams.ChannelFromString( sz );

		GetDlgItemText( hwndDlg, IDC_VOLUME, sz, sizeof( sz ) );
		outparams.VolumeFromString( sz );

		GetDlgItemText( hwndDlg, IDC_SOUNDLEVEL, sz, sizeof( sz ) );
		outparams.SoundLevelFromString( sz );

		GetDlgItemText( hwndDlg, IDC_PITCH, sz, sizeof( sz ) );
		outparams.PitchFromString( sz );

		bool owneronly = SendMessage( GetDlgItem( hwndDlg, IDC_OWNERONLY ), BM_GETCHECK, 0, 0 ) == BST_CHECKED ? true : false;

		outparams.SetOnlyPlayToOwner( owneronly );

		g_pSoundEmitterSystem->UpdateSoundParameters( item->GetName(), outparams );
	}

	// Repopulate things
	GetWorkspaceManager()->RefreshBrowsers();
}
//-----------------------------------------------------------------------------
// Purpose: 
// Input  : *soundname - 
//			params - 
// Output : Returns true on success, false on failure.
//-----------------------------------------------------------------------------
bool CSoundEmitterSystemBase::InitSoundInternalParameters( const char *soundname, KeyValues *kv, CSoundParametersInternal& params )
{
	KeyValues *pKey = kv->GetFirstSubKey();
	while ( pKey )
	{
		if ( !Q_strcasecmp( pKey->GetName(), "channel" ) )
		{
			params.ChannelFromString( pKey->GetString() );
		}
		else if ( !Q_strcasecmp( pKey->GetName(), "volume" ) )
		{
			params.VolumeFromString( pKey->GetString() );
		}
		else if ( !Q_strcasecmp( pKey->GetName(), "pitch" ) )
		{
			params.PitchFromString( pKey->GetString() );
		}
		else if ( !Q_strcasecmp( pKey->GetName(), "wave" ) )
		{
			CUtlSymbol sym = m_Waves.AddString( pKey->GetString() );
			params.soundnames.AddToTail( sym );
		}
		else if ( !Q_strcasecmp( pKey->GetName(), "rndwave" ) )
		{
			KeyValues *pWaves = pKey->GetFirstSubKey();
			while ( pWaves )
			{
				CUtlSymbol sym = m_Waves.AddString( pWaves->GetString() );
				params.soundnames.AddToTail( sym );

				pWaves = pWaves->GetNextKey();
			}
		}
		else if ( !Q_strcasecmp( pKey->GetName(), "attenuation" ) )
		{
			if ( !Q_strncasecmp( pKey->GetString(), "SNDLVL_", strlen( "SNDLVL_" ) ) )
			{
				DevMsg( "CSoundEmitterSystemBase::GetParametersForSound:  sound %s has \"attenuation\" with %s value!\n",
					soundname, pKey->GetString() );
			}

			if ( !Q_strncasecmp( pKey->GetString(), "ATTN_", strlen( "ATTN_" ) ) )
			{
				params.soundlevel.start = ATTN_TO_SNDLVL( TranslateAttenuation( pKey->GetString() ) );
				params.soundlevel.range = 0.0f;
			}
			else
			{
				interval_t interval;
				interval = ReadInterval( pKey->GetString() );

				// Translate from attenuation to soundlevel
				float start = interval.start;
				float end	= interval.start + interval.range;

				params.soundlevel.start = ATTN_TO_SNDLVL( start );
				params.soundlevel.range = ATTN_TO_SNDLVL( end ) - ATTN_TO_SNDLVL( start );
			}
		}
		else if ( !Q_strcasecmp( pKey->GetName(), "soundlevel" ) )
		{
			if ( !Q_strncasecmp( pKey->GetString(), "ATTN_", strlen( "ATTN_" ) ) )
			{
				DevMsg( "CSoundEmitterSystemBase::GetParametersForSound:  sound %s has \"soundlevel\" with %s value!\n",
					soundname, pKey->GetString() );
			}

			params.SoundLevelFromString( pKey->GetString() );
		}
		else if ( !Q_strcasecmp( pKey->GetName(), "play_to_owner_only" ) )
		{
			params.play_to_owner_only = pKey->GetInt() ? true : false;
		}
		else if ( !Q_strcasecmp( pKey->GetName(), "precache" ) )
		{
			params.precache = pKey->GetInt() ? true : false;
		}

		pKey = pKey->GetNextKey();
	}

	return true;
}