Skip to content

Commit

Permalink
Adds utility function and method to be able to enact a load of subsce…
Browse files Browse the repository at this point in the history
…nes at a specific world position

Adds loadIf conditional logic to evaluate if a subscene is 'allowed' to load when tested
Adds isAlwaysActive to GameMode to be able to flag a gamemode as being defaulted to on and used automatically
Updated GetGameModesList function to return an arrayObject of the gamemodes found
Overhauled CallGameModeFunction to utilize the gamemodes list with active/alwaysActive modes being called against, rather than level-scanning
Updated ChooseLevelMenu to be able to toggle on/off multiple gamemodes with an image indicator if it's active or not
  • Loading branch information
Areloch committed Oct 4, 2024
1 parent 20a01d9 commit e4d07c7
Show file tree
Hide file tree
Showing 14 changed files with 258 additions and 197 deletions.
21 changes: 21 additions & 0 deletions Engine/source/T3D/Scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,21 @@ Vector<SceneObject*> Scene::getObjectsByClass(String className)
return Vector<SceneObject*>();
}

void Scene::loadAtPosition(const Point3F& position)
{
for (U32 i = 0; i < mSubScenes.size(); i++)
{
Box3F testBox = Box3F(0.5);
testBox.setCenter(position);

if (mSubScenes[i]->testBox(testBox))
{
mSubScenes[i]->setUnloadTimeMS(-1);
mSubScenes[i]->load();
}
}
}

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")
Expand Down Expand Up @@ -489,3 +504,9 @@ DefineEngineMethod(Scene, save, bool, (const char* fileName), (""),
{
return object->saveScene(StringTable->insert(fileName));
}

DefineEngineMethod(Scene, loadAtPosition, void, (Point3F position), (Point3F::Zero),
"Loads any subscenes at a given point by force.\n")
{
object->loadAtPosition(position);
}
2 changes: 2 additions & 0 deletions Engine/source/T3D/Scene.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ class Scene : public NetObject, public virtual ITickable
template <class T>
Vector<T*> getObjectsByClass();

void loadAtPosition(const Point3F& position);

static Scene *getRootScene()
{
if (Scene::smSceneList.empty())
Expand Down
16 changes: 13 additions & 3 deletions Engine/source/T3D/SubScene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ void SubScene::initPersistFields()
addGroup("SubScene");
addField("isGlobalLayer", TypeBool, Offset(mGlobalLayer, SubScene), "");
INITPERSISTFIELD_LEVELASSET(Level, SubScene, "The level asset to load.");
addField("loadIf", TypeCommand, Offset(mLoadIf, SubScene), "evaluation condition (true/false)");
addField("gameModes", TypeGameModeList, Offset(mGameModesNames, SubScene), "The game modes that this subscene is associated with.");
endGroup("SubScene");

Expand Down Expand Up @@ -143,9 +144,18 @@ bool SubScene::testBox(const Box3F& testBox)
if (mGlobalLayer)
return true;

bool isOverlapped = getWorldBox().isOverlapped(testBox);

return getWorldBox().isOverlapped(testBox);
bool passes = getWorldBox().isOverlapped(testBox);
if (passes && !mLoadIf.isEmpty())
{
//test the mapper plugged in condition line
String resVar = getIdString() + String(".result");
Con::setBoolVariable(resVar.c_str(), false);
String command = resVar + "=" + mLoadIf + ";";
Con::evaluatef(command.c_str());
passes = Con::getBoolVariable(resVar.c_str());
}

return passes;
}

void SubScene::write(Stream& stream, U32 tabStop, U32 flags)
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 @@ -38,6 +38,7 @@ class SubScene : public SceneGroup
S32 mStartUnloadTimerMS;

bool mLoaded;
String mLoadIf;

bool mGlobalLayer;
public:
Expand Down
40 changes: 32 additions & 8 deletions Engine/source/T3D/gameMode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include "gui/containers/guiDynamicCtrlArrayCtrl.h"
#endif

#include "console/arrayObject.h"

IMPLEMENT_CONOBJECT(GameMode);

IMPLEMENT_CALLBACK(GameMode, onActivated, void, (), (),
Expand Down Expand Up @@ -47,7 +49,9 @@ ConsoleSetType(TypeGameModeList)

GameMode::GameMode() :
mGameModeName(StringTable->EmptyString()),
mGameModeDesc(StringTable->EmptyString())
mGameModeDesc(StringTable->EmptyString()),
mIsActive(false),
mIsAlwaysActive(false)
{
INIT_ASSET(PreviewImage);
}
Expand All @@ -62,6 +66,7 @@ void GameMode::initPersistFields()
INITPERSISTFIELD_IMAGEASSET(PreviewImage, GameMode, "Preview Image");

addField("active", TypeBool, Offset(mIsActive, GameMode), "Is the gamemode active");
addField("alwaysActive", TypeBool, Offset(mIsAlwaysActive, GameMode), "Is the gamemode always active");
}

bool GameMode::onAdd()
Expand Down Expand Up @@ -110,6 +115,11 @@ void GameMode::setActive(const bool& active)
onDeactivated_callback();
}

void GameMode::setAlwaysActive(const bool& alwaysActive)
{
mIsAlwaysActive = alwaysActive;
}

DefineEngineMethod(GameMode, isActive, bool, (), ,
"Returns if the GameMode is currently active.\n"
"@return The active status of the GameMode")
Expand All @@ -124,24 +134,38 @@ DefineEngineMethod(GameMode, setActive, void, (bool active), (true),
object->setActive(active);
}

DefineEngineFunction(getGameModesList, const char*, (), , "")
DefineEngineMethod(GameMode, isALwaysActive, bool, (), ,
"Returns if the GameMode is currently active.\n"
"@return The active status of the GameMode")
{
return object->isActive();
}

DefineEngineMethod(GameMode, setAlwaysActive, void, (bool alwaysActive), (true),
"Sets the active state of the GameMode.\n"
"@param active A bool of the state the GameMode should be set to")
{
object->setAlwaysActive(alwaysActive);
}

DefineEngineFunction(getGameModesList, ArrayObject*, (), , "")
{
char* returnBuffer = Con::getReturnBuffer(1024);
ArrayObject* dictionary = new ArrayObject();
dictionary->registerObject();

String formattedList;
char activeValBuffer[16];

for (SimGroup::iterator itr = Sim::getRootGroup()->begin(); itr != Sim::getRootGroup()->end(); itr++)
{
GameMode* gm = dynamic_cast<GameMode*>(*itr);
if (gm)
{
formattedList += String(gm->getName()) + ";";
dSprintf(activeValBuffer, 16, "%d", (gm->mIsActive || gm->mIsAlwaysActive));
dictionary->push_back(gm->getName(), activeValBuffer);
}
}

dSprintf(returnBuffer, 1024, "%s", formattedList.c_str());

return returnBuffer;
return dictionary;
}

//-----------------------------------------------------------------------------
Expand Down
4 changes: 4 additions & 0 deletions Engine/source/T3D/gameMode.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class GameMode : public SimObject
DECLARE_ASSET_SETGET(GameMode, PreviewImage);

bool mIsActive;
bool mIsAlwaysActive;

public:

Expand All @@ -34,6 +35,9 @@ class GameMode : public SimObject
bool isActive() { return mIsActive; }
void setActive(const bool& active);

bool isAlwaysActive() { return mIsAlwaysActive; }
void setAlwaysActive(const bool& alwaysActive);

DECLARE_CONOBJECT(GameMode);

static void findGameModes(const char* gameModeList, Vector<GameMode*>* outGameModes);
Expand Down
58 changes: 14 additions & 44 deletions Templates/BaseGame/game/core/utility/scripts/scene.tscript
Original file line number Diff line number Diff line change
@@ -1,52 +1,22 @@
function callGamemodeFunction(%gameModeFuncName, %arg0, %arg1, %arg2, %arg3, %arg4, %arg5, %arg6)
{
%activeSceneCount = getSceneCount();
%hasGameMode = 0;
for(%i=0; %i < %activeSceneCount; %i++)
%validGameModeCall = false;
%gamemodeList = getGameModesList();
%gameModeCount = %gamemodeList.count();
for(%i=0; %i < %gameModeCount; %i++)
{
%gamemodeName = getScene(%i).gameModeName;
if(%gamemodeName !$= "")
%gameModeObj = %gamemodeList.getKey(%i);
%active = %gamemodeList.getValue(%i);

if(!isObject(%gameModeObj) || !%active)
continue;

if(%gameModeObj.isMethod(%gameModeFuncName))
{
//if the scene defines a game mode, go ahead and envoke it here
if(isObject(%gamemodeName) && %gamemodeName.isMethod(%gameModeFuncName))
{
eval(%gamemodeName @ "."@%gameModeFuncName@"(\""@%arg0@"\", \""@%arg1@"\", \""@%arg2@"\", \""@%arg3@"\", \""@%arg4@"\", \""@%arg5@"\", \""@%arg6@"\");" );
%hasGameMode = 1;
}
else
{
//if we don't have an object, attempt the static call
if(isMethod(%gamemodeName, %gameModeFuncName))
{
eval(%gamemodeName @ "::"@%gameModeFuncName@"(\""@%arg0@"\", \""@%arg1@"\", \""@%arg2@"\", \""@%arg3@"\", \""@%arg4@"\", \""@%arg5@"\", \""@%arg6@"\");" );
%hasGameMode = 1;
}
}
eval(%gameModeObj @ "."@%gameModeFuncName@"(\""@%arg0@"\", \""@%arg1@"\", \""@%arg2@"\", \""@%arg3@"\", \""@%arg4@"\", \""@%arg5@"\", \""@%arg6@"\");" );
%validGameModeCall = true;
}
}

//if none of our scenes have gamemodes, we need to kick off a default
if(%hasGameMode == 0)
{
%defaultModeName = ProjectSettings.value("Gameplay/GameModes/defaultModeName");
if(%defaultModeName !$= "")
{
if(isObject(%defaultModeName) && %defaultModeName.isMethod(%gameModeFuncName))
{
eval(%defaultModeName @ "."@%gameModeFuncName@"(\""@%arg0@"\", \""@%arg1@"\", \""@%arg2@"\", \""@%arg3@"\", \""@%arg4@"\", \""@%arg5@"\", \""@%arg6@"\");" );
%hasGameMode = 1;
}
else
{
if(isMethod(%defaultModeName, %gameModeFuncName))
{
eval(%defaultModeName @ "::"@%gameModeFuncName@"(\""@%arg0@"\", \""@%arg1@"\", \""@%arg2@"\", \""@%arg3@"\", \""@%arg4@"\", \""@%arg5@"\", \""@%arg6@"\");" );
%hasGameMode = 1;
}
}
}
}

return %hasGameMode;
return %validGameModeCall;
}
27 changes: 15 additions & 12 deletions Templates/BaseGame/game/data/UI/guis/ChooseLevelMenu.gui
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ $guiContent = new GuiControl(ChooseLevelMenu) {
canSaveDynamicFields = "1";
currentMenuIdx = "0";
launchInEditor = "0";
previewButtonSize = "445 120";

new GuiInputCtrl(ChooseLevelInputHandler) {
ignoreMouseEvents = "1";
Expand Down Expand Up @@ -40,8 +39,8 @@ $guiContent = new GuiControl(ChooseLevelMenu) {
new GuiStackControl(ChooseLevelMenuTabList) {
stackingType = "Horizontal";
padding = "10";
position = "405 61";
extent = "470 41";
position = "485 61";
extent = "310 41";
horizSizing = "center";
profile = "GuiDefaultProfile";
tooltipProfile = "GuiToolTipProfile";
Expand Down Expand Up @@ -73,10 +72,12 @@ $guiContent = new GuiControl(ChooseLevelMenu) {
position = "320 0";
extent = "150 41";
profile = "GuiMenuButtonProfile";
visible = "0";
command = "ChooseLevelMenu.openMenu(2);";
tooltipProfile = "GuiToolTipProfile";
internalName = "ConfigBtn";
class = "ChooseLevelMenuButton";
hidden = "1";
};
};
new GuiControl(ChooseLevelMenuNavButtonOverlay) {
Expand All @@ -89,15 +90,15 @@ $guiContent = new GuiControl(ChooseLevelMenu) {

new GuiBitmapCtrl(ChooseLevelMenuPrevNavIcon) {
BitmapAsset = "UI:Keyboard_Black_Q_image";
position = "405 24";
position = "485 24";
extent = "40 40";
vertSizing = "top";
profile = "GuiNonModalDefaultProfile";
tooltipProfile = "GuiToolTipProfile";
};
new GuiBitmapCtrl(ChooseLevelMenuNextNavIcon) {
BitmapAsset = "UI:Keyboard_Black_E_image";
position = "515 24";
position = "595 24";
extent = "40 40";
vertSizing = "top";
profile = "GuiNonModalDefaultProfile";
Expand All @@ -121,24 +122,25 @@ $guiContent = new GuiControl(ChooseLevelMenu) {

new GuiStackControl(GameModePreviewArray) {
padding = "5";
position = "0 1";
extent = "445 120";
position = "1 1";
extent = "443 60";
horizSizing = "width";
vertSizing = "height";
profile = "GuiMenuDefaultProfile";
tooltipProfile = "GuiToolTipProfile";
};
};
new GuiBitmapCtrl(GameModePreviewBitmap) {
BitmapAsset = "UI:no_preview_image";
position = "448 0";
extent = "440 440";
horizSizing = "left";
profile = "GuiNonModalDefaultProfile";
visible = "0";
tooltipProfile = "GuiToolTipProfile";
hidden = "1";
};
new GuiTextCtrl(GameModeNameText) {
text = "Example Level";
text = "DeathMatchGame";
position = "448 445";
extent = "440 20";
horizSizing = "left";
Expand Down Expand Up @@ -175,7 +177,7 @@ $guiContent = new GuiControl(ChooseLevelMenu) {
new GuiStackControl(LevelPreviewArray) {
padding = "5";
position = "0 1";
extent = "445 120";
extent = "445 60";
horizSizing = "width";
vertSizing = "height";
profile = "GuiMenuDefaultProfile";
Expand Down Expand Up @@ -277,6 +279,7 @@ $guiContent = new GuiControl(ChooseLevelMenu) {
tooltipProfile = "GuiToolTipProfile";
};
new GuiTextEditCtrl(serverNameCTRL) {
text = "Torque 3D Server";
position = "606 4";
extent = "295 22";
horizSizing = "left";
Expand Down Expand Up @@ -374,8 +377,8 @@ $guiContent = new GuiControl(ChooseLevelMenu) {
profile = "GuiMenuPanelProfile";
tooltipProfile = "GuiToolTipProfile";

new GuiIconButtonCtrl(ChooseLevelStartBtn) {
BitmapAsset = "UI:Keyboard_Black_Space_image";
new GuiIconButtonCtrl(ChooseLevelNextBtn) {
BitmapAsset = "UI:Keyboard_Black_Blank_image";
sizeIconToButton = "1";
makeIconSquare = "1";
textLocation = "Center";
Expand Down
Loading

0 comments on commit e4d07c7

Please sign in to comment.