sfxState.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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 _SFXSTATE_H_
  23. #define _SFXSTATE_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 _SFXCOMMON_H_
  34. #include "sfx/sfxCommon.h"
  35. #endif
  36. /// A boolean switch used to modify playlist behavior.
  37. ///
  38. class SFXState : public SimDataBlock
  39. {
  40. public:
  41. typedef SimDataBlock Parent;
  42. enum
  43. {
  44. MaxIncludedStates = 4,
  45. MaxExcludedStates = 4
  46. };
  47. protected:
  48. /// Reference count for activation.
  49. U32 mActiveCount;
  50. /// Reference count for disabling.
  51. U32 mDisableCount;
  52. /// States that will be activated when this state is activated.
  53. SFXState* mIncludedStates[ MaxIncludedStates ];
  54. /// States that will be disabled when this state is activated.
  55. SFXState* mExcludedStates[ MaxExcludedStates ];
  56. /// Call when state has become active.
  57. void _onActivate();
  58. /// Call when state has gone back to being deactive.
  59. void _onDeactivate();
  60. /// @name Callbacks
  61. /// @{
  62. DECLARE_CALLBACK( void, onActivate, () );
  63. DECLARE_CALLBACK( void, onDeactivate, () );
  64. /// @}
  65. public:
  66. ///
  67. SFXState();
  68. /// Return true if the state is currently active (activated and not disabled).
  69. bool isActive() const { return ( !isDisabled() && mActiveCount > 0 ); }
  70. /// Return true if the state is currently disabled.
  71. bool isDisabled() const { return ( mDisableCount > 0 ); }
  72. /// Activate this state. activate/deactivate calls balance each other.
  73. /// Activating a disabled state will not make it active.
  74. void activate();
  75. ///
  76. void deactivate();
  77. /// Re-enable this state.
  78. void enable();
  79. /// Disable this state so that it cannot be activated. This is used
  80. /// by state exclusion.
  81. void disable();
  82. // SimDataBlock.
  83. virtual bool onAdd();
  84. virtual bool preload( bool server, String& errorStr );
  85. virtual void packData( BitStream* stream );
  86. virtual void unpackData( BitStream* stream );
  87. static void initPersistFields();
  88. DECLARE_CONOBJECT( SFXState );
  89. DECLARE_CATEGORY( "SFX" );
  90. DECLARE_DESCRIPTION( "A datablock describing a particular state for the SFX system." );
  91. };
  92. #endif // !_SFXSTATE_H_