Kaynağa Gözat

adds a mechanism to inject additional steps into mission loading
leverages the EventManager and ScriptMsgListener() classes to set up a third mission load stage triggered by the following flow:
function <module>::onLoadMap(%this) starts an execution chain that leads to <module>::finishMapLoad()
each <module>::finishMapLoad() MUST contain the line
Core_ClientServer.GetEventManager().postEvent( "mapLoadComplete" );
once all have called back that they have finished thier tasks, players finish loading into a hosted mission

AzaezelX 2 yıl önce
ebeveyn
işleme
2e47e7d823

+ 30 - 0
Templates/BaseGame/game/core/clientServer/Core_ClientServer.tscript

@@ -12,6 +12,33 @@
 // 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::onLoadMap(%this)
+{
+    %this.finishMapLoad();
+}
+
+function Core_ClientServer::finishMapLoad()
+{
+    Core_ClientServer.GetEventManager().postEvent( "mapLoadComplete" );
+}
+
+function Core_ClientServerListener::onMapLoadComplete(%this)
+{
+    $moduleLoadedDone++;
+    %numModsNeedingLoaded = 0;
+    %modulesList = ModuleDatabase.findModules();
+    for(%i=0; %i < getWordCount(%modulesList); %i++)
+    {
+        %module = getWord(%modulesList, %i);
+        if (%module.ModuleId.isMethod("finishMapLoad"))
+            %numModsNeedingLoaded++;
+    }
+    if ($moduleLoadedDone == %numModsNeedingLoaded)
+    {
+        loadMissionStage3();  
+    }
+}
+
 function Core_ClientServer::onCreate( %this )
 {
    echo("\n--------- Initializing Directory: scripts ---------");
@@ -33,6 +60,9 @@ function Core_ClientServer::onCreate( %this )
    {
       initClient();
    }
+   %this.GetEventManager().registerEvent("mapLoadComplete");
+   %this.listener = new ScriptMsgListener() {class = Core_ClientServerListener;}; 
+   %this.GetEventManager().subscribe( %this.listener, "mapLoadComplete" ); 
 }
 
 function Core_ClientServer::onDestroy( %this )

+ 8 - 1
Templates/BaseGame/game/core/clientServer/scripts/server/levelLoad.tscript

@@ -126,7 +126,14 @@ function loadMissionStage2()
    // Set mission name.
    if( isObject( theLevelInfo ) )
       $Server::MissionName = theLevelInfo.levelName;
+   $moduleLoadedDone = 0;
+   callOnModules("onLoadMap");
 
+}
+
+function loadMissionStage3() 
+{
+   echo("*** Stage 3 load");
    
    %hasGameMode = callGamemodeFunction("onCreateGame");
    
@@ -143,8 +150,8 @@ function loadMissionStage2()
 
    // Go ahead and launch the game
    %hasGameMode = callGamemodeFunction("onMissionStart");
+   
 }
-
 function endMission()
 {
    if (!isObject( getScene(0) ))

+ 7 - 0
Templates/BaseGame/game/core/utility/scripts/module.tscript

@@ -317,3 +317,10 @@ function SimSet::unQueueExec(%scopeSet, %execFilePath)
       %execFileList.echo();
 }
 
+function SimSet::GetEventManager(%this)
+{
+   if( !isObject( %this.eventManager ) )
+      %this.eventManager = new EventManager() { queue = "ModuleEventManager"; };
+      
+   return %this.eventManager;
+}