sfxTypes.cpp

Engine/source/sfx/sfxTypes.cpp

More...

Public Functions

ConsoleGetType(TypeSFXAmbienceName )
ConsoleGetType(TypeSFXDescriptionName )
ConsoleGetType(TypeSFXEnvironmentName )
ConsoleGetType(TypeSFXStateName )
ConsoleGetType(TypeSFXTrackName )
ConsoleSetType(TypeSFXParameterName )
ConsoleSetType(TypeSFXSourceName )
ConsoleType(SFXAmbience , TypeSFXAmbienceName , SFXAmbience * , "" )
ConsoleType(SFXDescription , TypeSFXDescriptionName , SFXDescription * , "" )
ConsoleType(SFXEnvironment , TypeSFXEnvironmentName , SFXEnvironment * , "" )
ConsoleType(SFXSource , TypeSFXSourceName , SFXSource * , "" )
ConsoleType(SFXState , TypeSFXStateName , SFXState * , "" )
ConsoleType(SFXTrack , TypeSFXTrackName , SFXTrack * , "" )
ConsoleType(string , TypeSFXParameterName , StringTableEntry , "" )
sfxRead(BitStream * stream, SFXAmbience ** ambience)
sfxRead(BitStream * stream, SFXDescription ** description)
sfxRead(BitStream * stream, SFXEnvironment ** environment)
sfxRead(BitStream * stream, SFXState ** state)
sfxRead(BitStream * stream, SFXTrack ** track)
bool
sfxReadAndResolve(BitStream * stream, SFXSource ** source, String & errorString)
bool
sfxResolve(SFXAmbience ** ambience, String & errorString)
bool
sfxResolve(SFXDescription ** description, String & errorString)
bool
sfxResolve(SFXEnvironment ** environment, String & errorString)
bool
sfxResolve(SFXState ** state, String & errorString)
bool
sfxResolve(SFXTrack ** track, String & errorString)
sfxWrite(BitStream * stream, SFXAmbience * ambience)
sfxWrite(BitStream * stream, SFXDescription * description)
sfxWrite(BitStream * stream, SFXEnvironment * environment)
sfxWrite(BitStream * stream, SFXSource * source)
sfxWrite(BitStream * stream, SFXState * state)
sfxWrite(BitStream * stream, SFXTrack * track)
sRead(BitStream * stream, T ** ptr)
bool
sResolve(T ** ptr, String & errorString)
sWrite(BitStream * stream, T * ptr)

Detailed Description

Public Functions

ConsoleGetType(TypeSFXAmbienceName )

ConsoleGetType(TypeSFXDescriptionName )

ConsoleGetType(TypeSFXEnvironmentName )

ConsoleGetType(TypeSFXStateName )

ConsoleGetType(TypeSFXTrackName )

ConsoleSetType(TypeSFXParameterName )

ConsoleSetType(TypeSFXSourceName )

ConsoleType(SFXAmbience , TypeSFXAmbienceName , SFXAmbience * , "" )

ConsoleType(SFXDescription , TypeSFXDescriptionName , SFXDescription * , "" )

ConsoleType(SFXEnvironment , TypeSFXEnvironmentName , SFXEnvironment * , "" )

ConsoleType(SFXSource , TypeSFXSourceName , SFXSource * , "" )

ConsoleType(SFXState , TypeSFXStateName , SFXState * , "" )

ConsoleType(SFXTrack , TypeSFXTrackName , SFXTrack * , "" )

ConsoleType(string , TypeSFXParameterName , StringTableEntry , "" )

sfxRead(BitStream * stream, SFXAmbience ** ambience)

sfxRead(BitStream * stream, SFXDescription ** description)

sfxRead(BitStream * stream, SFXEnvironment ** environment)

sfxRead(BitStream * stream, SFXState ** state)

sfxRead(BitStream * stream, SFXTrack ** track)

sfxReadAndResolve(BitStream * stream, SFXSource ** source, String & errorString)

sfxResolve(SFXAmbience ** ambience, String & errorString)

sfxResolve(SFXDescription ** description, String & errorString)

sfxResolve(SFXEnvironment ** environment, String & errorString)

sfxResolve(SFXState ** state, String & errorString)

sfxResolve(SFXTrack ** track, String & errorString)

sfxWrite(BitStream * stream, SFXAmbience * ambience)

sfxWrite(BitStream * stream, SFXDescription * description)

sfxWrite(BitStream * stream, SFXEnvironment * environment)

sfxWrite(BitStream * stream, SFXSource * source)

sfxWrite(BitStream * stream, SFXState * state)

sfxWrite(BitStream * stream, SFXTrack * track)

sRead(BitStream * stream, T ** ptr)

sResolve(T ** ptr, String & errorString)

sWrite(BitStream * stream, T * ptr)

  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/sfxTypes.h"
 25#include "sfx/sfxDescription.h"
 26#include "sfx/sfxTrack.h"
 27#include "sfx/sfxEnvironment.h"
 28#include "sfx/sfxState.h"
 29#include "sfx/sfxAmbience.h"
 30#include "sfx/sfxSource.h"
 31#include "core/stringTable.h"
 32#include "core/stream/bitStream.h"
 33#include "platform/typetraits.h"
 34
 35
 36//RDTODO: find a more optimal way to transmit names rather than using full
 37//  strings; don't know how to facilitate NetStrings for this as we don't
 38//  have access to the connection
 39
 40
 41template< class T >
 42inline void sWrite( BitStream* stream, T* ptr )
 43{
 44   if( stream->writeFlag( ptr != NULL ) )
 45   {
 46      if( stream->writeFlag( ptr->isClientOnly() ) )
 47         stream->writeString( ptr->getName() );
 48      else
 49         stream->writeRangedU32( ptr->getId(), DataBlockObjectIdFirst, DataBlockObjectIdLast );
 50   }
 51}
 52template< class T >
 53inline void sRead( BitStream* stream, T** ptr )
 54{
 55   if( !stream->readFlag() )
 56      *ptr = NULL;
 57   else
 58   {
 59      if( stream->readFlag() )
 60      {
 61         StringTableEntry name = stream->readSTString();
 62         
 63         AssertFatal( !( uintptr_t( name ) & 0x1 ), "sRead - misaligned pointer" ); // StringTableEntry pointers are always word-aligned.
 64         
 65         *( ( StringTableEntry* ) ptr ) = name;
 66      }
 67      else
 68         *reinterpret_cast< U32* >( ptr ) =
 69            ( stream->readRangedU32( DataBlockObjectIdFirst, DataBlockObjectIdLast ) << 1 ) | 0x1;
 70   }
 71}
 72template< class T >
 73inline bool sResolve( T** ptr, String& errorString )
 74{
 75   if( !*ptr )
 76      return true;
 77   else if( *reinterpret_cast< U32* >( ptr ) & 0x1 )
 78   {
 79      U32 id = *reinterpret_cast< U32* >( ptr ) >> 1;
 80      
 81      T* p;
 82      if( !Sim::findObject( id, p ) )
 83      {
 84         errorString = String::ToString( "sfxResolve - Could not resolve networked %s datalock with id '%i'",
 85            T::getStaticClassRep()->getClassName(), id );
 86         *ptr = NULL;
 87         return false;
 88      }
 89      
 90      *ptr = p;
 91   }
 92   else
 93   {
 94      StringTableEntry name = *( ( StringTableEntry* ) ptr );
 95         
 96      T* p;
 97      if( !Sim::findObject( name, p ) )
 98      {
 99         errorString = String::ToString( "sfxResolve - Could not resolve local %s datablock with name '%s'",
100            T::getStaticClassRep()->getClassName(), name );
101         *ptr = NULL;
102         return false;
103      }
104      
105      *ptr = p;
106   }
107   
108   return true;
109}
110
111
112//=============================================================================
113//    TypeSFXSourceName.
114//=============================================================================
115
116ConsoleType(SFXSource, TypeSFXSourceName, SFXSource*, "")
117
118ConsoleGetType( TypeSFXSourceName )
119{
120   SFXSource** obj = ( SFXSource** ) dptr;
121   if( !*obj )
122      return "";
123   else
124      return Con::getReturnBuffer( ( *obj )->getName() );
125}
126
127ConsoleSetType( TypeSFXSourceName )
128{
129   if( argc == 1 )
130   {
131      SFXSource** obj = ( SFXSource**) dptr;
132      Sim::findObject( argv[ 0 ], *obj );
133   }
134   else
135      Con::printf("(TypeSFXSourceName) Cannot set multiple args to a single SFXSource.");
136}
137
138//=============================================================================
139//    TypeSFXParameterName.
140//=============================================================================
141
142ConsoleType(string, TypeSFXParameterName, StringTableEntry, "")
143
144ConsoleGetType( TypeSFXParameterName )
145{
146   return *( ( const char** ) dptr );
147}
148
149ConsoleSetType( TypeSFXParameterName )
150{
151   if( argc == 1 )
152      *( ( const char** ) dptr ) = StringTable->insert( argv[ 0 ] );
153   else
154      Con::errorf( "(TypeSFXParameterName) Cannot set multiple args to a single SFXParameter." );
155}
156
157//=============================================================================
158//    TypeSFXDescriptionName.
159//=============================================================================
160
161ConsoleType(SFXDescription, TypeSFXDescriptionName, SFXDescription*, "")
162
163ConsoleSetType( TypeSFXDescriptionName )
164{
165   if( argc == 1 )
166   {
167      SFXDescription* description;
168      Sim::findObject( argv[ 0 ], description );
169      *( ( SFXDescription** ) dptr ) = description;
170   }
171   else
172      Con::errorf( "(TypeSFXDescriptionName) Cannot set multiple args to a single SFXDescription.");
173}
174
175ConsoleGetType( TypeSFXDescriptionName )
176{
177   SFXDescription* description = *( ( SFXDescription** ) dptr );
178   if( !description || !description->getName() )
179      return "";
180   else
181      return description->getName();
182}
183
184//=============================================================================
185//    TypeSFXTrackName.
186//=============================================================================
187
188ConsoleType( SFXTrack, TypeSFXTrackName, SFXTrack*, "" )
189
190ConsoleSetType( TypeSFXTrackName )
191{
192   if( argc == 1 )
193   {
194      SFXTrack* track;
195      Sim::findObject( argv[ 0 ], track );
196      *( ( SFXTrack** ) dptr ) = track;
197   }
198   else
199      Con::errorf( "(TypeSFXTrackName) Cannot set multiple args to a single SFXTrack.");
200}
201
202ConsoleGetType( TypeSFXTrackName )
203{
204   SFXTrack* track = *( ( SFXTrack** ) dptr );
205   if( !track || !track->getName() )
206      return "";
207   else
208      return track->getName();
209}
210
211//=============================================================================
212//    TypeSFXEnvironmentName.
213//=============================================================================
214
215ConsoleType(SFXEnvironment, TypeSFXEnvironmentName, SFXEnvironment*, "")
216
217ConsoleSetType( TypeSFXEnvironmentName )
218{
219   if( argc == 1 )
220   {
221      SFXEnvironment* environment;
222      Sim::findObject( argv[ 0 ], environment );
223      *( ( SFXEnvironment** ) dptr ) = environment;
224   }
225   else
226      Con::errorf( "(TypeSFXEnvironmentName) Cannot set multiple args to a single SFXEnvironment.");
227}
228
229ConsoleGetType( TypeSFXEnvironmentName )
230{
231   SFXEnvironment* environment = *( ( SFXEnvironment** ) dptr );
232   if( !environment || !environment->getName() )
233      return "";
234   else
235      return environment->getName();
236}
237
238//=============================================================================
239//    TypeSFXStateName.
240//=============================================================================
241
242ConsoleType(SFXState, TypeSFXStateName, SFXState*, "")
243
244ConsoleSetType( TypeSFXStateName )
245{
246   if( argc == 1 )
247   {
248      SFXState* state;
249      Sim::findObject( argv[ 0 ], state );
250      *( ( SFXState** ) dptr ) = state;
251   }
252   else
253      Con::errorf( "(TypeSFXStateName) Cannot set multiple args to a single SFXState.");
254}
255
256ConsoleGetType( TypeSFXStateName )
257{
258   SFXState* state = *( ( SFXState** ) dptr );
259   if( !state || !state->getName() )
260      return "";
261   else
262      return state->getName();
263}
264
265//=============================================================================
266//    TypeSFXAmbienceName.
267//=============================================================================
268
269ConsoleType(SFXAmbience, TypeSFXAmbienceName, SFXAmbience*, "")
270
271ConsoleSetType( TypeSFXAmbienceName )
272{
273   if( argc == 1 )
274   {
275      SFXAmbience* ambience;
276      Sim::findObject( argv[ 0 ], ambience );
277      *( ( SFXAmbience** ) dptr ) = ambience;
278   }
279   else
280      Con::errorf( "(TypeSFXAmbienceName) Cannot set multiple args to a single SFXAmbience.");
281}
282
283ConsoleGetType( TypeSFXAmbienceName )
284{
285   SFXAmbience* ambience = *( ( SFXAmbience** ) dptr );
286   if( !ambience || !ambience->getName() )
287      return "";
288   else
289      return ambience->getName();
290}
291
292//=============================================================================
293//    I/O.
294//=============================================================================
295
296//-----------------------------------------------------------------------------
297
298void sfxWrite( BitStream* stream, SFXSource* source )
299{
300   if( stream->writeFlag( source != NULL ) )
301      stream->writeString( source->getName() );
302}
303
304//-----------------------------------------------------------------------------
305
306void sfxWrite( BitStream* stream, SFXDescription* description )
307{
308   sWrite( stream, description );
309}
310
311//-----------------------------------------------------------------------------
312
313void sfxWrite( BitStream* stream, SFXTrack* track )
314{
315   sWrite( stream, track );
316}
317
318//-----------------------------------------------------------------------------
319
320void sfxWrite( BitStream* stream, SFXEnvironment* environment )
321{
322   sWrite( stream, environment );
323}
324
325//-----------------------------------------------------------------------------
326
327void sfxWrite( BitStream* stream, SFXState* state )
328{
329   sWrite( stream, state );
330}
331
332//-----------------------------------------------------------------------------
333
334void sfxWrite( BitStream* stream, SFXAmbience* ambience )
335{
336   sWrite( stream, ambience );
337}
338
339//-----------------------------------------------------------------------------
340
341void sfxRead( BitStream* stream, SFXDescription** description )
342{
343   sRead( stream, description );
344}
345
346//-----------------------------------------------------------------------------
347
348void sfxRead( BitStream* stream, SFXTrack** track )
349{
350   sRead( stream, track );
351}
352
353//-----------------------------------------------------------------------------
354
355void sfxRead( BitStream* stream, SFXEnvironment** environment )
356{
357   sRead( stream, environment );
358}
359
360//-----------------------------------------------------------------------------
361
362void sfxRead( BitStream* stream, SFXState** state )
363{
364   sRead( stream, state );
365}
366
367//-----------------------------------------------------------------------------
368
369void sfxRead( BitStream* stream, SFXAmbience** ambience )
370{
371   sRead( stream, ambience );
372}
373
374//-----------------------------------------------------------------------------
375
376bool sfxResolve( SFXDescription** description, String& errorString )
377{
378   return sResolve( description, errorString );
379}
380
381//-----------------------------------------------------------------------------
382
383bool sfxResolve( SFXTrack** track, String& errorString )
384{
385   return sResolve( track, errorString );
386}
387
388//-----------------------------------------------------------------------------
389
390bool sfxResolve( SFXEnvironment** environment, String& errorString )
391{
392   return sResolve( environment, errorString );
393}
394
395//-----------------------------------------------------------------------------
396
397bool sfxResolve( SFXState** state, String& errorString )
398{
399   return sResolve( state, errorString );
400}
401
402//-----------------------------------------------------------------------------
403
404bool sfxResolve( SFXAmbience** ambience, String& errorString )
405{
406   return sResolve( ambience, errorString );
407}
408
409//-----------------------------------------------------------------------------
410
411bool sfxReadAndResolve( BitStream* stream, SFXSource** source, String& errorString )
412{
413   if( !stream->readFlag() )
414   {
415      *source = NULL;
416      return true;
417   }
418   
419   const char* name = stream->readSTString();
420
421   SFXSource* object;
422   if( !Sim::findObject( name, object ) )
423   {
424      errorString = String::ToString( "sfxReadAndResolve - no SFXSource '%s'", name );
425      return false;
426   }
427   
428   *source = object;
429   return true;
430}
431