[gnome-games/wip/exalm/subprocess: 2/6] retro: Adapt to API changes in retro-gtk
- From: Alexander Mikhaylenko <alexm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-games/wip/exalm/subprocess: 2/6] retro: Adapt to API changes in retro-gtk
- Date: Thu, 30 Jan 2020 10:38:57 +0000 (UTC)
commit fcbcd0bfad7a9fffc5539a953becfd3f9782e9e2
Author: Alexander Mikhaylenko <alexm gnome org>
Date: Thu Jan 23 02:01:55 2020 +0500
retro: Adapt to API changes in retro-gtk
Stop using options-set signal, use retro_core_override_option_default()
for applying options instead.
Stop using RetroMainLoop, use new RetroCore methods instead. Use
core.iterate() instead of core.run().
Stop returning value in RetroGamepad.set_rumble_state() and add
get_supports_rumble() instead. Remove poll() and emit state-changed
signal when required.
Use file paths for state and memory instead of doing IO manually.
Stop returning value in RetroCore.shutdown signal.
plugins/nintendo-ds/src/nintendo-ds-runner.vala | 10 -----
src/core/savestate.vala | 23 +---------
src/retro/retro-gamepad.vala | 25 ++++++-----
src/retro/retro-options.vala | 3 +-
src/retro/retro-runner.vala | 59 +++++++++----------------
5 files changed, 38 insertions(+), 82 deletions(-)
---
diff --git a/plugins/nintendo-ds/src/nintendo-ds-runner.vala b/plugins/nintendo-ds/src/nintendo-ds-runner.vala
index 037424a9..84ee4eed 100644
--- a/plugins/nintendo-ds/src/nintendo-ds-runner.vala
+++ b/plugins/nintendo-ds/src/nintendo-ds-runner.vala
@@ -33,22 +33,12 @@ private class Games.NintendoDsRunner : RetroRunner {
layouts[Gdk.Key.@4] = NintendoDsLayout.QUICK_SWITCH;
}
- construct {
- game_init.connect (on_init);
- }
-
private bool core_supports_layouts () {
var core = get_core ();
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;
diff --git a/src/core/savestate.vala b/src/core/savestate.vala
index e7ef4824..0148977d 100644
--- a/src/core/savestate.vala
+++ b/src/core/savestate.vala
@@ -43,33 +43,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..d8117bde 100644
--- a/src/retro/retro-gamepad.vala
+++ b/src/retro/retro-gamepad.vala
@@ -21,8 +21,6 @@ private class Games.RetroGamepad : Object, Retro.Controller {
device.absolute_axis_event.connect (on_absolute_axis_event);
}
- public void poll () {}
-
public int16 get_input_state (Retro.Input input) {
switch (input.get_controller_type ()) {
case Retro.ControllerType.JOYPAD:
@@ -54,17 +52,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) {
@@ -101,22 +98,28 @@ private class Games.RetroGamepad : Object, Retro.Controller {
private void on_button_press_event (Manette.Event event) {
uint16 button;
- if (event.get_button (out button))
+ if (event.get_button (out button)) {
buttons[button] = true;
+ emit_state_changed ();
+ }
}
private void on_button_release_event (Manette.Event event) {
uint16 button;
- if (event.get_button (out button))
+ if (event.get_button (out button)) {
buttons[button] = false;
+ emit_state_changed ();
+ }
}
private void on_absolute_axis_event (Manette.Event event) {
uint16 axis;
double value;
- if (event.get_absolute (out axis, out value))
+ if (event.get_absolute (out axis, out value)) {
axes[axis] = (int16) (value * int16.MAX);
+ emit_state_changed ();
+ }
}
}
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 951e389b..98ce1f88 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.load_state (previewed_savestate.get_snapshot_path ());
if (previewed_savestate.has_media_data ())
media_set.selected_media_number = previewed_savestate.get_media_data ();
@@ -240,10 +239,10 @@ public class Games.RetroRunner : Object, Runner {
is_ready = true;
}
- core.run (); // Needed to finish preparing some cores.
+ core.iteration (); // Needed to finish preparing some cores.
core.reset ();
- loop.start ();
+ core.run ();
running = true;
}
@@ -255,13 +254,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.run ();
running = true;
}
@@ -275,9 +277,8 @@ 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.shutdown.connect (stop);
- loop = new Retro.MainLoop (core);
running = false;
is_initialized = true;
@@ -296,7 +297,6 @@ public class Games.RetroRunner : Object, Runner {
view = null;
input_manager = null;
- loop = null;
_running = false;
is_initialized = false;
@@ -324,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 ();
@@ -363,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
@@ -483,7 +481,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.save_state (tmp_live_savestate.get_snapshot_path ());
save_screenshot_in_tmp ();
// Populate the metadata file
@@ -541,27 +539,18 @@ 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)
+ if (core.get_memory_size (Retro.MemoryType.SAVE_RAM) == 0)
return;
- tmp_live_savestate.set_save_ram_data (save);
+ core.save_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.load_memory (Retro.MemoryType.SAVE_RAM, save_ram_path);
}
private void save_screenshot_in_tmp () throws Error {
@@ -592,12 +581,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)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]