sfxController.h
Engine/source/sfx/sfxController.h
Classes:
class
SFXSource that drives multi-source playback.
class
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 _SFXCONTROLLER_H_ 25#define _SFXCONTROLLER_H_ 26 27#ifndef _SFXSOURCE_H_ 28 #include "sfx/sfxSource.h" 29#endif 30#ifndef _SFXCOMMON_H_ 31 #include "sfx/sfxCommon.h" 32#endif 33#ifndef _SFXSOURCE_H_ 34 #include "sfx/sfxSource.h" 35#endif 36#ifndef _SFXPLAYLIST_H_ 37 #include "sfx/sfxPlayList.h" 38#endif 39#ifndef _TVECTOR_H_ 40 #include "core/util/tVector.h" 41#endif 42 43 44class SFXTrack; 45class SFXProfile; 46class SFXState; 47 48 49/// SFXSource that drives multi-source playback. 50/// 51/// Basically, this class is an interpreter for the instruction slots in 52/// SFXPlayLists. 53/// 54/// Controllers can be switched between states. When no state is set, all 55/// tracks from playlists that do not have a state set will be played. When 56/// setting a state, only tracks with the given state will be played. If 57/// currently tracks with a different state are playing, the respective 58/// controllers will transition out of their respective slots. 59/// 60class SFXController : public SFXSource 61{ 62 public: 63 64 typedef SFXSource Parent; 65 friend class SFXSystem; // _create 66 67 protected: 68 69 typedef SFXVariantFloat< 1> VariantFloat; 70 71 enum EOp 72 { 73 OP_Delay, 74 OP_WaitSingle, 75 OP_WaitAll, 76 OP_StopSingle, 77 OP_StopAll, 78 OP_Play, 79 OP_Jump, 80 OP_LoopBegin, 81 OP_LoopEnd, 82 }; 83 84 struct Insn 85 { 86 EOp mOpcode; 87 U32 mSlotIndex; 88 SFXState* mState; 89 90 union 91 { 92 VariantFloat mDelayTime; 93 U32 mJumpIp; 94 U32 mLoopCount; 95 } mArg; 96 97 Insn() {} 98 Insn( EOp opcode ) 99 : mOpcode( opcode ), mSlotIndex( U32_MAX ), mState( NULL ) {} 100 Insn( U32 slotIndex, SFXState* state ) 101 : mSlotIndex( slotIndex ), mState( state ) {} 102 Insn( EOp opcode, U32 slotIndex, SFXState* state ) 103 : mOpcode( opcode ), mSlotIndex( slotIndex ), mState( state ) {} 104 }; 105 106 /// 107 struct Source 108 { 109 /// The play-once source. 110 SimObjectPtr< SFXSource> mPtr; 111 112 /// The state to which the source is tied. Only taken over from 113 /// the instruction if the state mode is not set to ignored. 114 SFXState* mState; 115 116 /// Index of slot in playlist that this source was spawned on. 117 U32 mSlotIndex; 118 119 /// Volume scale factor to apply to the source. Saved as it may have been 120 /// randomly generated. 121 F32 mVolumeScale; 122 123 /// Pitch scale factor to apply to the source. Saved as it may have been 124 /// randomly generated. 125 F32 mPitchScale; 126 127 /// 128 F32 mFadeInTime; 129 130 /// 131 F32 mFadeOutTime; 132 133 Source() 134 : mState( 0 ) {} 135 }; 136 137 /// The current instruction in "mInsns". 138 U32 mIp; 139 140 /// The instruction list. This is compiled from the playlist and then executed 141 /// in the controller's update. 142 Vector< Insn> mInsns; 143 144 /// The stack of currently playing sources. 145 /// 146 /// All sources on this list are play-once sources so we can leave their lifetime 147 /// management to the SFX system. This is especially convenient in combination 148 /// with fade-outs where a source cannot be immediately deleted. 149 Vector< Source> mSources; 150 151 /// 152 bool mTrace; 153 154 /// 155 U32 mDelayEndTime; 156 157 /// 158 U32 mLoopCounter; 159 160 /// 161 SFXController( SFXPlayList* playList ); 162 163 /// 164 void _printInsn( Insn& insn ); 165 166 /// 167 void _compileList( SFXPlayList* playList ); 168 169 /// 170 void _genTransition( Insn& insn, SFXPlayList::ETransitionMode transition ); 171 172 /// 173 void _dumpInsns(); 174 175 /// 176 void _initInsn(); 177 178 /// 179 bool _execInsn(); 180 181 /// 182 void _advanceIp(); 183 184 /// 185 static SFXController* _create( SFXPlayList* playList ); 186 187 // SFXSource. 188 virtual void _play(); 189 virtual void _pause(); 190 virtual void _stop(); 191 virtual void _onParameterEvent( SFXParameter* parameter, SFXParameterEvent event ); 192 virtual void _updateVolume( const MatrixF& listener ); 193 virtual void _updatePitch(); 194 virtual void _updatePriority(); 195 virtual void _update(); 196 197 public: 198 199 ~SFXController(); 200 201 /// Constructor for the sake of ConsoleObject. 202 explicit SFXController() {} 203 204 /// Return the playlist being played back by the controller. 205 SFXPlayList* getPlayList() const; 206 207 /// Return the index of the playlist slot being processed by the controller. 208 U32 getCurrentSlot() const; 209 210 /// Set the index of the playlist slot to process. 211 void setCurrentSlot( U32 index ); 212 213 // SFXSource. 214 static void initPersistFields(); 215 216 DECLARE_CONOBJECT( SFXController ); 217 DECLARE_DESCRIPTION( "Controls the playback of an SFXPlayList." ); 218}; 219 220#endif // !_SFXCONTROLLER_H_ 221 222
