sfxState.h

Engine/source/sfx/sfxState.h

More...

Classes:

class

A boolean switch used to modify playlist behavior.

Detailed Description

  1
  2//-----------------------------------------------------------------------------
  3// Copyright (c) 2012 GarageGames, LLC
  4//
  5// Permission is hereby granted, free of charge, to any person obtaining a copy
  6// of this software and associated documentation files (the "Software"), to
  7// deal in the Software without restriction, including without limitation the
  8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  9// sell copies of the Software, and to permit persons to whom the Software is
 10// furnished to do so, subject to the following conditions:
 11//
 12// The above copyright notice and this permission notice shall be included in
 13// all copies or substantial portions of the Software.
 14//
 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 21// IN THE SOFTWARE.
 22//-----------------------------------------------------------------------------
 23
 24#ifndef _SFXSTATE_H_
 25#define _SFXSTATE_H_
 26
 27#ifndef _SIMDATABLOCK_H_
 28   #include "console/simDatablock.h"
 29#endif
 30#ifndef _CONSOLETYPES_H_
 31   #include "console/consoleTypes.h"
 32#endif
 33#ifndef _TVECTOR_H_
 34   #include "core/util/tVector.h"
 35#endif
 36#ifndef _SFXCOMMON_H_
 37   #include "sfx/sfxCommon.h"
 38#endif
 39
 40
 41/// A boolean switch used to modify playlist behavior.
 42///
 43class SFXState : public SimDataBlock
 44{
 45   public:
 46   
 47      typedef SimDataBlock Parent;
 48      
 49      enum
 50      {
 51         MaxIncludedStates = 4,
 52         MaxExcludedStates = 4
 53      };
 54      
 55   protected:
 56   
 57      /// Reference count for activation.
 58      U32 mActiveCount;
 59      
 60      /// Reference count for disabling.
 61      U32 mDisableCount;
 62      
 63      /// States that will be activated when this state is activated.
 64      SFXState* mIncludedStates[ MaxIncludedStates ];
 65   
 66      /// States that will be disabled when this state is activated.
 67      SFXState* mExcludedStates[ MaxExcludedStates ];
 68                  
 69      /// Call when state has become active.
 70      void _onActivate();
 71      
 72      /// Call when state has gone back to being deactive.
 73      void _onDeactivate();
 74      
 75      /// @name Callbacks
 76      /// @{
 77      
 78      DECLARE_CALLBACK( void, onActivate, () );
 79      DECLARE_CALLBACK( void, onDeactivate, () );
 80      
 81      /// @}
 82      
 83   public:
 84   
 85      ///
 86      SFXState();
 87      
 88      /// Return true if the state is currently active (activated and not disabled).
 89      bool isActive() const { return ( !isDisabled() && mActiveCount > 0 ); }
 90      
 91      /// Return true if the state is currently disabled.
 92      bool isDisabled() const { return ( mDisableCount > 0 ); }
 93      
 94      /// Activate this state.  activate/deactivate calls balance each other.
 95      /// Activating a disabled state will not make it active.
 96      void activate();
 97      
 98      ///
 99      void deactivate();
100      
101      /// Re-enable this state.
102      void enable();
103      
104      /// Disable this state so that it cannot be activated.  This is used
105      /// by state exclusion.
106      void disable();
107      
108      // SimDataBlock.
109      virtual bool onAdd();
110      virtual bool preload( bool server, String& errorStr );
111      virtual void packData( BitStream* stream );
112      virtual void unpackData( BitStream* stream );
113      
114      static void initPersistFields();
115   
116      DECLARE_CONOBJECT( SFXState );
117      DECLARE_CATEGORY( "SFX" );
118      DECLARE_DESCRIPTION( "A datablock describing a particular state for the SFX system." );
119};
120
121#endif // !_SFXSTATE_H_
122