2
0

sfxEmitter.cpp 42 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177
  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. #include "platform/platform.h"
  23. #include "T3D/sfx/sfxEmitter.h"
  24. #include "sfx/sfxSystem.h"
  25. #include "sfx/sfxTrack.h"
  26. #include "sfx/sfxSource.h"
  27. #include "sfx/sfxTypes.h"
  28. #include "scene/sceneRenderState.h"
  29. #include "core/stream/bitStream.h"
  30. #include "sim/netConnection.h"
  31. #include "math/mathIO.h"
  32. #include "math/mQuat.h"
  33. #include "renderInstance/renderPassManager.h"
  34. #include "gfx/gfxTransformSaver.h"
  35. #include "gfx/gfxDrawUtil.h"
  36. #include "gfx/primBuilder.h"
  37. #include "console/engineAPI.h"
  38. IMPLEMENT_CO_NETOBJECT_V1( SFXEmitter );
  39. ConsoleDocClass( SFXEmitter,
  40. "@brief An invisible 3D object that emits sound.\n\n"
  41. "Sound emitters are used to place sounds in the level. They are full 3D objects with their own position and orientation and "
  42. "when assigned 3D sounds, the transform and velocity of the sound emitter object will be applied to the 3D sound.\n\n"
  43. "Sound emitters can be set up of in either of two ways:\n"
  44. "<ul>\n"
  45. "<li><p>By assigning an existing SFXTrack to the emitter's #track property.</p>\n"
  46. "<p>In this case the general sound setup (3D, streaming, looping, etc.) will be taken from #track. However, the emitter's "
  47. "own properties will still override their corresponding properties in the #track's SFXDescription.</p></li>\n"
  48. "<li><p>By directly assigning a sound file to the emitter's #fileName property.</p>\n"
  49. "<p>In this case, the sound file will be set up for playback according to the properties defined on the emitter.</p>\n"
  50. "</ul>\n\n"
  51. "Using #playOnAdd emitters can be configured to start playing immediately when they are added to the system (e.g. when the level "
  52. "objects are loaded from the mission file).\n\n"
  53. "@note A sound emitter need not necessarily emit a 3D sound. Instead, sound emitters may also be used to play "
  54. "non-positional sounds. For placing background audio to a level, however, it is usually easier to use LevelInfo::soundAmbience.\n\n"
  55. "@section SFXEmitter_networking Sound Emitters and Networking\n\n"
  56. "It is important to be aware of the fact that sounds will only play client-side whereas SFXEmitter objects are server-side "
  57. "entities. This means that a server-side object has no connection to the actual sound playing on the client. It is thus "
  58. "not possible for the server-object to perform queries about playback status and other source-related properties as these "
  59. "may in fact differ from client to client.\n\n"
  60. "@ingroup SFX\n"
  61. );
  62. extern bool gEditingMission;
  63. bool SFXEmitter::smRenderEmitters;
  64. F32 SFXEmitter::smRenderPointSize = 0.8f;
  65. F32 SFXEmitter::smRenderRadialIncrements = 5.f;
  66. F32 SFXEmitter::smRenderSweepIncrements = 5.f;
  67. F32 SFXEmitter::smRenderPointDistance = 5.f;
  68. ColorI SFXEmitter::smRenderColorPlayingInRange( 50, 255, 50, 255 );
  69. ColorI SFXEmitter::smRenderColorPlayingOutOfRange( 50, 128, 50, 255 );
  70. ColorI SFXEmitter::smRenderColorStoppedInRange( 0, 0, 0, 255 );
  71. ColorI SFXEmitter::smRenderColorStoppedOutOfRange( 128, 128, 128, 255 );
  72. ColorI SFXEmitter::smRenderColorInnerCone( 0, 0, 255, 255 );
  73. ColorI SFXEmitter::smRenderColorOuterCone( 255, 0, 255, 255 );
  74. ColorI SFXEmitter::smRenderColorOutsideVolume( 255, 0, 0, 255 );
  75. ColorI SFXEmitter::smRenderColorRangeSphere( 200, 0, 0, 90 );
  76. //-----------------------------------------------------------------------------
  77. SFXEmitter::SFXEmitter()
  78. : SceneObject(),
  79. mSource( NULL ),
  80. mTrack( NULL ),
  81. mUseTrackDescriptionOnly( false ),
  82. mLocalProfile( &mDescription ),
  83. mPlayOnAdd( true )
  84. {
  85. mTypeMask |= MarkerObjectType;
  86. mNetFlags.set( Ghostable | ScopeAlways );
  87. mDescription.mIs3D = true;
  88. mDescription.mIsLooping = true;
  89. mDescription.mIsStreaming = false;
  90. mDescription.mFadeInTime = -1.f;
  91. mDescription.mFadeOutTime = -1.f;
  92. mLocalProfile._registerSignals();
  93. mObjBox.minExtents.set( -1.f, -1.f, -1.f );
  94. mObjBox.maxExtents.set( 1.f, 1.f, 1.f );
  95. }
  96. //-----------------------------------------------------------------------------
  97. SFXEmitter::~SFXEmitter()
  98. {
  99. mLocalProfile._unregisterSignals();
  100. if( mSource )
  101. SFX_DELETE( mSource );
  102. }
  103. //-----------------------------------------------------------------------------
  104. void SFXEmitter::consoleInit()
  105. {
  106. Con::addVariable( "$SFXEmitter::renderEmitters", TypeBool, &smRenderEmitters,
  107. "Whether to render enhanced range feedback in the editor on all emitters regardless of selection state.\n"
  108. "@ingroup SFX\n");
  109. //TODO: not implemented ATM
  110. //Con::addVariable( "$SFXEmitter::renderPointSize", TypeF32, &smRenderPointSize );
  111. Con::addVariable( "$SFXEmitter::renderPointDistance", TypeF32, &smRenderPointDistance,
  112. "The distance between individual points in the sound emitter rendering in the editor as the points move from the emitter's center away to maxDistance.\n"
  113. "@ingroup SFX\n");
  114. Con::addVariable( "$SFXEmitter::renderRadialIncrements", TypeF32, &smRenderRadialIncrements,
  115. "The stepping (in degrees) for the radial sweep along the axis of the XY plane sweep for sound emitter rendering in the editor.\n"
  116. "@ingroup SFX\n");
  117. Con::addVariable( "$SFXEmitter::renderSweepIncrements", TypeF32, &smRenderSweepIncrements,
  118. "The stepping (in degrees) for the radial sweep on the XY plane for sound emitter rendering in the editor.\n"
  119. "@ingroup SFX\n");
  120. Con::addVariable( "$SFXEmitter::renderColorPlayingInRange", TypeColorI, &smRenderColorPlayingInRange,
  121. "The color with which to render a sound emitter's marker cube in the editor when the emitter's sound is playing and in range of the listener.\n"
  122. "@ingroup SFX\n" );
  123. Con::addVariable( "$SFXEmitter::renderColorPlayingOutOfRange", TypeColorI, &smRenderColorPlayingOutOfRange,
  124. "The color with which to render a sound emitter's marker cube in the editor when the emitter's sound is playing but out of the range of the listener.\n"
  125. "@ingroup SFX\n" );
  126. Con::addVariable( "$SFXEmitter::renderColorStoppedInRange", TypeColorI, &smRenderColorStoppedInRange,
  127. "The color with which to render a sound emitter's marker cube in the editor when the emitter's sound is not playing but the emitter is in range of the listener.\n"
  128. "@ingroup SFX\n" );
  129. Con::addVariable( "$SFXEmitter::renderColorStoppedOutOfRange", TypeColorI, &smRenderColorStoppedOutOfRange,
  130. "The color with which to render a sound emitter's marker cube in the editor when the emitter's sound is not playing and the emitter is out of range of the listener.\n"
  131. "@ingroup SFX\n" );
  132. Con::addVariable( "$SFXEmitter::renderColorInnerCone", TypeColorI, &smRenderColorInnerCone,
  133. "The color with which to render dots in the inner sound cone (Editor only).\n"
  134. "@ingroup SFX\n");
  135. Con::addVariable( "$SFXEmitter::renderColorOuterCone", TypeColorI, &smRenderColorOuterCone,
  136. "The color with which to render dots in the outer sound cone (Editor only).\n"
  137. "@ingroup SFX\n" );
  138. Con::addVariable( "$SFXEmitter::renderColorOutsideVolume", TypeColorI, &smRenderColorOutsideVolume,
  139. "The color with which to render dots outside of the outer sound cone (Editor only).\n"
  140. "@ingroup SFX\n" );
  141. Con::addVariable( "$SFXEmitter::renderColorRangeSphere", TypeColorI, &smRenderColorRangeSphere,
  142. "The color of the range sphere with which to render sound emitters in the editor.\n"
  143. "@ingroup SFX\n" );
  144. }
  145. //-----------------------------------------------------------------------------
  146. void SFXEmitter::initPersistFields()
  147. {
  148. addGroup( "Media" );
  149. addField( "track", TypeSFXTrackName, Offset( mTrack, SFXEmitter),
  150. "The track which the emitter should play.\n"
  151. "@note If assigned, this field will take precedence over a #fileName that may also be assigned to the "
  152. "emitter." );
  153. addField( "fileName", TypeStringFilename, Offset( mLocalProfile.mFilename, SFXEmitter),
  154. "The sound file to play.\n"
  155. "Use @b either this property @b or #track. If both are assigned, #track takes precendence. The primary purpose of this "
  156. "field is to avoid the need for the user to define SFXTrack datablocks for all sounds used in a level." );
  157. endGroup( "Media");
  158. addGroup( "Sound" );
  159. addField( "playOnAdd", TypeBool, Offset( mPlayOnAdd, SFXEmitter ),
  160. "Whether playback of the emitter's sound should start as soon as the emitter object is added to the level.\n"
  161. "If this is true, the emitter will immediately start to play when the level is loaded." );
  162. addField( "useTrackDescriptionOnly", TypeBool, Offset( mUseTrackDescriptionOnly, SFXEmitter ),
  163. "If this is true, all fields except for #playOnAdd and #track are ignored on the emitter object.\n"
  164. "This is useful to prevent fields in the #track's description from being overridden by emitter fields." );
  165. addField( "isLooping", TypeBool, Offset( mDescription.mIsLooping, SFXEmitter ),
  166. "Whether to play #fileName in an infinite loop.\n"
  167. "If a #track is assigned, the value of this field is ignored.\n"
  168. "@see SFXDescription::isLooping" );
  169. addField( "isStreaming", TypeBool, Offset( mDescription.mIsStreaming, SFXEmitter ),
  170. "Whether to use streamed playback for #fileName.\n"
  171. "If a #track is assigned, the value of this field is ignored.\n"
  172. "@see SFXDescription::isStreaming\n\n"
  173. "@ref SFX_streaming" );
  174. addField( "sourceGroup", TypeSFXSourceName, Offset( mDescription.mSourceGroup, SFXEmitter ),
  175. "The SFXSource to which to assign the sound of this emitter as a child.\n"
  176. "@note This field is ignored if #useTrackDescriptionOnly is true.\n\n"
  177. "@see SFXDescription::sourceGroup" );
  178. addField( "volume", TypeF32, Offset( mDescription.mVolume, SFXEmitter ),
  179. "Volume level to apply to the sound.\n"
  180. "@note This field is ignored if #useTrackDescriptionOnly is true.\n\n"
  181. "@see SFXDescription::volume" );
  182. addField( "pitch", TypeF32, Offset( mDescription.mPitch, SFXEmitter ),
  183. "Pitch shift to apply to the sound. Default is 1 = play at normal speed.\n"
  184. "@note This field is ignored if #useTrackDescriptionOnly is true.\n\n"
  185. "@see SFXDescription::pitch" );
  186. addField( "fadeInTime", TypeF32, Offset( mDescription.mFadeInTime, SFXEmitter ),
  187. "Number of seconds to gradually fade in volume from zero when playback starts.\n"
  188. "@note This field is ignored if #useTrackDescriptionOnly is true.\n\n"
  189. "@see SFXDescription::fadeInTime" );
  190. addField( "fadeOutTime", TypeF32, Offset( mDescription.mFadeOutTime, SFXEmitter ),
  191. "Number of seconds to gradually fade out volume down to zero when playback is stopped or paused.\n"
  192. "@note This field is ignored if #useTrackDescriptionOnly is true.\n\n"
  193. "@see SFXDescription::fadeOutTime" );
  194. endGroup( "Sound");
  195. addGroup( "3D Sound" );
  196. addField( "is3D", TypeBool, Offset( mDescription.mIs3D, SFXEmitter ),
  197. "Whether to play #fileName as a positional (3D) sound or not.\n"
  198. "If a #track is assigned, the value of this field is ignored.\n\n"
  199. "@see SFXDescription::is3D" );
  200. addField( "referenceDistance", TypeF32, Offset( mDescription.mMinDistance, SFXEmitter ),
  201. "Distance at which to start volume attenuation of the 3D sound.\n"
  202. "@note This field is ignored if #useTrackDescriptionOnly is true.\n\n"
  203. "@see SFXDescription::referenceDistance" );
  204. addField( "maxDistance", TypeF32, Offset( mDescription.mMaxDistance, SFXEmitter ),
  205. "Distance at which to stop volume attenuation of the 3D sound.\n"
  206. "@note This field is ignored if #useTrackDescriptionOnly is true.\n\n"
  207. "@see SFXDescription::maxDistance" );
  208. addField( "scatterDistance", TypePoint3F, Offset( mDescription.mScatterDistance, SFXEmitter ),
  209. "Bounds on random offset to apply to initial 3D sound position.\n"
  210. "@note This field is ignored if #useTrackDescriptionOnly is true.\n\n"
  211. "@see SFXDescription::scatterDistance" );
  212. addField( "coneInsideAngle", TypeS32, Offset( mDescription.mConeInsideAngle, SFXEmitter ),
  213. "Angle of inner volume cone of 3D sound in degrees.\n"
  214. "@note This field is ignored if #useTrackDescriptionOnly is true.\n\n"
  215. "@see SFXDescription::coneInsideAngle" );
  216. addField( "coneOutsideAngle", TypeS32, Offset( mDescription.mConeOutsideAngle, SFXEmitter ),
  217. "Angle of outer volume cone of 3D sound in degrees\n"
  218. "@note This field is ignored if #useTrackDescriptionOnly is true.\n\n"
  219. "@see SFXDescription::coneOutsideAngle" );
  220. addField( "coneOutsideVolume", TypeF32, Offset( mDescription.mConeOutsideVolume, SFXEmitter ),
  221. "Volume scale factor of outside of outer volume 3D sound cone.\n"
  222. "@note This field is ignored if #useTrackDescriptionOnly is true.\n\n"
  223. "@see SFXDescription::coneOutsideVolume" );
  224. endGroup( "3D Sound" );
  225. Parent::initPersistFields();
  226. }
  227. //-----------------------------------------------------------------------------
  228. U32 SFXEmitter::packUpdate( NetConnection *con, U32 mask, BitStream *stream )
  229. {
  230. U32 retMask = Parent::packUpdate( con, mask, stream );
  231. if( stream->writeFlag( mask & InitialUpdateMask ) )
  232. {
  233. // If this is the initial update then all the source
  234. // values are dirty and must be transmitted.
  235. mask |= TransformUpdateMask;
  236. mDirty = AllDirtyMask;
  237. // Clear the source masks... they are not
  238. // used during an initial update!
  239. mask &= ~AllSourceMasks;
  240. }
  241. stream->writeFlag( mPlayOnAdd );
  242. // transform
  243. if( stream->writeFlag( mask & TransformUpdateMask ) )
  244. stream->writeAffineTransform( mObjToWorld );
  245. // track
  246. if( stream->writeFlag( mDirty.test( Track ) ) )
  247. sfxWrite( stream, mTrack );
  248. // filename
  249. if( stream->writeFlag( mDirty.test( Filename ) ) )
  250. stream->writeString( mLocalProfile.mFilename );
  251. // volume
  252. if( stream->writeFlag( mDirty.test( Volume ) ) )
  253. stream->write( mDescription.mVolume );
  254. // pitch
  255. if( stream->writeFlag( mDirty.test( Pitch ) ) )
  256. stream->write( mDescription.mPitch );
  257. // islooping
  258. if( stream->writeFlag( mDirty.test( IsLooping ) ) )
  259. stream->writeFlag( mDescription.mIsLooping );
  260. // isStreaming
  261. if( stream->writeFlag( mDirty.test( IsStreaming ) ) )
  262. stream->writeFlag( mDescription.mIsStreaming );
  263. // is3d
  264. if( stream->writeFlag( mDirty.test( Is3D ) ) )
  265. stream->writeFlag( mDescription.mIs3D );
  266. // minDistance
  267. if( stream->writeFlag( mDirty.test( MinDistance ) ) )
  268. stream->write( mDescription.mMinDistance );
  269. // maxdistance
  270. if( stream->writeFlag( mDirty.test( MaxDistance) ) )
  271. stream->write( mDescription.mMaxDistance );
  272. // coneinsideangle
  273. if( stream->writeFlag( mDirty.test( ConeInsideAngle ) ) )
  274. stream->write( mDescription.mConeInsideAngle );
  275. // coneoutsideangle
  276. if( stream->writeFlag( mDirty.test( ConeOutsideAngle ) ) )
  277. stream->write( mDescription.mConeOutsideAngle );
  278. // coneoutsidevolume
  279. if( stream->writeFlag( mDirty.test( ConeOutsideVolume ) ) )
  280. stream->write( mDescription.mConeOutsideVolume );
  281. // sourcegroup
  282. if( stream->writeFlag( mDirty.test( SourceGroup ) ) )
  283. sfxWrite( stream, mDescription.mSourceGroup );
  284. // fadein
  285. if( stream->writeFlag( mDirty.test( FadeInTime ) ) )
  286. stream->write( mDescription.mFadeInTime );
  287. // fadeout
  288. if( stream->writeFlag( mDirty.test( FadeOutTime ) ) )
  289. stream->write( mDescription.mFadeOutTime );
  290. // scatterdistance
  291. if( stream->writeFlag( mDirty.test( ScatterDistance ) ) )
  292. mathWrite( *stream, mDescription.mScatterDistance );
  293. mDirty.clear();
  294. stream->writeFlag( mUseTrackDescriptionOnly );
  295. // We should never have both source masks
  296. // enabled at the same time!
  297. AssertFatal( ( mask & AllSourceMasks ) != AllSourceMasks,
  298. "SFXEmitter::packUpdate() - Bad source mask!" );
  299. // Write the source playback state.
  300. stream->writeFlag( mask & SourcePlayMask );
  301. stream->writeFlag( mask & SourceStopMask );
  302. return retMask;
  303. }
  304. //-----------------------------------------------------------------------------
  305. bool SFXEmitter::_readDirtyFlag( BitStream* stream, U32 mask )
  306. {
  307. bool flag = stream->readFlag();
  308. if ( flag )
  309. mDirty.set( mask );
  310. return flag;
  311. }
  312. //-----------------------------------------------------------------------------
  313. void SFXEmitter::unpackUpdate( NetConnection *conn, BitStream *stream )
  314. {
  315. Parent::unpackUpdate( conn, stream );
  316. // initial update?
  317. bool initialUpdate = stream->readFlag();
  318. mPlayOnAdd = stream->readFlag();
  319. // transform
  320. if ( _readDirtyFlag( stream, Transform ) )
  321. {
  322. MatrixF mat;
  323. stream->readAffineTransform(&mat);
  324. Parent::setTransform(mat);
  325. }
  326. // track
  327. if ( _readDirtyFlag( stream, Track ) )
  328. {
  329. String errorStr;
  330. if( !sfxReadAndResolve( stream, &mTrack, errorStr ) )
  331. Con::errorf( "%s", errorStr.c_str() );
  332. }
  333. // filename
  334. if ( _readDirtyFlag( stream, Filename ) )
  335. mLocalProfile.mFilename = stream->readSTString();
  336. // volume
  337. if ( _readDirtyFlag( stream, Volume ) )
  338. stream->read( &mDescription.mVolume );
  339. // pitch
  340. if( _readDirtyFlag( stream, Pitch ) )
  341. stream->read( &mDescription.mPitch );
  342. // islooping
  343. if ( _readDirtyFlag( stream, IsLooping ) )
  344. mDescription.mIsLooping = stream->readFlag();
  345. if( _readDirtyFlag( stream, IsStreaming ) )
  346. mDescription.mIsStreaming = stream->readFlag();
  347. // is3d
  348. if ( _readDirtyFlag( stream, Is3D ) )
  349. mDescription.mIs3D = stream->readFlag();
  350. // mindistance
  351. if ( _readDirtyFlag( stream, MinDistance ) )
  352. stream->read( &mDescription.mMinDistance );
  353. // maxdistance
  354. if ( _readDirtyFlag( stream, MaxDistance ) )
  355. {
  356. stream->read( &mDescription.mMaxDistance );
  357. mObjScale.set( mDescription.mMaxDistance, mDescription.mMaxDistance, mDescription.mMaxDistance );
  358. }
  359. // coneinsideangle
  360. if ( _readDirtyFlag( stream, ConeInsideAngle ) )
  361. stream->read( &mDescription.mConeInsideAngle );
  362. // coneoutsideangle
  363. if ( _readDirtyFlag( stream, ConeOutsideAngle ) )
  364. stream->read( &mDescription.mConeOutsideAngle );
  365. // coneoutsidevolume
  366. if ( _readDirtyFlag( stream, ConeOutsideVolume ) )
  367. stream->read( &mDescription.mConeOutsideVolume );
  368. // sourcegroup
  369. if ( _readDirtyFlag( stream, SourceGroup ) )
  370. {
  371. String errorStr;
  372. if( !sfxReadAndResolve( stream, &mDescription.mSourceGroup, errorStr ) )
  373. Con::errorf( "%s", errorStr.c_str() );
  374. }
  375. // fadein
  376. if ( _readDirtyFlag( stream, FadeInTime ) )
  377. stream->read( &mDescription.mFadeInTime );
  378. // fadeout
  379. if( _readDirtyFlag( stream, FadeOutTime ) )
  380. stream->read( &mDescription.mFadeOutTime );
  381. // scatterdistance
  382. if( _readDirtyFlag( stream, ScatterDistance ) )
  383. mathRead( *stream, &mDescription.mScatterDistance );
  384. mUseTrackDescriptionOnly = stream->readFlag();
  385. // update the emitter now?
  386. if ( !initialUpdate )
  387. _update();
  388. // Check the source playback masks.
  389. if ( stream->readFlag() ) // SourcePlayMask
  390. play();
  391. if ( stream->readFlag() ) // SourceStopMask
  392. stop();
  393. }
  394. //-----------------------------------------------------------------------------
  395. void SFXEmitter::onStaticModified( const char* slotName, const char* newValue )
  396. {
  397. // NOTE: The signature for this function is very
  398. // misleading... slotName is a StringTableEntry.
  399. // We don't check for changes on the client side.
  400. if ( isClientObject() )
  401. return;
  402. // Lookup and store the property names once here
  403. // and we can then just do pointer compares.
  404. static StringTableEntry slotPosition = StringTable->lookup( "position" );
  405. static StringTableEntry slotRotation = StringTable->lookup( "rotation" );
  406. static StringTableEntry slotScale = StringTable->lookup( "scale" );
  407. static StringTableEntry slotTrack = StringTable->lookup( "track" );
  408. static StringTableEntry slotFilename = StringTable->lookup( "fileName" );
  409. static StringTableEntry slotVolume = StringTable->lookup( "volume" );
  410. static StringTableEntry slotPitch = StringTable->lookup( "pitch" );
  411. static StringTableEntry slotIsLooping = StringTable->lookup( "isLooping" );
  412. static StringTableEntry slotIsStreaming= StringTable->lookup( "isStreaming" );
  413. static StringTableEntry slotIs3D = StringTable->lookup( "is3D" );
  414. static StringTableEntry slotRefDist = StringTable->lookup( "referenceDistance" );
  415. static StringTableEntry slotMaxDist = StringTable->lookup( "maxDistance" );
  416. static StringTableEntry slotConeInAng = StringTable->lookup( "coneInsideAngle" );
  417. static StringTableEntry slotConeOutAng = StringTable->lookup( "coneOutsideAngle" );
  418. static StringTableEntry slotConeOutVol = StringTable->lookup( "coneOutsideVolume" );
  419. static StringTableEntry slotFadeInTime = StringTable->lookup( "fadeInTime" );
  420. static StringTableEntry slotFadeOutTime= StringTable->lookup( "fadeOutTime" );
  421. static StringTableEntry slotScatterDistance = StringTable->lookup( "scatterDistance" );
  422. static StringTableEntry slotSourceGroup= StringTable->lookup( "sourceGroup" );
  423. static StringTableEntry slotUseTrackDescriptionOnly = StringTable->lookup( "useTrackDescriptionOnly" );
  424. // Set the dirty flags.
  425. mDirty.clear();
  426. if( slotName == slotPosition ||
  427. slotName == slotRotation ||
  428. slotName == slotScale )
  429. mDirty.set( Transform );
  430. else if( slotName == slotTrack )
  431. mDirty.set( Track );
  432. else if( slotName == slotFilename )
  433. mDirty.set( Filename );
  434. else if( slotName == slotVolume )
  435. mDirty.set( Volume );
  436. else if( slotName == slotPitch )
  437. mDirty.set( Pitch );
  438. else if( slotName == slotIsLooping )
  439. mDirty.set( IsLooping );
  440. else if( slotName == slotIsStreaming )
  441. mDirty.set( IsStreaming );
  442. else if( slotName == slotIs3D )
  443. mDirty.set( Is3D );
  444. else if( slotName == slotRefDist )
  445. mDirty.set( MinDistance );
  446. else if( slotName == slotMaxDist )
  447. mDirty.set( MaxDistance );
  448. else if( slotName == slotConeInAng )
  449. mDirty.set( ConeInsideAngle );
  450. else if( slotName == slotConeOutAng )
  451. mDirty.set( ConeOutsideAngle );
  452. else if( slotName == slotConeOutVol )
  453. mDirty.set( ConeOutsideVolume );
  454. else if( slotName == slotFadeInTime )
  455. mDirty.set( FadeInTime );
  456. else if( slotName == slotFadeOutTime )
  457. mDirty.set( FadeOutTime );
  458. else if( slotName == slotScatterDistance )
  459. mDirty.set( ScatterDistance );
  460. else if( slotName == slotSourceGroup )
  461. mDirty.set( SourceGroup );
  462. else if( slotName == slotUseTrackDescriptionOnly )
  463. mDirty.set( TrackOnly );
  464. if( mDirty )
  465. setMaskBits( DirtyUpdateMask );
  466. }
  467. //-----------------------------------------------------------------------------
  468. void SFXEmitter::inspectPostApply()
  469. {
  470. // Parent will call setScale so sync up scale with distance.
  471. F32 maxDistance = mDescription.mMaxDistance;
  472. if( mUseTrackDescriptionOnly && mTrack )
  473. maxDistance = mTrack->getDescription()->mMaxDistance;
  474. mObjScale.set( maxDistance, maxDistance, maxDistance );
  475. Parent::inspectPostApply();
  476. }
  477. //-----------------------------------------------------------------------------
  478. bool SFXEmitter::onAdd()
  479. {
  480. if( !Parent::onAdd() )
  481. return false;
  482. if( isServerObject() )
  483. {
  484. // Validate the data we'll be passing across
  485. // the network to the client.
  486. mDescription.validate();
  487. // Read an old 'profile' field for backwards-compatibility.
  488. if( !mTrack )
  489. {
  490. static const char* sProfile = StringTable->insert( "profile" );
  491. const char* profileName = getDataField( sProfile, NULL );
  492. if( profileName && profileName[ 0 ] )
  493. {
  494. if( !Sim::findObject( profileName, mTrack ) )
  495. Con::errorf( "SFXEmitter::onAdd - No SFXTrack '%s' in SFXEmitter '%i' (%s)", profileName, getId(), getName() );
  496. else
  497. {
  498. // Remove the old 'profile' field.
  499. setDataField( sProfile, NULL, "" );
  500. }
  501. }
  502. }
  503. // Convert a legacy 'channel' field, if we have one.
  504. static const char* sChannel = StringTable->insert( "channel" );
  505. const char* channelValue = getDataField( sChannel, NULL );
  506. if( channelValue && channelValue[ 0 ] )
  507. {
  508. const char* group = Con::evaluatef( "return sfxOldChannelToGroup( %s );", channelValue );
  509. SFXSource* sourceGroup;
  510. if( !Sim::findObject( group, sourceGroup ) )
  511. Con::errorf( "SFXEmitter::onAdd - could not resolve channel '%s' to SFXSource", channelValue );
  512. else
  513. {
  514. static const char* sSourceGroup = StringTable->insert( "sourceGroup" );
  515. setDataField( sSourceGroup, NULL, sourceGroup->getIdString() );
  516. // Remove the old 'channel' field.
  517. setDataField( sChannel, NULL, "" );
  518. }
  519. }
  520. }
  521. else
  522. {
  523. _update();
  524. // Do we need to start playback?
  525. if( mPlayOnAdd && mSource )
  526. mSource->play();
  527. }
  528. // Setup the bounds.
  529. mObjScale.set( mDescription.mMaxDistance, mDescription.mMaxDistance, mDescription.mMaxDistance );
  530. resetWorldBox();
  531. addToScene();
  532. return true;
  533. }
  534. //-----------------------------------------------------------------------------
  535. void SFXEmitter::onRemove()
  536. {
  537. SFX_DELETE( mSource );
  538. removeFromScene();
  539. Parent::onRemove();
  540. }
  541. //-----------------------------------------------------------------------------
  542. void SFXEmitter::_update()
  543. {
  544. AssertFatal( isClientObject(), "SFXEmitter::_update() - This shouldn't happen on the server!" );
  545. // Store the playback status so we
  546. // we can restore it.
  547. SFXStatus prevState = mSource ? mSource->getStatus() : SFXStatusNull;
  548. // Make sure all the settings are valid.
  549. mDescription.validate();
  550. const MatrixF& transform = getTransform();
  551. const VectorF& velocity = getVelocity();
  552. // Did we change the source?
  553. if( mDirty.test( Track | Filename | Is3D | IsLooping | IsStreaming | TrackOnly ) )
  554. {
  555. SFX_DELETE( mSource );
  556. // Do we have a track?
  557. if( mTrack )
  558. {
  559. mSource = SFX->createSource( mTrack, &transform, &velocity );
  560. if( !mSource )
  561. Con::errorf( "SFXEmitter::_update() - failed to create sound for track %i (%s)",
  562. mTrack->getId(), mTrack->getName() );
  563. // If we're supposed to play when the emitter is
  564. // added to the scene then also restart playback
  565. // when the profile changes.
  566. prevState = mPlayOnAdd ? SFXStatusPlaying : prevState;
  567. // Force an update of properties set on the local description.
  568. mDirty.set( AllDirtyMask );
  569. }
  570. // Else take the local profile
  571. else
  572. {
  573. // Clear the resource and buffer on profile
  574. // to force reload.
  575. mLocalProfile.mResource = NULL;
  576. mLocalProfile.mBuffer = NULL;
  577. if( !mLocalProfile.mFilename.isEmpty() )
  578. {
  579. mSource = SFX->createSource( &mLocalProfile, &transform, &velocity );
  580. if( !mSource )
  581. Con::errorf( "SFXEmitter::_update() - failed to create sound for: %s",
  582. mLocalProfile.mFilename.c_str() );
  583. prevState = mPlayOnAdd ? SFXStatusPlaying : prevState;
  584. }
  585. }
  586. mDirty.clear( Track | Filename | Is3D | IsLooping | IsStreaming | TrackOnly );
  587. }
  588. // Cheat if the editor is open and the looping state
  589. // is toggled on a local profile sound. It makes the
  590. // editor feel responsive and that things are working.
  591. if( gEditingMission &&
  592. !mTrack &&
  593. mPlayOnAdd &&
  594. mDirty.test( IsLooping ) )
  595. prevState = SFXStatusPlaying;
  596. bool useTrackDescriptionOnly = ( mUseTrackDescriptionOnly && mTrack );
  597. // The rest only applies if we have a source.
  598. if( mSource )
  599. {
  600. // Set the volume irrespective of the profile.
  601. if( mDirty.test( Volume ) && !useTrackDescriptionOnly )
  602. mSource->setVolume( mDescription.mVolume );
  603. if( mDirty.test( Pitch ) && !useTrackDescriptionOnly )
  604. mSource->setPitch( mDescription.mPitch );
  605. if( mDirty.test( FadeInTime | FadeOutTime ) && !useTrackDescriptionOnly )
  606. mSource->setFadeTimes( mDescription.mFadeInTime, mDescription.mFadeOutTime );
  607. if( mDirty.test( SourceGroup ) && mDescription.mSourceGroup && !useTrackDescriptionOnly )
  608. mDescription.mSourceGroup->addObject( mSource );
  609. // Skip these 3d only settings.
  610. if( mDescription.mIs3D )
  611. {
  612. if( mDirty.test( Transform ) )
  613. {
  614. mSource->setTransform( transform );
  615. mSource->setVelocity( velocity );
  616. }
  617. if( mDirty.test( MinDistance | MaxDistance ) && !useTrackDescriptionOnly )
  618. {
  619. mSource->setMinMaxDistance( mDescription.mMinDistance,
  620. mDescription.mMaxDistance );
  621. }
  622. if( mDirty.test( ConeInsideAngle | ConeOutsideAngle | ConeOutsideVolume ) && !useTrackDescriptionOnly )
  623. {
  624. mSource->setCone( F32( mDescription.mConeInsideAngle ),
  625. F32( mDescription.mConeOutsideAngle ),
  626. mDescription.mConeOutsideVolume );
  627. }
  628. mDirty.clear( Transform | MinDistance | MaxDistance | ConeInsideAngle | ConeOutsideAngle | ConeOutsideVolume );
  629. }
  630. // Restore the pre-update playback state.
  631. if( prevState == SFXStatusPlaying )
  632. mSource->play();
  633. mDirty.clear( Volume | Pitch | Transform | FadeInTime | FadeOutTime | SourceGroup );
  634. }
  635. }
  636. //-----------------------------------------------------------------------------
  637. void SFXEmitter::prepRenderImage( SceneRenderState* state )
  638. {
  639. // Only render in editor.
  640. if( !gEditingMission )
  641. return;
  642. ObjectRenderInst* ri = state->getRenderPass()->allocInst< ObjectRenderInst >();
  643. ri->renderDelegate.bind( this, &SFXEmitter::_renderObject );
  644. ri->type = RenderPassManager::RIT_Editor;
  645. ri->defaultKey = 0;
  646. ri->defaultKey2 = 0;
  647. state->getRenderPass()->addInst( ri );
  648. }
  649. //-----------------------------------------------------------------------------
  650. void SFXEmitter::_renderObject( ObjectRenderInst* ri, SceneRenderState* state, BaseMatInstance* overrideMat )
  651. {
  652. // Check to see if the emitter is in range and playing
  653. // and assign a proper color depending on this.
  654. ColorI color;
  655. if( _getPlaybackStatus() == SFXStatusPlaying )
  656. {
  657. if( isInRange() )
  658. color = smRenderColorPlayingInRange;
  659. else
  660. color = smRenderColorPlayingOutOfRange;
  661. }
  662. else
  663. {
  664. if( isInRange() )
  665. color = smRenderColorStoppedInRange;
  666. else
  667. color = smRenderColorStoppedOutOfRange;
  668. }
  669. // Draw the cube.
  670. GFXStateBlockDesc desc;
  671. desc.setZReadWrite( true, false );
  672. desc.setBlend( true );
  673. desc.setCullMode( GFXCullNone );
  674. GFXDrawUtil *drawer = GFX->getDrawUtil();
  675. drawer->drawCube( desc, Point3F( 0.5f, 0.5f, 0.5f ), getBoxCenter(), color );
  676. // Render visual feedback for 3D sounds.
  677. if( ( smRenderEmitters || isSelected() ) && is3D() )
  678. _render3DVisualFeedback();
  679. }
  680. //-----------------------------------------------------------------------------
  681. void SFXEmitter::_render3DVisualFeedback()
  682. {
  683. GFXTransformSaver saver;
  684. GFX->multWorld( getRenderTransform() );
  685. GFXStateBlockDesc desc;
  686. desc.setZReadWrite( true, false );
  687. desc.setBlend( true );
  688. desc.setCullMode( GFXCullNone );
  689. if( mRenderSB == NULL )
  690. mRenderSB = GFX->createStateBlock( desc );
  691. GFX->setStateBlock( mRenderSB );
  692. // Render the max range sphere.
  693. if( smRenderColorRangeSphere.alpha > 0 )
  694. GFX->getDrawUtil()->drawSphere( desc, mDescription.mMaxDistance, Point3F( 0.f, 0.f, 0.f ), smRenderColorRangeSphere );
  695. //TODO: some point size support in GFX would be nice
  696. // Prepare primitive list. Make sure we stay within limits.
  697. F32 radialIncrements = smRenderRadialIncrements;
  698. F32 sweepIncrements = smRenderSweepIncrements;
  699. F32 pointDistance = smRenderPointDistance;
  700. F32 numPoints;
  701. while( 1 )
  702. {
  703. numPoints = mCeil( 360.f / radialIncrements ) *
  704. mCeil( 360.f / sweepIncrements ) *
  705. ( mDescription.mMaxDistance / pointDistance );
  706. if( numPoints < 65536 )
  707. break;
  708. radialIncrements *= 1.1f;
  709. sweepIncrements *= 1.1f;
  710. pointDistance *= 1.5;
  711. }
  712. PrimBuild::begin( GFXPointList, numPoints );
  713. // Render inner cone.
  714. _renderCone(
  715. radialIncrements,
  716. sweepIncrements,
  717. pointDistance,
  718. mDescription.mConeInsideAngle, 0.f,
  719. mDescription.mVolume, mDescription.mVolume,
  720. smRenderColorInnerCone );
  721. // Outer Cone and Outside volume only get rendered if mConeOutsideVolume > 0
  722. if( mDescription.mConeOutsideVolume > 0.f )
  723. {
  724. const F32 outsideVolume = mDescription.mVolume * mDescription.mConeOutsideVolume;
  725. // Render outer cone.
  726. _renderCone(
  727. radialIncrements,
  728. sweepIncrements,
  729. pointDistance,
  730. mDescription.mConeOutsideAngle, mDescription.mConeInsideAngle,
  731. outsideVolume, mDescription.mVolume,
  732. smRenderColorOuterCone );
  733. // Render outside volume.
  734. _renderCone(
  735. radialIncrements,
  736. sweepIncrements,
  737. pointDistance,
  738. 360.f, mDescription.mConeOutsideAngle,
  739. outsideVolume, outsideVolume,
  740. smRenderColorOutsideVolume );
  741. }
  742. // Commit primitive list.
  743. PrimBuild::end();
  744. }
  745. //-----------------------------------------------------------------------------
  746. void SFXEmitter::_renderCone( F32 radialIncrements, F32 sweepIncrements,
  747. F32 pointDistance,
  748. F32 startAngle, F32 stopAngle,
  749. F32 startVolume, F32 stopVolume,
  750. const ColorI& color )
  751. {
  752. if( startAngle == stopAngle )
  753. return;
  754. const F32 startAngleRadians = mDegToRad( startAngle );
  755. const F32 stopAngleRadians = mDegToRad( stopAngle );
  756. const F32 radialIncrementsRadians = mDegToRad( radialIncrements );
  757. // Unit quaternions representing the start and end angle so we
  758. // can interpolate between the two without flipping.
  759. QuatF rotateZStart( EulerF( 0.f, 0.f, startAngleRadians / 2.f ) );
  760. QuatF rotateZEnd( EulerF( 0.f, 0.f, stopAngleRadians / 2.f ) );
  761. // Do an angular sweep on one side of our XY disc. Since we do a full 360 radial sweep
  762. // around Y for each angle, we only need to sweep over one side.
  763. const F32 increment = 1.f / ( ( ( startAngle / 2.f ) - ( stopAngle / 2.f ) ) / sweepIncrements );
  764. for( F32 t = 0.f; t < 1.0f; t += increment )
  765. {
  766. // Quaternion to rotate point into place on XY disc.
  767. QuatF rotateZ;
  768. rotateZ.interpolate( rotateZStart, rotateZEnd, t );
  769. // Quaternion to rotate one position around Y axis. Used for radial sweep.
  770. QuatF rotateYOne( EulerF( 0.f, radialIncrementsRadians, 0.f ) );
  771. // Do a radial sweep each step along the distance axis. For each step, volume is
  772. // the same for any point on the sweep circle.
  773. for( F32 y = pointDistance; y <= mDescription.mMaxDistance; y += pointDistance )
  774. {
  775. ColorI c = color;
  776. // Compute volume at current point. First off, find the interpolated volume
  777. // in the cone. Only for the outer cone will this actually result in
  778. // interpolation. For the remaining angles, the cone volume is constant.
  779. F32 volume = mLerp( startVolume, stopVolume, t );
  780. if( volume == 0.f )
  781. c.alpha = 0;
  782. else
  783. {
  784. // Apply distance attenuation.
  785. F32 attenuatedVolume = SFXDistanceAttenuation(
  786. SFX->getDistanceModel(),
  787. mDescription.mMinDistance,
  788. mDescription.mMaxDistance,
  789. y,
  790. volume,
  791. SFX->getRolloffFactor() ); //RDTODO
  792. // Fade alpha according to how much volume we
  793. // have left at the current point.
  794. c.alpha = F32( c.alpha ) * ( attenuatedVolume / 1.f );
  795. }
  796. PrimBuild::color( c );
  797. // Create points by doing a full 360 degree radial sweep around Y.
  798. Point3F p( 0.f, y, 0.f );
  799. rotateZ.mulP( p, &p );
  800. for( F32 radialAngle = 0.f; radialAngle < 360.f; radialAngle += radialIncrements )
  801. {
  802. PrimBuild::vertex3f( p.x, p.y, p.z );
  803. rotateYOne.mulP( p, &p );
  804. }
  805. }
  806. }
  807. }
  808. //-----------------------------------------------------------------------------
  809. void SFXEmitter::play()
  810. {
  811. if( mSource )
  812. mSource->play();
  813. else
  814. {
  815. // By clearing the playback masks first we
  816. // ensure the last playback command called
  817. // within a single tick is the one obeyed.
  818. clearMaskBits( AllSourceMasks );
  819. setMaskBits( SourcePlayMask );
  820. }
  821. }
  822. //-----------------------------------------------------------------------------
  823. void SFXEmitter::stop()
  824. {
  825. if ( mSource )
  826. mSource->stop();
  827. else
  828. {
  829. // By clearing the playback masks first we
  830. // ensure the last playback command called
  831. // within a single tick is the one obeyed.
  832. clearMaskBits( AllSourceMasks );
  833. setMaskBits( SourceStopMask );
  834. }
  835. }
  836. //-----------------------------------------------------------------------------
  837. SFXStatus SFXEmitter::_getPlaybackStatus() const
  838. {
  839. const SFXEmitter* emitter = this;
  840. // We only have a source playing on client objects, so if this is a server
  841. // object, we want to know the playback status on the local client connection's
  842. // version of this emitter.
  843. if( isServerObject() )
  844. {
  845. S32 index = NetConnection::getLocalClientConnection()->getGhostIndex( ( NetObject* ) this );
  846. if( index != -1 )
  847. emitter = dynamic_cast< SFXEmitter* >( NetConnection::getConnectionToServer()->resolveGhost( index ) );
  848. else
  849. emitter = NULL;
  850. }
  851. if( emitter && emitter->mSource )
  852. return emitter->mSource->getStatus();
  853. return SFXStatusNull;
  854. }
  855. //-----------------------------------------------------------------------------
  856. bool SFXEmitter::is3D() const
  857. {
  858. if( mTrack != NULL )
  859. return mTrack->getDescription()->mIs3D;
  860. else
  861. return mDescription.mIs3D;
  862. }
  863. //-----------------------------------------------------------------------------
  864. bool SFXEmitter::isInRange() const
  865. {
  866. if( !mDescription.mIs3D )
  867. return false;
  868. const SFXListenerProperties& listener = SFX->getListener();
  869. const Point3F listenerPos = listener.getTransform().getPosition();
  870. const Point3F emitterPos = getPosition();
  871. const F32 dist = mDescription.mMaxDistance;
  872. return ( ( emitterPos - listenerPos ).len() <= dist );
  873. }
  874. //-----------------------------------------------------------------------------
  875. void SFXEmitter::setTransform( const MatrixF &mat )
  876. {
  877. // Set the transform directly from the
  878. // matrix created by inspector.
  879. Parent::setTransform( mat );
  880. setMaskBits( TransformUpdateMask );
  881. }
  882. //-----------------------------------------------------------------------------
  883. void SFXEmitter::setScale( const VectorF &scale )
  884. {
  885. F32 maxDistance;
  886. if( mUseTrackDescriptionOnly && mTrack )
  887. maxDistance = mTrack->getDescription()->mMaxDistance;
  888. else
  889. {
  890. // Use the average of the three coords.
  891. maxDistance = ( scale.x + scale.y + scale.z ) / 3.0f;
  892. maxDistance = getMax( maxDistance, mDescription.mMinDistance );
  893. mDescription.mMaxDistance = maxDistance;
  894. mDirty.set( MaxDistance );
  895. setMaskBits( DirtyUpdateMask );
  896. }
  897. Parent::setScale( VectorF( maxDistance, maxDistance, maxDistance ) );
  898. }
  899. //=============================================================================
  900. // Console Methods.
  901. //=============================================================================
  902. // MARK: ---- Console Methods ----
  903. //-----------------------------------------------------------------------------
  904. DefineEngineMethod( SFXEmitter, play, void, (),,
  905. "Manually start playback of the emitter's sound.\n"
  906. "If this is called on the server-side object, the play command will be related to all client-side ghosts.\n" )
  907. {
  908. object->play();
  909. }
  910. //-----------------------------------------------------------------------------
  911. DefineEngineMethod( SFXEmitter, stop, void, (),,
  912. "Manually stop playback of the emitter's sound.\n"
  913. "If this is called on the server-side object, the stop command will be related to all client-side ghosts.\n" )
  914. {
  915. object->stop();
  916. }
  917. //-----------------------------------------------------------------------------
  918. DefineEngineMethod( SFXEmitter, getSource, SFXSource*, (),,
  919. "Get the sound source object from the emitter.\n\n"
  920. "@return The sound source used by the emitter or null."
  921. "@note This method will return null when called on the server-side SFXEmitter object. Only client-side ghosts "
  922. "actually hold on to %SFXSources.\n\n" )
  923. {
  924. return object->getSource();
  925. }