sfxFMODProject.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #ifndef _SFXFMODPROJECT_H_
  23. #define _SFXFMODPROJECT_H_
  24. #ifndef _SIMDATABLOCK_H_
  25. #include "console/simDatablock.h"
  26. #endif
  27. #ifndef _CONSOLETYPES_H_
  28. #include "console/consoleTypes.h"
  29. #endif
  30. #ifndef _TVECTOR_H_
  31. #include "core/util/tVector.h"
  32. #endif
  33. #ifndef _SFXSYSTEM_H_
  34. #include "sfx/sfxSystem.h"
  35. #endif
  36. #include "fmod_event.h"
  37. class SFXFMODEvent;
  38. class SFXFMODEventGroup;
  39. class SimGroup;
  40. /// Datablock that loads an FMOD Designer project.
  41. ///
  42. /// All events in the project are automatically made available as SFXFMODEvent track
  43. /// datablock instances. Each event object is automatically named by substituting
  44. /// the slashes in its fully qualified name with underscores and preprending the project
  45. /// name to this; event 'group1/group2/event' in the SFXFMODProject instance called
  46. /// 'project', for example, will be available as a TorqueScript object called
  47. /// 'project_group1_group2_event'.
  48. ///
  49. /// This class also works in a client-server environment where the server is
  50. /// not running FMOD. The event objects are cached in an auto-generated TorqueScript
  51. /// file alongside the .fev project file (x/y.fev -> x/y.fev.cs) which, when available
  52. /// and up-to-date, does not require FMOD for the server-side objects to correctly
  53. /// initialize.
  54. ///
  55. /// To establish good loading behavior and for good memory management, it is necessary to
  56. /// wisely distribute events to groups and to manually pre-load groups. The best solution
  57. /// probably is to have one group of common events that is loaded during game startup and
  58. /// then have one event group for each level in the game that is only loaded for the
  59. /// duration of its particular level.
  60. ///
  61. /// SFXFMODProject will propagate it's networking model to all its contents. This means
  62. /// that if the project is a non-networked datablock, then all event groups, events, and
  63. /// descriptions contained in the project will also be non-networked datablocks.
  64. ///
  65. /// It usually makes the most sense to use non-networked ("client-only") datablocks as
  66. /// otherwise the FMOD datablocks will be purged on each mission load.
  67. ///
  68. /// @note Only one project's music data can ever be loaded at any one time.
  69. /// Usually you wouldn't want more than a single SFXFMODProject instance in your game
  70. /// data. Also, only a single media path can be set through the designer API so when
  71. /// loading multiple projects, note that each project will set the media path to its
  72. /// own directory. For data loading to work, all project thus need to be placed in
  73. /// the same directory.
  74. ///
  75. class SFXFMODProject : public SimDataBlock
  76. {
  77. public:
  78. typedef SimDataBlock Parent;
  79. friend class SFXFMODEventGroup; // _addGroup
  80. friend class SFXFMODEvent; // _addEvent
  81. protected:
  82. ///
  83. String mFileName;
  84. ///
  85. String mMediaPath;
  86. ///
  87. SFXFMODEventGroup* mRootGroups;
  88. /// A flat list of all the groups in this projet.
  89. Vector< SFXFMODEventGroup* > mGroups;
  90. /// A flat list of all the events in the project.
  91. Vector< SFXFMODEvent* > mEvents;
  92. ///
  93. FMOD_EVENTPROJECT* mHandle;
  94. ///
  95. void _onSystemEvent( SFXSystemEventType event );
  96. ///
  97. void _clear();
  98. ///
  99. bool _load();
  100. ///
  101. void _addEvent( SFXFMODEvent* event );
  102. ///
  103. void _addGroup( SFXFMODEventGroup* group );
  104. ///
  105. void _removeEvent( SFXFMODEvent* event );
  106. ///
  107. void _removeGroup( SFXFMODEventGroup* group );
  108. public:
  109. ///
  110. SFXFMODProject();
  111. virtual ~SFXFMODProject();
  112. ///
  113. void acquire( bool recursive = false );
  114. ///
  115. void release();
  116. ///
  117. const String& getFileName() const { return mFileName; }
  118. // SimDataBlock.
  119. virtual bool onAdd();
  120. virtual void onRemove();
  121. virtual bool preload( bool server, String& errorStr );
  122. virtual void packData( BitStream* stream );
  123. virtual void unpackData( BitStream* stream );
  124. static void initPersistFields();
  125. DECLARE_CONOBJECT( SFXFMODProject );
  126. DECLARE_CATEGORY( "SFX FMOD" );
  127. DECLARE_DESCRIPTION( "An FMOD Designer project." );
  128. };
  129. #endif // !_SFXFMODPROJECT_H_