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.

153 lines
4.1 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Sound management functions. Exposes a list of available sounds.
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #ifndef SOUNDSSYSTEM_H
  8. #define SOUNDSSYSTEM_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. #include "utlvector.h"
  13. //-----------------------------------------------------------------------------
  14. // Contains lists of all sounds available for use
  15. //-----------------------------------------------------------------------------
  16. enum SoundType_t
  17. {
  18. SOUND_TYPE_RAW = 0,
  19. SOUND_TYPE_GAMESOUND,
  20. SOUND_TYPE_SCENE, // vcd file
  21. SOUND_TYPE_COUNT,
  22. };
  23. class CSoundSystem
  24. {
  25. public:
  26. CSoundSystem(void);
  27. virtual ~CSoundSystem(void);
  28. bool Initialize( );
  29. void ShutDown(void);
  30. // Build the list of sounds
  31. bool BuildSoundList( SoundType_t type );
  32. // Sound list iteration
  33. int SoundCount( SoundType_t type );
  34. const char *SoundName( SoundType_t type, int nIndex );
  35. const char *SoundFile( SoundType_t type, int nIndex );
  36. const char *SoundSourceFile( SoundType_t type, int nIndex );
  37. // Search through all the sounds for the specified one.
  38. bool FindSoundByName( const char *pFilename, SoundType_t *type, int *nIndex );
  39. // Plays a sound
  40. bool Play( SoundType_t type, int nIndex );
  41. bool PlayScene( const char *pFileName ); // Play the first sound in the specified scene.
  42. // Stops any playing sound.
  43. void StopSound();
  44. // Opens the source file associated with a sound
  45. void OpenSource( SoundType_t type, int nIndex );
  46. private:
  47. struct SoundInfo_t
  48. {
  49. char *m_pSoundName;
  50. char *m_pSoundFile;
  51. const char *m_pSourceFile;
  52. };
  53. struct StringCache_t
  54. {
  55. enum
  56. {
  57. STRING_CACHE_SIZE = 128 * 1024,
  58. };
  59. char m_pBuf[STRING_CACHE_SIZE];
  60. int m_nTailIndex; // Next address to fill
  61. StringCache_t *m_pNext;
  62. };
  63. struct SoundList_t
  64. {
  65. CUtlVector< SoundInfo_t > m_Sounds;
  66. StringCache_t *m_pStrings;
  67. };
  68. private:
  69. typedef bool (CSoundSystem::*pDirCallbackFn)( const char *pDirectoryName );
  70. // Allocate, deallocate a string cache
  71. StringCache_t *CreateStringCache( StringCache_t* pPrevious );
  72. void DestroyStringCache( StringCache_t *pCache );
  73. // Adds a string to the string cache
  74. char *AddStringToCache( SoundType_t type, const char *pString );
  75. // Adds a sound to a sound list
  76. void AddSoundToList( SoundType_t type, const char *pSoundName, const char *pActualFile, const char *pSourceFile );
  77. // Cleans up the sound list
  78. void CleanupSoundList( SoundType_t type );
  79. // Goes into all subdirectories and calls the callback for each one..
  80. bool RecurseIntoDirectories( char const* pDirectoryName, pDirCallbackFn fn );
  81. // Add all sounds that lie within a single directory recursively
  82. bool ProcessDirectory_RawFileList( char const* pDirectoryName );
  83. bool ProcessDirectory_SceneFileList( char const* pDirectoryName );
  84. // Add all sounds that lie within a single directory
  85. void BuildFileListInDirectory( char const* pDirectoryName, const char *pExt, SoundType_t soundType );
  86. // Gamesounds may have macros embedded in them
  87. void AddGameSoundToList( const char *pGameSound, char const *pFileName, const char *pSourceFile );
  88. // Load all game sounds from a particular file
  89. void AddGameSoundsFromFile( const char *pFileName );
  90. // Populate the list of game sounds
  91. bool BuildGameSoundList();
  92. private:
  93. SoundList_t m_SoundList[SOUND_TYPE_COUNT];
  94. };
  95. //-----------------------------------------------------------------------------
  96. // Sound list iteration
  97. //-----------------------------------------------------------------------------
  98. inline int CSoundSystem::SoundCount( SoundType_t type )
  99. {
  100. return m_SoundList[type].m_Sounds.Count();
  101. }
  102. inline const char *CSoundSystem::SoundName( SoundType_t type, int nIndex )
  103. {
  104. return m_SoundList[type].m_Sounds[nIndex].m_pSoundName;
  105. }
  106. inline const char *CSoundSystem::SoundFile( SoundType_t type, int nIndex )
  107. {
  108. return m_SoundList[type].m_Sounds[nIndex].m_pSoundFile;
  109. }
  110. inline const char *CSoundSystem::SoundSourceFile( SoundType_t type, int nIndex )
  111. {
  112. return m_SoundList[type].m_Sounds[nIndex].m_pSourceFile;
  113. }
  114. extern CSoundSystem g_Sounds;
  115. #endif // SOUNDSYSTEM_H