mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-03-25 07:09:27 +00:00
sound asset refactor init
This commit is contained in:
parent
d87655bb3a
commit
2bf2da74a0
4 changed files with 130 additions and 11 deletions
|
|
@ -110,6 +110,55 @@ ConsoleSetType(TypeSoundAssetId)
|
|||
Con::warnf("(TypeAssetId) - Cannot set multiple args to a single asset.");
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// REFACTOR
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
IMPLEMENT_STRUCT(AssetPtr<SoundAsset>, AssetPtrSoundAsset, , "")
|
||||
END_IMPLEMENT_STRUCT
|
||||
|
||||
ConsoleType(SoundAssetPtr, TypeSoundAssetPtrRefactor, AssetPtr<SoundAsset>, ASSET_ID_FIELD_PREFIX)
|
||||
|
||||
|
||||
ConsoleGetType(TypeSoundAssetPtrRefactor)
|
||||
{
|
||||
// Fetch asset Id.
|
||||
return (*((AssetPtr<SoundAsset>*)dptr)).getAssetId();
|
||||
}
|
||||
|
||||
ConsoleSetType(TypeSoundAssetPtrRefactor)
|
||||
{
|
||||
// Was a single argument specified?
|
||||
if (argc == 1)
|
||||
{
|
||||
// Yes, so fetch field value.
|
||||
const char* pFieldValue = argv[0];
|
||||
|
||||
// Fetch asset pointer.
|
||||
AssetPtr<SoundAsset>* pAssetPtr = dynamic_cast<AssetPtr<SoundAsset>*>((AssetPtrBase*)(dptr));
|
||||
|
||||
// Is the asset pointer the correct type?
|
||||
if (pAssetPtr == NULL)
|
||||
{
|
||||
// No, so fail.
|
||||
Con::warnf("(TypeSoundAssetPtr) - Failed to set asset Id '%d'.", pFieldValue);
|
||||
return;
|
||||
}
|
||||
|
||||
// Set asset.
|
||||
pAssetPtr->setAssetId(pFieldValue);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Warn.
|
||||
Con::warnf("(TypeSoundAssetPtr) - Cannot set multiple args to a single asset.");
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// REFACTOR END
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
const String SoundAsset::mErrCodeStrings[] =
|
||||
{
|
||||
"BadProfile",
|
||||
|
|
|
|||
|
|
@ -180,6 +180,9 @@ protected:
|
|||
DefineConsoleType(TypeSoundAssetPtr, SoundAsset)
|
||||
DefineConsoleType(TypeSoundAssetId, String)
|
||||
|
||||
DECLARE_STRUCT(AssetPtr<SoundAsset>)
|
||||
DefineConsoleType(TypeSoundAssetPtrRefactor, AssetPtr<SoundAsset>)
|
||||
|
||||
#pragma region Singular Asset Macros
|
||||
|
||||
//Singular assets
|
||||
|
|
@ -579,5 +582,74 @@ if (m##name##AssetId[index] != StringTable->EmptyString())\
|
|||
}
|
||||
#pragma endregion
|
||||
|
||||
|
||||
#pragma region Refactor Asset Macros
|
||||
|
||||
#define DECLARE_SOUNDASSET_REFACTOR(className, name) \
|
||||
private: \
|
||||
AssetPtr<SoundAsset> m##name##Asset; \
|
||||
public: \
|
||||
void _set##name(StringTableEntry _in) { \
|
||||
\
|
||||
if (m##name##Asset.getAssetId() == _in) \
|
||||
return; \
|
||||
\
|
||||
if (!AssetDatabase.isDeclaredAsset(_in)) \
|
||||
{ \
|
||||
StringTableEntry imageAssetId = StringTable->EmptyString(); \
|
||||
AssetQuery query; \
|
||||
S32 foundAssetcount = AssetDatabase.findAssetLooseFile(&query, _in); \
|
||||
if (foundAssetcount != 0) \
|
||||
{ \
|
||||
imageAssetId = query.mAssetList[0]; \
|
||||
} \
|
||||
m##name##Asset = imageAssetId; \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
m##name##Asset = _in; \
|
||||
} \
|
||||
}; \
|
||||
\
|
||||
inline StringTableEntry _get##name(void) const { return m##name##Asset.getAssetId(); } \
|
||||
AssetPtr<SoundAsset> get##name##Asset(void) { return m##name##Asset; } \
|
||||
static bool _set##name##Data(void* obj, const char* index, const char* data) { static_cast<className*>(obj)->_set##name(_getStringTable()->insert(data)); return false; }
|
||||
|
||||
#define DECLARE_SOUNDASSET_NET_REFACTOR(className, name, profile, mask) \
|
||||
private: \
|
||||
AssetPtr<SoundAsset> m##name##Asset; \
|
||||
public: \
|
||||
void _set##name(StringTableEntry _in){ \
|
||||
if(m##name##Asset.getAssetId() == _in) \
|
||||
return; \
|
||||
\
|
||||
if(!AssetDatabase.isDeclaredAsset(_in)) \
|
||||
{ \
|
||||
StringTableEntry imageAssetId = StringTable->EmptyString(); \
|
||||
AssetQuery query; \
|
||||
S32 foundAssetcount = AssetDatabase.findAssetLooseFile(&query, _in); \
|
||||
if (foundAssetcount != 0) \
|
||||
{ \
|
||||
imageAssetId = query.mAssetList[0]; \
|
||||
} \
|
||||
m##name##Asset = imageAssetId; \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
m##name##Asset = _in; \
|
||||
} \
|
||||
setMaskBits(mask); \
|
||||
}; \
|
||||
\
|
||||
inline StringTableEntry _get##name(void) const { return m##name##Asset.getAssetId(); } \
|
||||
AssetPtr<SoundAsset> get##name##Asset(void) { return m##name##Asset; } \
|
||||
static bool _set##name##Data(void* obj, const char* index, const char* data) { static_cast<className*>(obj)->_set##name(_getStringTable()->insert(data)); return false;}
|
||||
|
||||
|
||||
#define INITPERSISTFIELD_SSOUNDASSET_REFACTOR(name, consoleClass, docs) \
|
||||
addProtectedField(assetText(name, Asset), TypeSoundAssetPtrRefactor, Offset(m##name##Asset, consoleClass), _set##name##Data, &defaultProtectedGetFn, assetDoc(name, asset docs.));
|
||||
|
||||
#pragma endregion
|
||||
|
||||
#endif // _ASSET_BASE_H_
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue