mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-07-12 23:24:41 +00:00
Merge pull request #970 from Areloch/ScriptableAssets
Expands ScriptAsset behavior to operate as a generic type-settable asset
This commit is contained in:
commit
dfd25dbd52
6 changed files with 50 additions and 4 deletions
|
|
@ -89,6 +89,15 @@ ConsoleSetType(TypeScriptAssetPtr)
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
IMPLEMENT_CALLBACK(ScriptAsset, onInitializeAsset, void, (), (),
|
||||||
|
"@brief When the ScriptAsset is initialized(loaded) by the AssetManager.\n\n");
|
||||||
|
|
||||||
|
IMPLEMENT_CALLBACK(ScriptAsset, onRefreshAsset, void, (), (),
|
||||||
|
"@brief When the ScriptAsset is refreshed by the AssetManager.\n\n");
|
||||||
|
|
||||||
|
IMPLEMENT_CALLBACK(ScriptAsset, onUnloadAsset, void, (), (),
|
||||||
|
"@brief When the ScriptAsset is unloaded by the AssetManager.\n\n");
|
||||||
|
|
||||||
ScriptAsset::ScriptAsset() : AssetBase(), mIsServerSide(true)
|
ScriptAsset::ScriptAsset() : AssetBase(), mIsServerSide(true)
|
||||||
{
|
{
|
||||||
mScriptFile = StringTable->EmptyString();
|
mScriptFile = StringTable->EmptyString();
|
||||||
|
|
@ -123,6 +132,12 @@ void ScriptAsset::copyTo(SimObject* object)
|
||||||
|
|
||||||
void ScriptAsset::initializeAsset()
|
void ScriptAsset::initializeAsset()
|
||||||
{
|
{
|
||||||
|
if (mpAssetDefinition->mAssetType != StringTable->insert("ScriptAsset"))
|
||||||
|
{
|
||||||
|
//if we've got a custom type, treat it as our namespace, too
|
||||||
|
setClassNamespace(mpAssetDefinition->mAssetType);
|
||||||
|
}
|
||||||
|
|
||||||
mScriptPath = getOwned() ? expandAssetFilePath(mScriptFile) : mScriptPath;
|
mScriptPath = getOwned() ? expandAssetFilePath(mScriptFile) : mScriptPath;
|
||||||
|
|
||||||
if (Torque::FS::IsScriptFile(mScriptPath))
|
if (Torque::FS::IsScriptFile(mScriptPath))
|
||||||
|
|
@ -138,7 +153,7 @@ void ScriptAsset::initializeAsset()
|
||||||
{
|
{
|
||||||
AssetPtr<ScriptAsset> scriptAsset = assetDependenciesItr->value;
|
AssetPtr<ScriptAsset> scriptAsset = assetDependenciesItr->value;
|
||||||
|
|
||||||
mScriptAssets.push_front(scriptAsset);
|
mScriptAssetDependencies.push_front(scriptAsset);
|
||||||
|
|
||||||
// Next dependency.
|
// Next dependency.
|
||||||
assetDependenciesItr++;
|
assetDependenciesItr++;
|
||||||
|
|
@ -147,6 +162,8 @@ void ScriptAsset::initializeAsset()
|
||||||
|
|
||||||
Con::executeFile(mScriptPath, false, false);
|
Con::executeFile(mScriptPath, false, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onInitializeAsset_callback();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScriptAsset::onAssetRefresh()
|
void ScriptAsset::onAssetRefresh()
|
||||||
|
|
@ -156,13 +173,20 @@ void ScriptAsset::onAssetRefresh()
|
||||||
if (Torque::FS::IsScriptFile(mScriptPath))
|
if (Torque::FS::IsScriptFile(mScriptPath))
|
||||||
{
|
{
|
||||||
//Refresh any dependencies we may have
|
//Refresh any dependencies we may have
|
||||||
for (U32 i = 0; i < mScriptAssets.size(); i++)
|
for (U32 i = 0; i < mScriptAssetDependencies.size(); i++)
|
||||||
{
|
{
|
||||||
mScriptAssets[i]->onAssetRefresh();
|
mScriptAssetDependencies[i]->onAssetRefresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
Con::executeFile(mScriptPath, false, false);
|
Con::executeFile(mScriptPath, false, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onRefreshAsset_callback();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ScriptAsset::unloadAsset()
|
||||||
|
{
|
||||||
|
onUnloadAsset_callback();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScriptAsset::setScriptFile(const char* pScriptFile)
|
void ScriptAsset::setScriptFile(const char* pScriptFile)
|
||||||
|
|
@ -205,3 +229,4 @@ DefineEngineMethod(ScriptAsset, execScript, bool, (), ,
|
||||||
{
|
{
|
||||||
return object->execScript();
|
return object->execScript();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -52,7 +52,7 @@ class ScriptAsset : public AssetBase
|
||||||
StringTableEntry mScriptPath;
|
StringTableEntry mScriptPath;
|
||||||
bool mIsServerSide;
|
bool mIsServerSide;
|
||||||
|
|
||||||
Vector<AssetPtr<ScriptAsset>> mScriptAssets;
|
Vector<AssetPtr<ScriptAsset>> mScriptAssetDependencies;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ScriptAsset();
|
ScriptAsset();
|
||||||
|
|
@ -72,9 +72,14 @@ public:
|
||||||
|
|
||||||
bool execScript();
|
bool execScript();
|
||||||
|
|
||||||
|
DECLARE_CALLBACK(void, onInitializeAsset, ());
|
||||||
|
DECLARE_CALLBACK(void, onRefreshAsset, ());
|
||||||
|
DECLARE_CALLBACK(void, onUnloadAsset, ());
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void initializeAsset(void);
|
virtual void initializeAsset(void);
|
||||||
virtual void onAssetRefresh(void);
|
virtual void onAssetRefresh(void);
|
||||||
|
virtual void unloadAsset(void);
|
||||||
|
|
||||||
static bool setScriptFile(void *obj, const char *index, const char *data) { static_cast<ScriptAsset*>(obj)->setScriptFile(data); return false; }
|
static bool setScriptFile(void *obj, const char *index, const char *data) { static_cast<ScriptAsset*>(obj)->setScriptFile(data); return false; }
|
||||||
static const char* getScriptFile(void* obj, const char* data) { return static_cast<ScriptAsset*>(obj)->getScriptFile(); }
|
static const char* getScriptFile(void* obj, const char* data) { return static_cast<ScriptAsset*>(obj)->getScriptFile(); }
|
||||||
|
|
|
||||||
|
|
@ -50,6 +50,7 @@ StringTableEntry assetCategoryField = StringTable->insert("AssetCategory");
|
||||||
StringTableEntry assetAutoUnloadField = StringTable->insert("AssetAutoUnload");
|
StringTableEntry assetAutoUnloadField = StringTable->insert("AssetAutoUnload");
|
||||||
StringTableEntry assetInternalField = StringTable->insert("AssetInternal");
|
StringTableEntry assetInternalField = StringTable->insert("AssetInternal");
|
||||||
StringTableEntry assetPrivateField = StringTable->insert("AssetPrivate");
|
StringTableEntry assetPrivateField = StringTable->insert("AssetPrivate");
|
||||||
|
StringTableEntry assetTypeField = StringTable->insert("AssetType");
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
const String AssetBase::mErrCodeStrings[] =
|
const String AssetBase::mErrCodeStrings[] =
|
||||||
|
|
|
||||||
|
|
@ -46,6 +46,7 @@ extern StringTableEntry assetCategoryField;
|
||||||
extern StringTableEntry assetInternalField;
|
extern StringTableEntry assetInternalField;
|
||||||
extern StringTableEntry assetPrivateField;
|
extern StringTableEntry assetPrivateField;
|
||||||
extern StringTableEntry assetAutoUnloadField;
|
extern StringTableEntry assetAutoUnloadField;
|
||||||
|
extern StringTableEntry assetTypeField;
|
||||||
|
|
||||||
//#define ASSET_BASE_ASSETNAME_FIELD "AssetName"
|
//#define ASSET_BASE_ASSETNAME_FIELD "AssetName"
|
||||||
//#define ASSET_BASE_ASSETDESCRIPTION_FIELD "AssetDescription"
|
//#define ASSET_BASE_ASSETDESCRIPTION_FIELD "AssetDescription"
|
||||||
|
|
@ -137,6 +138,7 @@ public:
|
||||||
protected:
|
protected:
|
||||||
virtual void initializeAsset(void) {}
|
virtual void initializeAsset(void) {}
|
||||||
virtual void onAssetRefresh(void) {}
|
virtual void onAssetRefresh(void) {}
|
||||||
|
virtual void unloadAsset(void) {}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
static bool setAssetName(void *obj, const char *array, const char *data) { static_cast<AssetBase*>(obj)->setAssetName(data); return false; }
|
static bool setAssetName(void *obj, const char *array, const char *data) { static_cast<AssetBase*>(obj)->setAssetName(data); return false; }
|
||||||
|
|
|
||||||
|
|
@ -2988,6 +2988,8 @@ void AssetManager::unloadAsset( AssetDefinition* pAssetDefinition )
|
||||||
// Debug Profiling.
|
// Debug Profiling.
|
||||||
PROFILE_SCOPE(AssetManager_UnloadAsset);
|
PROFILE_SCOPE(AssetManager_UnloadAsset);
|
||||||
|
|
||||||
|
pAssetDefinition->mpAssetBase->unloadAsset();
|
||||||
|
|
||||||
// Destroy the asset.
|
// Destroy the asset.
|
||||||
if(pAssetDefinition->mpAssetBase->isProperlyAdded())
|
if(pAssetDefinition->mpAssetBase->isProperlyAdded())
|
||||||
pAssetDefinition->mpAssetBase->deleteObject();
|
pAssetDefinition->mpAssetBase->deleteObject();
|
||||||
|
|
|
||||||
|
|
@ -129,6 +129,17 @@ public:
|
||||||
mAssetDefinition.mAssetInternal = dAtob( pPropertyValue );
|
mAssetDefinition.mAssetInternal = dAtob( pPropertyValue );
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
else if (propertyName == assetTypeField)
|
||||||
|
{
|
||||||
|
if (mAssetDefinition.mAssetType == StringTable->insert("ScriptAsset"))
|
||||||
|
{
|
||||||
|
//We're gunna special-casehere.
|
||||||
|
//If it's a ScriptAsset and it defines an AssetType property, we presume
|
||||||
|
//that's the ScriptAsset's special asset type, so we set it here
|
||||||
|
mAssetDefinition.mAssetType = StringTable->insert(pPropertyValue);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fetch property word count.
|
// Fetch property word count.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue