[gnome-games] retro: Adapt to API changes in retro-gtk



commit e9441efb1ea21e29086ccd6a08229e770365baf2
Author: Adrien Plazas <kekun plazas laposte net>
Date:   Wed Oct 11 22:28:32 2017 +0200

    retro: Adapt to API changes in retro-gtk

 src/retro/retro-gamepad.vala       |   20 ++++++++++----------
 src/retro/retro-input-manager.vala |   32 ++++++++++++++++----------------
 src/retro/retro-runner.vala        |   24 ++++++++++++++----------
 3 files changed, 40 insertions(+), 36 deletions(-)
---
diff --git a/src/retro/retro-gamepad.vala b/src/retro/retro-gamepad.vala
index 9c619bf..3055f62 100644
--- a/src/retro/retro-gamepad.vala
+++ b/src/retro/retro-gamepad.vala
@@ -1,6 +1,6 @@
 // This file is part of GNOME Games. License: GPL-3.0+.
 
-private class Games.RetroGamepad: Object, Retro.InputDevice {
+private class Games.RetroGamepad: Object, Retro.Controller {
        public Gamepad gamepad { get; construct; }
        public bool present_analog_sticks { get; construct; }
 
@@ -22,26 +22,26 @@ private class Games.RetroGamepad: Object, Retro.InputDevice {
 
        public void poll () {}
 
-       public int16 get_input_state (Retro.DeviceType device, uint index, uint id) {
-               switch (device) {
-               case Retro.DeviceType.JOYPAD:
+       public int16 get_input_state (Retro.ControllerType controller_type, uint index, uint id) {
+               switch (controller_type) {
+               case Retro.ControllerType.JOYPAD:
                        return get_button_pressed ((Retro.JoypadId) id) ? int16.MAX : 0;
-               case Retro.DeviceType.ANALOG:
+               case Retro.ControllerType.ANALOG:
                        return get_analog_value ((Retro.AnalogIndex) index, (Retro.AnalogId) id);
                default:
                        return 0;
                }
        }
 
-       public Retro.DeviceType get_device_type () {
+       public Retro.ControllerType get_controller_type () {
                if (present_analog_sticks)
-                       return Retro.DeviceType.ANALOG;
+                       return Retro.ControllerType.ANALOG;
 
-               return Retro.DeviceType.JOYPAD;
+               return Retro.ControllerType.JOYPAD;
        }
 
-       public uint64 get_device_capabilities () {
-               return (1 << Retro.DeviceType.JOYPAD) | (1 << Retro.DeviceType.ANALOG);
+       public uint64 get_capabilities () {
+               return (1 << Retro.ControllerType.JOYPAD) | (1 << Retro.ControllerType.ANALOG);
        }
 
        public bool get_button_pressed (Retro.JoypadId button) {
diff --git a/src/retro/retro-input-manager.vala b/src/retro/retro-input-manager.vala
index bdf24a1..c6c7dd4 100644
--- a/src/retro/retro-input-manager.vala
+++ b/src/retro/retro-input-manager.vala
@@ -2,9 +2,9 @@
 
 private class Games.RetroInputManager : Object {
        private Retro.Core core;
-       private Retro.InputDevice core_view_joypad;
+       private Retro.Controller core_view_joypad;
        private GamepadMonitor gamepad_monitor;
-       private Retro.InputDevice?[] input_devices;
+       private Retro.Controller?[] controllers;
        private int core_view_joypad_port;
        private bool present_analog_sticks;
 
@@ -12,20 +12,20 @@ private class Games.RetroInputManager : Object {
                this.core = core;
                this.present_analog_sticks = present_analog_sticks;
 
-               core_view_joypad = view.as_input_device (Retro.DeviceType.JOYPAD);
+               core_view_joypad = view.as_controller (Retro.ControllerType.JOYPAD);
                core.set_keyboard (view);
 
                gamepad_monitor = GamepadMonitor.get_instance ();
                gamepad_monitor.foreach_gamepad ((gamepad) => {
-                       var port = input_devices.length;
+                       var port = controllers.length;
                        var retro_gamepad = new RetroGamepad (gamepad, present_analog_sticks);
-                       input_devices += retro_gamepad;
+                       controllers += retro_gamepad;
                        core.set_controller (port, retro_gamepad);
                        gamepad.unplugged.connect (() => handle_gamepad_unplugged (port));
                });
 
-               core_view_joypad_port = input_devices.length;
-               input_devices += core_view_joypad;
+               core_view_joypad_port = controllers.length;
+               controllers += core_view_joypad;
                core.set_controller (core_view_joypad_port, core_view_joypad);
                gamepad_monitor.gamepad_plugged.connect (handle_gamepad_plugged);
        }
@@ -35,17 +35,17 @@ private class Games.RetroInputManager : Object {
                // plugged as a last resort.
                var port = core_view_joypad_port;
                var retro_gamepad = new RetroGamepad (gamepad, present_analog_sticks);
-               input_devices[port] = retro_gamepad;
+               controllers[port] = retro_gamepad;
                core.set_controller (port, retro_gamepad);
                gamepad.unplugged.connect (() => handle_gamepad_unplugged (port));
 
                // Assign the CoreView's joypad to another unplugged port if it
                // exists and return.
-               for (var i = core_view_joypad_port; i < input_devices.length; i++) {
-                       if (input_devices[i] == null) {
+               for (var i = core_view_joypad_port; i < controllers.length; i++) {
+                       if (controllers[i] == null) {
                                // Found an unplugged port and so assigning core_view_joypad to it
                                core_view_joypad_port = i;
-                               input_devices[core_view_joypad_port] = core_view_joypad;
+                               controllers[core_view_joypad_port] = core_view_joypad;
                                core.set_controller (core_view_joypad_port, core_view_joypad);
 
                                return;
@@ -54,8 +54,8 @@ private class Games.RetroInputManager : Object {
 
                // Now it means that there is no unplugged port so append the
                // CoreView's joypad to ports.
-               core_view_joypad_port = input_devices.length;
-               input_devices += core_view_joypad;
+               core_view_joypad_port = controllers.length;
+               controllers += core_view_joypad;
                core.set_controller (core_view_joypad_port, core_view_joypad);
        }
 
@@ -63,16 +63,16 @@ private class Games.RetroInputManager : Object {
                if (core_view_joypad_port > port) {
                        // Remove the controller and shift the CoreView's joypad to
                        // "lesser" port.
-                       input_devices[core_view_joypad_port] = null;
+                       controllers[core_view_joypad_port] = null;
                        core.remove_controller (core_view_joypad_port);
                        core_view_joypad_port = port;
-                       input_devices[core_view_joypad_port] = core_view_joypad;
+                       controllers[core_view_joypad_port] = core_view_joypad;
                        core.set_controller (core_view_joypad_port, core_view_joypad);
                }
                else {
                        // Just remove the controller as no need to shift the
                        // CoreView's joypad.
-                       input_devices[port] = null;
+                       controllers[port] = null;
                        core.remove_controller (port);
                }
        }
diff --git a/src/retro/retro-runner.vala b/src/retro/retro-runner.vala
index f7261ec..48c1508 100644
--- a/src/retro/retro-runner.vala
+++ b/src/retro/retro-runner.vala
@@ -13,7 +13,7 @@ public class Games.RetroRunner : Object, Runner {
                get {
                        try {
                                init ();
-                               if (!core.supports_serialization ())
+                               if (!core.get_can_access_state ())
                                        return false;
 
                                var snapshot_path = get_snapshot_path ();
@@ -349,7 +349,7 @@ public class Games.RetroRunner : Object, Runner {
                if (media_set.get_size () > 1)
                        save_media_data ();
 
-               if (!core.supports_serialization ())
+               if (!core.get_can_access_state ())
                        return;
 
                save_snapshot ();
@@ -381,7 +381,8 @@ public class Games.RetroRunner : Object, Runner {
        }
 
        private void save_ram () throws Error{
-               var save = core.get_memory (Retro.MemoryType.SAVE_RAM);
+               var bytes = core.get_memory (Retro.MemoryType.SAVE_RAM);
+               var save = bytes.get_data ();
                if (save.length == 0)
                        return;
 
@@ -406,7 +407,8 @@ public class Games.RetroRunner : Object, Runner {
                if (data.length != expected_size)
                        warning ("Unexpected RAM data size: got %lu, expected %lu\n", data.length, 
expected_size);
 
-               core.set_memory (Retro.MemoryType.SAVE_RAM, data);
+               var bytes = new Bytes.take (data);
+               core.set_memory (Retro.MemoryType.SAVE_RAM, bytes);
        }
 
        private string get_snapshot_path () throws Error {
@@ -421,10 +423,11 @@ public class Games.RetroRunner : Object, Runner {
        }
 
        private void save_snapshot () throws Error {
-               if (!core.supports_serialization ())
+               if (!core.get_can_access_state ())
                        return;
 
-               var buffer = core.get_state ();
+               var bytes = core.get_state ();
+               var buffer = bytes.get_data ();
 
                var dir = Application.get_snapshots_dir ();
                try_make_dir (dir);
@@ -435,7 +438,7 @@ public class Games.RetroRunner : Object, Runner {
        }
 
        private void load_snapshot () throws Error {
-               if (!core.supports_serialization ())
+               if (!core.get_can_access_state ())
                        return;
 
                var snapshot_path = get_snapshot_path ();
@@ -446,7 +449,8 @@ public class Games.RetroRunner : Object, Runner {
                uint8[] data = null;
                FileUtils.get_data (snapshot_path, out data);
 
-               core.set_state (data);
+               var bytes = new Bytes.take (data);
+               core.set_state (bytes);
        }
 
        private void save_media_data () throws Error {
@@ -492,7 +496,7 @@ public class Games.RetroRunner : Object, Runner {
        }
 
        private void save_screenshot () throws Error {
-               if (!core.supports_serialization ())
+               if (!core.get_can_access_state ())
                        return;
 
                var pixbuf = view.pixbuf;
@@ -525,7 +529,7 @@ public class Games.RetroRunner : Object, Runner {
        }
 
        private void load_screenshot () throws Error {
-               if (!core.supports_serialization ())
+               if (!core.get_can_access_state ())
                        return;
 
                var screenshot_path = get_screenshot_path ();


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