mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-02-12 19:31:41 +00:00
Adds function for sceneObjects to report utilized assets
Add reporting of used assets to tsStatics and TerrData When saving a Scene, it will write static object asset dependencies to it's levelAsset Shifted level loader logic to pass up the levelAsset rather than full level path Made it so when level is loading, the levelAsset loads its dependencies. When the level is ended, as part of cleanup, they are unloaded Shifts defaultEditorLevel to be an actual asset and made the ToolsModule load assets Fixes the Save As action to correctly save out to the new level asset Fixed the autoLoadAssets logic to be cleaner and not manually check types Removed extra, unused DefaultEditorFile file
This commit is contained in:
parent
f7dbfff42d
commit
40dd926873
21 changed files with 263 additions and 255 deletions
|
|
@ -1,4 +1,5 @@
|
|||
#include "Scene.h"
|
||||
#include "T3D/assets/LevelAsset.h"
|
||||
|
||||
Scene * Scene::smRootScene = nullptr;
|
||||
Vector<Scene*> Scene::smSceneList;
|
||||
|
|
@ -180,6 +181,93 @@ void Scene::unpackUpdate(NetConnection *conn, BitStream *stream)
|
|||
|
||||
}
|
||||
|
||||
void Scene::dumpUtilizedAssets()
|
||||
{
|
||||
Con::printf("Dumping utilized assets in scene!");
|
||||
|
||||
Vector<StringTableEntry> utilizedAssetsList;
|
||||
for (U32 i = 0; i < mPermanentObjects.size(); i++)
|
||||
{
|
||||
mPermanentObjects[i]->getUtilizedAssets(&utilizedAssetsList);
|
||||
}
|
||||
|
||||
for (U32 i = 0; i < mDynamicObjects.size(); i++)
|
||||
{
|
||||
mDynamicObjects[i]->getUtilizedAssets(&utilizedAssetsList);
|
||||
}
|
||||
|
||||
for (U32 i = 0; i < utilizedAssetsList.size(); i++)
|
||||
{
|
||||
Con::printf("Utilized Asset: %s", utilizedAssetsList[i]);
|
||||
}
|
||||
|
||||
Con::printf("Utilized Asset dump complete!");
|
||||
}
|
||||
|
||||
StringTableEntry Scene::getOriginatingFile()
|
||||
{
|
||||
return getFilename();
|
||||
}
|
||||
|
||||
StringTableEntry Scene::getLevelAsset()
|
||||
{
|
||||
StringTableEntry levelFile = getFilename();
|
||||
|
||||
if (levelFile == StringTable->EmptyString())
|
||||
return StringTable->EmptyString();
|
||||
|
||||
AssetQuery* query = new AssetQuery();
|
||||
query->registerObject();
|
||||
|
||||
S32 foundAssetcount = AssetDatabase.findAssetLooseFile(query, levelFile);
|
||||
if (foundAssetcount == 0)
|
||||
return StringTable->EmptyString();
|
||||
else
|
||||
return query->mAssetList[0];
|
||||
}
|
||||
|
||||
bool Scene::saveScene(StringTableEntry fileName)
|
||||
{
|
||||
//So, we ultimately want to not only save out the level, but also collate all the assets utilized
|
||||
//by the static objects in the scene so we can have those before we parse the level file itself
|
||||
//Useful for preloading or stat tracking
|
||||
|
||||
//First, save the level file
|
||||
if (fileName == StringTable->EmptyString())
|
||||
{
|
||||
fileName = getOriginatingFile();
|
||||
}
|
||||
|
||||
bool saveSuccess = save(fileName);
|
||||
|
||||
if (!saveSuccess)
|
||||
return false;
|
||||
|
||||
//Get the level asset
|
||||
StringTableEntry levelAsset = getLevelAsset();
|
||||
if (levelAsset == StringTable->EmptyString())
|
||||
return saveSuccess;
|
||||
|
||||
LevelAsset* levelAssetDef = AssetDatabase.acquireAsset<LevelAsset>(levelAsset);
|
||||
levelAssetDef->clearAssetDependencyFields("staticObjectAssetDependency");
|
||||
|
||||
//Next, lets build out our
|
||||
Vector<StringTableEntry> utilizedAssetsList;
|
||||
for (U32 i = 0; i < mPermanentObjects.size(); i++)
|
||||
{
|
||||
mPermanentObjects[i]->getUtilizedAssets(&utilizedAssetsList);
|
||||
}
|
||||
|
||||
for (U32 i = 0; i < utilizedAssetsList.size(); i++)
|
||||
{
|
||||
levelAssetDef->addAssetDependencyField("staticObjectAssetDependency", utilizedAssetsList[i]);
|
||||
}
|
||||
|
||||
saveSuccess = levelAssetDef->saveAsset();
|
||||
|
||||
return saveSuccess;
|
||||
}
|
||||
|
||||
//
|
||||
Vector<SceneObject*> Scene::getObjectsByClass(String className, bool checkSubscenes)
|
||||
{
|
||||
|
|
@ -251,3 +339,34 @@ DefineEngineMethod(Scene, getObjectsByClass, String, (String className), (""),
|
|||
//return object->getObjectsByClass(className);
|
||||
return "";
|
||||
}
|
||||
|
||||
DefineEngineMethod(Scene, dumpUtilizedAssets, void, (), ,
|
||||
"Get the root Scene object that is loaded.\n"
|
||||
"@return The id of the Root Scene. Will be 0 if no root scene is loaded")
|
||||
{
|
||||
object->dumpUtilizedAssets();
|
||||
}
|
||||
|
||||
DefineEngineMethod(Scene, getOriginatingFile, const char*, (), ,
|
||||
"Get the root Scene object that is loaded.\n"
|
||||
"@return The id of the Root Scene. Will be 0 if no root scene is loaded")
|
||||
{
|
||||
return object->getOriginatingFile();
|
||||
}
|
||||
|
||||
DefineEngineMethod(Scene, getLevelAsset, const char*, (), ,
|
||||
"Get the root Scene object that is loaded.\n"
|
||||
"@return The id of the Root Scene. Will be 0 if no root scene is loaded")
|
||||
{
|
||||
return object->getLevelAsset();
|
||||
}
|
||||
|
||||
DefineEngineMethod(Scene, save, bool, (const char* fileName), (""),
|
||||
"Save out the object to the given file.\n"
|
||||
"@param fileName The name of the file to save to."
|
||||
"@param selectedOnly If true, only objects marked as selected will be saved out.\n"
|
||||
"@param preAppendString Text which will be preprended directly to the object serialization.\n"
|
||||
"@param True on success, false on failure.")
|
||||
{
|
||||
return object->saveScene(StringTable->insert(fileName));
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue