internal static void LoadMultiplayer(MyObjectBuilder_World world, MyMultiplayerBase multiplayerSession) { //MyAudio.Static.Mute = true; Static = new MySession(multiplayerSession.SyncLayer); Static.Mods = world.Checkpoint.Mods; Static.Settings = world.Checkpoint.Settings; Static.CurrentPath = MyLocalCache.GetSessionSavesPath(MyUtils.StripInvalidChars(world.Checkpoint.SessionName), false, false); if (!MyDefinitionManager.Static.TryGetDefinition<MyScenarioDefinition>(world.Checkpoint.Scenario, out Static.Scenario)) Static.Scenario = MyDefinitionManager.Static.GetScenarioDefinitions().FirstOrDefault(); FixIncorrectSettings(Static.Settings); Static.WorldBoundaries = world.Checkpoint.WorldBoundaries; if (Static.WorldBoundaries.Min != Vector3D.Zero || Static.WorldBoundaries.Max != Vector3D.Zero) MyPerGameSettings.SingleCluster = true; Static.InGameTime = MyObjectBuilder_Checkpoint.DEFAULT_DATE; Static.LoadMembersFromWorld(world, multiplayerSession); MySandboxGame.Static.SessionCompatHelper.FixSessionComponentObjectBuilders(world.Checkpoint, world.Sector); Static.PrepareComponents(world.Checkpoint); // No controlled object long hostObj = world.Checkpoint.ControlledObject; world.Checkpoint.ControlledObject = -1; if (multiplayerSession != null) { MyHud.Chat.RegisterChat(multiplayerSession); Static.Gpss.RegisterChat(multiplayerSession); } Static.CameraController = MySpectatorCameraController.Static; Static.LoadWorld(world.Checkpoint, world.Sector); if (Sync.IsServer) { Static.InitializeFactions(); } Static.Settings.AutoSaveInMinutes = 0; Static.IsCameraAwaitingEntity = true; multiplayerSession.StartProcessingClientMessages(); MyLocalCache.ClearLastSessionInfo(); MyNetworkStats.Static.ClearStats(); Sync.Layer.TransportLayer.ClearStats(); Static.BeforeStartComponents(); }
internal static void CreateWithEmptyWorld(MyMultiplayerBase multiplayerSession) { Debug.Assert(!Sync.IsServer); Static = new MySession(multiplayerSession.SyncLayer, false); Static.InGameTime = MyObjectBuilder_Checkpoint.DEFAULT_DATE; MyHud.Chat.RegisterChat(multiplayerSession); Static.Gpss.RegisterChat(multiplayerSession); Static.CameraController = MySpectatorCameraController.Static; Static.Settings = new MyObjectBuilder_SessionSettings(); Static.Settings.Battle = true; Static.Settings.AutoSaveInMinutes = 0; Static.IsCameraAwaitingEntity = true; Static.PrepareComponents(new List<MyObjectBuilder_Checkpoint.ModItem>()); multiplayerSession.StartProcessingClientMessagesWithEmptyWorld(); if (Sync.IsServer) { Static.InitializeFactions(); } MyLocalCache.ClearLastSessionInfo(); // Player must be created for selection in factions. if (!Engine.Platform.Game.IsDedicated && Static.LocalHumanPlayer == null) { Sync.Players.RequestNewPlayer(0, MySteam.UserName, null); } MyNetworkStats.Static.ClearStats(); Sync.Layer.TransportLayer.ClearStats(); }
/// <summary> /// Initializes a new single player session and start new game with parameters /// </summary> public static void Start( string name, string description, string password, MyObjectBuilder_SessionSettings settings, List<MyObjectBuilder_Checkpoint.ModItem> mods, MyWorldGenerator.Args generationArgs) { MyLog.Default.WriteLineAndConsole("Starting world " + name); MyEntityContainerEventExtensions.InitEntityEvents(); Static = new MySession(); Static.Name = name; Static.Mods = mods; Static.Description = description; Static.Password = password; Static.Settings = settings; Static.Scenario = generationArgs.Scenario; FixIncorrectSettings(Static.Settings); Static.WorldBoundaries = generationArgs.Scenario.WorldBoundaries; double tmp = settings.WorldSizeKm * 500; //half size if (tmp > 0) { MyPerGameSettings.SingleCluster = true; Static.WorldBoundaries.Min = new Vector3D(-tmp, -tmp, -tmp); Static.WorldBoundaries.Max = new Vector3D(tmp, tmp, tmp); } Static.InGameTime = generationArgs.Scenario.GameDate;//MyObjectBuilder_Checkpoint.DEFAULT_DATE; Static.RequiresDX = generationArgs.Scenario.HasPlanets ? 11 : 9; if (Static.OnlineMode != MyOnlineModeEnum.OFFLINE) StartServerRequest(); Static.IsCameraAwaitingEntity = true; // Find new non existing folder. The game folder name may be different from game name, so we have to // make sure we don't overwrite another save string safeName = MyUtils.StripInvalidChars(name); Static.CurrentPath = MyLocalCache.GetSessionSavesPath(safeName, false, false); while (Directory.Exists(Static.CurrentPath)) { Static.CurrentPath = MyLocalCache.GetSessionSavesPath(safeName + MyUtils.GetRandomInt(int.MaxValue).ToString("########"), false, false); } Static.PrepareComponents(mods, generationArgs.Scenario != null ? generationArgs.Scenario.GameDefinition : default(MyDefinitionId?)); //TODO: This is from broken merge from MEPlanets, when we do merge I will fixorz //MySector.EnvironmentDefinition = MyDefinitionManager.Static.GetDefinition<MyEnvironmentDefinition>(generationArgs.Scenario.Environment); MyWorldGenerator.GenerateWorld(generationArgs); if (Sync.IsServer) { // Factions have to be initialized before world is generated/loaded. Static.InitializeFactions(); } if (!Engine.Platform.Game.IsDedicated) { var playerId = new MyPlayer.PlayerId(Sync.MyId, 0); MyToolBarCollection.RequestCreateToolbar(playerId); } Static.SendSessionStartStats(); var scenarioName = generationArgs.Scenario.DisplayNameText.ToString(); Static.LogSettings(scenarioName, generationArgs.AsteroidAmount); MySector.InitEnvironmentSettings(); if (generationArgs.Scenario.SunDirection.IsValid()) { MySector.SunProperties.SunDirectionNormalized = Vector3.Normalize(generationArgs.Scenario.SunDirection); MySector.SunProperties.BaseSunDirectionNormalized = Vector3.Normalize(generationArgs.Scenario.SunDirection); } //Because blocks fills SubBlocks in this method.. //TODO: Create LoadPhase2 MyEntities.UpdateOnceBeforeFrame(); Static.Save(); MyLocalCache.SaveLastLoadedTime(Static.CurrentPath, DateTime.Now); Static.BeforeStartComponents(); // Initialize Spectator light MySpectatorCameraController.Static.InitLight(false); }
public static void Load(string sessionPath, MyObjectBuilder_Checkpoint checkpoint, ulong checkpointSizeInBytes) { ProfilerShort.Begin("MySession.Static.Load"); MyLog.Default.WriteLineAndConsole("Loading session: " + sessionPath); //MyAudio.Static.Mute = true; MyLocalCache.SaveLastLoadedTime(sessionPath, DateTime.Now); MyEntityIdentifier.Reset(); ulong sectorSizeInBytes; ProfilerShort.Begin("MyLocalCache.LoadSector"); if (checkpoint.WorldBoundaries.Min != Vector3D.Zero || checkpoint.WorldBoundaries.Max != Vector3D.Zero) MyPerGameSettings.SingleCluster = true; var sector = MyLocalCache.LoadSector(sessionPath, checkpoint.CurrentSector, out sectorSizeInBytes); ProfilerShort.End(); if (sector == null) { //TODO: If game - show error messagebox and return to menu // If DS console - write error to console and exit DS // If DS service - pop up silent exception (dont send report) throw new ApplicationException("Sector could not be loaded"); } ulong voxelsSizeInBytes = GetVoxelsSizeInBytes(sessionPath); #if false if ( MyFakes.DEBUG_AVOID_RANDOM_AI ) MyBBSetSampler.ResetRandomSeed(); #endif MyCubeGrid.Preload(); Static = new MySession(); Static.Mods = checkpoint.Mods; Static.Settings = checkpoint.Settings; Static.CurrentPath = sessionPath; if (Static.OnlineMode != MyOnlineModeEnum.OFFLINE) StartServerRequest(); MySandboxGame.Static.SessionCompatHelper.FixSessionComponentObjectBuilders(checkpoint, sector); Static.PrepareComponents(checkpoint); ProfilerShort.Begin("MySession.Static.LoadWorld"); Static.LoadWorld(checkpoint, sector); ProfilerShort.End(); if (Sync.IsServer) { Static.InitializeFactions(); } Static.WorldSizeInBytes = checkpointSizeInBytes + sectorSizeInBytes + voxelsSizeInBytes; // CH: I don't think it's needed. If there are problems with missing characters, look at it //FixMissingCharacter(); MyLocalCache.SaveLastSessionInfo(sessionPath); Static.SendSessionStartStats(); Static.LogSettings(); MyHud.Notifications.Get(MyNotificationSingletons.WorldLoaded).SetTextFormatArguments(Static.Name); MyHud.Notifications.Add(MyNotificationSingletons.WorldLoaded); if (MyFakes.LOAD_UNCONTROLLED_CHARACTERS == false) Static.RemoveUncontrolledCharacters(); MyNetworkStats.Static.ClearStats(); Sync.Layer.TransportLayer.ClearStats(); Static.BeforeStartComponents(); MyLog.Default.WriteLineAndConsole("Session loaded"); ProfilerShort.End(); }