Torque3D/Engine/source/T3D/Scene.cpp

373 lines
9.4 KiB
C++
Raw Normal View History

#include "Scene.h"
#include "T3D/assets/LevelAsset.h"
Scene * Scene::smRootScene = nullptr;
Vector<Scene*> Scene::smSceneList;
IMPLEMENT_CO_NETOBJECT_V1(Scene);
Scene::Scene() :
mIsSubScene(false),
mParentScene(nullptr),
mSceneId(-1),
mIsEditing(false),
mIsDirty(false)
{
mGameModeName = StringTable->EmptyString();
}
Scene::~Scene()
{
}
void Scene::initPersistFields()
{
Parent::initPersistFields();
addGroup("Internal");
addField("isSubscene", TypeBool, Offset(mIsSubScene, Scene), "", AbstractClassRep::FIELD_HideInInspectors);
addField("isEditing", TypeBool, Offset(mIsEditing, Scene), "", AbstractClassRep::FIELD_HideInInspectors);
addField("isDirty", TypeBool, Offset(mIsDirty, Scene), "", AbstractClassRep::FIELD_HideInInspectors);
endGroup("Internal");
addGroup("Gameplay");
addField("gameModeName", TypeString, Offset(mGameModeName, Scene), "The name of the gamemode that this scene utilizes");
endGroup("Gameplay");
}
bool Scene::onAdd()
{
if (!Parent::onAdd())
return false;
smSceneList.push_back(this);
mSceneId = smSceneList.size() - 1;
/*if (smRootScene == nullptr)
{
//we're the first scene, so we're the root. woo!
smRootScene = this;
}
else
{
mIsSubScene = true;
smRootScene->mSubScenes.push_back(this);
}*/
return true;
}
void Scene::onRemove()
{
Parent::onRemove();
smSceneList.remove(this);
mSceneId = -1;
/*if (smRootScene == this)
{
for (U32 i = 0; i < mSubScenes.size(); i++)
{
mSubScenes[i]->deleteObject();
}
}
else if (smRootScene != nullptr)
{
for (U32 i = 0; i < mSubScenes.size(); i++)
{
if(mSubScenes[i]->getId() == getId())
smRootScene->mSubScenes.erase(i);
}
}*/
}
Moved unneeded modules to Templates/Modules Added templated getObjectsByClass to Scene for easier engine-side polling of objects, including nested checks for subscenes Proper init'ing of mGamemodeName in LevelAsset, as well as proper fieldType for mIsSubLevel D3D11 added logic to handle scaling down of textures in cubemap arrays for lower texture resolution preferences Added ability to collapse groups programmatically to GuiVariableInspector Upped PSSM shadowmap max size to 4096 Caught GL deferred lighting/probes up to D3D11 Temporarily disabled forward lighting/probes on GL materials until conversion finished Upped smMaxInstancingVerts to 2000 from 200 to support slightly more detailed meshes being instanced Reordered project settings so they load ahead of core modules, so that core modules can actually use project settings Established current preset file for PostFXManager to use for reverting WIP logic for forcing probes to update as part of level lighting load step in loading process Streamlined PostFXManager code, removing unnecessary/redundant files Coverted HDR, Lightrays and SSAO and ExamplePostEffect to use new PostFX Manager/Editor paradigm PostFX manager now enacts callbacks so that postFXs' can process their own settings as well as provide editor fields Changed PostFX editor to work with new callbacks via using VariableInspector Updated PostEffectAsset's template file so new PostFX's will now automatically register with the PostFXManager and have the needed new callbacks for integration Made HDR on by default, removed enable field from editing Made probe bake resolution a project setting Updated many GL postFX shaders to have proper case for PostFx.glsl Example module now loads ExampleGUI and ExamplePostEffect during init'ing Removed unneeded autoload definitions from ExampleModule's module file Fixed Graphics Adapter settings field to properly display as well as apply setting Updated many referenced profiles in tools folder to use the Tools specific gui profiles to make theming more consistent Fixed coloration of tools button bitmap to make theming more consistent Updated a few theme settings for improved visibility with theme, particularly selected/highlighted text Moved AssetBrowser field types to separated folder/files Updated new module creation to properly utilize template file instead of overriding it with a programmatic script generation. Removed unneded default autoload definitions from new modules Added WIP for editing Module/Asset dependencies Updated the PostEffectAsset to properly generate glsl and hlsl files from templates Updated module editor window to display only necessary fields Added WIP of TerrainAsset Added shaderCache gitignore file so folder isn't lost
2019-09-29 11:44:43 +00:00
void Scene::onPostAdd()
{
if (isMethod("onPostAdd"))
Con::executef(this, "onPostAdd");
}
void Scene::addObject(SimObject* object)
{
//Child scene
Scene* scene = dynamic_cast<Scene*>(object);
if (scene)
{
//We'll keep these principly separate so they don't get saved into each other
mSubScenes.push_back(scene);
return;
}
SceneObject* sceneObj = dynamic_cast<SceneObject*>(object);
if (sceneObj)
{
//We'll operate on the presumption that if it's being added via regular parantage means, it's considered permanent
mPermanentObjects.push_back(sceneObj);
Parent::addObject(object);
return;
}
//Do it like regular, though we should probably bail if we're trying to add non-scene objects to the scene?
Parent::addObject(object);
}
void Scene::removeObject(SimObject* object)
{
//Child scene
Scene* scene = dynamic_cast<Scene*>(object);
if (scene)
{
//We'll keep these principly separate so they don't get saved into each other
mSubScenes.remove(scene);
return;
}
SceneObject* sceneObj = dynamic_cast<SceneObject*>(object);
if (sceneObj)
{
//We'll operate on the presumption that if it's being added via regular parantage means, it's considered permanent
mPermanentObjects.remove(sceneObj);
Parent::removeObject(object);
return;
}
Parent::removeObject(object);
}
void Scene::addDynamicObject(SceneObject* object)
{
mDynamicObjects.push_back(object);
//Do it like regular, though we should probably bail if we're trying to add non-scene objects to the scene?
Parent::addObject(object);
}
void Scene::removeDynamicObject(SceneObject* object)
{
mDynamicObjects.remove(object);
//Do it like regular, though we should probably bail if we're trying to add non-scene objects to the scene?
Parent::removeObject(object);
}
void Scene::interpolateTick(F32 delta)
{
}
void Scene::processTick()
{
}
void Scene::advanceTime(F32 timeDelta)
{
}
U32 Scene::packUpdate(NetConnection *conn, U32 mask, BitStream *stream)
{
bool ret = Parent::packUpdate(conn, mask, stream);
return ret;
}
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;
}
//
Moved unneeded modules to Templates/Modules Added templated getObjectsByClass to Scene for easier engine-side polling of objects, including nested checks for subscenes Proper init'ing of mGamemodeName in LevelAsset, as well as proper fieldType for mIsSubLevel D3D11 added logic to handle scaling down of textures in cubemap arrays for lower texture resolution preferences Added ability to collapse groups programmatically to GuiVariableInspector Upped PSSM shadowmap max size to 4096 Caught GL deferred lighting/probes up to D3D11 Temporarily disabled forward lighting/probes on GL materials until conversion finished Upped smMaxInstancingVerts to 2000 from 200 to support slightly more detailed meshes being instanced Reordered project settings so they load ahead of core modules, so that core modules can actually use project settings Established current preset file for PostFXManager to use for reverting WIP logic for forcing probes to update as part of level lighting load step in loading process Streamlined PostFXManager code, removing unnecessary/redundant files Coverted HDR, Lightrays and SSAO and ExamplePostEffect to use new PostFX Manager/Editor paradigm PostFX manager now enacts callbacks so that postFXs' can process their own settings as well as provide editor fields Changed PostFX editor to work with new callbacks via using VariableInspector Updated PostEffectAsset's template file so new PostFX's will now automatically register with the PostFXManager and have the needed new callbacks for integration Made HDR on by default, removed enable field from editing Made probe bake resolution a project setting Updated many GL postFX shaders to have proper case for PostFx.glsl Example module now loads ExampleGUI and ExamplePostEffect during init'ing Removed unneeded autoload definitions from ExampleModule's module file Fixed Graphics Adapter settings field to properly display as well as apply setting Updated many referenced profiles in tools folder to use the Tools specific gui profiles to make theming more consistent Fixed coloration of tools button bitmap to make theming more consistent Updated a few theme settings for improved visibility with theme, particularly selected/highlighted text Moved AssetBrowser field types to separated folder/files Updated new module creation to properly utilize template file instead of overriding it with a programmatic script generation. Removed unneded default autoload definitions from new modules Added WIP for editing Module/Asset dependencies Updated the PostEffectAsset to properly generate glsl and hlsl files from templates Updated module editor window to display only necessary fields Added WIP of TerrainAsset Added shaderCache gitignore file so folder isn't lost
2019-09-29 11:44:43 +00:00
Vector<SceneObject*> Scene::getObjectsByClass(String className, bool checkSubscenes)
{
return Vector<SceneObject*>();
}
DefineEngineFunction(getScene, Scene*, (U32 sceneId), (0),
"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")
{
if (Scene::smSceneList.empty() || sceneId >= Scene::smSceneList.size())
return nullptr;
return Scene::smSceneList[sceneId];
}
DefineEngineFunction(getSceneCount, S32, (),,
"Get the number of active Scene objects that are loaded.\n"
"@return The number of active scenes")
{
return Scene::smSceneList.size();
}
DefineEngineFunction(getRootScene, S32, (), ,
"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")
{
Scene* root = Scene::getRootScene();
if (root)
return root->getId();
return 0;
}
DefineEngineMethod(Scene, getRootScene, S32, (),,
"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")
{
Scene* root = Scene::getRootScene();
if (root)
return root->getId();
return 0;
}
DefineEngineMethod(Scene, addDynamicObject, void, (SceneObject* sceneObj), (nullAsType<SceneObject*>()),
"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->addDynamicObject(sceneObj);
}
DefineEngineMethod(Scene, removeDynamicObject, void, (SceneObject* sceneObj), (nullAsType<SceneObject*>()),
"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->removeDynamicObject(sceneObj);
}
DefineEngineMethod(Scene, getObjectsByClass, String, (String className), (""),
"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")
{
if (className == String::EmptyString)
return "";
//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));
}