Caught the main modules up to new module script file paradigm

Have initServer only get called when a server is actually started for the first time
Added utility method callGamemodeFunction to streamline exec'ing of gamemode function calls
Added onClientConnect gamemode function, called when the client establishes the connection
Added onInitialControlSet gamemode function, called when the client actively gains control in the game, to allow gamemodes to special override GUI settings or input commands
Cleaned up init'ng of the engine so stock UI module isn't required to trip configuration of the canvas
Added fallback so if nothing set the main content control for the UI after boot, we attempt to set the defined mainMenuGUI, on the chance nothing explicitly sets it on load
This commit is contained in:
Areloch 2019-09-02 16:13:24 -05:00
parent 3b2927801e
commit 9e1544880e
23 changed files with 377 additions and 408 deletions

View file

@ -1,7 +1,6 @@
function CoreModule::onCreate(%this)
{
// ----------------------------------------------------------------------------
// Initialize core sub system functionality such as audio, the Canvas, PostFX,
// rendermanager, light managers, etc.

View file

@ -12,17 +12,17 @@
// When a local game is started - a listen server - via calling StartGame() a server is created and then the client is
// connected to it via createAndConnectToLocalServer().
function Core_ClientServer::create( %this )
function Core_ClientServer::onCreate( %this )
{
echo("\n--------- Initializing Directory: scripts ---------");
exec( "./scripts/client/client.cs" );
exec( "./scripts/server/server.cs" );
$Game::MainScene = getScene(0);
initServer();
%dbList = new ArrayObject(DatablockFilesList);
new ArrayObject(DatablockFilesList);
$Game::firstTimeServerRun = true;
// Start up in either client, or dedicated server mode
if ($Server::Dedicated)
@ -35,7 +35,7 @@ function Core_ClientServer::create( %this )
}
}
function Core_ClientServer::destroy( %this )
function Core_ClientServer::onDestroy( %this )
{
// Ensure that we are disconnected and/or the server is destroyed.
// This prevents crashes due to the SceneGraph being deleted before

View file

@ -3,7 +3,7 @@
VersionId="1"
Description="Default module for the game."
ScriptFile="Core_ClientServer.cs"
CreateFunction="create"
DestroyFunction="destroy"
CreateFunction="onCreate"
DestroyFunction="onDestroy"
Group="Core">
</ModuleDefinition>

View file

@ -50,6 +50,9 @@ function GameConnection::initialControlSet(%this)
if (isObject(%playGUIName) && Canvas.getContent() != %playGUIName.getId())
Canvas.setContent(%playGUIName);
//We allow the gamemodes to step in and override the canvas setting, or do any special input overrides here
%hasGameMode = callGamemodeFunction("onInitialControlSet");
}
}

View file

@ -81,6 +81,8 @@ function GameConnection::onConnect( %this, %clientData )
%this.connectData = %clientData;
callGamemodeFunction("onClientConnect", %this);
$Server::PlayerCount++;
}
@ -151,33 +153,7 @@ function GameConnection::onDrop(%client, %reason)
if($missionRunning)
{
%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;
}
}
}
%hasGameMode = callGamemodeFunction("onClientLeaveGame", %client);
}
removeFromServerGuidList( %client.guid );

View file

@ -150,33 +150,7 @@ function serverCmdMissionStartPhase3Ack(%client, %seq)
%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, "onClientEnterGame"))
{
eval(getScene(%i).gameModeName @ "::onClientEnterGame(" @ %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, "onClientEnterGame"))
{
eval(%defaultModeName @ "::onClientEnterGame(" @ %client @ ");" );
%hasGameMode = 1;
}
}
}
%hasGameMode = callGamemodeFunction("onClientEnterGame", %client);
//if that also failed, just spawn a camera
if(%hasGameMode == 0)

View file

@ -137,33 +137,7 @@ function loadMissionStage2()
// Go ahead and launch the game
%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;
}
}
}
%hasGameMode = callGamemodeFunction("onMissionStart");
}
function endMission()
@ -176,33 +150,7 @@ function endMission()
// Inform the game code we're done.
%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;
}
}
}
%hasGameMode = callGamemodeFunction("onMissionEnded");
// Inform the clients
for( %clientIndex = 0; %clientIndex < ClientGroup.getCount(); %clientIndex++ ) {
@ -235,31 +183,5 @@ function resetMission()
// 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;
}
}
}
%hasGameMode = callGamemodeFunction("onMissionReset", %client);
}

View file

@ -126,6 +126,11 @@ function createAndConnectToLocalServer( %serverType, %level )
/// Specify the level to load on the server
function createServer(%serverType, %level)
{
if($Game::firstTimeServerRun == true)
{
initServer();
$Game::firstTimeServerRun = false;
}
// Increase the server session number. This is used to make sure we're
// working with the server session we think we are.
$Server::Session++;
@ -197,12 +202,8 @@ function onServerCreated()
physicsStartSimulation("server");
%cnt = DatablockFilesList.count();
loadDatablockFiles( DatablockFilesList, true );
%cnt = DatablockFilesList.count();
// Keep track of when the game started
$Game::StartTime = $Sim::Time;

View file

@ -20,4 +20,33 @@ function Core_Rendering::onCreate(%this)
function Core_Rendering::onDestroy(%this)
{
}
function Core_Rendering::initClient(%this)
{
// Start rendering and stuff.
initRenderManager();
initLightingSystems("Advanced Lighting");
//load prefs
%prefPath = getPrefpath();
if ( isFile( %prefPath @ "/clientPrefs.cs" ) )
exec( %prefPath @ "/clientPrefs.cs" );
else
exec("data/defaults.cs");
configureCanvas();
//Autodetect settings if it's our first time
if($pref::Video::autoDetect)
GraphicsMenu.Autodetect();
postFXInit();
closeSplashWindow();
// As we know at this point that the initial load is complete,
// we can hide any splash screen we have, and show the canvas.
// This keeps things looking nice, instead of having a blank window
Canvas.showWindow();
}

View file

@ -7,6 +7,7 @@ function Core_Utility::onCreate(%this)
exec("./scripts/gameObjectManagement.cs");
exec("./scripts/persistanceManagement.cs");
exec("./scripts/module.cs");
exec("./scripts/scene.cs");
}
function Core_Utility::onDestroy(%this)

View file

@ -0,0 +1,36 @@
function callGamemodeFunction(%gameModeFuncName, %data)
{
if(%data !$= "")
%data = "\""@%data@"\"";
%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, %gameModeFuncName))
{
eval(getScene(%i).gameModeName @ "::"@%gameModeFuncName@"("@%data@");" );
%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, %gameModeFuncName))
{
eval(%defaultModeName @ "::"@%gameModeFuncName@"("@%data@");" );
%hasGameMode = 1;
}
}
}
return %hasGameMode;
}