Skip to content

Commit

Permalink
Merge pull request #1379 from Areloch/VariousSubSceneFixes
Browse files Browse the repository at this point in the history
Various Subscene Fixes
  • Loading branch information
Azaezel authored Feb 6, 2025
2 parents 3c80f69 + 0d338f2 commit b47ffb2
Show file tree
Hide file tree
Showing 10 changed files with 124 additions and 84 deletions.
27 changes: 26 additions & 1 deletion Engine/source/T3D/SubScene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include "gameMode.h"
#include "console/persistenceManager.h"
#include "console/script.h"
#include "environment/meshRoad.h"
#include "environment/river.h"
#include "scene/sceneRenderState.h"
#include "renderInstance/renderPassManager.h"
#include "gfx/gfxDrawUtil.h"
Expand All @@ -29,7 +31,8 @@ SubScene::SubScene() :
mFreezeLoading(false),
mTickPeriodMS(1000),
mCurrTick(0),
mGlobalLayer(false)
mGlobalLayer(false),
mSaving(false)
{
mNetFlags.set(Ghostable | ScopeAlways);

Expand Down Expand Up @@ -65,6 +68,7 @@ void SubScene::initPersistFields()
addGroup("SubScene");
addField("isGlobalLayer", TypeBool, Offset(mGlobalLayer, SubScene), "");
INITPERSISTFIELD_LEVELASSET(Level, SubScene, "The level asset to load.");
addField("tickPeriodMS", TypeS32, Offset(mTickPeriodMS, SubScene), "evaluation rate (ms)");
addField("gameModes", TypeGameModeList, Offset(mGameModesNames, SubScene), "The game modes that this subscene is associated with.");
endGroup("SubScene");

Expand Down Expand Up @@ -263,6 +267,9 @@ void SubScene::_onFileChanged(const Torque::Path& path)
if(mLevelAsset.isNull() || Torque::Path(mLevelAsset->getLevelPath()) != path)
return;

if (mSaving)
return;

AssertFatal(path == mLevelAsset->getLevelPath(), "Prefab::_onFileChanged - path does not match filename.");

_closeFile(false);
Expand Down Expand Up @@ -336,6 +343,9 @@ void SubScene::load()
if (mFreezeLoading)
return;

if (mSaving)
return;

_loadFile(true);
mLoaded = true;

Expand All @@ -362,6 +372,9 @@ void SubScene::unload()
if (mFreezeLoading)
return;

if (mSaving)
return;

if (isSelected())
{
mStartUnloadTimerMS = Sim::getCurrentTime();
Expand Down Expand Up @@ -421,10 +434,15 @@ bool SubScene::save()
if (mLevelAsset.isNull())
return false;

if (mSaving)
return false;

//If we're flagged for unload, push back the unload timer so we can't accidentally trip be saving partway through an unload
if (mStartUnloadTimerMS != -1)
mStartUnloadTimerMS = Sim::getCurrentTime();

mSaving = true;

PersistenceManager prMger;

StringTableEntry levelPath = mLevelAsset->getLevelPath();
Expand All @@ -449,6 +467,11 @@ bool SubScene::save()
prMger.setDirty((*itr), levelPath);
}
}

if(dynamic_cast<MeshRoad*>(childObj) || dynamic_cast<River*>(childObj))
{
prMger.addRemoveField(childObj, "position");
}
}

prMger.saveDirty();
Expand All @@ -466,6 +489,8 @@ bool SubScene::save()
//Finally, save
saveSuccess = mLevelAsset->saveAsset();

mSaving = false;

return saveSuccess;
}

Expand Down
1 change: 1 addition & 0 deletions Engine/source/T3D/SubScene.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class SubScene : public SceneGroup
S32 mStartUnloadTimerMS;

bool mLoaded;
bool mSaving;
bool mFreezeLoading;

String mLoadIf;
Expand Down
12 changes: 10 additions & 2 deletions Engine/source/T3D/assets/LevelAsset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
// Debug Profiling.
#include "platform/profiler.h"
#include "gfx/gfxDrawUtil.h"
#include "T3D/SubScene.h"


//-----------------------------------------------------------------------------
Expand Down Expand Up @@ -479,8 +480,15 @@ GuiControl* GuiInspectorTypeLevelAssetPtr::constructEditControl()
// Create "Open in Editor" button
mEditButton = new GuiBitmapButtonCtrl();

dSprintf(szBuffer, sizeof(szBuffer), "$createAndAssignField = %s; AssetBrowser.setupCreateNewAsset(\"LevelAsset\", AssetBrowser.selectedModule, \"createAndAssignLevelAsset\");",
getIdString());
String setSubSceneValue = "$createLevelAssetIsSubScene = \"\";";
if(dynamic_cast<SubScene*>(mInspector->getInspectObject()) != NULL)
{
setSubSceneValue = "$createLevelAssetIsSubScene = true;";
}

dSprintf(szBuffer, sizeof(szBuffer), "$createAndAssignField = %s; %s AssetBrowser.setupCreateNewAsset(\"LevelAsset\", AssetBrowser.selectedModule, \"createAndAssignLevelAsset\");",
getIdString(),
setSubSceneValue.c_str());
mEditButton->setField("Command", szBuffer);

char bitmapName[512] = "ToolsModule:iconAdd_image";
Expand Down
4 changes: 2 additions & 2 deletions Engine/source/T3D/convexShape.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ const char* ConvexShape::getSpecialFieldOut(StringTableEntry fieldName, const U3
char buffer[1024];
dMemset(buffer, 0, 1024);

dSprintf(buffer, 1024, "%g %g %g %g %g %g %g %i %g %g %g %g %g %i %i",
dSprintf(buffer, 1024, "surface = \"%g %g %g %g %g %g %g %i %g %g %g %g %g %i %i\";",
quat.x, quat.y, quat.z, quat.w, pos.x, pos.y, pos.z, mSurfaceUVs[index].matID,
mSurfaceUVs[index].offset.x, mSurfaceUVs[index].offset.y, mSurfaceUVs[index].scale.x,
mSurfaceUVs[index].scale.y, mSurfaceUVs[index].zRot, mSurfaceUVs[index].horzFlip, mSurfaceUVs[index].vertFlip);
Expand All @@ -541,7 +541,7 @@ const char* ConvexShape::getSpecialFieldOut(StringTableEntry fieldName, const U3
char buffer[1024];
dMemset(buffer, 0, 1024);

dSprintf(buffer, 1024, "%s", mSurfaceTextures[index].getMaterial());
dSprintf(buffer, 1024, "surfaceTexture = \"%s\";", mSurfaceTextures[index].getMaterial());

return StringTable->insert(buffer);
}
Expand Down
Loading

0 comments on commit b47ffb2

Please sign in to comment.