diff --git a/Engine/source/T3D/assets/ScriptAsset.cpp b/Engine/source/T3D/assets/ScriptAsset.cpp index 06d6db061..9fe05c329 100644 --- a/Engine/source/T3D/assets/ScriptAsset.cpp +++ b/Engine/source/T3D/assets/ScriptAsset.cpp @@ -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) { mScriptFile = StringTable->EmptyString(); @@ -123,6 +132,12 @@ void ScriptAsset::copyTo(SimObject* object) 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; if (Torque::FS::IsScriptFile(mScriptPath)) @@ -138,7 +153,7 @@ void ScriptAsset::initializeAsset() { AssetPtr scriptAsset = assetDependenciesItr->value; - mScriptAssets.push_front(scriptAsset); + mScriptAssetDependencies.push_front(scriptAsset); // Next dependency. assetDependenciesItr++; @@ -147,6 +162,8 @@ void ScriptAsset::initializeAsset() Con::executeFile(mScriptPath, false, false); } + + onInitializeAsset_callback(); } void ScriptAsset::onAssetRefresh() @@ -156,13 +173,20 @@ void ScriptAsset::onAssetRefresh() if (Torque::FS::IsScriptFile(mScriptPath)) { //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); } + + onRefreshAsset_callback(); +} + +void ScriptAsset::unloadAsset() +{ + onUnloadAsset_callback(); } void ScriptAsset::setScriptFile(const char* pScriptFile) @@ -205,3 +229,4 @@ DefineEngineMethod(ScriptAsset, execScript, bool, (), , { return object->execScript(); } + diff --git a/Engine/source/T3D/assets/ScriptAsset.h b/Engine/source/T3D/assets/ScriptAsset.h index d73273bc4..392080ef7 100644 --- a/Engine/source/T3D/assets/ScriptAsset.h +++ b/Engine/source/T3D/assets/ScriptAsset.h @@ -52,7 +52,7 @@ class ScriptAsset : public AssetBase StringTableEntry mScriptPath; bool mIsServerSide; - Vector> mScriptAssets; + Vector> mScriptAssetDependencies; public: ScriptAsset(); @@ -72,9 +72,14 @@ public: bool execScript(); + DECLARE_CALLBACK(void, onInitializeAsset, ()); + DECLARE_CALLBACK(void, onRefreshAsset, ()); + DECLARE_CALLBACK(void, onUnloadAsset, ()); + protected: virtual void initializeAsset(void); virtual void onAssetRefresh(void); + virtual void unloadAsset(void); static bool setScriptFile(void *obj, const char *index, const char *data) { static_cast(obj)->setScriptFile(data); return false; } static const char* getScriptFile(void* obj, const char* data) { return static_cast(obj)->getScriptFile(); } diff --git a/Engine/source/assets/assetBase.cpp b/Engine/source/assets/assetBase.cpp index 3741ece3d..4223b8654 100644 --- a/Engine/source/assets/assetBase.cpp +++ b/Engine/source/assets/assetBase.cpp @@ -50,6 +50,7 @@ StringTableEntry assetCategoryField = StringTable->insert("AssetCategory"); StringTableEntry assetAutoUnloadField = StringTable->insert("AssetAutoUnload"); StringTableEntry assetInternalField = StringTable->insert("AssetInternal"); StringTableEntry assetPrivateField = StringTable->insert("AssetPrivate"); +StringTableEntry assetTypeField = StringTable->insert("AssetType"); //----------------------------------------------------------------------------- const String AssetBase::mErrCodeStrings[] = diff --git a/Engine/source/assets/assetBase.h b/Engine/source/assets/assetBase.h index 516376663..17dbc3be3 100644 --- a/Engine/source/assets/assetBase.h +++ b/Engine/source/assets/assetBase.h @@ -46,6 +46,7 @@ extern StringTableEntry assetCategoryField; extern StringTableEntry assetInternalField; extern StringTableEntry assetPrivateField; extern StringTableEntry assetAutoUnloadField; +extern StringTableEntry assetTypeField; //#define ASSET_BASE_ASSETNAME_FIELD "AssetName" //#define ASSET_BASE_ASSETDESCRIPTION_FIELD "AssetDescription" @@ -137,6 +138,7 @@ public: protected: virtual void initializeAsset(void) {} virtual void onAssetRefresh(void) {} + virtual void unloadAsset(void) {} protected: static bool setAssetName(void *obj, const char *array, const char *data) { static_cast(obj)->setAssetName(data); return false; } diff --git a/Engine/source/assets/assetManager.cpp b/Engine/source/assets/assetManager.cpp index 8f2c84f3e..9d925d873 100644 --- a/Engine/source/assets/assetManager.cpp +++ b/Engine/source/assets/assetManager.cpp @@ -2988,6 +2988,8 @@ void AssetManager::unloadAsset( AssetDefinition* pAssetDefinition ) // Debug Profiling. PROFILE_SCOPE(AssetManager_UnloadAsset); + pAssetDefinition->mpAssetBase->unloadAsset(); + // Destroy the asset. if(pAssetDefinition->mpAssetBase->isProperlyAdded()) pAssetDefinition->mpAssetBase->deleteObject(); diff --git a/Engine/source/assets/tamlAssetDeclaredVisitor.h b/Engine/source/assets/tamlAssetDeclaredVisitor.h index fd5b643f9..bbab18ebe 100644 --- a/Engine/source/assets/tamlAssetDeclaredVisitor.h +++ b/Engine/source/assets/tamlAssetDeclaredVisitor.h @@ -129,6 +129,17 @@ public: mAssetDefinition.mAssetInternal = dAtob( pPropertyValue ); 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.