[gnome-games/wip/exalm/subprocess] Adapt for subprocess retro-gtk



commit 9e0d48d80662c3ab5feb72653a6776e8eab28a75
Author: Alexander Mikhaylenko <alexm gnome org>
Date:   Sun Jan 5 20:54:01 2020 +0500

    Adapt for subprocess retro-gtk

 flatpak/org.gnome.Games.json                    |  3 +-
 plugins/nintendo-ds/src/nintendo-ds-runner.vala | 10 ----
 src/core/runner.vala                            |  1 +
 src/core/savestate.vala                         | 23 +--------
 src/retro/retro-gamepad.vala                    | 11 ++---
 src/retro/retro-options.vala                    |  3 +-
 src/retro/retro-runner.vala                     | 64 +++++++++----------------
 src/ui/display-view.vala                        |  3 ++
 8 files changed, 37 insertions(+), 81 deletions(-)
---
diff --git a/flatpak/org.gnome.Games.json b/flatpak/org.gnome.Games.json
index 83ebd0cf..0be9bff3 100644
--- a/flatpak/org.gnome.Games.json
+++ b/flatpak/org.gnome.Games.json
@@ -218,7 +218,8 @@
             "sources" : [
                 {
                     "type" : "git",
-                    "url" : "https://gitlab.gnome.org/GNOME/retro-gtk.git";
+                    "url" : "https://gitlab.gnome.org/exalm/retro-gtk.git";,
+                    "branch" : "wip/exalm/subprocess3"
                 }
             ]
         },
diff --git a/plugins/nintendo-ds/src/nintendo-ds-runner.vala b/plugins/nintendo-ds/src/nintendo-ds-runner.vala
index bfebab0f..a554fe3b 100644
--- a/plugins/nintendo-ds/src/nintendo-ds-runner.vala
+++ b/plugins/nintendo-ds/src/nintendo-ds-runner.vala
@@ -34,7 +34,6 @@ private class Games.NintendoDsRunner : RetroRunner {
        }
 
        construct {
-               game_init.connect (on_init);
        }
 
        private bool core_supports_layouts () {
@@ -43,12 +42,6 @@ private class Games.NintendoDsRunner : RetroRunner {
                return core != null && core.has_option (SCREENS_LAYOUT_OPTION);
        }
 
-       private void on_init () {
-               var core = get_core ();
-
-               core.options_set.connect (update_screen_layout);
-       }
-
        private void update_screen_layout () {
                if (!core_supports_layouts ())
                        return;
@@ -70,9 +63,6 @@ private class Games.NintendoDsRunner : RetroRunner {
        }
 
        public override Gtk.Widget? get_extra_widget () {
-               if (!core_supports_layouts ())
-                       return null;
-
                return new NintendoDsLayoutSwitcher (this);
        }
 
diff --git a/src/core/runner.vala b/src/core/runner.vala
index 7a10160b..98d23542 100644
--- a/src/core/runner.vala
+++ b/src/core/runner.vala
@@ -3,6 +3,7 @@
 public interface Games.Runner : Object {
        public signal void new_savestate_created ();
        public signal void stopped ();
+       public signal void crash (string message);
 
        public abstract bool can_fullscreen { get; }
        public abstract bool can_resume { get; }
diff --git a/src/core/savestate.vala b/src/core/savestate.vala
index 192a85a1..36e690e7 100644
--- a/src/core/savestate.vala
+++ b/src/core/savestate.vala
@@ -80,33 +80,14 @@ public class Games.Savestate : Object {
                }
        }
 
-       public void set_snapshot_data (Bytes snapshot_data) throws Error {
-               var buffer = snapshot_data.get_data ();
-               var snapshot_path = Path.build_filename (path, "snapshot");
-
-               FileUtils.set_data (snapshot_path, buffer);
-       }
-
-       public Bytes get_snapshot_data () throws Error {
-               var snapshot_path = Path.build_filename (path, "snapshot");
-
-               uint8[] data = null;
-               FileUtils.get_data (snapshot_path, out data);
-               var bytes = new Bytes.take (data);
-
-               return bytes;
+       public string get_snapshot_path () {
+               return Path.build_filename (path, "snapshot");
        }
 
        public string get_save_ram_path () {
                return Path.build_filename (path, "save");
        }
 
-       public void set_save_ram_data (uint8[] save_ram_data) throws Error {
-               var save_ram_path = Path.build_filename (path, "save");
-
-               FileUtils.set_data (save_ram_path, save_ram_data);
-       }
-
        public string get_screenshot_path () {
                return Path.build_filename (path, "screenshot");
        }
diff --git a/src/retro/retro-gamepad.vala b/src/retro/retro-gamepad.vala
index 637f8438..127b6897 100644
--- a/src/retro/retro-gamepad.vala
+++ b/src/retro/retro-gamepad.vala
@@ -54,17 +54,16 @@ private class Games.RetroGamepad : Object, Retro.Controller {
                return (1 << Retro.ControllerType.JOYPAD) | (1 << Retro.ControllerType.ANALOG);
        }
 
-       public bool set_rumble_state (Retro.RumbleEffect effect, uint16 strength) {
-               rumble_effect[effect] = strength;
+       public bool get_supports_rumble () {
+               return device.has_rumble ();
+       }
 
-               if (!device.has_rumble ())
-                       return false;
+       public void set_rumble_state (Retro.RumbleEffect effect, uint16 strength) {
+               rumble_effect[effect] = strength;
 
                device.rumble (rumble_effect[Retro.RumbleEffect.STRONG],
                               rumble_effect[Retro.RumbleEffect.WEAK],
                               uint16.MAX);
-
-               return true;
        }
 
        private bool get_button_pressed (Retro.JoypadId button) {
diff --git a/src/retro/retro-options.vala b/src/retro/retro-options.vala
index 22c4e869..ea79f822 100644
--- a/src/retro/retro-options.vala
+++ b/src/retro/retro-options.vala
@@ -15,9 +15,8 @@ private class Games.RetroOptions : Object {
 
                foreach (var key in options_keys) {
                        var val = keyfile.get_string (OPTIONS_GROUP, key);
-                       var option = core.get_option (key);
 
-                       option.set_value (val);
+                       core.override_option_default (key, val);
                }
        }
 }
diff --git a/src/retro/retro-runner.vala b/src/retro/retro-runner.vala
index f80a8db1..e810d7df 100644
--- a/src/retro/retro-runner.vala
+++ b/src/retro/retro-runner.vala
@@ -30,7 +30,6 @@ public class Games.RetroRunner : Object, Runner {
        private Retro.Core core;
        private Retro.CoreView view;
        private RetroInputManager input_manager;
-       private Retro.MainLoop loop;
        private InputMode _input_mode;
        public InputMode input_mode {
                get { return _input_mode; }
@@ -198,12 +197,12 @@ public class Games.RetroRunner : Object, Runner {
        }
 
        public void load_previewed_savestate () throws Error {
-               loop.stop ();
+               core.stop ();
 
                tmp_live_savestate = previewed_savestate.clone_in_tmp ();
                core.save_directory = tmp_live_savestate.get_save_directory_path ();
                load_save_ram (previewed_savestate.get_save_ram_path ());
-               core.set_state (previewed_savestate.get_snapshot_data ());
+               core.set_state (previewed_savestate.get_snapshot_path ());
 
                if (previewed_savestate.has_media_data ())
                        media_set.selected_media_number = previewed_savestate.get_media_data ();
@@ -242,7 +241,7 @@ public class Games.RetroRunner : Object, Runner {
                }
                core.reset ();
 
-               loop.start ();
+               core.start ();
 
                if (latest_savestate != null)
                        load_extra_savestate_metadata (latest_savestate, true);
@@ -251,13 +250,16 @@ public class Games.RetroRunner : Object, Runner {
        }
 
        public void resume () {
+               if (!is_initialized)
+                       return;
+
                if (!is_ready) {
                        critical ("RetroRunner.resume() cannot be called if the game isn't playing");
                        return;
                }
 
                // Unpause an already running game
-               loop.start ();
+               core.start ();
                running = true;
        }
 
@@ -271,11 +273,12 @@ public class Games.RetroRunner : Object, Runner {
                // Keep the internal values of input_mode in sync between RetroRunner and RetroInputManager
                _input_mode = input_manager.input_mode;
 
-               core.shutdown.connect (on_shutdown);
-
-               core.run (); // Needed to finish preparing some cores.
+               core.shutdown.connect (stop);
+               core.crashed.connect ((core, error) => {
+                       stop ();
+                       crash (error);
+               });
 
-               loop = new Retro.MainLoop (core);
                running = false;
 
                is_initialized = true;
@@ -294,7 +297,6 @@ public class Games.RetroRunner : Object, Runner {
                view = null;
 
                input_manager = null;
-               loop = null;
 
                _running = false;
                is_initialized = false;
@@ -322,14 +324,12 @@ public class Games.RetroRunner : Object, Runner {
 
                var options_path = get_options_path ();
                if (FileUtils.test (options_path, FileTest.EXISTS))
-                       core.options_set.connect (() => {
-                               try {
-                                       var options = new RetroOptions (options_path);
-                                       options.apply (core);
-                               } catch (Error e) {
-                                       critical (e.message);
-                               }
-                       });
+                       try {
+                               var options = new RetroOptions (options_path);
+                               options.apply (core);
+                       } catch (Error e) {
+                               critical (e.message);
+                       }
 
                game_init ();
 
@@ -361,7 +361,7 @@ public class Games.RetroRunner : Object, Runner {
                        return;
 
                current_state_pixbuf = view.get_pixbuf ();
-               loop.stop ();
+               core.stop ();
 
                //FIXME:
                // In the future here there will be code which updates the currently
@@ -479,7 +479,7 @@ public class Games.RetroRunner : Object, Runner {
                if (media_set.get_size () > 1)
                        tmp_live_savestate.set_media_data (media_set);
 
-               tmp_live_savestate.set_snapshot_data (core.get_state ());
+               core.get_state (tmp_live_savestate.get_snapshot_path ());
                save_screenshot_in_tmp ();
 
                // Populate the metadata file
@@ -544,27 +544,15 @@ public class Games.RetroRunner : Object, Runner {
        }
 
        private void store_save_ram_in_tmp () throws Error {
-               var bytes = core.get_memory (Retro.MemoryType.SAVE_RAM);
-               var save = bytes.get_data ();
-               if (save.length == 0)
-                       return;
-
-               tmp_live_savestate.set_save_ram_data (save);
+               core.get_memory (Retro.MemoryType.SAVE_RAM,
+                                tmp_live_savestate.get_save_ram_path ());
        }
 
        private void load_save_ram (string save_ram_path) throws Error {
                if (!FileUtils.test (save_ram_path, FileTest.EXISTS))
                        return;
 
-               uint8[] data = null;
-               FileUtils.get_data (save_ram_path, out data);
-
-               var expected_size = core.get_memory_size (Retro.MemoryType.SAVE_RAM);
-               if (data.length != expected_size)
-                       warning ("Unexpected RAM data size: got %lu, expected %lu\n", data.length, 
expected_size);
-
-               var bytes = new Bytes.take (data);
-               core.set_memory (Retro.MemoryType.SAVE_RAM, bytes);
+               core.set_memory (Retro.MemoryType.SAVE_RAM, save_ram_path);
        }
 
        private void save_screenshot_in_tmp () throws Error {
@@ -595,12 +583,6 @@ public class Games.RetroRunner : Object, Runner {
                             null);
        }
 
-       private bool on_shutdown () {
-               stop ();
-
-               return true;
-       }
-
        private string get_unsupported_system_message () {
                var platform_name = platform.get_name ();
                if (platform_name != null)
diff --git a/src/ui/display-view.vala b/src/ui/display-view.vala
index b718e707..5e74ed04 100644
--- a/src/ui/display-view.vala
+++ b/src/ui/display-view.vala
@@ -286,6 +286,9 @@ private class Games.DisplayView : Object, UiView {
                header_bar.media_set = runner.media_set;
                box.header_bar.media_set = runner.media_set;
 
+               runner.crash.connect (message => {
+               });
+
                is_fullscreen = settings.get_boolean ("fullscreen") && runner.can_fullscreen;
 
                if (!runner.can_resume) {


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