Torque3D Documentation / _generateds / sceneAmbientSoundObject.impl.h

sceneAmbientSoundObject.impl.h

Engine/source/scene/mixin/sceneAmbientSoundObject.impl.h

More...

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 _SCENEAMBIENTSOUNDOBJECT_IMPL_H_
 25#define _SCENEAMBIENTSOUNDOBJECT_IMPL_H_
 26
 27#include "platform/platform.h"
 28#include "scene/mixin/sceneAmbientSoundObject.h"
 29
 30#include "T3D/sfx/sfx3DWorld.h"
 31#include "sfx/sfxTypes.h"
 32#include "sfx/sfxAmbience.h"
 33#include "core/stream/bitStream.h"
 34#include "console/engineAPI.h"
 35
 36
 37
 38
 39//-----------------------------------------------------------------------------
 40
 41template< typename Base >
 42SceneAmbientSoundObject< Base >::SceneAmbientSoundObject()
 43   : mSoundAmbience( NULL )
 44{
 45}
 46
 47//-----------------------------------------------------------------------------
 48
 49template< typename Base >
 50void SceneAmbientSoundObject< Base >::initPersistFields()
 51{
 52   Parent::addGroup( "Sound" );
 53      Parent::addProtectedField( "soundAmbience", TypeSFXAmbienceName, Offset( mSoundAmbience, SceneAmbientSoundObject ),
 54         &_setSoundAmbience, &defaultProtectedGetFn,
 55         "Ambient sound environment for the space." );
 56   Parent::endGroup( "Sound" );
 57
 58   Parent::initPersistFields();
 59}
 60
 61//-----------------------------------------------------------------------------
 62
 63template< typename Base >
 64U32 SceneAmbientSoundObject< Base >::packUpdate( NetConnection* connection, U32 mask, BitStream* stream )
 65{
 66   U32 retMask = Parent::packUpdate( connection, mask, stream );
 67
 68   if( stream->writeFlag( mask & SoundMask ) )
 69      sfxWrite( stream, mSoundAmbience );
 70
 71   return retMask;
 72}
 73
 74//-----------------------------------------------------------------------------
 75
 76template< typename Base >
 77void SceneAmbientSoundObject< Base >::unpackUpdate( NetConnection* connection, BitStream* stream )
 78{
 79   Parent::unpackUpdate( connection, stream );
 80
 81   if( stream->readFlag() ) // SoundMask
 82   {
 83      SFXAmbience* ambience;
 84
 85      String errorStr;
 86      if( !sfxReadAndResolve( stream, &ambience, errorStr ) )
 87         Con::errorf( "SceneAmbientSoundObject::unpackUpdate - bad packet: %s", errorStr.c_str() );
 88      else
 89         setSoundAmbience( ambience );
 90   }
 91}
 92
 93//-----------------------------------------------------------------------------
 94
 95template< typename Base >
 96void SceneAmbientSoundObject< Base >::setSoundAmbience( SFXAmbience* ambience )
 97{
 98   if( mSoundAmbience == ambience )
 99      return;
100
101   mSoundAmbience = ambience;
102
103   if( this->isServerObject() )
104      this->setMaskBits( SoundMask );
105   else if( this->isProperlyAdded() && gSFX3DWorld )
106      gSFX3DWorld->notifyChanged( this );
107}
108
109//-----------------------------------------------------------------------------
110
111template< typename Base >
112bool SceneAmbientSoundObject< Base >::_setSoundAmbience( void* object, const char* index, const char* data )
113{
114   SceneAmbientSoundObject* p = reinterpret_cast< SceneAmbientSoundObject* >( object );
115   SFXAmbience* ambience = EngineUnmarshallData< SFXAmbience*>()( data );
116   p->setSoundAmbience( ambience );
117   return false;
118}
119
120#endif // _SCENEAMBIENTSOUNDOBJECT_IMPL_H_
121