[gnome-games/wip/exalm/runner-refactor: 32/56] retro-runner: Stop storing the list of snapshots



commit 801b1756ae88d75ae3a07e156700bd11b519b350
Author: Alexander Mikhaylenko <alexm gnome org>
Date:   Fri Mar 6 18:30:41 2020 +0500

    retro-runner: Stop storing the list of snapshots
    
    Defer that to SnapshotsManager.

 src/core/snapshot-manager.vala | 11 +++++++++++
 src/retro/retro-runner.vala    | 19 ++++++++++---------
 2 files changed, 21 insertions(+), 9 deletions(-)
---
diff --git a/src/core/snapshot-manager.vala b/src/core/snapshot-manager.vala
index 8f073436..87694d16 100644
--- a/src/core/snapshot-manager.vala
+++ b/src/core/snapshot-manager.vala
@@ -50,6 +50,17 @@ public class Games.SnapshotManager : Object {
                return snapshots;
        }
 
+       public bool has_snapshots () {
+               return snapshots.length > 0;
+       }
+
+       public Savestate? get_latest_snapshot () {
+               if (has_snapshots ())
+                       return snapshots[0];
+
+               return null;
+       }
+
        private void trim_autosaves () {
                int n_autosaves = 1;
 
diff --git a/src/retro/retro-runner.vala b/src/retro/retro-runner.vala
index f22a96eb..484753d8 100644
--- a/src/retro/retro-runner.vala
+++ b/src/retro/retro-runner.vala
@@ -6,7 +6,12 @@ public class Games.RetroRunner : Object, Runner {
        }
 
        public bool can_resume {
-               get { return game_savestates.length != 0; }
+               get {
+                       if (snapshot_manager == null)
+                               return false;
+
+                       return snapshot_manager.has_snapshots ();
+               }
        }
 
        public bool supports_savestates {
@@ -42,7 +47,6 @@ public class Games.RetroRunner : Object, Runner {
        private Game game;
        private SnapshotManager snapshot_manager;
 
-       private Savestate[] game_savestates;
        private Savestate latest_savestate;
        private Savestate previewed_savestate;
 
@@ -129,10 +133,7 @@ public class Games.RetroRunner : Object, Runner {
                try {
                        snapshot_manager = new SnapshotManager (game, get_core_id ());
 
-                       // Step 1) Load the game's savestates ----------------------------------
-                       game_savestates = snapshot_manager.get_snapshots ();
-                       if (game_savestates.length != 0)
-                               latest_savestate = game_savestates[0];
+                       latest_savestate = snapshot_manager.get_latest_snapshot ();
 
                        tmp_save_dir = create_tmp_save_dir ();
                        if (latest_savestate != null)
@@ -212,10 +213,10 @@ public class Games.RetroRunner : Object, Runner {
        }
 
        public Savestate[] get_savestates () {
-               if (game_savestates == null)
-                       critical ("RetroRunner hasn't loaded snapshots. Call try_init_phase_one()");
+               if (snapshot_manager == null)
+                       return {};
 
-               return game_savestates;
+               return snapshot_manager.get_snapshots ();
        }
 
        public void start () throws Error {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]