mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-07-12 07:04:36 +00:00
Implemented initial pass at proper client/server separation handling for module initialization
Added GameModeName to Scene Added function to get number of active scenes Added logic to level/client loading to enact gameplay mode logic driven by either Scene's GameModeName or project setting's default game mode Added template module.cs file for module creation and adjusted new module logic in AssetBrowser to create off template Updated FPSGameplay code to have deathmatchGame mode work with new GameMode logic Updated EmptyLevel scene to define deathMatchGame as gamemode Updated FPSGameplay module script to properly client/server initialize
This commit is contained in:
parent
d97c05b411
commit
7dc03ae17a
32 changed files with 774 additions and 294 deletions
|
|
@ -25,7 +25,6 @@ function CoreModule::onCreate(%this)
|
|||
ModuleDatabase.LoadExplicit( "Core_PostFX" );
|
||||
ModuleDatabase.LoadExplicit( "Core_Components" );
|
||||
ModuleDatabase.LoadExplicit( "Core_GameObjects" );
|
||||
ModuleDatabase.LoadExplicit( "Core_ClientServer" );
|
||||
|
||||
new Settings(ProjectSettings) { file = "core/settings.xml"; };
|
||||
ProjectSettings.read();
|
||||
|
|
|
|||
|
|
@ -20,6 +20,8 @@ function initClient()
|
|||
exec( %prefPath @ "/clientPrefs.cs" );
|
||||
else
|
||||
exec( "data/defaults.cs" );
|
||||
|
||||
callOnModules("initClient");
|
||||
|
||||
loadMaterials();
|
||||
|
||||
|
|
|
|||
|
|
@ -32,18 +32,7 @@ function GameConnection::onConnectionAccepted(%this)
|
|||
// datablocks and objects are ghosted over.
|
||||
physicsInitWorld( "client" );
|
||||
|
||||
//Get our modules so we can exec any specific client-side loading/handling
|
||||
%modulesList = ModuleDatabase.findModules(true);
|
||||
for(%i=0; %i < getWordCount(%modulesList); %i++)
|
||||
{
|
||||
%module = getWord(%modulesList, %i);
|
||||
%moduleID = %module.ModuleId;
|
||||
|
||||
if(%module.scopeSet.isMethod("onCreateClient"))
|
||||
{
|
||||
eval(%module.scopeSet @ ".onCreateClient();");
|
||||
}
|
||||
}
|
||||
callOnModules("onCreateClient", "Game");
|
||||
}
|
||||
|
||||
function GameConnection::initialControlSet(%this)
|
||||
|
|
@ -141,14 +130,5 @@ function disconnectedCleanup()
|
|||
// We can now delete the client physics simulation.
|
||||
physicsDestroyWorld( "client" );
|
||||
|
||||
//Get our modules so we can exec any specific client-side loading/handling
|
||||
%modulesList = ModuleDatabase.findModules(true);
|
||||
for(%i=0; %i < getWordCount(%modulesList); %i++)
|
||||
{
|
||||
%module = getWord(%modulesList, %i);
|
||||
if(%module.scopeSet.isMethod("onDestroyClient"))
|
||||
{
|
||||
eval(%module.scopeSet @ ".onDestroyClient();");
|
||||
}
|
||||
}
|
||||
callOnModules("onDestroyClient", "Game");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -150,7 +150,35 @@ function GameConnection::onDrop(%client, %reason)
|
|||
}
|
||||
|
||||
if($missionRunning)
|
||||
theLevelInfo.onClientLeaveGame();
|
||||
{
|
||||
%hasGameMode = 0;
|
||||
for(%i=0; %i < %activeSceneCount; %i++)
|
||||
{
|
||||
if(getScene(%i).gameModeName !$= "")
|
||||
{
|
||||
//if the scene defines a game mode, go ahead and envoke it here
|
||||
if(isMethod(getScene(%i).gameModeName, "onClientLeaveGame"))
|
||||
{
|
||||
eval(getScene(%i).gameModeName @ "::onClientLeaveGame(" @ %client @ ");" );
|
||||
%hasGameMode = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//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(isMethod(%defaultModeName, "onClientLeaveGame"))
|
||||
{
|
||||
eval(%defaultModeName @ "::onClientLeaveGame(" @ %client @ ");" );
|
||||
%hasGameMode = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
removeFromServerGuidList( %client.guid );
|
||||
|
||||
|
|
|
|||
|
|
@ -148,12 +148,38 @@ function serverCmdMissionStartPhase3Ack(%client, %seq)
|
|||
%entity.notify("onClientConnect", %client);
|
||||
}
|
||||
|
||||
//Have any special game-play handling here
|
||||
if(theLevelInfo.isMethod("onClientEnterGame"))
|
||||
%activeSceneCount = getSceneCount();
|
||||
|
||||
%hasGameMode = 0;
|
||||
for(%i=0; %i < %activeSceneCount; %i++)
|
||||
{
|
||||
theLevelInfo.onClientEnterGame(%client);
|
||||
if(getScene(%i).gameModeName !$= "")
|
||||
{
|
||||
//if the scene defines a game mode, go ahead and envoke it here
|
||||
if(isMethod(getScene(%i).gameModeName, "onClientEnterGame"))
|
||||
{
|
||||
eval(getScene(%i).gameModeName @ "::onClientEnterGame(" @ %client @ ");" );
|
||||
%hasGameMode = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
//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(isMethod(%defaultModeName, "onClientEnterGame"))
|
||||
{
|
||||
eval(%defaultModeName @ "::onClientEnterGame(" @ %client @ ");" );
|
||||
%hasGameMode = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//if that also failed, just spawn a camera
|
||||
if(%hasGameMode == 0)
|
||||
{
|
||||
//No Game mode class for the level info, so just spawn a default camera
|
||||
// Set the control object to the default camera
|
||||
|
|
|
|||
|
|
@ -135,8 +135,35 @@ function loadMissionStage2()
|
|||
ClientGroup.getObject(%clientIndex).loadMission();
|
||||
|
||||
// Go ahead and launch the game
|
||||
if(TheLevelInfo.isMethod("onMissionStart"))
|
||||
TheLevelInfo.onMissionStart();
|
||||
%activeSceneCount = getSceneCount();
|
||||
|
||||
%hasGameMode = 0;
|
||||
for(%i=0; %i < %activeSceneCount; %i++)
|
||||
{
|
||||
if(getScene(%i).gameModeName !$= "")
|
||||
{
|
||||
//if the scene defines a game mode, go ahead and envoke it here
|
||||
if(isMethod(getScene(%i).gameModeName, "onMissionStart"))
|
||||
{
|
||||
eval(getScene(%i).gameModeName @ "::onMissionStart();" );
|
||||
%hasGameMode = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//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(isMethod(%defaultModeName, "onMissionStart"))
|
||||
{
|
||||
eval(%defaultModeName @ "::onMissionStart();" );
|
||||
%hasGameMode = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function endMission()
|
||||
|
|
@ -147,7 +174,35 @@ function endMission()
|
|||
echo("*** ENDING MISSION");
|
||||
|
||||
// Inform the game code we're done.
|
||||
TheLevelInfo.onMissionEnded();
|
||||
%activeSceneCount = getSceneCount();
|
||||
|
||||
%hasGameMode = 0;
|
||||
for(%i=0; %i < %activeSceneCount; %i++)
|
||||
{
|
||||
if(getScene(%i).gameModeName !$= "")
|
||||
{
|
||||
//if the scene defines a game mode, go ahead and envoke it here
|
||||
if(isMethod(getScene(%i).gameModeName, "onMissionEnded"))
|
||||
{
|
||||
eval(getScene(%i).gameModeName @ "::onMissionEnded();" );
|
||||
%hasGameMode = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//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(isMethod(%defaultModeName, "onMissionEnded"))
|
||||
{
|
||||
eval(%defaultModeName @ "::onMissionEnded();" );
|
||||
%hasGameMode = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Inform the clients
|
||||
for( %clientIndex = 0; %clientIndex < ClientGroup.getCount(); %clientIndex++ ) {
|
||||
|
|
@ -176,6 +231,35 @@ function resetMission()
|
|||
$instantGroup = MissionCleanup;
|
||||
|
||||
clearServerPaths();
|
||||
//
|
||||
TheLevelInfo.onMissionReset();
|
||||
|
||||
// Inform the game code we're resetting.
|
||||
%activeSceneCount = getSceneCount();
|
||||
|
||||
%hasGameMode = 0;
|
||||
for(%i=0; %i < %activeSceneCount; %i++)
|
||||
{
|
||||
if(getScene(%i).gameModeName !$= "")
|
||||
{
|
||||
//if the scene defines a game mode, go ahead and envoke it here
|
||||
if(isMethod(getScene(%i).gameModeName, "onMissionReset"))
|
||||
{
|
||||
eval(getScene(%i).gameModeName @ "::onMissionReset(" @ %client @ ");" );
|
||||
%hasGameMode = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//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(isMethod(%defaultModeName, "onMissionReset"))
|
||||
{
|
||||
eval(%defaultModeName @ "::onMissionReset(" @ %client @ ");" );
|
||||
%hasGameMode = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -52,6 +52,8 @@ function initServer()
|
|||
|
||||
// Specify where the mission files are.
|
||||
$Server::MissionFileSpec = "data/levels/*.mis";
|
||||
|
||||
callOnModules("initServer");
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
|
@ -156,17 +158,8 @@ function createServer(%serverType, %level)
|
|||
schedule(0,0,startHeartbeat);
|
||||
}
|
||||
|
||||
//Get our modules so we can exec any specific server-side loading/handling
|
||||
%modulesList = ModuleDatabase.findModules(true);
|
||||
for(%i=0; %i < getWordCount(%modulesList); %i++)
|
||||
{
|
||||
%module = getWord(%modulesList, %i);
|
||||
if(%module.scopeSet.isMethod("onCreateServer"))
|
||||
{
|
||||
eval(%module.scopeSet @ ".onCreateServer();");
|
||||
}
|
||||
}
|
||||
|
||||
callOnModules("onCreateServer", "Game");
|
||||
|
||||
// Let the game initialize some things now that the
|
||||
// the server has been created
|
||||
onServerCreated();
|
||||
|
|
@ -241,15 +234,7 @@ function destroyServer()
|
|||
deleteDataBlocks();
|
||||
|
||||
//Get our modules so we can exec any specific server-side loading/handling
|
||||
%modulesList = ModuleDatabase.findModules(true);
|
||||
for(%i=0; %i < getWordCount(%modulesList); %i++)
|
||||
{
|
||||
%module = getWord(%modulesList, %i);
|
||||
if(%module.scopeSet.isMethod("onDestroyServer"))
|
||||
{
|
||||
eval(%module.scopeSet @ ".onDestroyServer();");
|
||||
}
|
||||
}
|
||||
callOnModules("onDestroyServer", "Game");
|
||||
|
||||
// Save any server settings
|
||||
%prefPath = getPrefpath();
|
||||
|
|
@ -273,8 +258,35 @@ function onServerDestroyed()
|
|||
echo("*** ENDING MISSION");
|
||||
|
||||
// Inform the game code we're done.
|
||||
if(TheLevelInfo.isMethod("onMissionEnded"))
|
||||
TheLevelInfo.onMissionEnded();
|
||||
%activeSceneCount = getSceneCount();
|
||||
|
||||
%hasGameMode = 0;
|
||||
for(%i=0; %i < %activeSceneCount; %i++)
|
||||
{
|
||||
if(getScene(%i).gameModeName !$= "")
|
||||
{
|
||||
//if the scene defines a game mode, go ahead and envoke it here
|
||||
if(isMethod(getScene(%i).gameModeName, "onMissionEnded"))
|
||||
{
|
||||
eval(getScene(%i).gameModeName @ "::onMissionEnded();" );
|
||||
%hasGameMode = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//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(isMethod(%defaultModeName, "onMissionEnded"))
|
||||
{
|
||||
eval(%defaultModeName @ "::onMissionEnded();" );
|
||||
%hasGameMode = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Inform the clients
|
||||
for( %clientIndex = 0; %clientIndex < ClientGroup.getCount(); %clientIndex++ ) {
|
||||
|
|
|
|||
Binary file not shown.
Binary file not shown.
|
|
@ -5,9 +5,4 @@
|
|||
<Setting name="coreModulePath">core/</Setting>
|
||||
</Group>
|
||||
</Group>
|
||||
<Group name="Gameplay">
|
||||
<Group name="GameModes">
|
||||
<Setting name="defaultModeName">a</Setting>
|
||||
</Group>
|
||||
</Group>
|
||||
</ProjectSettings>
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ function Core_Utility::onCreate(%this)
|
|||
exec("./scripts/helperFunctions.cs");
|
||||
exec("./scripts/gameObjectManagement.cs");
|
||||
exec("./scripts/persistanceManagement.cs");
|
||||
exec("./scripts/module.cs");
|
||||
}
|
||||
|
||||
function Core_Utility::onDestroy(%this)
|
||||
|
|
|
|||
20
Templates/BaseGame/game/core/utility/scripts/module.cs
Normal file
20
Templates/BaseGame/game/core/utility/scripts/module.cs
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
function callOnModules(%functionName, %moduleGroup)
|
||||
{
|
||||
//Get our modules so we can exec any specific client-side loading/handling
|
||||
%modulesList = ModuleDatabase.findModules(false);
|
||||
for(%i=0; %i < getWordCount(%modulesList); %i++)
|
||||
{
|
||||
%module = getWord(%modulesList, %i);
|
||||
|
||||
if(%moduleGroup !$= "")
|
||||
{
|
||||
if(%module.group !$= %moduleGroup)
|
||||
continue;
|
||||
}
|
||||
|
||||
if(isObject(%module.scopeSet) && %module.scopeSet.isMethod(%functionName))
|
||||
{
|
||||
eval(%module.scopeSet @ "." @ %functionName @ "();");
|
||||
}
|
||||
}
|
||||
}
|
||||
0
Templates/BaseGame/game/core/utility/scripts/scene.cs
Normal file
0
Templates/BaseGame/game/core/utility/scripts/scene.cs
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
function SimObject::notify(%this, %signalName)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
function SimObject::removeNotify(%this, %signalName)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
function SimObject::removeNotify(%this, %signalName)
|
||||
{
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue