[gnome-games] Revert "retro: Adapt to API changes in retro-gtk"
- From: Alexander Mikhaylenko <alexm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-games] Revert "retro: Adapt to API changes in retro-gtk"
- Date: Wed, 22 Jan 2020 20:45:06 +0000 (UTC)
commit df0bf403f3072ca4ccff5291681546040d38ba63
Author: Alexander Mikhaylenko <alexm gnome org>
Date: Wed Jan 22 20:44:48 2020 +0000
Revert "retro: Adapt to API changes in retro-gtk"
This reverts commit fbfb2ba547d942aa42ce346c14ec64236a14eb8b
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 | 57 ++++++++++++++++---------
5 files changed, 81 insertions(+), 37 deletions(-)
---
diff --git a/plugins/nintendo-ds/src/nintendo-ds-runner.vala b/plugins/nintendo-ds/src/nintendo-ds-runner.vala
index 4cd1677d..bfebab0f 100644
--- a/plugins/nintendo-ds/src/nintendo-ds-runner.vala
+++ b/plugins/nintendo-ds/src/nintendo-ds-runner.vala
@@ -33,12 +33,22 @@ 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 36e690e7..192a85a1 100644
--- a/src/core/savestate.vala
+++ b/src/core/savestate.vala
@@ -80,14 +80,33 @@ public class Games.Savestate : Object {
}
}
- public string get_snapshot_path () {
- return Path.build_filename (path, "snapshot");
+ 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_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 d8117bde..637f8438 100644
--- a/src/retro/retro-gamepad.vala
+++ b/src/retro/retro-gamepad.vala
@@ -21,6 +21,8 @@ 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:
@@ -52,16 +54,17 @@ private class Games.RetroGamepad : Object, Retro.Controller {
return (1 << Retro.ControllerType.JOYPAD) | (1 << Retro.ControllerType.ANALOG);
}
- public bool get_supports_rumble () {
- return device.has_rumble ();
- }
-
- public void set_rumble_state (Retro.RumbleEffect effect, uint16 strength) {
+ public bool set_rumble_state (Retro.RumbleEffect effect, uint16 strength) {
rumble_effect[effect] = strength;
+ if (!device.has_rumble ())
+ return false;
+
device.rumble (rumble_effect[Retro.RumbleEffect.STRONG],
rumble_effect[Retro.RumbleEffect.WEAK],
uint16.MAX);
+
+ return true;
}
private bool get_button_pressed (Retro.JoypadId button) {
@@ -98,28 +101,22 @@ 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 ea79f822..22c4e869 100644
--- a/src/retro/retro-options.vala
+++ b/src/retro/retro-options.vala
@@ -15,8 +15,9 @@ 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);
- core.override_option_default (key, val);
+ option.set_value (val);
}
}
}
diff --git a/src/retro/retro-runner.vala b/src/retro/retro-runner.vala
index d021a179..f80a8db1 100644
--- a/src/retro/retro-runner.vala
+++ b/src/retro/retro-runner.vala
@@ -30,6 +30,7 @@ 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; }
@@ -197,12 +198,12 @@ public class Games.RetroRunner : Object, Runner {
}
public void load_previewed_savestate () throws Error {
- core.stop ();
+ loop.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.load_state (previewed_savestate.get_snapshot_path ());
+ core.set_state (previewed_savestate.get_snapshot_data ());
if (previewed_savestate.has_media_data ())
media_set.selected_media_number = previewed_savestate.get_media_data ();
@@ -241,7 +242,7 @@ public class Games.RetroRunner : Object, Runner {
}
core.reset ();
- core.start ();
+ loop.start ();
if (latest_savestate != null)
load_extra_savestate_metadata (latest_savestate, true);
@@ -250,16 +251,13 @@ 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
- core.start ();
+ loop.start ();
running = true;
}
@@ -273,10 +271,11 @@ 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 (stop);
+ core.shutdown.connect (on_shutdown);
core.run (); // Needed to finish preparing some cores.
+ loop = new Retro.MainLoop (core);
running = false;
is_initialized = true;
@@ -295,6 +294,7 @@ public class Games.RetroRunner : Object, Runner {
view = null;
input_manager = null;
+ loop = null;
_running = false;
is_initialized = false;
@@ -322,12 +322,14 @@ public class Games.RetroRunner : Object, Runner {
var options_path = get_options_path ();
if (FileUtils.test (options_path, FileTest.EXISTS))
- try {
- var options = new RetroOptions (options_path);
- options.apply (core);
- } catch (Error e) {
- critical (e.message);
- }
+ core.options_set.connect (() => {
+ try {
+ var options = new RetroOptions (options_path);
+ options.apply (core);
+ } catch (Error e) {
+ critical (e.message);
+ }
+ });
game_init ();
@@ -359,7 +361,7 @@ public class Games.RetroRunner : Object, Runner {
return;
current_state_pixbuf = view.get_pixbuf ();
- core.stop ();
+ loop.stop ();
//FIXME:
// In the future here there will be code which updates the currently
@@ -477,7 +479,7 @@ public class Games.RetroRunner : Object, Runner {
if (media_set.get_size () > 1)
tmp_live_savestate.set_media_data (media_set);
- core.save_state (tmp_live_savestate.get_snapshot_path ());
+ tmp_live_savestate.set_snapshot_data (core.get_state ());
save_screenshot_in_tmp ();
// Populate the metadata file
@@ -542,18 +544,27 @@ public class Games.RetroRunner : Object, Runner {
}
private void store_save_ram_in_tmp () throws Error {
- if (core.get_memory_size (Retro.MemoryType.SAVE_RAM) == 0)
+ var bytes = core.get_memory (Retro.MemoryType.SAVE_RAM);
+ var save = bytes.get_data ();
+ if (save.length == 0)
return;
- core.save_memory (Retro.MemoryType.SAVE_RAM,
- tmp_live_savestate.get_save_ram_path ());
+ tmp_live_savestate.set_save_ram_data (save);
}
private void load_save_ram (string save_ram_path) throws Error {
if (!FileUtils.test (save_ram_path, FileTest.EXISTS))
return;
- core.load_memory (Retro.MemoryType.SAVE_RAM, save_ram_path);
+ 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);
}
private void save_screenshot_in_tmp () throws Error {
@@ -584,6 +595,12 @@ 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]