sfxState.cpp

Engine/source/sfx/sfxState.cpp

More...

Public Functions

ConsoleDocClass(SFXState , "@brief A boolean switch used <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> modify playlist <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">behavior.\n\n</a>" "Sound system states are used <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> allow playlist controllers <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> make decisions based on global state. This is useful, <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> " " example, <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> couple audio playback <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> gameplay state. Certain states may, <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> example, represent different locations that the " "listener can be in, like underwater, in open space, or indoors. Other states could represent moods of the current gameplay " " situation, like , <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> example, an aggressive mood during <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">combat.\n\n</a>" "By activating and deactivating sound states according <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> gameplay state, <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> set of concurrently running playlists may " "react and adapt <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> changes in the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">game.\n\n</a>" " @section SFXState_activation Activation and <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">Deactivation\n</a>" "At any time, <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> given state can be either active or inactive. Calling activate() on <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> state increases an internal " "counter and calling deactivate() decreases the counter. Only when the <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1ad43c3812e6d13e0518d9f8b8f463ffcf">count</a> reaches zero will the state be " "<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">deactivated.\n\n</a>" "In addition <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> the activation count, states also maintain <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> disabling count. Calling disable() increases this <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1ad43c3812e6d13e0518d9f8b8f463ffcf">count</a> " "and calling enable() decreases it. As long as this <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1ad43c3812e6d13e0518d9f8b8f463ffcf">count</a> is greater than zero, <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> given state will not be activated " "even <a href="/coding/file/tsmeshintrinsics_8cpp/#tsmeshintrinsics_8cpp_1a4e4fa7e3399708e0777b5308db01278c">if</a> its activation <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1ad43c3812e6d13e0518d9f8b8f463ffcf">count</a> is non-zero. Calling disable() on an active state will not only increase the disabling " "<a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1ad43c3812e6d13e0518d9f8b8f463ffcf">count</a> but also deactivate the state. Calling enable() on <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> state with <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> positive activation <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1ad43c3812e6d13e0518d9f8b8f463ffcf">count</a> will re-activate " "the state when the disabling <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1ad43c3812e6d13e0518d9f8b8f463ffcf">count</a> reaches <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">zero.\n\n</a>" " @section SFXState_dependencies State <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">Dependencies\n</a>" "By listing other states in in its #includedStates and #excludedStates fields, <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> state may automatically trigger the " "activation or disabling of other states in the sytem when it is activated. This allows <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> form dependency chains " "between individual <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">states.\n\n</a>" " @<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">tsexample\n</a>" "//State indicating that the listener is <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">submerged.\n</a>" "singleton <a href="/coding/class/classsfxstate/">SFXState</a>(AudioLocationUnderwater)\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "{\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " parentGroup=AudioLocation;\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "//AudioStateExclusive is <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> class defined in the core scripts that will <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">automatically\n</a>" "//ensure <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> state <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> deactivate all the sibling SFXStates in its parentGroup when <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">it\n</a>" "//is <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">activated.\n</a>" " className=\"AudioStateExclusive\";\n" "};\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "// State suitable e.g. <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">combat.\n</a>" "singleton <a href="/coding/class/classsfxstate/">SFXState</a>( AudioMoodAggressive )\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "{\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "   parentGroup = AudioMood;\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "   className = \"AudioStateExclusive\";\n" "};\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "@<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">endtsexample\n\n</a>" "@see <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">SFXPlayList\n</a>" "@see <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">SFXController\n</a>" "@see <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">SFXPlayList::state\n</a>" "@see <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">SFXPlayList::stateMode\n\n</a>" "@ref <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">SFX_interactive\n\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">SFX\n</a>" "@ingroup Datablocks" )
DefineEngineFunction(sfxGetActiveStates , const char * , () , "Return <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> newline-separated list of all active <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">states.\n</a>" "@return A list of the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">form\n</a>" "@<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">verbatim\n</a>" "stateName1 NL stateName2 NL stateName3 ...\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "@<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">endverbatim\n</a>" "where each element is the name of an active state <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">object.\n\n</a>" "@<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">tsexample\n</a>" "// Disable all active <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">states.\n</a>" "foreach$( %state in sfxGetActiveStates() )\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " %state.disable();\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "@<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">endtsexample\n\n</a>" "@ingroup <a href="/coding/file/sfxsystem_8h/#sfxsystem_8h_1a52e87f85ae30be82ffefd31b5c03e03d">SFX</a>" )
DefineEngineMethod(SFXState , activate , void , () , "Increase the activation <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1ad43c3812e6d13e0518d9f8b8f463ffcf">count</a> on the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">state.\n</a>" "If the state isn'<a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1aded116371789db1fd63c90ef00c95a3d">t</a> already active and it is not disabled, the state will be <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">activated.\n</a>" " @see <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">isActive\n</a>" " @see <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">deactivate\n</a>" )
DefineEngineMethod(SFXState , deactivate , void , () , "Decrease the activation <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1ad43c3812e6d13e0518d9f8b8f463ffcf">count</a> on the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">state.\n</a>" "If the <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1ad43c3812e6d13e0518d9f8b8f463ffcf">count</a> reaches zero and the state was not disabled, the state will be <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">deactivated.\n</a>" " @see <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">isActive\n</a>" " @see <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">activate\n</a>" )
DefineEngineMethod(SFXState , disable , void , () , "Increase the disabling <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1ad43c3812e6d13e0518d9f8b8f463ffcf">count</a> of the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">state.\n</a>" "If the state is currently active, it will be <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">deactivated.\n</a>" " @see <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">isDisabled\n</a>" )
DefineEngineMethod(SFXState , enable , void , () , "Decrease the disabling <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1ad43c3812e6d13e0518d9f8b8f463ffcf">count</a> of the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">state.\n</a>" "If the disabling <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1ad43c3812e6d13e0518d9f8b8f463ffcf">count</a> reaches zero <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a0e48c1f64b558d03d870367324920354">while</a> the activation <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1ad43c3812e6d13e0518d9f8b8f463ffcf">count</a> is still non- zero, " "the state will be reactivated <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">again.\n</a>" " @see <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">isDisabled\n</a>" )
DefineEngineMethod(SFXState , isActive , bool , () , "Test whether the state is currently <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">active.\n</a>" "This is true when the activation <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1ad43c3812e6d13e0518d9f8b8f463ffcf">count</a> is)
DefineEngineMethod(SFXState , isDisabled , bool , () , "Test whether the state is currently <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">disabled.\n</a>" "This is true when the disabling <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1ad43c3812e6d13e0518d9f8b8f463ffcf">count</a> of the state is non-<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">zero.\n</a>" "@return True <a href="/coding/file/tsmeshintrinsics_8cpp/#tsmeshintrinsics_8cpp_1a4e4fa7e3399708e0777b5308db01278c">if</a> the state is <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">disabled.\n\n</a>" "@see <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">disable\n</a>" )
IMPLEMENT_CALLBACK(SFXState , onActivate , void , () , () , "Called when the state goes from inactive <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> active." )
IMPLEMENT_CALLBACK(SFXState , onDeactivate , void , () , () , "called when the state goes from active <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> deactive." )
sgActiveStates(__FILE__ , __LINE__ )

Detailed Description

Public Functions

ConsoleDocClass(SFXState , "@brief A boolean switch used <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> modify playlist <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">behavior.\n\n</a>" "Sound system states are used <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> allow playlist controllers <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> make decisions based on global state. This is useful, <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> " " example, <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> couple audio playback <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> gameplay state. Certain states may, <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> example, represent different locations that the " "listener can be in, like underwater, in open space, or indoors. Other states could represent moods of the current gameplay " " situation, like , <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> example, an aggressive mood during <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">combat.\n\n</a>" "By activating and deactivating sound states according <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> gameplay state, <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> set of concurrently running playlists may " "react and adapt <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> changes in the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">game.\n\n</a>" " @section SFXState_activation Activation and <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">Deactivation\n</a>" "At any time, <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> given state can be either active or inactive. Calling activate() on <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> state increases an internal " "counter and calling deactivate() decreases the counter. Only when the <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1ad43c3812e6d13e0518d9f8b8f463ffcf">count</a> reaches zero will the state be " "<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">deactivated.\n\n</a>" "In addition <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> the activation count, states also maintain <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> disabling count. Calling disable() increases this <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1ad43c3812e6d13e0518d9f8b8f463ffcf">count</a> " "and calling enable() decreases it. As long as this <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1ad43c3812e6d13e0518d9f8b8f463ffcf">count</a> is greater than zero, <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> given state will not be activated " "even <a href="/coding/file/tsmeshintrinsics_8cpp/#tsmeshintrinsics_8cpp_1a4e4fa7e3399708e0777b5308db01278c">if</a> its activation <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1ad43c3812e6d13e0518d9f8b8f463ffcf">count</a> is non-zero. Calling disable() on an active state will not only increase the disabling " "<a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1ad43c3812e6d13e0518d9f8b8f463ffcf">count</a> but also deactivate the state. Calling enable() on <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> state with <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> positive activation <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1ad43c3812e6d13e0518d9f8b8f463ffcf">count</a> will re-activate " "the state when the disabling <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1ad43c3812e6d13e0518d9f8b8f463ffcf">count</a> reaches <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">zero.\n\n</a>" " @section SFXState_dependencies State <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">Dependencies\n</a>" "By listing other states in in its #includedStates and #excludedStates fields, <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> state may automatically trigger the " "activation or disabling of other states in the sytem when it is activated. This allows <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> form dependency chains " "between individual <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">states.\n\n</a>" " @<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">tsexample\n</a>" "//State indicating that the listener is <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">submerged.\n</a>" "singleton <a href="/coding/class/classsfxstate/">SFXState</a>(AudioLocationUnderwater)\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "{\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " parentGroup=AudioLocation;\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "//AudioStateExclusive is <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> class defined in the core scripts that will <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">automatically\n</a>" "//ensure <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> state <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> deactivate all the sibling SFXStates in its parentGroup when <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">it\n</a>" "//is <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">activated.\n</a>" " className=\"AudioStateExclusive\";\n" "};\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "// State suitable e.g. <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">combat.\n</a>" "singleton <a href="/coding/class/classsfxstate/">SFXState</a>( AudioMoodAggressive )\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "{\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "   parentGroup = AudioMood;\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "   className = \"AudioStateExclusive\";\n" "};\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "@<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">endtsexample\n\n</a>" "@see <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">SFXPlayList\n</a>" "@see <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">SFXController\n</a>" "@see <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">SFXPlayList::state\n</a>" "@see <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">SFXPlayList::stateMode\n\n</a>" "@ref <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">SFX_interactive\n\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">SFX\n</a>" "@ingroup Datablocks" )

DefineEngineFunction(sfxGetActiveStates , const char * , () , "Return <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> newline-separated list of all active <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">states.\n</a>" "@return A list of the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">form\n</a>" "@<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">verbatim\n</a>" "stateName1 NL stateName2 NL stateName3 ...\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "@<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">endverbatim\n</a>" "where each element is the name of an active state <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">object.\n\n</a>" "@<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">tsexample\n</a>" "// Disable all active <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">states.\n</a>" "foreach$( %state in sfxGetActiveStates() )\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " %state.disable();\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "@<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">endtsexample\n\n</a>" "@ingroup <a href="/coding/file/sfxsystem_8h/#sfxsystem_8h_1a52e87f85ae30be82ffefd31b5c03e03d">SFX</a>" )

DefineEngineMethod(SFXState , activate , void , () , "Increase the activation <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1ad43c3812e6d13e0518d9f8b8f463ffcf">count</a> on the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">state.\n</a>" "If the state isn'<a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1aded116371789db1fd63c90ef00c95a3d">t</a> already active and it is not disabled, the state will be <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">activated.\n</a>" " @see <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">isActive\n</a>" " @see <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">deactivate\n</a>" )

DefineEngineMethod(SFXState , deactivate , void , () , "Decrease the activation <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1ad43c3812e6d13e0518d9f8b8f463ffcf">count</a> on the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">state.\n</a>" "If the <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1ad43c3812e6d13e0518d9f8b8f463ffcf">count</a> reaches zero and the state was not disabled, the state will be <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">deactivated.\n</a>" " @see <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">isActive\n</a>" " @see <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">activate\n</a>" )

DefineEngineMethod(SFXState , disable , void , () , "Increase the disabling <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1ad43c3812e6d13e0518d9f8b8f463ffcf">count</a> of the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">state.\n</a>" "If the state is currently active, it will be <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">deactivated.\n</a>" " @see <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">isDisabled\n</a>" )

DefineEngineMethod(SFXState , enable , void , () , "Decrease the disabling <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1ad43c3812e6d13e0518d9f8b8f463ffcf">count</a> of the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">state.\n</a>" "If the disabling <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1ad43c3812e6d13e0518d9f8b8f463ffcf">count</a> reaches zero <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a0e48c1f64b558d03d870367324920354">while</a> the activation <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1ad43c3812e6d13e0518d9f8b8f463ffcf">count</a> is still non- zero, " "the state will be reactivated <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">again.\n</a>" " @see <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">isDisabled\n</a>" )

DefineEngineMethod(SFXState , isActive , bool , () , "Test whether the state is currently <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">active.\n</a>" "This is true when the activation <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1ad43c3812e6d13e0518d9f8b8f463ffcf">count</a> is)

DefineEngineMethod(SFXState , isDisabled , bool , () , "Test whether the state is currently <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">disabled.\n</a>" "This is true when the disabling <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1ad43c3812e6d13e0518d9f8b8f463ffcf">count</a> of the state is non-<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">zero.\n</a>" "@return True <a href="/coding/file/tsmeshintrinsics_8cpp/#tsmeshintrinsics_8cpp_1a4e4fa7e3399708e0777b5308db01278c">if</a> the state is <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">disabled.\n\n</a>" "@see <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">disable\n</a>" )

IMPLEMENT_CALLBACK(SFXState , onActivate , void , () , () , "Called when the state goes from inactive <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> active." )

IMPLEMENT_CALLBACK(SFXState , onDeactivate , void , () , () , "called when the state goes from active <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> deactive." )

IMPLEMENT_CO_DATABLOCK_V1(SFXState )

sgActiveStates(__FILE__ , __LINE__ )

  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#include "sfx/sfxState.h"
 25#include "sfx/sfxTypes.h"
 26#include "core/stream/bitStream.h"
 27#include "console/engineAPI.h"
 28
 29
 30//#define DEBUG_SPEW
 31
 32
 33IMPLEMENT_CO_DATABLOCK_V1( SFXState );
 34
 35
 36ConsoleDocClass( SFXState,
 37   "@brief A boolean switch used to modify playlist behavior.\n\n"
 38   
 39   "Sound system states are used to allow playlist controllers to make decisions based on global state.  This is useful, for "
 40   "example, to couple audio playback to gameplay state.  Certain states may, for example, represent different locations that the "
 41   "listener can be in, like underwater, in open space, or indoors.  Other states could represent moods of the current gameplay "
 42   "situation, like, for example, an aggressive mood during combat.\n\n"
 43   
 44   "By activating and deactivating sound states according to gameplay state, a set of concurrently running playlists may "
 45   "react and adapt to changes in the game.\n\n"
 46   
 47   "@section SFXState_activation Activation and Deactivation\n"
 48   
 49   "At any time, a given state can be either active or inactive.  Calling activate() on a state increases an internal "
 50   "counter and calling deactivate() decreases the counter.  Only when the count reaches zero will the state be "
 51   "deactivated.\n\n"
 52   
 53   "In addition to the activation count, states also maintain a disabling count.  Calling disable() increases this count "
 54   "and calling enable() decreases it.  As long as this count is greater than zero, a given state will not be activated "
 55   "even if its activation count is non-zero.  Calling disable() on an active state will not only increase the disabling "
 56   "count but also deactivate the state.  Calling enable() on a state with a positive activation count will re-activate "
 57   "the state when the disabling count reaches zero.\n\n"
 58   
 59   "@section SFXState_dependencies State Dependencies\n"
 60   
 61   "By listing other states in in its #includedStates and #excludedStates fields, a state may automatically trigger the "
 62   "activation or disabling of other states in the sytem when it is activated.  This allows to form dependency chains "
 63   "between individual states.\n\n"
 64   
 65   "@tsexample\n"
 66   "// State indicating that the listener is submerged.\n"
 67   "singleton SFXState( AudioLocationUnderwater )\n"
 68   "{\n"
 69   "   parentGroup = AudioLocation;\n"
 70   "   // AudioStateExclusive is a class defined in the core scripts that will automatically\n"
 71   "   // ensure for a state to deactivate all the sibling SFXStates in its parentGroup when it\n"
 72   "   // is activated.\n"
 73   "   className = \"AudioStateExclusive\";\n"
 74   "};\n"
 75   "\n"
 76   "// State suitable e.g. for combat.\n"
 77   "singleton SFXState( AudioMoodAggressive )\n"
 78   "{\n"
 79   "   parentGroup = AudioMood;\n"
 80   "   className = \"AudioStateExclusive\";\n"
 81   "};\n"
 82   "@endtsexample\n\n"
 83   
 84   "@see SFXPlayList\n"
 85   "@see SFXController\n"
 86   "@see SFXPlayList::state\n"
 87   "@see SFXPlayList::stateMode\n\n"
 88   "@ref SFX_interactive\n\n"
 89   
 90   "@ingroup SFX\n"
 91   "@ingroup Datablocks"
 92);
 93
 94
 95IMPLEMENT_CALLBACK( SFXState, onActivate, void, (), (),
 96   "Called when the state goes from inactive to active." );
 97IMPLEMENT_CALLBACK( SFXState, onDeactivate, void, (), (),
 98   "called when the state goes from active to deactive." );
 99   
100
101static Vector< SFXState*> sgActiveStates( __FILE__, __LINE__ );
102
103
104//-----------------------------------------------------------------------------
105
106SFXState::SFXState()
107   : mActiveCount( 0 ),
108     mDisableCount( 0 )
109{
110   dMemset( mIncludedStates, 0, sizeof( mIncludedStates ) );
111   dMemset( mExcludedStates, 0, sizeof( mExcludedStates ) );
112}
113
114//-----------------------------------------------------------------------------
115
116void SFXState::initPersistFields()
117{
118   addGroup( "State" );
119   
120      addField( "includedStates", TypeSFXStateName, Offset( mIncludedStates, SFXState ),
121         MaxIncludedStates,
122         "States that will automatically be activated when this state is activated.\n\n"
123         "@ref SFXState_activation" );
124      addField( "excludedStates", TypeSFXStateName, Offset( mExcludedStates, SFXState ),
125         MaxExcludedStates,
126         "States that will automatically be disabled when this state is activated.\n\n"
127         "@ref SFXState_activation" );
128   
129   endGroup( "State" );
130   
131   Parent::initPersistFields();
132}
133
134//-----------------------------------------------------------------------------
135
136void SFXState::activate()
137{
138   mActiveCount ++;
139   if( mActiveCount == 1 && !isDisabled() )
140      _onActivate();  
141}
142
143//-----------------------------------------------------------------------------
144
145void SFXState::deactivate()
146{
147   if( !mActiveCount )
148      return;
149      
150   mActiveCount --;
151   if( !mActiveCount && !isDisabled() )
152      _onDeactivate();
153}
154
155//-----------------------------------------------------------------------------
156
157void SFXState::enable()
158{
159   if( !mDisableCount )
160      return;
161      
162   mDisableCount --;
163   
164   if( !mDisableCount && mActiveCount > 0 )
165      _onActivate();
166}
167
168//-----------------------------------------------------------------------------
169
170void SFXState::disable()
171{
172   mDisableCount ++;
173   
174   if( mDisableCount == 1 && mActiveCount > 0 )
175      _onDeactivate();
176}
177
178//-----------------------------------------------------------------------------
179
180bool SFXState::onAdd()
181{
182   if( !Parent::onAdd() )
183      return false;
184
185   Sim::getSFXStateSet()->addObject( this );
186      
187   return true;
188}
189
190//-----------------------------------------------------------------------------
191
192bool SFXState::preload( bool server, String& errorStr )
193{
194   if( !Parent::preload( server, errorStr ) )
195      return false;
196
197   if( !server )
198   {
199      for( U32 i = 0; i < MaxIncludedStates; ++ i )
200         if( !sfxResolve( &mIncludedStates[ i ], errorStr ) )
201            return false;
202         
203      for( U32 i = 0; i < MaxExcludedStates; ++ i )
204         if( !sfxResolve( &mExcludedStates[ i ], errorStr ) )
205            return false;
206   }
207            
208   return true;
209}
210
211//-----------------------------------------------------------------------------
212
213void SFXState::packData( BitStream* stream )
214{
215   Parent::packData( stream );
216      
217   for( U32 i = 0; i < MaxIncludedStates; ++ i )
218      sfxWrite( stream, mIncludedStates[ i ] );
219   for( U32 i = 0; i < MaxExcludedStates; ++ i )
220      sfxWrite( stream, mExcludedStates[ i ] );
221}
222
223//-----------------------------------------------------------------------------
224
225void SFXState::unpackData( BitStream* stream )
226{
227   Parent::unpackData( stream );
228   
229   for( U32 i = 0; i < MaxIncludedStates; ++ i )
230      sfxRead( stream, &mIncludedStates[ i ] );
231   for( U32 i = 0; i < MaxExcludedStates; ++ i )
232      sfxRead( stream, &mExcludedStates[ i ] );
233}
234
235//-----------------------------------------------------------------------------
236
237void SFXState::_onActivate()
238{
239   #ifdef DEBUG_SPEW
240   Platform::outputDebugString( "[SFXState] Activating '%s'", getName() );
241   #endif
242   
243   onActivate_callback();
244      
245   // Add the state to the list.
246      
247   sgActiveStates.push_back( this );
248
249   // Activate included states.
250      
251   for( U32 i = 0; i < MaxIncludedStates; ++ i )
252      if( mIncludedStates[ i ] )
253         mIncludedStates[ i ]->activate();
254         
255   // Disable excluded states.
256         
257   for( U32 i = 0; i < MaxExcludedStates; ++ i )
258      if( mExcludedStates[ i ] )
259         mExcludedStates[ i ]->disable();
260}
261
262//-----------------------------------------------------------------------------
263
264void SFXState::_onDeactivate()
265{
266   #ifdef DEBUG_SPEW
267   Platform::outputDebugString( "[SFXState] Deactivating '%s'", getName() );
268   #endif
269
270   onDeactivate_callback();
271      
272   // Remove the state from the list.
273      
274   for( U32 i = 0; i < sgActiveStates.size(); ++ i )
275      if( sgActiveStates[ i ] == this )
276      {
277         sgActiveStates.erase_fast( i );
278         break;
279      }
280
281   // Deactivate included states.
282      
283   for( U32 i = 0; i < MaxIncludedStates; ++ i )
284      if( mIncludedStates[ i ] )
285         mIncludedStates[ i ]->deactivate();
286         
287   // Enable excluded states.
288         
289   for( U32 i = 0; i < MaxExcludedStates; ++ i )
290      if( mExcludedStates[ i ] )
291         mExcludedStates[ i ]->enable();
292}
293
294//=============================================================================
295//    Console Methods.
296//=============================================================================
297// MARK: ---- Console Methods ----
298
299//-----------------------------------------------------------------------------
300
301DefineEngineMethod( SFXState, isActive, bool, (),,
302   "Test whether the state is currently active.\n"
303   "This is true when the activation count is >0 and the disabling count is =0.\n"
304   "@return True if the state is currently active.\n"
305   "@see activate" )
306{
307   return object->isActive();
308}
309
310//-----------------------------------------------------------------------------
311
312DefineEngineMethod( SFXState, activate, void, (),,
313   "Increase the activation count on the state.\n"
314   "If the state isn't already active and it is not disabled, the state will be activated.\n"
315   "@see isActive\n"
316   "@see deactivate\n" )
317{
318   object->activate();
319}
320
321//-----------------------------------------------------------------------------
322
323DefineEngineMethod( SFXState, deactivate, void, (),,
324   "Decrease the activation count on the state.\n"
325   "If the count reaches zero and the state was not disabled, the state will be deactivated.\n"
326   "@see isActive\n"
327   "@see activate\n" )
328{
329   object->deactivate();
330}
331
332//-----------------------------------------------------------------------------
333
334DefineEngineMethod( SFXState, isDisabled, bool, (),,
335   "Test whether the state is currently disabled.\n"
336   "This is true when the disabling count of the state is non-zero.\n"
337   "@return True if the state is disabled.\n\n"
338   "@see disable\n" )
339{
340   return object->isDisabled();
341}
342
343//-----------------------------------------------------------------------------
344
345DefineEngineMethod( SFXState, disable, void, (),,
346   "Increase the disabling count of the state.\n"
347   "If the state is currently active, it will be deactivated.\n"
348   "@see isDisabled\n" )
349{
350   object->disable();
351}
352
353//-----------------------------------------------------------------------------
354
355DefineEngineMethod( SFXState, enable, void, (),,
356   "Decrease the disabling count of the state.\n"
357   "If the disabling count reaches zero while the activation count is still non-zero, "
358      "the state will be reactivated again.\n"
359   "@see isDisabled\n" )
360{
361   object->enable();
362}
363
364//=============================================================================
365//    Console Functions.
366//=============================================================================
367// MARK: ---- Console Functions ----
368
369//-----------------------------------------------------------------------------
370
371DefineEngineFunction( sfxGetActiveStates, const char*, (),,
372   "Return a newline-separated list of all active states.\n"
373   "@return A list of the form\n"
374   "@verbatim\n"
375      "stateName1 NL stateName2 NL stateName3 ...\n"
376   "@endverbatim\n"
377   "where each element is the name of an active state object.\n\n"
378   "@tsexample\n"
379      "// Disable all active states.\n"
380      "foreach$( %state in sfxGetActiveStates() )\n"
381      "   %state.disable();\n"
382   "@endtsexample\n\n"
383   "@ingroup SFX" )
384{
385   StringBuilder str;
386   
387   bool isFirst = true;
388   for( U32 i = 0; i < sgActiveStates.size(); ++ i )
389   {
390      if( !isFirst )
391         str.append( ' ' );
392         
393      str.append( sgActiveStates[ i ]->getName() );
394      isFirst = false;
395   }
396   
397   return Con::getReturnBuffer( str );
398}
399