mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-04-20 03:45:26 +00:00
Implementation of Subscenes, SceneGroups and Gamemodes
Standardizes Gamemodes to be an actual class with data and utility functions that can be parsed Adds inspector field handling for selecting gamemodes Updated Scene class to work with Gamemodes for the gamemode field Updates editor suite elements to be able to create SubScenes, SceneGroups and Gamemodes Adds ability to convert SimGroup to SubScene Updates BaseUI's chooselevel menu to have gamemode selection and filters shown levels based on selected gamemode
This commit is contained in:
parent
0d07823ecd
commit
ae8eca48e1
36 changed files with 2963 additions and 173 deletions
|
|
@ -0,0 +1,176 @@
|
|||
//This file implements game mode logic for an Example gamemode. The primary functions:
|
||||
//@@::onMissionStart
|
||||
//@@::onMissionReset
|
||||
//@@::onMissionEnd
|
||||
//Are the primary hooks for the server to start, restart and end any active gamemodes
|
||||
//onMissionStart, for example is called from core/clientServer/scripts/server/levelLoad.cs
|
||||
//It's called once the server has successfully loaded the level, and has parsed
|
||||
//through any active scenes to get GameModeNames defined by them. It then iterates
|
||||
//over them and calls these callbacks to envoke gamemode behaviors. This allows multiple
|
||||
//gamemodes to be in effect at one time. Modules can implement as many gamemodes as you want.
|
||||
//
|
||||
//For levels that can be reused for multiple gammodes, the general setup would be a primary level file
|
||||
//with the Scene in it having the main geometry, weapons, terrain, etc. You would then have subScenes that
|
||||
//each contain what's necessary for the given gamemode, such as a subScene that just adds the flags and capture
|
||||
//triggers for a CTF mode. The subscene would then have it's GameModeName defined to run the CTF gamemode logic
|
||||
//and the levelLoad code will execute it.
|
||||
|
||||
if(!isObject(@@))
|
||||
{
|
||||
new GameMode(@@){};
|
||||
}
|
||||
|
||||
//This function is called when the level finishes loading. It sets up the initial configuration, variables and
|
||||
//spawning and dynamic objects, timers or rules needed for the gamemode to run
|
||||
function @@::onMissionStart(%this)
|
||||
{
|
||||
//set up the game and game variables
|
||||
%this.initGameVars();
|
||||
|
||||
if (%this.isActive())
|
||||
{
|
||||
error("@@::onMissionStart: End the game first!");
|
||||
return;
|
||||
}
|
||||
|
||||
%this.setActive(true);
|
||||
}
|
||||
|
||||
//This function is called when the level ends. It can be envoked due to the gamemode ending
|
||||
//but is also kicked off when the game server is shut down as a form of cleanup for anything the gamemode
|
||||
//created or is managing like the above mentioned dynamic objects or timers
|
||||
function @@::onMissionEnded(%this)
|
||||
{
|
||||
if (!%this.isActive())
|
||||
{
|
||||
error("@@::onMissionEnded: No game running!");
|
||||
return;
|
||||
}
|
||||
|
||||
%this.setActive(false);
|
||||
}
|
||||
|
||||
//This function is called in the event the server resets and is used to re-initialize the gamemode
|
||||
function @@::onMissionReset(%this)
|
||||
{
|
||||
// Called by resetMission(), after all the temporary mission objects
|
||||
// have been deleted.
|
||||
%this.initGameVars();
|
||||
}
|
||||
|
||||
//This sets up our gamemode's duration time
|
||||
function @@::initGameVars(%this)
|
||||
{
|
||||
// Set the gameplay parameters
|
||||
%this.duration = 30 * 60;
|
||||
}
|
||||
|
||||
//This is called when the timer runs out, allowing the gamemode to end
|
||||
function @@::onGameDurationEnd(%this)
|
||||
{
|
||||
//we don't end if we're currently editing the level
|
||||
if (%this.duration && !(EditorIsActive() && GuiEditorIsActive()))
|
||||
%this.onMissionEnded();
|
||||
}
|
||||
|
||||
//This is called to actually spawn a control object for the player to utilize
|
||||
//A player character, spectator camera, etc.
|
||||
function @@::spawnControlObject(%this, %client)
|
||||
{
|
||||
//In this example, we just spawn a camera
|
||||
/*if (!isObject(%client.camera))
|
||||
{
|
||||
if(!isObject(Observer))
|
||||
{
|
||||
datablock CameraData(Observer)
|
||||
{
|
||||
mode = "Observer";
|
||||
};
|
||||
}
|
||||
|
||||
%client.camera = spawnObject("Camera", Observer);
|
||||
}
|
||||
|
||||
// If we have a camera then set up some properties
|
||||
if (isObject(%client.camera))
|
||||
{
|
||||
MissionCleanup.add( %this.camera );
|
||||
%client.camera.scopeToClient(%client);
|
||||
|
||||
%client.setControlObject(%client.camera);
|
||||
|
||||
%client.camera.setTransform("0 0 1 0 0 0 0");
|
||||
}*/
|
||||
|
||||
}
|
||||
|
||||
//This is called when the client has finished loading the mission, but aren't "in" it yet
|
||||
//allowing for some last-second prepwork
|
||||
function @@::onClientMissionLoaded(%this)
|
||||
{
|
||||
$clientLoaded++;
|
||||
if ($clientLoaded == $clientConneted)
|
||||
$gameReady = true;
|
||||
}
|
||||
|
||||
//This is called when the client has initially established a connection to the game server
|
||||
//It's used for setting up anything ahead of time for the client, such as loading in client-passed
|
||||
//config stuffs, saved data or the like that should be handled BEFORE the client has actually entered
|
||||
//the game itself
|
||||
function @@::onClientConnect(%this, %client)
|
||||
{
|
||||
$clientConneted++;
|
||||
getPlayer(%client);
|
||||
}
|
||||
|
||||
|
||||
//This is called when a client enters the game server. It's used to spawn a player object
|
||||
//set up any client-specific properties such as saved configs, values, their name, etc
|
||||
//These callbacks are activated in core/clientServer/scripts/server/levelDownload.cs
|
||||
function @@::onClientEnterGame(%this, %client)
|
||||
{
|
||||
$Game::DefaultPlayerClass = "Player";
|
||||
$Game::DefaultPlayerDataBlock = "DefaultPlayerData";
|
||||
$Game::DefaultPlayerSpawnGroups = "spawn_player CameraSpawnPoints PlayerSpawnPoints PlayerDropPoints";
|
||||
|
||||
$Game::DefaultCameraClass = "Camera";
|
||||
$Game::DefaultCameraDataBlock = "Observer";
|
||||
$Game::DefaultCameraSpawnGroups = "spawn_player CameraSpawnPoints PlayerSpawnPoints PlayerDropPoints";
|
||||
|
||||
|
||||
//Spawn NPCs for the map and stuff here?
|
||||
|
||||
// This function currently relies on some helper functions defined in
|
||||
// core/scripts/spawn.cs. For custom spawn behaviors one can either
|
||||
// override the properties on the SpawnSphere's or directly override the
|
||||
// functions themselves.
|
||||
}
|
||||
|
||||
function @@::onSceneLoaded(%this)
|
||||
{
|
||||
}
|
||||
|
||||
function @@::onSceneUnloaded(%this)
|
||||
{
|
||||
}
|
||||
|
||||
function @@::onSubsceneLoaded(%this)
|
||||
{
|
||||
}
|
||||
|
||||
function @@::onSubsceneUnloaded(%this)
|
||||
{
|
||||
}
|
||||
|
||||
//This is called when the player leaves the game server. It's used to clean up anything that
|
||||
//was spawned or setup for the client when it connected, in onClientEnterGame
|
||||
//These callbacks are activated in core/clientServer/scripts/server/levelDownload.cs
|
||||
function @@::onClientLeaveGame(%this, %client)
|
||||
{
|
||||
// Cleanup the camera
|
||||
if (isObject(%this.camera))
|
||||
%this.camera.delete();
|
||||
// Cleanup the player
|
||||
if (isObject(%this.player))
|
||||
%this.player.delete();
|
||||
}
|
||||
|
|
@ -9,6 +9,8 @@ function @@::onDestroy(%this)
|
|||
//This is called when the server is initially set up by the game application
|
||||
function @@::initServer(%this)
|
||||
{
|
||||
//--FILE EXEC BEGIN--
|
||||
//--FILE EXEC END--
|
||||
}
|
||||
|
||||
//This is called when the server is created for an actual game/map to be played
|
||||
|
|
@ -17,16 +19,14 @@ function @@::onCreateGameServer(%this)
|
|||
//These are common managed data files. For any datablock-based stuff that gets generated by the editors
|
||||
//(that doesn't have a specific associated file, like data for a player class) will go into these.
|
||||
//So we'll register them now if they exist.
|
||||
if(isFile("./scripts/managedData/managedDatablocks." @ $TorqueScriptFileExtension))
|
||||
%this.registerDatablock("./scripts/managedData/managedDatablocks");
|
||||
if(isFile("./scripts/managedData/managedForestItemData." @ $TorqueScriptFileExtension))
|
||||
%this.registerDatablock("./scripts/managedData/managedForestItemData");
|
||||
if(isFile("./scripts/managedData/managedForestBrushData." @ $TorqueScriptFileExtension))
|
||||
%this.registerDatablock("./scripts/managedData/managedForestBrushData");
|
||||
if(isFile("./scripts/managedData/managedParticleEmitterData." @ $TorqueScriptFileExtension))
|
||||
%this.registerDatablock("./scripts/managedData/managedParticleEmitterData");
|
||||
if(isFile("./scripts/managedData/managedParticleData." @ $TorqueScriptFileExtension))
|
||||
%this.registerDatablock("./scripts/managedData/managedParticleData");
|
||||
%this.registerDatablock("./scripts/managedData/managedDatablocks");
|
||||
%this.registerDatablock("./scripts/managedData/managedForestItemData");
|
||||
%this.registerDatablock("./scripts/managedData/managedForestBrushData");
|
||||
%this.registerDatablock("./scripts/managedData/managedParticleEmitterData");
|
||||
%this.registerDatablock("./scripts/managedData/managedParticleData");
|
||||
|
||||
//--DATABLOCK EXEC BEGIN--
|
||||
//--DATABLOCK EXEC END--
|
||||
}
|
||||
|
||||
//This is called when the server is shut down due to the game/map being exited
|
||||
|
|
@ -37,6 +37,8 @@ function @@::onDestroyGameServer(%this)
|
|||
//This is called when the client is initially set up by the game application
|
||||
function @@::initClient(%this)
|
||||
{
|
||||
//--FILE EXEC BEGIN--
|
||||
//--FILE EXEC END--
|
||||
}
|
||||
|
||||
//This is called when a client connects to a server
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue