sceneAmbientSoundObject.impl.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #ifndef _SCENEAMBIENTSOUNDOBJECT_IMPL_H_
  23. #define _SCENEAMBIENTSOUNDOBJECT_IMPL_H_
  24. #include "platform/platform.h"
  25. #include "scene/mixin/sceneAmbientSoundObject.h"
  26. #include "T3D/sfx/sfx3DWorld.h"
  27. #include "sfx/sfxTypes.h"
  28. #include "sfx/sfxAmbience.h"
  29. #include "core/stream/bitStream.h"
  30. #include "console/engineAPI.h"
  31. //-----------------------------------------------------------------------------
  32. template< typename Base >
  33. SceneAmbientSoundObject< Base >::SceneAmbientSoundObject()
  34. : mSoundAmbience( NULL )
  35. {
  36. }
  37. //-----------------------------------------------------------------------------
  38. template< typename Base >
  39. void SceneAmbientSoundObject< Base >::initPersistFields()
  40. {
  41. Parent::addGroup( "Sound" );
  42. Parent::addProtectedField( "soundAmbience", TypeSFXAmbienceName, Offset( mSoundAmbience, SceneAmbientSoundObject ),
  43. &_setSoundAmbience, &defaultProtectedGetFn,
  44. "Ambient sound environment for the space." );
  45. Parent::endGroup( "Sound" );
  46. Parent::initPersistFields();
  47. }
  48. //-----------------------------------------------------------------------------
  49. template< typename Base >
  50. U32 SceneAmbientSoundObject< Base >::packUpdate( NetConnection* connection, U32 mask, BitStream* stream )
  51. {
  52. U32 retMask = Parent::packUpdate( connection, mask, stream );
  53. if( stream->writeFlag( mask & SoundMask ) )
  54. sfxWrite( stream, mSoundAmbience );
  55. return retMask;
  56. }
  57. //-----------------------------------------------------------------------------
  58. template< typename Base >
  59. void SceneAmbientSoundObject< Base >::unpackUpdate( NetConnection* connection, BitStream* stream )
  60. {
  61. Parent::unpackUpdate( connection, stream );
  62. if( stream->readFlag() ) // SoundMask
  63. {
  64. SFXAmbience* ambience;
  65. String errorStr;
  66. if( !sfxReadAndResolve( stream, &ambience, errorStr ) )
  67. Con::errorf( "SceneAmbientSoundObject::unpackUpdate - bad packet: %s", errorStr.c_str() );
  68. else
  69. setSoundAmbience( ambience );
  70. }
  71. }
  72. //-----------------------------------------------------------------------------
  73. template< typename Base >
  74. void SceneAmbientSoundObject< Base >::setSoundAmbience( SFXAmbience* ambience )
  75. {
  76. if( mSoundAmbience == ambience )
  77. return;
  78. mSoundAmbience = ambience;
  79. if( this->isServerObject() )
  80. this->setMaskBits( SoundMask );
  81. else if( this->isProperlyAdded() && gSFX3DWorld )
  82. gSFX3DWorld->notifyChanged( this );
  83. }
  84. //-----------------------------------------------------------------------------
  85. template< typename Base >
  86. bool SceneAmbientSoundObject< Base >::_setSoundAmbience( void* object, const char* index, const char* data )
  87. {
  88. SceneAmbientSoundObject* p = reinterpret_cast< SceneAmbientSoundObject* >( object );
  89. SFXAmbience* ambience = EngineUnmarshallData< SFXAmbience* >()( data );
  90. p->setSoundAmbience( ambience );
  91. return false;
  92. }
  93. #endif // _SCENEAMBIENTSOUNDOBJECT_IMPL_H_