Skip to content

Commit 2a89788

Browse files
committed
AutoSave - step 1
1 parent ebafd5d commit 2a89788

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

Source/RunActivity/Viewer3D/Popups/QuitWindow.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ void buttonQuit_Click(Control arg1, Point arg2)
7070
void buttonSave_Click(Control arg1, Point arg2)
7171
{
7272
GameStateRunActivity.Save();
73+
Owner.Viewer.LastSave = Owner.Viewer.RealTime + 60 * 15;
7374
}
7475

7576
void buttonContinue_Click(Control arg1, Point arg2)

Source/RunActivity/Viewer3D/Viewer.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ public class Viewer
7676
/// Monotonically increasing time value (in seconds) for the game/viewer. Starts at 0 and only ever increases, at real-time.
7777
/// </summary>
7878
public double RealTime { get; private set; }
79+
public double LastSave = -1;
7980
InfoDisplay InfoDisplay;
8081
public WindowManager WindowManager { get; private set; }
8182
public MessagesWindow MessagesWindow { get; private set; } // Game message window (special, always visible)
@@ -296,6 +297,8 @@ public Viewer(Simulator simulator, Orts.Viewer3D.Processes.Game game)
296297
Settings = simulator.Settings;
297298
Use3DCabProperty = Settings.GetSavingProperty<bool>("Use3DCab");
298299

300+
LastSave = 15 * 60;
301+
299302
RenderProcess = game.RenderProcess;
300303
UpdaterProcess = game.UpdaterProcess;
301304
LoaderProcess = game.LoaderProcess;
@@ -736,6 +739,14 @@ public void Update(RenderFrame frame, float elapsedRealTime)
736739
RealTime += elapsedRealTime;
737740
var elapsedTime = new ElapsedTime(Simulator.GetElapsedClockSeconds(elapsedRealTime), elapsedRealTime);
738741

742+
// auto save
743+
if (RealTime > LastSave && !Simulator.Paused)
744+
{
745+
GameStateRunActivity.Save();
746+
LastSave = RealTime + 15 * 60;
747+
}
748+
749+
// show message
739750
if (ComposeMessageWindow.Visible == true)
740751
{
741752
UserInput.Handled();
@@ -930,7 +941,11 @@ void HandleUserInput(ElapsedTime elapsedTime)
930941
Simulator.GameSpeed = 1;
931942
Simulator.Confirmer.ConfirmWithPerCent(CabControl.SimulationSpeed, CabSetting.Off, Simulator.GameSpeed * 100);
932943
}
933-
if (UserInput.IsPressed(UserCommand.GameSave)) { GameStateRunActivity.Save(); }
944+
if (UserInput.IsPressed(UserCommand.GameSave))
945+
{
946+
GameStateRunActivity.Save();
947+
LastSave = RealTime + 60 * 15;
948+
}
934949
if (UserInput.IsPressed(UserCommand.DisplayHelpWindow)) if (UserInput.IsDown(UserCommand.DisplayNextWindowTab)) HelpWindow.TabAction(); else HelpWindow.Visible = !HelpWindow.Visible;
935950
if (UserInput.IsPressed(UserCommand.DisplayTrackMonitorWindow)) if (UserInput.IsDown(UserCommand.DisplayNextWindowTab)) TrackMonitorWindow.TabAction(); else TrackMonitorWindow.Visible = !TrackMonitorWindow.Visible;
936951
if (UserInput.IsPressed(UserCommand.DisplayTrainDrivingWindow)) if (UserInput.IsDown(UserCommand.DisplayNextWindowTab)) TrainDrivingWindow.TabAction(); else TrainDrivingWindow.Visible = !TrainDrivingWindow.Visible;

0 commit comments

Comments
 (0)