[retro-gtk] retro-gobject: Set Core callbacks in C
- From: Adrien Plazas <aplazas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [retro-gtk] retro-gobject: Set Core callbacks in C
- Date: Tue, 24 Jan 2017 16:20:23 +0000 (UTC)
commit 0d2f44b6a2b2b285a31f68f52427d596f15142ad
Author: Adrien Plazas <kekun plazas laposte net>
Date: Thu Jan 19 18:57:46 2017 +0100
retro-gobject: Set Core callbacks in C
This makes the code simpler.
https://bugzilla.gnome.org/show_bug.cgi?id=777489
retro-gobject/core.vala | 19 +++----------
retro-gobject/retro-environment.c | 52 ++++++++++++++++++++++++-------------
2 files changed, 38 insertions(+), 33 deletions(-)
---
diff --git a/retro-gobject/core.vala b/retro-gobject/core.vala
index b4b273d..a78391f 100644
--- a/retro-gobject/core.vala
+++ b/retro-gobject/core.vala
@@ -274,12 +274,8 @@ public class Core : Object {
*/
public signal bool message (string message, uint frames);
- private extern void *get_module_environment_interface ();
- private extern void *get_module_video_refresh_cb ();
- private extern void *get_module_audio_sample_cb ();
- private extern void *get_module_audio_sample_batch_cb ();
- private extern void *get_module_input_poll_cb ();
- private extern void *get_module_input_state_cb ();
+ private extern void set_environment_interface ();
+ private extern void set_callbacks ();
internal Module module;
@@ -299,14 +295,7 @@ public class Core : Object {
libretro_path = File.new_for_path (file_name).resolve_relative_path ("").get_path ();
module = new Module (libretro_path);
-
- push_cb_data ();
- module.set_video_refresh (get_module_video_refresh_cb ());
- module.set_audio_sample (get_module_audio_sample_cb ());
- module.set_audio_sample_batch (get_module_audio_sample_batch_cb ());
- module.set_input_poll (get_module_input_poll_cb ());
- module.set_input_state (get_module_input_state_cb ());
- pop_cb_data ();
+ set_callbacks ();
}
~Core () {
@@ -320,8 +309,8 @@ public class Core : Object {
* Must be called before loading a game and running the core.
*/
public virtual signal void init () {
+ set_environment_interface ();
push_cb_data ();
- module.set_environment (get_module_environment_interface ());
module.init ();
pop_cb_data ();
diff --git a/retro-gobject/retro-environment.c b/retro-gobject/retro-environment.c
index bb5187d..7d1b440 100644
--- a/retro-gobject/retro-environment.c
+++ b/retro-gobject/retro-environment.c
@@ -333,10 +333,6 @@ static gboolean on_environment_interface (unsigned cmd, gpointer data) {
return environment_core_command (self, cmd, data);
}
-gpointer retro_core_get_module_environment_interface (RetroCore *self) {
- return on_environment_interface;
-}
-
static void on_video_refresh (guint8* data, guint width, guint height, gsize pitch) {
RetroCore *self;
RetroVideo *video;
@@ -375,10 +371,6 @@ static void on_audio_sample (gint16 left, gint16 right) {
retro_audio_play_sample (audio, left, right);
}
-gpointer retro_core_get_module_audio_sample_cb (RetroCore *self) {
- return on_audio_sample;
-}
-
static gsize on_audio_sample_batch (gint16* data, int frames) {
RetroCore *self;
RetroAudio *audio;
@@ -396,10 +388,6 @@ static gsize on_audio_sample_batch (gint16* data, int frames) {
return retro_audio_play_batch (audio, data, frames * 2, frames);
}
-gpointer retro_core_get_module_audio_sample_batch_cb (RetroCore *self) {
- return on_audio_sample_batch;
-}
-
static void on_input_poll () {
RetroCore *self;
RetroInput *input;
@@ -417,10 +405,6 @@ static void on_input_poll () {
retro_input_poll (input);
}
-gpointer retro_core_get_module_input_poll_cb (RetroCore *self) {
- return on_input_poll;
-}
-
static gint16 on_input_state (guint port, guint device, guint index, guint id) {
RetroCore *self;
RetroInput *input;
@@ -438,6 +422,38 @@ static gint16 on_input_state (guint port, guint device, guint index, guint id) {
return retro_input_get_state (input, port, device, index, id);
}
-gpointer retro_core_get_module_input_state_cb (RetroCore *self) {
- return on_input_state;
+void retro_core_set_environment_interface (RetroCore *self) {
+ RetroModule *module;
+ RetroCallbackSetter set_environment;
+
+ module = self->module;
+ set_environment = retro_module_get_set_environment (module);
+
+ retro_core_push_cb_data (self);
+ set_environment (on_environment_interface);
+ retro_core_pop_cb_data ();
+}
+
+void retro_core_set_callbacks (RetroCore *self) {
+ RetroModule *module;
+ RetroCallbackSetter set_video_refresh;
+ RetroCallbackSetter set_audio_sample;
+ RetroCallbackSetter set_audio_sample_batch;
+ RetroCallbackSetter set_input_poll;
+ RetroCallbackSetter set_input_state;
+
+ module = self->module;
+ set_video_refresh = retro_module_get_set_video_refresh (module);
+ set_audio_sample = retro_module_get_set_audio_sample (module);
+ set_audio_sample_batch = retro_module_get_set_audio_sample_batch (module);
+ set_input_poll = retro_module_get_set_input_poll (module);
+ set_input_state = retro_module_get_set_input_state (module);
+
+ retro_core_push_cb_data (self);
+ set_video_refresh (on_video_refresh);
+ set_audio_sample (on_audio_sample);
+ set_audio_sample_batch (on_audio_sample_batch);
+ set_input_poll (on_input_poll);
+ set_input_state (on_input_state);
+ retro_core_pop_cb_data ();
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]