Skip to content

Commit ad78f86

Browse files
authored
Merge pull request #932 from Azaezel/alpha402/LevelLoadInjection
adds a mechanism to inject additional steps into mission loading
2 parents 1203023 + 29e06fc commit ad78f86

File tree

3 files changed

+84
-1
lines changed

3 files changed

+84
-1
lines changed

Templates/BaseGame/game/core/clientServer/Core_ClientServer.tscript

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,70 @@
1212
// When a local game is started - a listen server - via calling StartGame() a server is created and then the client is
1313
// connected to it via createAndConnectToLocalServer().
1414

15+
function Core_ClientServer::clearLoadStatus()
16+
{
17+
Core_ClientServer.moduleLoadedDone = 0;
18+
Core_ClientServer.moduleLoadedFailed = 0;
19+
}
20+
function Core_ClientServer::onLoadMap(%this)
21+
{
22+
%this.finishMapLoad();
23+
}
24+
25+
function Core_ClientServer::finishMapLoad(%this)
26+
{
27+
Core_ClientServer.GetEventManager().postEvent( "mapLoadComplete" );
28+
}
29+
30+
function Core_ClientServer::FailMapLoad(%this, %moduleName, %isFine)
31+
{
32+
Core_ClientServer.failedModuleName = %moduleName;
33+
Core_ClientServer.GetEventManager().postEvent( "mapLoadFail", %isFine );
34+
}
35+
36+
function Core_ClientServerListener::onMapLoadComplete(%this)
37+
{
38+
Core_ClientServer.moduleLoadedDone++;
39+
%numModsNeedingLoaded = 0;
40+
%modulesList = ModuleDatabase.findModules();
41+
for(%i=0; %i < getWordCount(%modulesList); %i++)
42+
{
43+
%module = getWord(%modulesList, %i);
44+
if (%module.ModuleId.isMethod("finishMapLoad"))
45+
%numModsNeedingLoaded++;
46+
}
47+
if (Core_ClientServer.moduleLoadedDone == %numModsNeedingLoaded)
48+
{
49+
loadMissionStage3();
50+
}
51+
}
52+
53+
function Core_ClientServerListener::onmapLoadFail(%this, %isFine)
54+
{
55+
if (%isFine)
56+
{
57+
%this.onMapLoadComplete();
58+
return;
59+
}
60+
61+
Core_ClientServer.moduleLoadedFailed++;
62+
if (Core_ClientServer.moduleLoadedFailed>1) return; // yeah, we know
63+
64+
$Server::LoadFailMsg = Core_ClientServer.failedModuleName @" failed to load mission specific data!";
65+
error($Server::LoadFailMsg);
66+
// Inform clients that are already connected
67+
68+
for (%clientIndex = 0; %clientIndex < ClientGroup.getCount(); %clientIndex++)
69+
{
70+
%cl = ClientGroup.getObject( %clientIndex );
71+
%cl.onConnectionDropped($Server::LoadFailMsg);
72+
%cl.endMission();
73+
%cl.resetGhosting();
74+
%cl.clearPaths();
75+
}
76+
destroyServer();
77+
}
78+
1579
function Core_ClientServer::onCreate( %this )
1680
{
1781
echo("\n--------- Initializing Directory: scripts ---------");
@@ -33,6 +97,11 @@ function Core_ClientServer::onCreate( %this )
3397
{
3498
initClient();
3599
}
100+
%this.GetEventManager().registerEvent("mapLoadComplete");
101+
%this.GetEventManager().registerEvent("mapLoadFail");
102+
%this.listener = new ScriptMsgListener() {class = Core_ClientServerListener;};
103+
%this.GetEventManager().subscribe( %this.listener, "mapLoadComplete" );
104+
%this.GetEventManager().subscribe( %this.listener, "mapLoadFail" );
36105
}
37106

38107
function Core_ClientServer::onDestroy( %this )

Templates/BaseGame/game/core/clientServer/scripts/server/levelLoad.tscript

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,14 @@ function loadMissionStage2()
126126
// Set mission name.
127127
if( isObject( theLevelInfo ) )
128128
$Server::MissionName = theLevelInfo.levelName;
129+
Core_ClientServer.clearLoadStatus();
130+
callOnModules("onLoadMap");
129131

132+
}
133+
134+
function loadMissionStage3()
135+
{
136+
echo("*** Stage 3 load");
130137

131138
%hasGameMode = callGamemodeFunction("onCreateGame");
132139

@@ -143,8 +150,8 @@ function loadMissionStage2()
143150

144151
// Go ahead and launch the game
145152
%hasGameMode = callGamemodeFunction("onMissionStart");
153+
146154
}
147-
148155
function endMission()
149156
{
150157
if (!isObject( getScene(0) ))

Templates/BaseGame/game/core/utility/scripts/module.tscript

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,3 +317,10 @@ function SimSet::unQueueExec(%scopeSet, %execFilePath)
317317
%execFileList.echo();
318318
}
319319

320+
function SimSet::GetEventManager(%this)
321+
{
322+
if( !isObject( %this.eventManager ) )
323+
%this.eventManager = new EventManager() { queue = "ModuleEventManager"; };
324+
325+
return %this.eventManager;
326+
}

0 commit comments

Comments
 (0)