示例#1
0
        public override void SaveData()
        {
            try
            {
                if (MyAPIGateway.Utilities == null)                 // Because this isn't initialised on the first save for some reason
                {
                    return;
                }

                T saveData = GetSaveData();
                MyAPIGateway.Utilities.SetVariable(GetSaveDataFileName(), MyAPIGateway.Utilities.SerializeToXML(saveData));
                if (DebugSaveData)
                {
                    MyAPIGateway.Parallel.Start(() =>
                    {
                        using (var sw = MyAPIGateway.Utilities.WriteFileInWorldStorage("SaveDataSnapshot.xml",
                                                                                       typeof(CalCore))) sw.Write(MyAPIGateway.Utilities.SerializeToXML(saveData));
                    });
                }
            }
            catch (Exception e)
            {
                ModLog.Error(e);
            }
        }
示例#2
0
        public override void UpdateBeforeSimulation()
        {
            try
            {
                updateCount = ++updateCount % MaxUpdatesCount;

                if (!init && updateCount > UpdatesUntilInitAttempted)
                {
                    ModLog.Init();
                    machineType = MyAPIGateway.Multiplayer.IsServer ? MachineType.Host : MachineType.Client;
                    InitCommon(modProxy);
                    if (machineType == MachineType.Host)
                    {
                        InitHostPreLoading();
                        LoadSaveData();
                        InitHostPostLoading(modProxy);
                    }
                    else
                    {
                        InitClient(modProxy);
                    }
                    modProxy.InitModSystems();
                    init = true;
                }

                modProxy.Update1();

                if (updateCount % 30 == 0)
                {
                    modProxy.Update30();
                }

                if (updateCount % 60 == 0)
                {
                    modProxy.Update60();                     // There are 60 updates per second with simspeed at normal
                }

                if (updateCount % 300 == 0)
                {
                    modProxy.Update300();
                }

                if (updateCount % 1200 == 0)
                {
                    modProxy.Update1200();
                }
            }
            catch (Exception e)
            {
                ModLog.Error(e);
            }
        }
示例#3
0
 protected override void UnloadData()
 {
     try
     {
         init = false;
         modProxy.Shutdown();
     }
     catch (Exception ex)
     {
         ModLog.Error(ex);
     }
     ModLog.Close();
 }
示例#4
0
 private void LoadSaveData()
 {
     try
     {
         string xmlData;
         if (MyAPIGateway.Utilities.GetVariable(GetSaveDataFileName(), out xmlData))                 // New saving system
         {
             LoadPreviousGame(MyAPIGateway.Utilities.SerializeFromXML <T>(xmlData));
         }
         else
         {
             StartedNewGame();
         }
     }
     catch (Exception e)
     {
         ModLog.Error(e);
     }
 }