Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

175 lines
6.5 KiB

  1. //===== Copyright � 1996-2005, Valve Corporation, All rights reserved. ======//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //===========================================================================//
  7. #ifndef SOUNDEMITTERSYSTEMBASE_H
  8. #define SOUNDEMITTERSYSTEMBASE_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. #include "SoundEmitterSystem/isoundemittersystembase.h"
  13. #include "tier1/utldict.h"
  14. #include "soundflags.h"
  15. #include "tier2/interval.h"
  16. #include "tier1/utlsortvector.h"
  17. #include "tier1/mempool.h"
  18. #include "tier2/tier2.h"
  19. soundlevel_t TextToSoundLevel( const char *key );
  20. struct CSoundEntry
  21. {
  22. CUtlSymbol m_Name;
  23. CSoundParametersInternal m_SoundParams;
  24. uint16 m_nScriptFileIndex;
  25. bool m_bRemoved : 1;
  26. bool m_bIsOverride : 1;
  27. class CSoundEntryLess
  28. {
  29. public:
  30. bool Less( CSoundEntry * const & lhs, CSoundEntry *const & rhs, void *pCtx )
  31. {
  32. return ( Q_stricmp( lhs->m_Name.String(), rhs->m_Name.String() ) < 0 ) ? true : false;
  33. }
  34. };
  35. DECLARE_FIXEDSIZE_ALLOCATOR(CSoundEntry);
  36. };
  37. //-----------------------------------------------------------------------------
  38. // Purpose: Base class for sound emitter system handling (can be used by tools)
  39. //-----------------------------------------------------------------------------
  40. class CSoundEmitterSystemBase : public CTier2AppSystem< ISoundEmitterSystemBase >
  41. {
  42. typedef CTier2AppSystem< ISoundEmitterSystemBase > BaseClass;
  43. public:
  44. CSoundEmitterSystemBase();
  45. virtual ~CSoundEmitterSystemBase() { }
  46. // Methods of IAppSystem
  47. virtual bool Connect( CreateInterfaceFn factory );
  48. virtual InitReturnVal_t Init();
  49. virtual void Shutdown();
  50. virtual void Disconnect();
  51. virtual void *QueryInterface( const char *pInterfaceName );
  52. public:
  53. virtual int GetSoundIndex( const char *pName ) const;
  54. virtual bool IsValidIndex( int index );
  55. virtual int GetSoundCount( void );
  56. virtual const char *GetSoundName( int index );
  57. virtual bool GetParametersForSound( const char *soundname, CSoundParameters& params, gender_t gender, bool isbeingemitted = false );
  58. virtual const char *GetWaveName( CUtlSymbol& sym );
  59. virtual CUtlSymbol AddWaveName( const char *name );
  60. virtual soundlevel_t LookupSoundLevel( const char *soundname );
  61. virtual const char *GetWavFileForSound( const char *soundname, char const *actormodel );
  62. virtual const char *GetWavFileForSound( const char *soundname, gender_t gender );
  63. virtual int CheckForMissingWavFiles( bool verbose );
  64. virtual const char *GetSourceFileForSound( int index ) const;
  65. // Iteration methods
  66. virtual int First() const;
  67. virtual int Next( int i ) const;
  68. virtual int InvalidIndex() const;
  69. virtual CSoundParametersInternal *InternalGetParametersForSound( int index );
  70. // The host application is responsible for dealing with dirty sound scripts, etc.
  71. virtual bool AddSound( const char *soundname, const char *scriptfile, const CSoundParametersInternal& params );
  72. virtual void RemoveSound( const char *soundname );
  73. virtual void MoveSound( const char *soundname, const char *newscript );
  74. virtual void RenameSound( const char *soundname, const char *newname );
  75. virtual void UpdateSoundParameters( const char *soundname, const CSoundParametersInternal& params );
  76. virtual int GetNumSoundScripts() const;
  77. virtual char const *GetSoundScriptName( int index ) const;
  78. virtual bool IsSoundScriptDirty( int index ) const;
  79. virtual int FindSoundScript( const char *name ) const;
  80. virtual void SaveChangesToSoundScript( int scriptindex );
  81. virtual void ExpandSoundNameMacros( CSoundParametersInternal& params, char const *wavename );
  82. virtual gender_t GetActorGender( char const *actormodel );
  83. virtual void GenderExpandString( char const *actormodel, char const *in, char *out, int maxlen );
  84. virtual void GenderExpandString( gender_t gender, char const *in, char *out, int maxlen );
  85. virtual bool IsUsingGenderToken( char const *soundname );
  86. virtual unsigned int GetManifestFileTimeChecksum();
  87. virtual bool GetParametersForSoundEx( const char *soundname, HSOUNDSCRIPTHASH& handle, CSoundParameters& params, gender_t gender, bool isbeingemitted = false );
  88. virtual soundlevel_t LookupSoundLevelByHandle( char const *soundname, HSOUNDSCRIPTHASH& handle );
  89. virtual KeyValues *GetOperatorKVByHandle( HSOUNDSCRIPTHASH& handle );
  90. virtual char const *GetSoundNameForHash( unsigned int hash ) const; // Returns NULL if hash not found!!!
  91. virtual int GetSoundIndexForHash( unsigned int hash ) const;
  92. virtual unsigned int HashSoundName( char const *pchSndName ) const;
  93. virtual bool IsValidHash( unsigned int hash ) const;
  94. // Called from both client and server (single player) or just one (server only in dedicated server and client only if connected to a remote server)
  95. // Called by LevelInitPreEntity to override sound scripts for the mod with level specific overrides based on custom mapnames, etc.
  96. virtual void AddSoundOverrides( char const *scriptfile );
  97. // Called by either client or server in LevelShutdown to clear out custom overrides
  98. virtual void ClearSoundOverrides();
  99. virtual void DescribeSound( char const *soundname );
  100. virtual void Flush();
  101. virtual void AddSoundsFromFile( const char *filename, bool bPreload, bool bAutoCache, bool bIsOverride = false );
  102. private:
  103. bool InitSoundInternalParameters( const char *soundname, KeyValues *kv, CSoundParametersInternal& params );
  104. bool LoadGameSoundManifest();
  105. void ShutdownSounds();
  106. void LoadGlobalActors();
  107. float TranslateAttenuation( const char *key );
  108. soundlevel_t TranslateSoundLevel( const char *key );
  109. int TranslateChannel( const char *name );
  110. int FindBestSoundForGender( SoundFile *pSoundnames, int c, gender_t gender, int &nRandomSeed );
  111. void EnsureAvailableSlotsForGender( SoundFile *pSoundnames, int c, gender_t gender );
  112. void AddSoundName( CSoundParametersInternal& params, char const *wavename, gender_t gender );
  113. void AddHash( char const *pchSoundName, int nIndex );
  114. void RemoveHash( char const *pchSoundName );
  115. CUtlDict< gender_t, uint8 > m_ActorGenders;
  116. CUtlVector< CSoundEntry * > m_Sounds;
  117. CUtlVector< CSoundEntry * > m_SavedOverrides;
  118. CUtlVector< FileNameHandle_t > m_OverrideFiles;
  119. struct CSoundScriptFile
  120. {
  121. FileNameHandle_t hFilename;
  122. bool dirty;
  123. };
  124. CUtlVector< CSoundScriptFile > m_SoundKeyValues;
  125. int m_nInitCount;
  126. unsigned int m_uManifestPlusScriptChecksum;
  127. CUtlSymbolTable m_Waves;
  128. // This is a reverse mapping from crc of the soundname to the sound entry
  129. struct soundEntryHash_t
  130. {
  131. int soundIndex;
  132. CSoundEntry *pEntry;
  133. };
  134. CUtlMap< HSOUNDSCRIPTHASH, soundEntryHash_t > m_HashToSoundEntry;
  135. };
  136. #endif // SOUNDEMITTERSYSTEMBASE_H