Beispiel #1
0
        /// <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);

            double radius = settings.WorldSizeKm * 500; //half size
            if (radius > 0)
            {
                Static.WorldBoundaries = new BoundingBoxD(new Vector3D(-radius, -radius, -radius), new Vector3D(radius, radius, radius));
            }

            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.PrepareBaseSession(mods, generationArgs.Scenario);

            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);

            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.BeforeStartComponents();

            Static.Save();
            MyLocalCache.SaveLastLoadedTime(Static.CurrentPath, DateTime.Now);

            // Initialize Spectator light
            MySpectatorCameraController.Static.InitLight(false);
        }
Beispiel #2
0
        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");

            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.PrepareBaseSession(checkpoint, sector);

            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();
        }