2018-01-28 14:48:02 -06:00
# pragma once
//-----------------------------------------------------------------------------
// Copyright (c) 2013 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
# ifndef SOUND_ASSET_H
# define SOUND_ASSET_H
# ifndef _ASSET_BASE_H_
# include "assets/assetBase.h"
# endif
# ifndef _ASSET_DEFINITION_H_
# include "assets/assetDefinition.h"
# endif
# ifndef _STRINGUNIT_H_
# include "string/stringUnit.h"
# endif
# ifndef _ASSET_FIELD_TYPES_H_
# include "assets/assetFieldTypes.h"
# endif
2022-05-26 18:04:37 -05:00
# ifndef _ASSET_PTR_H_
# include "assets/assetPtr.h"
# endif
2021-07-19 01:07:08 -05:00
# ifndef _BITSTREAM_H_
# include "core/stream/bitStream.h"
# endif
# ifndef _SFXRESOURCE_H_
# include "sfx/sfxResource.h"
# endif
# ifndef _SFXDESCRIPTION_H_
# include "sfx/sfxDescription.h"
# endif // !_SFXDESCRIPTION_H_
# ifndef _SFXPROFILE_H_
# include "sfx/sfxProfile.h"
# endif // !_SFXPROFILE_H_
2022-05-26 18:04:37 -05:00
# ifndef _RESOURCEMANAGER_H_
# include "core/resourceManager.h"
# endif
2021-10-03 02:56:26 -05:00
# include "assetMacroHelpers.h"
2021-07-19 01:07:08 -05:00
class SFXResource ;
2018-01-28 14:48:02 -06:00
//-----------------------------------------------------------------------------
class SoundAsset : public AssetBase
{
typedef AssetBase Parent ;
protected :
2019-05-04 11:49:42 -05:00
StringTableEntry mSoundFile ;
2020-08-09 01:32:27 -05:00
StringTableEntry mSoundPath ;
2021-07-19 01:07:08 -05:00
SFXProfile mSFXProfile ;
SFXDescription mProfileDesc ;
// subtitles
StringTableEntry mSubtitleString ;
bool mPreload ;
/*These will be needed in the refactor!
Resource < SFXResource > mSoundResource ;
// SFXDesctriptions, some off these will be removed
2018-01-28 14:48:02 -06:00
F32 mPitchAdjust ;
F32 mVolumeAdjust ;
2021-07-19 01:07:08 -05:00
bool mIs3D ;
bool mLoop ;
bool mIsStreaming ;
bool mUseHardware ;
F32 mMinDistance ;
F32 mMaxDistance ;
U32 mConeInsideAngle ;
U32 mConeOutsideAngle ;
F32 mConeOutsideVolume ;
F32 mRolloffFactor ;
Point3F mScatterDistance ;
F32 mPriority ;
*/
typedef Signal < void ( ) > SoundAssetChanged ;
SoundAssetChanged mChangeSignal ;
2018-01-28 14:48:02 -06:00
public :
SoundAsset ( ) ;
virtual ~ SoundAsset ( ) ;
/// Engine.
static void initPersistFields ( ) ;
virtual void copyTo ( SimObject * object ) ;
2021-07-19 01:07:08 -05:00
//SFXResource* getSound() { return mSoundResource; }
Resource < SFXResource > getSoundResource ( ) { return mSFXProfile . getResource ( ) ; }
2018-01-28 14:48:02 -06:00
/// Declare Console Object.
DECLARE_CONOBJECT ( SoundAsset ) ;
2020-08-24 20:24:50 -05:00
void setSoundFile ( const char * pSoundFile ) ;
2021-07-19 01:07:08 -05:00
bool loadSound ( ) ;
2019-05-04 11:49:42 -05:00
inline StringTableEntry getSoundFile ( void ) const { return mSoundFile ; } ;
2020-08-09 01:32:27 -05:00
inline StringTableEntry getSoundPath ( void ) const { return mSoundPath ; } ;
2021-07-19 01:07:08 -05:00
SFXProfile * getSfxProfile ( ) { return & mSFXProfile ; }
SFXDescription * getSfxDescription ( ) { return & mProfileDesc ; }
bool isLoop ( ) { return mProfileDesc . mIsLooping ; }
bool is3D ( ) { return mProfileDesc . mIs3D ; }
2021-08-31 00:54:05 -05:00
static StringTableEntry getAssetIdByFileName ( StringTableEntry fileName ) ;
static U32 getAssetById ( StringTableEntry assetId , AssetPtr < SoundAsset > * materialAsset ) ;
static U32 getAssetByFileName ( StringTableEntry fileName , AssetPtr < SoundAsset > * matAsset ) ;
2020-08-09 01:32:27 -05:00
2018-01-28 14:48:02 -06:00
protected :
virtual void initializeAsset ( void ) ;
2021-07-19 01:07:08 -05:00
void _onResourceChanged ( const Torque : : Path & path ) ;
2018-01-28 14:48:02 -06:00
virtual void onAssetRefresh ( void ) ;
2019-05-04 11:49:42 -05:00
static bool setSoundFile ( void * obj , const char * index , const char * data ) { static_cast < SoundAsset * > ( obj ) - > setSoundFile ( data ) ; return false ; }
static const char * getSoundFile ( void * obj , const char * data ) { return static_cast < SoundAsset * > ( obj ) - > getSoundFile ( ) ; }
2018-01-28 14:48:02 -06:00
} ;
DefineConsoleType ( TypeSoundAssetPtr , SoundAsset )
2021-07-19 01:07:08 -05:00
DefineConsoleType ( TypeSoundAssetId , String )
# pragma region Singular Asset Macros
//Singular assets
/// <Summary>
/// Declares a sound asset
/// This establishes the assetId, asset and legacy filepath fields, along with supplemental getter and setter functions
/// </Summary>
2021-08-31 00:54:05 -05:00
# define DECLARE_SOUNDASSET(className, name) public: \
2021-07-19 01:07:08 -05:00
Resource < SFXResource > m # # name ; \
StringTableEntry m # # name # # Name ; \
StringTableEntry m # # name # # AssetId ; \
AssetPtr < SoundAsset > m # # name # # Asset = NULL ; \
2021-08-31 00:54:05 -05:00
SFXProfile * m # # name # # Profile = NULL ; \
2022-05-26 18:04:37 -05:00
SFXDescription * m # # name # # Desc = NULL ; \
2023-01-01 22:55:26 -05:00
SimObjectId m # # name # # SFXId = 0 ; \
2021-07-19 01:07:08 -05:00
public : \
2021-08-31 00:54:05 -05:00
const StringTableEntry get # # name # # File ( ) const { return m # # name # # Name ; } \
2021-07-19 01:07:08 -05:00
void set # # name # # File ( const FileName & _in ) { m # # name # # Name = StringTable - > insert ( _in . c_str ( ) ) ; } \
const AssetPtr < SoundAsset > & get # # name # # Asset ( ) const { return m # # name # # Asset ; } \
void set # # name # # Asset ( const AssetPtr < SoundAsset > & _in ) { m # # name # # Asset = _in ; } \
\
bool _set # # name ( StringTableEntry _in ) \
{ \
if ( m # # name # # AssetId ! = _in | | m # # name # # Name ! = _in ) \
{ \
2021-08-29 17:41:20 -05:00
if ( _in = = NULL | | _in = = StringTable - > EmptyString ( ) ) \
2021-07-19 01:07:08 -05:00
{ \
m # # name # # Name = StringTable - > EmptyString ( ) ; \
m # # name # # AssetId = StringTable - > EmptyString ( ) ; \
m # # name # # Asset = NULL ; \
m # # name = NULL ; \
return true ; \
} \
\
if ( AssetDatabase . isDeclaredAsset ( _in ) ) \
{ \
m # # name # # AssetId = _in ; \
\
U32 assetState = SoundAsset : : getAssetById ( m # # name # # AssetId , & m # # name # # Asset ) ; \
\
if ( SoundAsset : : Ok = = assetState ) \
{ \
m # # name # # Name = StringTable - > EmptyString ( ) ; \
} \
} \
else \
{ \
2021-08-31 00:54:05 -05:00
StringTableEntry assetId = SoundAsset : : getAssetIdByFileName ( _in ) ; \
2021-07-19 01:07:08 -05:00
if ( assetId ! = StringTable - > EmptyString ( ) ) \
{ \
m # # name # # AssetId = assetId ; \
if ( SoundAsset : : getAssetById ( m # # name # # AssetId , & m # # name # # Asset ) = = SoundAsset : : Ok ) \
{ \
m # # name # # Name = StringTable - > EmptyString ( ) ; \
} \
} \
else \
{ \
m # # name # # Name = _in ; \
m # # name # # AssetId = StringTable - > EmptyString ( ) ; \
m # # name # # Asset = NULL ; \
} \
} \
} \
if ( get # # name ( ) ! = StringTable - > EmptyString ( ) & & m # # name # # Asset . notNull ( ) ) \
{ \
m # # name = m # # name # # Asset - > getSoundResource ( ) ; \
} \
else \
{ \
m # # name = NULL ; \
} \
2021-09-28 17:33:36 -05:00
if ( get # # name ( ) = = StringTable - > EmptyString ( ) ) \
return true ; \
2021-07-19 01:07:08 -05:00
\
2021-09-28 21:10:48 +01:00
if ( get # # name ( ) = = StringTable - > EmptyString ( ) ) \
return true ; \
2021-08-31 00:54:05 -05:00
if ( m # # name # # Asset . notNull ( ) & & m # # name # # Asset - > getStatus ( ) ! = SoundAsset : : Ok ) \
2021-07-19 01:07:08 -05:00
{ \
2021-08-31 00:54:05 -05:00
Con : : errorf ( " %s(%s)::_set%s() - sound asset failure \" %s \" due to [%s] " , macroText ( className ) , getName ( ) , macroText ( name ) , _in , SoundAsset : : getAssetErrstrn ( m # # name # # Asset - > getStatus ( ) ) . c_str ( ) ) ; \
2021-07-19 01:07:08 -05:00
return false ; \
} \
2022-06-03 03:23:27 -05:00
else if ( ! m # # name & & ( m # # name # # Name ! = StringTable - > EmptyString ( ) & & ! Sim : : findObject ( m # # name # # Name ) ) ) \
2021-07-19 01:07:08 -05:00
{ \
Con : : errorf ( " %s(%s)::_set%s() - Couldn't load sound \" %s \" " , macroText ( className ) , getName ( ) , macroText ( name ) , _in ) ; \
return false ; \
} \
return true ; \
} \
\
const StringTableEntry get # # name ( ) const \
{ \
if ( m # # name # # Asset & & ( m # # name # # Asset - > getSoundPath ( ) ! = StringTable - > EmptyString ( ) ) ) \
return m # # name # # Asset - > getSoundPath ( ) ; \
else if ( m # # name # # AssetId ! = StringTable - > EmptyString ( ) ) \
return m # # name # # AssetId ; \
else if ( m # # name # # Name ! = StringTable - > EmptyString ( ) ) \
return StringTable - > insert ( m # # name # # Name ) ; \
else \
return StringTable - > EmptyString ( ) ; \
} \
Resource < SFXResource > get # # name # # Resource ( ) \
{ \
return m # # name ; \
2021-09-26 17:30:13 -05:00
} \
SFXProfile * get # # name # # Profile ( ) \
{ \
2022-07-27 16:28:07 -05:00
if ( get # # name ( ) ! = StringTable - > EmptyString ( ) & & m # # name # # Asset . notNull ( ) ) { \
2022-05-26 18:04:37 -05:00
m # # name # # Profile = m # # name # # Asset - > getSfxProfile ( ) ; \
2022-07-27 16:28:07 -05:00
return m # # name # # Profile ; } \
2022-05-26 18:04:37 -05:00
return NULL ; \
} \
SFXDescription * get # # name # # Description ( ) \
{ \
2022-07-27 16:28:07 -05:00
if ( get # # name ( ) ! = StringTable - > EmptyString ( ) & & m # # name # # Asset . notNull ( ) ) { \
2022-05-26 18:04:37 -05:00
m # # name # # Desc = m # # name # # Asset - > getSfxDescription ( ) ; \
2022-07-27 16:28:07 -05:00
return m # # name # # Desc ; } \
2021-09-26 17:30:13 -05:00
return NULL ; \
2021-09-28 18:16:14 -05:00
} \
2021-09-28 18:50:35 -05:00
bool is # # name # # Valid ( ) { return ( get # # name ( ) ! = StringTable - > EmptyString ( ) & & m # # name # # Asset - > getStatus ( ) = = AssetBase : : Ok ) ; }
2021-07-19 01:07:08 -05:00
# ifdef TORQUE_SHOW_LEGACY_FILE_FIELDS
# define INITPERSISTFIELD_SOUNDASSET(name, consoleClass, docs) \
addProtectedField ( assetText ( name , File ) , TypeSoundFilename , Offset ( m # # name # # Name , consoleClass ) , _set # # name # # Data , & defaultProtectedGetFn , assetText ( name , docs ) ) ; \
addProtectedField ( assetText ( name , Asset ) , TypeSoundAssetId , Offset ( m # # name # # AssetId , consoleClass ) , _set # # name # # Data , & defaultProtectedGetFn , assetText ( name , asset reference . ) ) ;
# else
# define INITPERSISTFIELD_SOUNDASSET(name, consoleClass, docs) \
addProtectedField ( assetText ( name , File ) , TypeSoundFilename , Offset ( m # # name # # Name , consoleClass ) , _set # # name # # Data , & defaultProtectedGetFn , assetText ( name , docs ) , AbstractClassRep : : FIELD_HideInInspectors ) ; \
addProtectedField ( assetText ( name , Asset ) , TypeSoundAssetId , Offset ( m # # name # # AssetId , consoleClass ) , _set # # name # # Data , & defaultProtectedGetFn , assetText ( name , asset reference . ) ) ;
# endif // TORQUE_SHOW_LEGACY_FILE_FIELDS
2022-05-26 18:04:37 -05:00
//network send - datablock
# define PACKDATA_SOUNDASSET(name)\
if ( stream - > writeFlag ( m # # name # # Asset . notNull ( ) ) ) \
{ \
2022-06-04 00:59:06 -05:00
stream - > writeString ( m # # name # # Asset . getAssetId ( ) ) ; \
2022-05-26 18:04:37 -05:00
} \
else \
2022-06-04 00:59:06 -05:00
{ \
if ( stream - > writeFlag ( Sim : : findObject ( m # # name # # Name ) ) ) \
{ \
SFXTrack * sndTrack ; \
Sim : : findObject ( m # # name # # Name , sndTrack ) ; \
stream - > writeRangedU32 ( SimObjectId ( sndTrack - > getId ( ) ) , DataBlockObjectIdFirst , DataBlockObjectIdLast ) ; \
} \
else \
{ \
stream - > writeString ( m # # name # # Name ) ; \
} \
}
2022-05-26 18:04:37 -05:00
//network recieve - datablock
# define UNPACKDATA_SOUNDASSET(name)\
if ( stream - > readFlag ( ) ) \
{ \
2022-06-04 00:59:06 -05:00
m # # name # # AssetId = stream - > readSTString ( ) ; \
_set # # name ( m # # name # # AssetId ) ; \
2022-05-26 18:04:37 -05:00
} \
else \
{ \
2022-06-04 00:59:06 -05:00
if ( stream - > readFlag ( ) ) \
{ \
m # # name # # SFXId = stream - > readRangedU32 ( DataBlockObjectIdFirst , DataBlockObjectIdLast ) ; \
} \
else \
{ \
m # # name # # Name = stream - > readSTString ( ) ; \
_set # # name ( m # # name # # Name ) ; \
} \
2022-05-26 18:04:37 -05:00
}
2021-07-19 01:07:08 -05:00
# pragma endregion
2018-01-28 14:48:02 -06:00
2021-09-20 09:55:36 +01:00
# pragma region Arrayed Asset Macros
2022-06-04 00:59:06 -05:00
# define INIT_SOUNDASSET_ARRAY(name, index) \
{ \
m # # name # # Name [ index ] = StringTable - > EmptyString ( ) ; \
m # # name # # AssetId [ index ] = StringTable - > EmptyString ( ) ; \
m # # name # # Asset [ index ] = NULL ; \
m # # name [ index ] = NULL ; \
m # # name # # Profile [ index ] = NULL ; \
m # # name # # SFXId [ index ] = 0 ; \
}
2021-09-20 10:49:34 +01:00
# define DECLARE_SOUNDASSET_ARRAY(className,name,max) public: \
static const U32 sm # # name # # Count = max ; \
2021-09-20 09:55:36 +01:00
Resource < SFXResource > m # # name [ max ] ; \
StringTableEntry m # # name # # Name [ max ] ; \
StringTableEntry m # # name # # AssetId [ max ] ; \
2021-09-20 10:49:34 +01:00
AssetPtr < SoundAsset > m # # name # # Asset [ max ] ; \
SFXProfile * m # # name # # Profile [ max ] ; \
2022-06-04 00:59:06 -05:00
SimObjectId m # # name # # SFXId [ max ] ; \
2021-09-20 09:55:36 +01:00
public : \
2021-09-20 10:49:34 +01:00
const StringTableEntry get # # name # # File ( const U32 & index ) const { return m # # name # # Name [ index ] ; } \
void set # # name # # File ( const FileName & _in , const U32 & index ) { m # # name # # Name [ index ] = StringTable - > insert ( _in . c_str ( ) ) ; } \
const AssetPtr < SoundAsset > & get # # name # # Asset ( const U32 & index ) const { return m # # name # # Asset [ index ] ; } \
void set # # name # # Asset ( const AssetPtr < SoundAsset > & _in , const U32 & index ) { m # # name # # Asset [ index ] = _in ; } \
2021-09-20 09:55:36 +01:00
\
2021-09-20 10:49:34 +01:00
bool _set # # name ( StringTableEntry _in , const U32 & index ) \
2021-09-20 09:55:36 +01:00
{ \
2021-09-20 10:49:34 +01:00
if ( m # # name # # AssetId [ index ] ! = _in | | m # # name # # Name [ index ] ! = _in ) \
2021-09-20 09:55:36 +01:00
{ \
2021-09-20 10:49:34 +01:00
if ( index > = sm # # name # # Count | | index < 0 ) \
return false ; \
2021-09-20 09:55:36 +01:00
if ( _in = = NULL | | _in = = StringTable - > EmptyString ( ) ) \
{ \
2021-09-20 10:49:34 +01:00
m # # name # # Name [ index ] = StringTable - > EmptyString ( ) ; \
m # # name # # AssetId [ index ] = StringTable - > EmptyString ( ) ; \
m # # name # # Asset [ index ] = NULL ; \
m # # name [ index ] = NULL ; \
return true ; \
} \
else if ( _in [ 0 ] = = ' $ ' | | _in [ 0 ] = = ' # ' ) \
{ \
m # # name # # Name [ index ] = _in ; \
m # # name # # AssetId [ index ] = StringTable - > EmptyString ( ) ; \
m # # name # # Asset [ index ] = NULL ; \
m # # name [ index ] = NULL ; \
2021-09-20 09:55:36 +01:00
return true ; \
} \
\
if ( AssetDatabase . isDeclaredAsset ( _in ) ) \
{ \
2021-09-20 10:49:34 +01:00
m # # name # # AssetId [ index ] = _in ; \
2021-09-20 09:55:36 +01:00
\
2021-09-20 10:49:34 +01:00
U32 assetState = SoundAsset : : getAssetById ( m # # name # # AssetId [ index ] , & m # # name # # Asset [ index ] ) ; \
2021-09-20 09:55:36 +01:00
\
if ( SoundAsset : : Ok = = assetState ) \
{ \
2021-09-20 10:49:34 +01:00
m # # name # # Name [ index ] = StringTable - > EmptyString ( ) ; \
2021-09-20 09:55:36 +01:00
} \
} \
else \
{ \
StringTableEntry assetId = SoundAsset : : getAssetIdByFileName ( _in ) ; \
if ( assetId ! = StringTable - > EmptyString ( ) ) \
{ \
2021-09-20 10:49:34 +01:00
m # # name # # AssetId [ index ] = assetId ; \
if ( SoundAsset : : getAssetById ( m # # name # # AssetId [ index ] , & m # # name # # Asset [ index ] ) = = SoundAsset : : Ok ) \
2021-09-20 09:55:36 +01:00
{ \
2021-09-20 10:49:34 +01:00
m # # name # # Name [ index ] = StringTable - > EmptyString ( ) ; \
2021-09-20 09:55:36 +01:00
} \
} \
else \
{ \
2021-09-20 10:49:34 +01:00
m # # name # # Name [ index ] = _in ; \
m # # name # # AssetId [ index ] = StringTable - > EmptyString ( ) ; \
m # # name # # Asset [ index ] = NULL ; \
2021-09-20 09:55:36 +01:00
} \
} \
} \
2021-09-20 10:49:34 +01:00
if ( get # # name ( index ) ! = StringTable - > EmptyString ( ) & & m # # name # # Asset [ index ] . notNull ( ) ) \
2021-09-20 09:55:36 +01:00
{ \
2021-09-20 10:49:34 +01:00
m # # name [ index ] = m # # name # # Asset [ index ] - > getSoundResource ( ) ; \
2021-09-20 09:55:36 +01:00
} \
else \
{ \
2021-09-20 10:49:34 +01:00
m # # name [ index ] = NULL ; \
2021-09-20 09:55:36 +01:00
} \
2021-09-26 17:30:13 -05:00
if ( get # # name ( index ) = = StringTable - > EmptyString ( ) ) \
return true ; \
2021-09-20 09:55:36 +01:00
\
2021-09-20 10:49:34 +01:00
if ( m # # name # # Asset [ index ] . notNull ( ) & & m # # name # # Asset [ index ] - > getStatus ( ) ! = SoundAsset : : Ok ) \
2021-09-20 09:55:36 +01:00
{ \
2021-09-20 10:49:34 +01:00
Con : : errorf ( " %s(%s)::_set%s(%i) - sound asset failure \" %s \" due to [%s] " , macroText ( className ) , getName ( ) , macroText ( name ) , index , _in , SoundAsset : : getAssetErrstrn ( m # # name # # Asset [ index ] - > getStatus ( ) ) . c_str ( ) ) ; \
2021-09-20 09:55:36 +01:00
return false ; \
} \
2022-06-03 03:23:27 -05:00
else if ( ! m # # name [ index ] & & ( m # # name # # Name [ index ] ! = StringTable - > EmptyString ( ) & & ! Sim : : findObject ( m # # name # # Name [ index ] ) ) ) \
2021-09-20 09:55:36 +01:00
{ \
2021-09-20 10:49:34 +01:00
Con : : errorf ( " %s(%s)::_set%s(%i) - Couldn't load sound \" %s \" " , macroText ( className ) , getName ( ) , macroText ( name ) , index , _in ) ; \
2021-09-20 09:55:36 +01:00
return false ; \
} \
return true ; \
} \
\
2021-09-20 10:49:34 +01:00
const StringTableEntry get # # name ( const U32 & index ) const \
2021-09-20 09:55:36 +01:00
{ \
2021-09-20 10:49:34 +01:00
if ( m # # name # # Asset [ index ] & & ( m # # name # # Asset [ index ] - > getSoundPath ( ) ! = StringTable - > EmptyString ( ) ) ) \
return m # # name # # Asset [ index ] - > getSoundPath ( ) ; \
else if ( m # # name # # AssetId [ index ] ! = StringTable - > EmptyString ( ) ) \
return m # # name # # AssetId [ index ] ; \
else if ( m # # name # # Name [ index ] ! = StringTable - > EmptyString ( ) ) \
return StringTable - > insert ( m # # name # # Name [ index ] ) ; \
2021-09-20 09:55:36 +01:00
else \
return StringTable - > EmptyString ( ) ; \
} \
2021-09-20 10:49:34 +01:00
Resource < SFXResource > get # # name # # Resource ( const U32 & id ) \
2021-09-20 09:55:36 +01:00
{ \
2021-09-20 10:49:34 +01:00
if ( id > = sm # # name # # Count | | id < 0 ) \
return ResourceManager : : get ( ) . load ( " " ) ; \
return m # # name [ id ] ; \
2021-09-26 17:30:13 -05:00
} \
SFXProfile * get # # name # # Profile ( const U32 & id ) \
{ \
if ( get # # name ( id ) ! = StringTable - > EmptyString ( ) & & m # # name # # Asset [ id ] . notNull ( ) ) \
return m # # name # # Asset [ id ] - > getSfxProfile ( ) ; \
return NULL ; \
2021-09-28 18:16:14 -05:00
} \
2021-09-28 18:50:35 -05:00
bool is # # name # # Valid ( const U32 & id ) { return ( get # # name ( id ) ! = StringTable - > EmptyString ( ) & & m # # name # # Asset [ id ] - > getStatus ( ) = = AssetBase : : Ok ) ; }
2021-09-20 09:55:36 +01:00
# ifdef TORQUE_SHOW_LEGACY_FILE_FIELDS
# define INITPERSISTFIELD_IMAGEASSET_ARRAY(name, arraySize, consoleClass, docs) \
2021-09-20 10:49:34 +01:00
addProtectedField ( # name , TypeSoundFilename , Offset ( m # # name # # Name , consoleClass ) , _set # # name # # Data , & defaultProtectedGetFn , arraySize , assetDoc ( name , docs ) ) ; \
2021-09-20 09:55:36 +01:00
addProtectedField ( assetText ( name , Asset ) , TypeImageAssetId , Offset ( m # # name # # AssetId , consoleClass ) , _set # # name # # Data , & defaultProtectedGetFn , arraySize , assetDoc ( name , asset docs . ) ) ;
# else
# define INITPERSISTFIELD_SOUNDASSET_ARRAY(name, arraySize, consoleClass, docs) \
2021-09-20 10:49:34 +01:00
addProtectedField ( # name , TypeSoundFilename , Offset ( m # # name # # Name , consoleClass ) , _set # # name # # Data , & defaultProtectedGetFn , arraySize , assetDoc ( name , docs ) , AbstractClassRep : : FIELD_HideInInspectors ) ; \
addProtectedField ( assetText ( name , Asset ) , TypeSoundAssetId , Offset ( m # # name # # AssetId , consoleClass ) , _set # # name # # Data , & defaultProtectedGetFn , arraySize , assetDoc ( name , asset docs . ) ) ;
2021-09-20 09:55:36 +01:00
# endif
# define LOAD_SOUNDASSET_ARRAY(name, index)\
if ( m # # name # # AssetId [ index ] ! = StringTable - > EmptyString ( ) ) \
{ \
S32 assetState = SoundAsset : : getAssetById ( m # # name # # AssetId [ index ] , & m # # name # # Asset [ index ] ) ; \
if ( assetState = = SoundAsset : : Ok ) \
{ \
m # # name # # Name [ index ] = StringTable - > EmptyString ( ) ; \
} \
2021-10-11 14:38:14 -05:00
else Con : : warnf ( " Warning: %s::LOAD_SOUNDASSET_ARRAY(%s[%i])-%s " , mClassName , m # # name # # AssetId [ index ] , index , ImageAsset : : getAssetErrstrn ( assetState ) . c_str ( ) ) ; \
2021-09-20 09:55:36 +01:00
}
2021-10-02 23:24:46 -05:00
# define assetEnumNameConcat(x,suff)(new std::string( x + std::string(#suff)))->c_str()
# define INITPERSISTFIELD_SOUNDASSET_ENUMED(name, enumType, maxValue, consoleClass, docs) \
for ( U32 i = 0 ; i < maxValue ; i + + ) \
{ \
2021-10-11 14:38:14 -05:00
const enumType itter = static_cast < enumType > ( i ) ; \
const char * enumString = castConsoleTypeToString ( static_cast < enumType > ( itter ) ) ; \
2021-10-02 23:24:46 -05:00
if ( enumString & & enumString [ 0 ] ) \
2021-10-03 02:56:26 -05:00
{ \
2023-01-01 16:56:59 -06:00
addField ( assetEnumNameConcat ( enumString , File ) , TypeSoundFilename , Offset ( m # # name # # Name [ 0 ] , consoleClass ) + sizeof ( m # # name # # Name [ 0 ] ) * i , assetText ( name , docs ) , AbstractClassRep : : FIELD_HideInInspectors ) ; \
addField ( assetEnumNameConcat ( enumString , Asset ) , TypeSoundAssetId , Offset ( m # # name # # AssetId [ 0 ] , consoleClass ) + sizeof ( m # # name # # AssetId [ 0 ] ) * i , assetText ( name , asset reference . ) ) ; \
2021-10-02 23:24:46 -05:00
} \
}
2022-06-04 00:59:06 -05:00
# define PACKDATA_SOUNDASSET_ARRAY(name, index)\
2022-12-27 21:10:15 -06:00
if ( stream - > writeFlag ( AssetDatabase . isDeclaredAsset ( m # # name # # AssetId [ index ] ) ) ) \
2022-06-04 00:59:06 -05:00
{ \
2022-12-27 21:10:15 -06:00
stream - > writeString ( m # # name # # AssetId [ index ] ) ; \
2022-06-04 00:59:06 -05:00
} \
else \
{ \
if ( stream - > writeFlag ( Sim : : findObject ( m # # name # # Name [ index ] ) ) ) \
{ \
SFXTrack * sndTrack ; \
Sim : : findObject ( m # # name # # Name [ index ] , sndTrack ) ; \
stream - > writeRangedU32 ( SimObjectId ( sndTrack - > getId ( ) ) , DataBlockObjectIdFirst , DataBlockObjectIdLast ) ; \
} \
else \
{ \
stream - > writeString ( m # # name # # Name [ index ] ) ; \
} \
}
//network recieve - datablock
# define UNPACKDATA_SOUNDASSET_ARRAY(name, index)\
if ( stream - > readFlag ( ) ) \
{ \
m # # name # # AssetId [ index ] = stream - > readSTString ( ) ; \
_set # # name ( m # # name # # AssetId [ index ] , index ) ; \
} \
else \
{ \
if ( stream - > readFlag ( ) ) \
{ \
m # # name # # SFXId [ index ] = stream - > readRangedU32 ( DataBlockObjectIdFirst , DataBlockObjectIdLast ) ; \
} \
else \
{ \
m # # name # # Name [ index ] = stream - > readSTString ( ) ; \
_set # # name ( m # # name # # Name [ index ] , index ) ; \
} \
}
2021-09-20 09:55:36 +01:00
# pragma endregion
2018-01-28 14:48:02 -06:00
# endif // _ASSET_BASE_H_