[gnome-games/wip/exalm/runner-refactor: 50/56] retro-runner: Reorder functions to match Runner better



commit 72656d7f14f5fcb3994c434d3900615e56bd9880
Author: Alexander Mikhaylenko <alexm gnome org>
Date:   Sat Mar 7 16:45:49 2020 +0500

    retro-runner: Reorder functions to match Runner better

 src/retro/retro-runner.vala | 206 +++++++++++++++++++++-----------------------
 1 file changed, 100 insertions(+), 106 deletions(-)
---
diff --git a/src/retro/retro-runner.vala b/src/retro/retro-runner.vala
index 5efbb62c..e35d8767 100644
--- a/src/retro/retro-runner.vala
+++ b/src/retro/retro-runner.vala
@@ -112,6 +112,14 @@ public class Games.RetroRunner : Object, Runner {
                deinit ();
        }
 
+       public Gtk.Widget get_display () {
+               return view;
+       }
+
+       public virtual HeaderBarWidget? get_extra_widget () {
+               return null;
+       }
+
        private string get_unsupported_system_message () {
                var platform_name = game.platform.get_name ();
                if (platform_name != null)
@@ -131,6 +139,18 @@ public class Games.RetroRunner : Object, Runner {
                return DirUtils.make_tmp ("games_save_dir_XXXXXX");
        }
 
+       private string get_options_path () throws Error {
+               assert (core != null);
+
+               var core_filename = core.get_filename ();
+               var file = File.new_for_path (core_filename);
+               var basename = file.get_basename ();
+               var options_name = basename.split (".")[0];
+               options_name = options_name.replace ("_libretro", "");
+
+               return @"$(Config.OPTIONS_DIR)/$options_name.options";
+       }
+
        private void prepare_core () throws Error {
                string module_path;
                if (core_descriptor != null) {
@@ -221,16 +241,75 @@ public class Games.RetroRunner : Object, Runner {
                        preview_savestate (latest_savestate);
        }
 
-       public Gtk.Widget get_display () {
-               return view;
+       public void start () throws Error {
+               assert (core_loaded);
+
+               resume ();
        }
 
-       public virtual HeaderBarWidget? get_extra_widget () {
-               return null;
+       public void restart () throws Error {
+               current_state_pixbuf = view.get_pixbuf ();
+               try_create_savestate (true);
+               reset_metadata (latest_savestate);
+               core.reset ();
        }
 
-       public void preview_current_state () {
-               view.set_pixbuf (current_state_pixbuf);
+       public void resume () {
+               if (!core_loaded)
+                       return;
+
+               // Unpause an already running game
+               core.run ();
+               running = true;
+       }
+
+       public void pause () {
+               if (!core_loaded)
+                       return;
+
+               if (!running)
+                       return;
+
+               if (!is_error) {
+                       current_state_pixbuf = view.get_pixbuf ();
+                       core.stop ();
+               }
+
+               //FIXME:
+               // In the future here there will be code which updates the currently
+               // used temporary savestate
+
+               running = false;
+       }
+
+       public void stop () {
+               if (!core_loaded)
+                       return;
+
+               pause ();
+               deinit ();
+               stopped ();
+       }
+
+       public Savestate? try_create_savestate (bool is_automatic) {
+               if (!supports_savestates)
+                       return null;
+
+               if (!is_automatic)
+                       new_savestate_created ();
+
+               try {
+                       return snapshot_manager.create_snapshot (is_automatic, save_to_snapshot);
+               }
+               catch (Error e) {
+                       critical ("Failed to create snapshot: %s", e.message);
+
+                       return null;
+               }
+       }
+
+       public void delete_savestate (Savestate savestate) {
+               snapshot_manager.delete_snapshot (savestate);
        }
 
        public void preview_savestate (Savestate savestate) {
@@ -256,6 +335,10 @@ public class Games.RetroRunner : Object, Runner {
                view.set_pixbuf (pixbuf);
        }
 
+       public void preview_current_state () {
+               view.set_pixbuf (current_state_pixbuf);
+       }
+
        public void load_previewed_savestate () throws Error {
                load_savestate_metadata (previewed_savestate);
        }
@@ -267,28 +350,6 @@ public class Games.RetroRunner : Object, Runner {
                return snapshot_manager.get_snapshots ();
        }
 
-       public void start () throws Error {
-               assert (core_loaded);
-
-               resume ();
-       }
-
-       public void restart () throws Error {
-               current_state_pixbuf = view.get_pixbuf ();
-               try_create_savestate (true);
-               reset_metadata (latest_savestate);
-               core.reset ();
-       }
-
-       public void resume () {
-               if (!core_loaded)
-                       return;
-
-               // Unpause an already running game
-               core.run ();
-               running = true;
-       }
-
        private void deinit () {
                if (!core_loaded)
                        return;
@@ -308,34 +369,6 @@ public class Games.RetroRunner : Object, Runner {
                core_loaded = false;
        }
 
-       public void pause () {
-               if (!core_loaded)
-                       return;
-
-               if (!running)
-                       return;
-
-               if (!is_error) {
-                       current_state_pixbuf = view.get_pixbuf ();
-                       core.stop ();
-               }
-
-               //FIXME:
-               // In the future here there will be code which updates the currently
-               // used temporary savestate
-
-               running = false;
-       }
-
-       public void stop () {
-               if (!core_loaded)
-                       return;
-
-               pause ();
-               deinit ();
-               stopped ();
-       }
-
        public InputMode[] get_available_input_modes () {
                if (input_capabilities == null)
                        return { InputMode.GAMEPAD };
@@ -398,55 +431,6 @@ public class Games.RetroRunner : Object, Runner {
                }
        }
 
-       // Returns the created Savestate or null if the Savestate couldn't be created
-       // Currently the callers are the DisplayView and the SavestatesList
-       // In the future we might want to throw Errors from here in case there is
-       // something that can be done, but right now there's nothing we can do if
-       // savestate creation fails except warn the user of unsaved progress via the
-       // QuitDialog in the DisplayView
-       public Savestate? try_create_savestate (bool is_automatic) {
-               if (!supports_savestates)
-                       return null;
-
-               if (!is_automatic)
-                       new_savestate_created ();
-
-               try {
-                       return snapshot_manager.create_snapshot (is_automatic, save_to_snapshot);
-               }
-               catch (Error e) {
-                       critical ("Failed to create snapshot: %s", e.message);
-
-                       return null;
-               }
-       }
-
-       public void delete_savestate (Savestate savestate) {
-               snapshot_manager.delete_snapshot (savestate);
-       }
-
-       private string get_options_path () throws Error {
-               assert (core != null);
-
-               var core_filename = core.get_filename ();
-               var file = File.new_for_path (core_filename);
-               var basename = file.get_basename ();
-               var options_name = basename.split (".")[0];
-               options_name = options_name.replace ("_libretro", "");
-
-               return @"$(Config.OPTIONS_DIR)/$options_name.options";
-       }
-
-       private void load_save_ram (string save_ram_path) throws Error {
-               if (!FileUtils.test (save_ram_path, FileTest.EXISTS))
-                       return;
-
-               if (core.get_memory_size (Retro.MemoryType.SAVE_RAM) == 0)
-                       return;
-
-               core.load_memory (Retro.MemoryType.SAVE_RAM, save_ram_path);
-       }
-
        public Retro.Core get_core () {
                return core;
        }
@@ -479,6 +463,16 @@ public class Games.RetroRunner : Object, Runner {
                             null);
        }
 
+       private void load_save_ram (string save_ram_path) throws Error {
+               if (!FileUtils.test (save_ram_path, FileTest.EXISTS))
+                       return;
+
+               if (core.get_memory_size (Retro.MemoryType.SAVE_RAM) == 0)
+                       return;
+
+               core.load_memory (Retro.MemoryType.SAVE_RAM, save_ram_path);
+       }
+
        protected virtual void save_to_snapshot (Savestate savestate) throws Error {
                if (core.get_memory_size (Retro.MemoryType.SAVE_RAM) > 0)
                        core.save_memory (Retro.MemoryType.SAVE_RAM,
@@ -512,7 +506,7 @@ public class Games.RetroRunner : Object, Runner {
                if (last_savestate == null)
                        return;
 
-               load_save_ram (latest_savestate.get_save_ram_path ());
+               load_save_ram (last_savestate.get_save_ram_path ());
 
                if (last_savestate.has_media_data ())
                        media_set.selected_media_number = last_savestate.get_media_data ();


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