Skip to content

Commit

Permalink
Updates most of the handling of asset types to follow a more standard…
Browse files Browse the repository at this point in the history
…ized type-registration system.

This streamlines much of the code and makes it easier to find and follow how different asset, object and file types are handled by the asset browser
Also clears out various bits of cruft and old commented blocks of code
  • Loading branch information
Areloch committed Sep 28, 2024
1 parent 00e5482 commit 3442ace
Show file tree
Hide file tree
Showing 39 changed files with 1,864 additions and 3,481 deletions.
14 changes: 14 additions & 0 deletions Engine/source/T3D/assets/CppAsset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,3 +178,17 @@ void CppAsset::onAssetRefresh(void)

mHeaderPath = getOwned() ? expandAssetFilePath(mHeaderFile) : mHeaderPath;
}

DefineEngineMethod(CppAsset, getCodePath, const char*, (), ,
"Gets the code file filepath of this asset.\n"
"@return File path of the code file.")
{
return object->getCppFilePath();
}

DefineEngineMethod(CppAsset, getHeaderPath, const char*, (), ,
"Gets the header file filepath of this asset.\n"
"@return File path of the header file.")
{
return object->getHeaderFilePath();
}
6 changes: 3 additions & 3 deletions Engine/source/T3D/assets/CppAsset.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,16 @@ class CppAsset : public AssetBase
void setHeaderFile(const char* pHeaderFile);
inline StringTableEntry getHeaderFile(void) const { return mHeaderFile; };

inline StringTableEntry getCppFilePath(void) const { return mCodePath; };
inline StringTableEntry getHeaderFilePath(void) const { return mHeaderPath; };

protected:
void initializeAsset(void) override;
void onAssetRefresh(void) override;

static bool setCppFile(void *obj, const char *index, const char *data) { static_cast<CppAsset*>(obj)->setCppFile(data); return false; }
static const char* getCppFile(void* obj, const char* data) { return static_cast<CppAsset*>(obj)->getCppFile(); }

inline StringTableEntry getCppFilePath(void) const { return mCodePath; };
inline StringTableEntry getHeaderFilePath(void) const { return mHeaderPath; };

static bool setHeaderFile(void *obj, const char *index, const char *data) { static_cast<CppAsset*>(obj)->setHeaderFile(data); return false; }
static const char* getHeaderFile(void* obj, const char* data) { return static_cast<CppAsset*>(obj)->getHeaderFile(); }
};
Expand Down
47 changes: 47 additions & 0 deletions Engine/source/assets/assetManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1563,6 +1563,53 @@ bool AssetManager::restoreAssetTags( void )

//-----------------------------------------------------------------------------

const char* AssetManager::getAssetLooseFiles(const char* pAssetId)
{
// Debug Profiling.
PROFILE_SCOPE(AssetManager_getAssetLooseFIles);

// Sanity!
AssertFatal(pAssetId != NULL, "Cannot look up NULL asset Id.");

// Find asset.
AssetDefinition* pAssetDefinition = findAsset(pAssetId);

// Did we find the asset?
if (pAssetDefinition == NULL)
{
// No, so warn.
Con::warnf("Asset Manager: Failed to find asset Id '%s' as it does not exist.", pAssetId);
return String::EmptyString;
}

// Info.
if (mEchoInfo)
{
Con::printSeparator();
Con::printf("Asset Manager: Started getting loose files of Asset Id '%s'...", pAssetId);
}

String looseFileList = "";
Vector<StringTableEntry>& assetLooseFiles = pAssetDefinition->mAssetLooseFiles;
for (Vector<StringTableEntry>::iterator looseFileItr = assetLooseFiles.begin(); looseFileItr != assetLooseFiles.end(); ++looseFileItr)
{
// Fetch loose file.
StringTableEntry looseFile = *looseFileItr;

looseFileList += looseFile;

if (looseFileItr != assetLooseFiles.end())
looseFileList += "\t";
}

char* ret = Con::getReturnBuffer(1024);
dSprintf(ret, 1024, "%s", looseFileList.c_str());

return ret;
}

//-----------------------------------------------------------------------------

S32 QSORT_CALLBACK descendingAssetDefinitionLoadCount(const void* a, const void* b)
{
// Debug Profiling.
Expand Down
3 changes: 3 additions & 0 deletions Engine/source/assets/assetManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,9 @@ class AssetManager : public SimObject, public ModuleCallbacks
bool restoreAssetTags( void );
inline AssetTagsManifest* getAssetTags( void ) const { return mAssetTagsManifest; }

/// Loose File management
const char* getAssetLooseFiles(const char* pAssetId);

/// Info.
inline U32 getDeclaredAssetCount( void ) const { return (U32)mDeclaredAssets.size(); }
inline U32 getReferencedAssetCount( void ) const { return (U32)mReferencedAssets.size(); }
Expand Down
14 changes: 14 additions & 0 deletions Engine/source/assets/assetManager_ScriptBinding.h
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,20 @@ DefineEngineMethod(AssetManager, getAssetTags, S32, (), ,

//-----------------------------------------------------------------------------

DefineEngineMethod(AssetManager, getAssetLooseFiles, const char*, (const char* assetId), (""),
"Finds the specified asset Id and gets a list of its loose files.\n"
"@param assetId The selected asset Id.\n"
"@return A tab-delinated list of loose files associated to the assetId.\n")
{
// Fetch asset Id.
const char* pAssetId = assetId;

// Delete asset.
return object->getAssetLooseFiles(pAssetId);
}

//-----------------------------------------------------------------------------

DefineEngineMethod(AssetManager, findAllAssets, S32, (const char* assetQuery, bool ignoreInternal, bool ignorePrivate), ("", true, true),
"Performs an asset query searching for all assets optionally ignoring internal assets.\n"
"@param assetQuery The asset query object that will be populated with the results.\n"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ $guiContent = new GuiControl(AssetBrowser_editAsset) {
canSave = "1";
canSaveDynamicFields = "0";

new GuiInspector(AssetEditInspector) {
new GuiVariableInspector(AssetEditInspector) {
dividerMargin = "5";
showCustomFields = "1";
stackingType = "Vertical";
Expand Down
32 changes: 5 additions & 27 deletions Templates/BaseGame/game/tools/assetBrowser/main.tscript
Original file line number Diff line number Diff line change
Expand Up @@ -27,30 +27,9 @@ function initializeAssetBrowser()
$AssetBrowser::collectionSetsFile = "tools/assetBrowser/searchCollectionSets.xml";
$AssetBrowser::currentImportConfig = "";

if(!isObject(AssetFilterTypeList))
{
new ArrayObject(AssetFilterTypeList);
if(!isObject(ABAssetTypesList))
new ArrayObject(ABAssetTypesList){};

AssetFilterTypeList.add("All");
AssetFilterTypeList.add("ComponentAsset");
AssetFilterTypeList.add("CppAsset");
AssetFilterTypeList.add("CubemapAsset");
AssetFilterTypeList.add("GameObjectAsset");
AssetFilterTypeList.add("GUIAsset");
AssetFilterTypeList.add("ImageAsset");
AssetFilterTypeList.add("LevelAsset");
AssetFilterTypeList.add("MaterialAsset");
AssetFilterTypeList.add("ParticleAsset");
AssetFilterTypeList.add("PostFXAsset");
AssetFilterTypeList.add("ScriptAsset");
AssetFilterTypeList.add("ShapeAsset");
AssetFilterTypeList.add("ShapeAnimationAsset");
AssetFilterTypeList.add("SoundAsset");
AssetFilterTypeList.add("StateMachineAsset");
AssetFilterTypeList.add("TerrainAsset");
AssetFilterTypeList.add("TerrainMaterialAsset");
}

exec("./scripts/profiles." @ $TorqueScriptFileExtension);

exec("./guis/assetBrowser.gui");
Expand Down Expand Up @@ -89,9 +68,9 @@ function initializeAssetBrowser()
exec("./scripts/setAssetTarget." @ $TorqueScriptFileExtension);

//Processing for the different asset types
exec("./scripts/assetTypes/component." @ $TorqueScriptFileExtension);
exec("./scripts/assetTypes/genericAsset." @ $TorqueScriptFileExtension);

exec("./scripts/assetTypes/cpp." @ $TorqueScriptFileExtension);
exec("./scripts/assetTypes/gameObject." @ $TorqueScriptFileExtension);
exec("./scripts/assetTypes/gui." @ $TorqueScriptFileExtension);
exec("./scripts/assetTypes/image." @ $TorqueScriptFileExtension);
exec("./scripts/assetTypes/level." @ $TorqueScriptFileExtension);
Expand All @@ -100,8 +79,7 @@ function initializeAssetBrowser()
exec("./scripts/assetTypes/script." @ $TorqueScriptFileExtension);
exec("./scripts/assetTypes/shape." @ $TorqueScriptFileExtension);
exec("./scripts/assetTypes/shapeAnimation." @ $TorqueScriptFileExtension);
exec("./scripts/assetTypes/sound." @ $TorqueScriptFileExtension);
exec("./scripts/assetTypes/stateMachine." @ $TorqueScriptFileExtension);
exec("./scripts/assetTypes/sound." @ $TorqueScriptFileExtension);
exec("./scripts/assetTypes/cubemap." @ $TorqueScriptFileExtension);
exec("./scripts/assetTypes/folder." @ $TorqueScriptFileExtension);
exec("./scripts/assetTypes/terrain." @ $TorqueScriptFileExtension);
Expand Down
Loading

0 comments on commit 3442ace

Please sign in to comment.