SoundsManagment.cpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. //===========================================================================================================================
  2. // Spirenkov Maxim, 2003
  3. //===========================================================================================================================//
  4. // Mission objects
  5. //===========================================================================================================================
  6. // SoundsManagment
  7. //============================================================================================
  8. #include "SoundsManagment.h"
  9. #define BootupSoundBank "mini"
  10. //============================================================================================
  11. class SoundBanksKipper : public Service
  12. {
  13. public:
  14. SoundBanksKipper()
  15. {
  16. s = null;
  17. isLoad = false;
  18. }
  19. //Инициализация
  20. virtual bool Init()
  21. {
  22. isLoad = false;
  23. s = (ISoundService *)api->GetService("SoundService");
  24. if(!s)
  25. {
  26. api->Trace("GlobalSoundBankKipper error: SoundService not found! Not load global sound bank.");
  27. return false;
  28. }
  29. s->LoadSoundBank(BootupSoundBank);
  30. IFileService * fs = (IFileService *)api->GetService("FileService");
  31. if(fs)
  32. {
  33. bool isDelayedLoading = (fs->SystemIni()->GetLong("sound", "delayedloading", 0) != 0);
  34. if(isDelayedLoading)
  35. {
  36. return true;
  37. }
  38. }
  39. LoadSoundBanks();
  40. return true;
  41. }
  42. virtual ~SoundBanksKipper()
  43. {
  44. ISoundService * s = (ISoundService *)api->GetService("SoundService");
  45. Assert(s);
  46. #ifndef GAME_RUSSIAN
  47. s->ReleaseSoundBank(localBankPath.c_str());
  48. #endif
  49. s->ReleaseSoundBank(SoundService_GlobalSoundBank);
  50. s->ReleaseSoundBank(BootupSoundBank);
  51. }
  52. void LoadSoundBanks()
  53. {
  54. if(isLoad)
  55. {
  56. return;
  57. }
  58. isLoad = true;
  59. s->LoadSoundBank(SoundService_GlobalSoundBank);
  60. ILocStrings * ls = (ILocStrings *)api->GetService("LocStrings");
  61. if(!ls)
  62. {
  63. api->Trace("GlobalSoundBankKipper error: LocStrings not found! Not load local sound bank.");
  64. return;
  65. }
  66. #ifndef GAME_RUSSIAN
  67. localBankPath = SoundService_GlobalSoundBank;
  68. localBankPath += "_";
  69. localBankPath += ls->GetLocId();
  70. s->LoadSoundBank(localBankPath.c_str());
  71. #endif
  72. }
  73. private:
  74. ISoundService * s;
  75. bool isLoad;
  76. string localBankPath;
  77. };
  78. CREATE_SERVICE(SoundBanksKipper, 0x7fffffff - 10)
  79. //============================================================================================
  80. //Инициализировать объект
  81. bool LoadSoundBanks::Create(MOPReader & reader)
  82. {
  83. SoundBanksKipper * sbk = (SoundBanksKipper *)api->GetService("SoundBanksKipper");
  84. if(!sbk)
  85. {
  86. LogicDebugError("Service SoundBanksKipper not found");
  87. return false;
  88. }
  89. sbk->LoadSoundBanks();
  90. LogicDebug("Load sound banks...");
  91. return true;
  92. }
  93. MOP_BEGINLISTCG(LoadSoundBanks, "Load sound banks", '1.00', 0, "Load global and local sound banks when load mission", "Effects")
  94. MOP_ENDLIST(LoadSoundBanks)