private void ExecuteMapChange(bool noFadeWipe = false)
{
bool reloadingSameMap;
// close console and remove any prints from the notify lines
idE.Console.Close();
if(this.IsMultiplayer == true)
{
// make sure the mp GUI isn't up, or when players get back in the
// map, mpGame's menu and the gui will be out of sync.
SetUserInterface(null, null);
}
// mute sound
// TODO: soundSystem->SetMute( true );
// clear all menu sounds
// TODO: menuSoundWorld->ClearAllSoundEmitters();
// unpause the game sound world
// NOTE: we UnPause again later down. not sure this is needed
// TODO: sound
/*if ( sw->IsPaused() ) {
sw->UnPause();
}*/
if(noFadeWipe == false)
{
// capture the current screen and start a wipe
idConsole.Warning("TODO: StartWipe( wipeMaterial, true );");
// immediately complete the wipe to fade out the level transition
// run the wipe to completion
idConsole.Warning("TODO: CompleteWipe();");
}
// extract the map name from serverinfo
string mapString = _mapSpawnData.ServerInformation.GetString("si_map");
string mapFullName = string.Format("maps/{0}", Path.Combine(Path.GetDirectoryName(mapString), Path.GetFileNameWithoutExtension(mapString)));
// shut down the existing game if it is running
idConsole.Warning("TODO: UnloadMap();");
// don't do the deferred caching if we are reloading the same map
if(mapFullName == _currentMapName)
{
reloadingSameMap = true;
}
else
{
reloadingSameMap = false;
_currentMapName = mapFullName;
}
// note which media we are going to need to load
if(reloadingSameMap == false)
{
idE.DeclManager.BeginLevelLoad();
idE.RenderSystem.BeginLevelLoad();
idConsole.Warning("TODO: soundSystem->BeginLevelLoad();");
}
idE.UIManager.BeginLevelLoad();
idConsole.Warning("TODO: idE.UIManager.Reload(true);");
// set the loading gui that we will wipe to
LoadLoadingInterface(mapString);
// cause prints to force screen updates as a pacifier,
// and draw the loading gui instead of game draws
_insideExecuteMapChange = true;
// if this works out we will probably want all the sizes in a def file although this solution will
// work for new maps etc. after the first load. we can also drop the sizes into the default.cfg
// TODO: bytesneeded
/*fileSystem->ResetReadCount();
if ( !reloadingSameMap ) {
bytesNeededForMapLoad = GetBytesNeededForMapLoad( mapString.c_str() );
} else {
bytesNeededForMapLoad = 30 * 1024 * 1024;
}*/
ClearWipe();
// let the loading gui spin for 1 second to animate out
ShowLoadingInterface();
// note any warning prints that happen during the load process
idConsole.ClearWarnings(mapString);
// if net play, we get the number of clients during mapSpawnInfo processing
if(idE.AsyncNetwork.IsActive == false)
{
_clientCount = 1;
}
int start = idE.System.Milliseconds;
idConsole.WriteLine("--------- Map Initialization ---------");
idConsole.WriteLine("Map: {0}", mapString);
// let the renderSystem load all the geometry
if(_renderWorld.InitFromMap(mapFullName) == false)
{
idConsole.Error("couldn't load {0}", mapFullName);
}
// for the synchronous networking we needed to roll the angles over from
// level to level, but now we can just clear everything
idE.UserCommandGenerator.InitForNewMap();
_mapSpawnData.MapSpawnUserCommand = new idUserCommand[idE.MaxAsynchronousClients];
int count = _mapSpawnData.MapSpawnUserCommand.Length;
for(int i = 0; i < count; i++)
{
_mapSpawnData.MapSpawnUserCommand[i] = new idUserCommand();
}
// set the user info
for(int i = 0; i < _clientCount; i++)
{
idE.Game.SetUserInformation(i, _mapSpawnData.UserInformation[i], idE.AsyncNetwork.Client.IsActive, false);
idE.Game.SetPersistentPlayerInformation(i, _mapSpawnData.PersistentPlayerInformation[i]);
}
// load and spawn all other entities ( from a savegame possibly )
idConsole.Warning("TODO: save game");
/*if ( loadingSaveGame && savegameFile ) {
if ( game->InitFromSaveGame( fullMapName + ".map", rw, sw, savegameFile ) == false ) {
// If the loadgame failed, restart the map with the player persistent data
loadingSaveGame = false;
fileSystem->CloseFile( savegameFile );
savegameFile = NULL;
game->SetServerInfo( mapSpawnData.serverInfo );
game->InitFromNewMap( fullMapName + ".map", rw, sw, idAsyncNetwork::server.IsActive(), idAsyncNetwork::client.IsActive(), Sys_Milliseconds() );
}
} else */
{
// TODO: should be passing real sound world
idE.Game.SetServerInfo(_mapSpawnData.ServerInformation);
idE.Game.InitFromNewMap(mapFullName + ".map", _renderWorld, new idSoundWorld(), idE.AsyncNetwork.Server.IsActive, idE.AsyncNetwork.Client.IsActive, idE.System.Milliseconds);
}
if((idE.AsyncNetwork.IsActive == false) && (_loadingSaveGame == false))
{
// spawn players
for(int i = 0; i < _clientCount; i++)
{
idE.Game.SpawnPlayer(i);
}
}
// actually purge/load the media
if(reloadingSameMap == false)
{
idE.RenderSystem.EndLevelLoad();
// TODO: :soundSystem->EndLevelLoad( mapString.c_str() );
idE.DeclManager.EndLevelLoad();
// TODO: SetBytesNeededForMapLoad( mapString.c_str(), fileSystem->GetReadCount() );
}
idE.UIManager.EndLevelLoad();
if((idE.AsyncNetwork.IsActive == false) && (_loadingSaveGame == false))
{
// run a few frames to allow everything to settle
for(int i = 0; i < 10; i++)
{
idE.Game.RunFrame(_mapSpawnData.MapSpawnUserCommand);
}
}
int msec = idE.System.Milliseconds - start;
idConsole.WriteLine("-----------------------------------");
idConsole.WriteLine("{0} msec to load {1}", msec, mapString);
// let the renderSystem generate interactions now that everything is spawned
_renderWorld.GenerateInteractions();
idConsole.PrintWarnings();
if((_guiLoading != null) /* TODO: bytesNeededForMapLoad*/)
{
float pct = _guiLoading.State.GetFloat("map_loading");
if(pct < 0.0f)
{
pct = 0.0f;
}
while(pct < 1.0f)
{
_guiLoading.State.Set("map_loading", pct);
_guiLoading.StateChanged(idE.System.FrameTime);
// TODO: Sys_GenerateEvents();
UpdateScreen();
pct += 0.05f;
}
}
// capture the current screen and start a wipe
// TODO: StartWipe( "wipe2Material" );
idE.UserCommandGenerator.Clear();
// start saving commands for possible writeCmdDemo usage
// TODO: log index
/*logIndex = 0;
statIndex = 0;
lastSaveIndex = 0;*/
// don't bother spinning over all the tics we spent loading
// TODO: lastGameTic = latchedTicNumber = com_ticNumber;
// remove any prints from the notify lines
// TODO: console->ClearNotifyLines();
// stop drawing the laoding screen
_insideExecuteMapChange = false;
// TODO: sound system
// set the game sound world for playback
/*soundSystem->SetPlayingSoundWorld( sw );
// when loading a save game the sound is paused
if ( sw->IsPaused() ) {
// unpause the game sound world
sw->UnPause();
}*/
// restart entity sound playback
// TODO: soundSystem->SetMute( false );
// we are valid for game draws now
_mapSpawned = true;
idE.EventLoop.ClearEvents();
}