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
2021-07-19 01:07:08 -05:00
# include "gui/editor/guiInspectorTypes.h"
# 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_
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 ; }
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 )
//-----------------------------------------------------------------------------
// TypeAssetId GuiInspectorField Class
//-----------------------------------------------------------------------------
class GuiInspectorTypeSoundAssetPtr : public GuiInspectorTypeFileName
{
typedef GuiInspectorTypeFileName Parent ;
public :
GuiBitmapButtonCtrl * mSoundButton ;
DECLARE_CONOBJECT ( GuiInspectorTypeSoundAssetPtr ) ;
static void consoleInit ( ) ;
virtual GuiControl * constructEditControl ( ) ;
virtual bool updateRects ( ) ;
} ;
class GuiInspectorTypeSoundAssetId : public GuiInspectorTypeSoundAssetPtr
{
typedef GuiInspectorTypeSoundAssetPtr Parent ;
public :
DECLARE_CONOBJECT ( GuiInspectorTypeSoundAssetId ) ;
static void consoleInit ( ) ;
} ;
# 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>
# define DECLARE_SOUNDASSET(className, name, profile) public: \
Resource < SFXResource > m # # name ; \
StringTableEntry m # # name # # Name ; \
StringTableEntry m # # name # # AssetId ; \
AssetPtr < SoundAsset > m # # name # # Asset = NULL ; \
SFXProfile * m # # name # # Profile = & profile ; \
public : \
const StringTableEntry get # # name # # File ( ) const { return m # # name # # Name ) ; } \
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 \
{ \
StringTableEntry assetId = SoundAsset : : getAssetIdByFilename ( _in ) ; \
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 ; \
} \
\
if ( m # # name # # Asset . notNull ( ) & & m # # name # # Asset - > getStatus ( ) ! = ShapeAsset : : Ok ) \
{ \
Con : : errorf ( " %s(%s)::_set%s() - sound asset failure \" %s \" due to [%s] " , macroText ( className ) , getName ( ) , macroText ( name ) , _in , ShapeAsset : : getAssetErrstrn ( m # # name # # Asset - > getStatus ( ) ) . c_str ( ) ) ; \
return false ; \
} \
2021-08-29 18:32:44 -05:00
else if ( m # # 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 ; \
}
# define DECLARE_SOUNDASSET_SETGET(className, name)\
static bool _set # # name # # Data ( void * obj , const char * index , const char * data ) \
{ \
bool ret = false ; \
className * object = static_cast < className * > ( obj ) ; \
ret = object - > _set # # name ( StringTable - > insert ( data ) ) ; \
return ret ; \
}
# define DECLARE_SOUNDASSET_NET_SETGET(className, name, bitmask)\
static bool _set # # name # # Data ( void * obj , const char * index , const char * data ) \
{ \
bool ret = false ; \
className * object = static_cast < className * > ( obj ) ; \
ret = object - > _set # # name ( StringTable - > insert ( data ) ) ; \
if ( ret ) \
object - > setMaskBits ( bitmask ) ; \
return ret ; \
}
# define DEF_SOUNDASSET_BINDS(className,name)\
DefineEngineMethod ( className , get # # name , String , ( ) , , " get name " ) \
{ \
return object - > get # # name ( ) ; \
} \
DefineEngineMethod ( className , get # # name # # Asset , String , ( ) , , assetText ( name , asset reference ) ) \
{ \
return object - > m # # name # # AssetId ; \
} \
DefineEngineMethod ( className , set # # name , bool , ( const char * shape ) , , assetText ( name , assignment . first tries asset then flat file . ) ) \
{ \
return object - > _set # # name ( StringTable - > insert ( shape ) ) ; \
}
# define INIT_SOUNDASSET(name) \
m # # name # # Name = StringTable - > EmptyString ( ) ; \
m # # name # # AssetId = StringTable - > EmptyString ( ) ; \
m # # name # # Asset = NULL ; \
m # # name = NULL ; \
# 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
# define CLONE_SOUNDASSET(name) \
m # # name # # Name = other . m # # name # # Name ; \
m # # name # # AssetId = other . m # # name # # AssetId ; \
m # # name # # Asset = other . m # # name # # Asset ; \
# define PACKDATA_SOUNDASSET(name)\
if ( stream - > writeFlag ( m # # name # # Asset . notNull ( ) ) ) \
{ \
stream - > writeString ( m # # name # # Asset . getAssetId ( ) ) ; \
} \
else \
stream - > writeString ( m # # name # # Name ) ;
# define UNPACKDATA_SOUNDASSET(name)\
if ( stream - > readFlag ( ) ) \
{ \
m # # name # # AssetId = stream - > readSTString ( ) ; \
_set # # name ( m # # name # # AssetId ) ; \
} \
else \
m # # name # # Name = stream - > readSTString ( ) ;
# define PACK_SOUNDASSET(netconn, name)\
if ( stream - > writeFlag ( m # # name # # Asset . notNull ( ) ) ) \
{ \
NetStringHandle assetIdStr = m # # name # # Asset . getAssetId ( ) ; \
netconn - > packNetStringHandleU ( stream , assetIdStr ) ; \
} \
else \
stream - > writeString ( m # # name # # Name ) ;
# define UNPACK_SOUNDASSET(netconn, name)\
if ( stream - > readFlag ( ) ) \
{ \
m # # name # # AssetId = StringTable - > insert ( netconn - > unpackNetStringHandleU ( stream ) . getString ( ) ) ; \
_set # # name ( m # # name # # AssetId ) ; \
} \
else \
m # # name # # Name = stream - > readSTString ( ) ;
# pragma endregion
2018-01-28 14:48:02 -06:00
# endif // _ASSET_BASE_H_