[retro-gtk] retro-gobject: Move retro-environment-interfaces.[ch] into retro-environment.c
- From: Adrien Plazas <aplazas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [retro-gtk] retro-gobject: Move retro-environment-interfaces.[ch] into retro-environment.c
- Date: Sat, 27 Aug 2016 20:31:41 +0000 (UTC)
commit 442a9b58527b61ed868bd40e7e9150cf5d8fa76a
Author: Adrien Plazas <kekun plazas laposte net>
Date: Mon Aug 1 15:30:48 2016 +0200
retro-gobject: Move retro-environment-interfaces.[ch] into retro-environment.c
This helps making the code cleaner.
https://bugzilla.gnome.org/show_bug.cgi?id=769880
retro-gobject/Makefile.am | 4 -
retro-gobject/retro-environment-interfaces.c | 344 --------------------
retro-gobject/retro-environment-interfaces.h | 55 ----
retro-gobject/retro-environment.c | 436 +++++++++++++++++++++++++-
4 files changed, 435 insertions(+), 404 deletions(-)
---
diff --git a/retro-gobject/Makefile.am b/retro-gobject/Makefile.am
index 63f8cf5..f851264 100644
--- a/retro-gobject/Makefile.am
+++ b/retro-gobject/Makefile.am
@@ -65,17 +65,13 @@ libretro_gobject_la_SOURCES = \
video.vala \
retro-core.c \
retro-environment.c \
- retro-environment-interfaces.c \
libretro-environment.h \
- retro-environment-interfaces.h \
$(NULL)
retro-core.c: retro-gobject-internal.h
retro-environment.c: retro-gobject-internal.h libretro-environment.h
-retro-environment-interfaces.c: retro-gobject-internal.h
-
libretro_gobject_la_LDFLAGS =
libretro_gobject_la_VALAFLAGS = \
diff --git a/retro-gobject/retro-environment.c b/retro-gobject/retro-environment.c
index 5c3bf45..02b635d 100644
--- a/retro-gobject/retro-environment.c
+++ b/retro-gobject/retro-environment.c
@@ -3,13 +3,357 @@
#include "retro-gobject-internal.h"
#include "libretro-environment.h"
-#include "retro-environment-interfaces.h"
+typedef struct {
+ guint64 caps;
+ guint width;
+ guint height;
+ gpointer start;
+ gpointer stop;
+ gpointer frame_raw_framebuffer;
+ gpointer frame_opengl_texture;
+ gpointer initialized;
+ gpointer deinitialized;
+} RetroCameraCallback;
+
+typedef struct {
+ gpointer start;
+ gpointer stop;
+ gpointer get_position;
+ gpointer set_interval;
+ gpointer initialized;
+ gpointer deinitialized;
+} RetroLocationCallback;
+
+typedef struct {
+ gpointer log;
+} RetroLogCallback;
typedef struct {
const gchar *msg;
guint frames;
} RetroMessage;
+typedef struct {
+ gpointer get_time_usec;
+ gpointer get_cpu_features;
+ gpointer get_perf_counter;
+ gpointer perf_register;
+ gpointer perf_start;
+ gpointer perf_stop;
+ gpointer perf_log;
+} RetroPerformanceCallback;
+
+typedef struct {
+ gpointer set_rumble_state;
+} RetroRumbleCallback;
+
+typedef struct {
+ gpointer set_sensor_state;
+ gpointer get_sensor_input;
+} RetroSensorCallback;
+
+static gboolean rumble_callback_set_rumble_state (guint port, RetroRumbleEffect effect, guint16 strength) {
+ RetroCore *cb_data = retro_core_get_cb_data ();
+ if (!cb_data)
+ g_return_val_if_reached (FALSE);
+
+ RetroRumble *interface = retro_core_get_rumble_interface (cb_data);
+ if (!interface)
+ g_return_val_if_reached (FALSE);
+
+ return RETRO_RUMBLE_GET_INTERFACE (interface)->set_rumble_state (interface, port, effect, strength);
+}
+
+static gboolean sensor_callback_set_sensor_state (guint port, RetroSensorAction action, guint rate) {
+ RetroCore *cb_data = retro_core_get_cb_data ();
+ if (!cb_data)
+ g_return_val_if_reached (FALSE);
+
+ RetroSensor *interface = retro_core_get_sensor_interface (cb_data);
+ if (!interface)
+ g_return_val_if_reached (FALSE);
+
+ return RETRO_SENSOR_GET_INTERFACE (interface)->set_sensor_state (interface, port, action, rate);
+}
+
+static gfloat sensor_callback_get_sensor_input (guint port, guint id) {
+ RetroCore *cb_data = retro_core_get_cb_data ();
+ if (!cb_data)
+ g_return_val_if_reached (0.0);
+
+ RetroSensor *interface = retro_core_get_sensor_interface (cb_data);
+ if (!interface)
+ g_return_val_if_reached (0.0);
+
+ return RETRO_SENSOR_GET_INTERFACE (interface)->get_sensor_input (interface, port, id);
+}
+
+static gboolean camera_callback_start () {
+ RetroCore *cb_data = retro_core_get_cb_data ();
+ if (!cb_data)
+ g_return_val_if_reached (FALSE);
+
+ RetroCamera *interface = retro_core_get_camera_interface (cb_data);
+ if (!interface)
+ g_return_val_if_reached (FALSE);
+
+ return RETRO_CAMERA_GET_INTERFACE (interface)->start (interface);
+}
+
+static void camera_callback_stop () {
+ RetroCore *cb_data = retro_core_get_cb_data ();
+ if (!cb_data)
+ g_return_if_reached ();
+
+ RetroCamera *interface = retro_core_get_camera_interface (cb_data);
+ if (!interface)
+ g_return_if_reached ();
+
+ RETRO_CAMERA_GET_INTERFACE (interface)->stop (interface);
+}
+
+static void camera_callback_frame_raw_framebuffer (guint32 *buffer, guint width, guint height, gsize pitch) {
+ RetroCore *cb_data = retro_core_get_cb_data ();
+ if (!cb_data)
+ g_return_if_reached ();
+
+ RetroCamera *interface = retro_core_get_camera_interface (cb_data);
+ if (!interface)
+ g_return_if_reached ();
+
+ RETRO_CAMERA_GET_INTERFACE (interface)->frame_raw_framebuffer (interface, buffer, width, height,
pitch);
+}
+
+static void camera_callback_frame_opengl_texture (guint texture_id, guint texture_target, gfloat *affine) {
+ RetroCore *cb_data = retro_core_get_cb_data ();
+ if (!cb_data)
+ g_return_if_reached ();
+
+ RetroCamera *interface = retro_core_get_camera_interface (cb_data);
+ if (!interface)
+ g_return_if_reached ();
+
+ RETRO_CAMERA_GET_INTERFACE (interface)->frame_opengl_texture (interface, texture_id, texture_target,
affine);
+}
+
+static void camera_callback_initialized () {
+ RetroCore *cb_data = retro_core_get_cb_data ();
+ if (!cb_data)
+ g_return_if_reached ();
+
+ RetroCamera *interface = retro_core_get_camera_interface (cb_data);
+ if (!interface)
+ g_return_if_reached ();
+
+ RETRO_CAMERA_GET_INTERFACE (interface)->initialized (interface);
+}
+
+static void camera_callback_deinitialized () {
+ RetroCore *cb_data = retro_core_get_cb_data ();
+ if (!cb_data)
+ g_return_if_reached ();
+
+ RetroCamera *interface = retro_core_get_camera_interface (cb_data);
+ if (!interface)
+ g_return_if_reached ();
+
+ RETRO_CAMERA_GET_INTERFACE (interface)->deinitialized (interface);
+}
+
+static void log_callback_log (guint level, const char *format, ...) {
+ RetroCore *cb_data = retro_core_get_cb_data ();
+ if (!cb_data)
+ g_return_if_reached ();
+
+ RetroLog *interface = retro_core_get_log_interface (cb_data);
+ if (!interface)
+ g_return_if_reached ();
+
+ // Get the arguments, set up the formatted message,
+ // pass it to the logging method and free it.
+ va_list args;
+ va_start (args, format);
+ char *message = g_strdup_vprintf (format, args);
+ RETRO_LOG_GET_INTERFACE (interface)->log (interface, level, message);
+ g_free (message);
+}
+
+static gint64 performance_callback_get_time_usec () {
+ RetroCore *cb_data = retro_core_get_cb_data ();
+ if (!cb_data)
+ g_return_val_if_reached (0);
+
+ RetroPerformance *interface = retro_core_get_performance_interface (cb_data);
+ if (!interface)
+ g_return_val_if_reached (0);
+
+ return RETRO_PERFORMANCE_GET_INTERFACE (interface)->get_time_usec (interface);
+}
+
+static guint64 performance_callback_get_cpu_features () {
+ RetroCore *cb_data = retro_core_get_cb_data ();
+ if (!cb_data)
+ g_return_val_if_reached (0);
+
+ RetroPerformance *interface = retro_core_get_performance_interface (cb_data);
+ if (!interface)
+ g_return_val_if_reached (0);
+
+ return RETRO_PERFORMANCE_GET_INTERFACE (interface)->get_cpu_features (interface);
+}
+
+static guint64 performance_callback_get_perf_counter () {
+ RetroCore *cb_data = retro_core_get_cb_data ();
+ if (!cb_data)
+ g_return_val_if_reached (0);
+
+ RetroPerformance *interface = retro_core_get_performance_interface (cb_data);
+ if (!interface)
+ g_return_val_if_reached (0);
+
+ return RETRO_PERFORMANCE_GET_INTERFACE (interface)->get_perf_counter (interface);
+}
+
+static void performance_callback_perf_register (RetroPerfCounter *counter) {
+ RetroCore *cb_data = retro_core_get_cb_data ();
+ if (!cb_data)
+ g_return_if_reached ();
+
+ RetroPerformance *interface = retro_core_get_performance_interface (cb_data);
+ if (!interface)
+ g_return_if_reached ();
+
+ RETRO_PERFORMANCE_GET_INTERFACE (interface)->perf_register (interface, counter);
+}
+
+static void performance_callback_perf_start (RetroPerfCounter *counter) {
+ RetroCore *cb_data = retro_core_get_cb_data ();
+ if (!cb_data)
+ g_return_if_reached ();
+
+ RetroPerformance *interface = retro_core_get_performance_interface (cb_data);
+ if (!interface)
+ g_return_if_reached ();
+
+ RETRO_PERFORMANCE_GET_INTERFACE (interface)->perf_start (interface, counter);
+}
+
+static void performance_callback_perf_stop (RetroPerfCounter *counter) {
+ RetroCore *cb_data = retro_core_get_cb_data ();
+ if (!cb_data)
+ g_return_if_reached ();
+
+ RetroPerformance *interface = retro_core_get_performance_interface (cb_data);
+ if (!interface)
+ g_return_if_reached ();
+
+ RETRO_PERFORMANCE_GET_INTERFACE (interface)->perf_stop (interface, counter);
+}
+
+static void performance_callback_perf_log () {
+ RetroCore *cb_data = retro_core_get_cb_data ();
+ if (!cb_data)
+ g_return_if_reached ();
+
+ RetroPerformance *interface = retro_core_get_performance_interface (cb_data);
+ if (!interface)
+ g_return_if_reached ();
+
+ RETRO_PERFORMANCE_GET_INTERFACE (interface)->perf_log (interface);
+}
+
+static gboolean location_callback_start () {
+ RetroCore *cb_data = retro_core_get_cb_data ();
+ if (!cb_data)
+ g_return_val_if_reached (FALSE);
+
+ RetroLocation *interface = retro_core_get_location_interface (cb_data);
+ if (!interface)
+ g_return_val_if_reached (FALSE);
+
+ return RETRO_LOCATION_GET_INTERFACE (interface)->start (interface);
+}
+
+static void location_callback_stop () {
+ RetroCore *cb_data = retro_core_get_cb_data ();
+ if (!cb_data)
+ g_return_if_reached ();
+
+ RetroLocation *interface = retro_core_get_location_interface (cb_data);
+ if (!interface)
+ g_return_if_reached ();
+
+ RETRO_LOCATION_GET_INTERFACE (interface)->stop (interface);
+}
+
+static gboolean location_callback_get_position (gdouble *lat, gdouble *lon, gdouble *horiz_accuracy, gdouble
*vert_accuracy) {
+ RetroCore *cb_data = retro_core_get_cb_data ();
+ if (!cb_data)
+ g_return_val_if_reached (FALSE);
+
+ RetroLocation *interface = retro_core_get_location_interface (cb_data);
+ if (!interface)
+ g_return_val_if_reached (FALSE);
+
+ return RETRO_LOCATION_GET_INTERFACE (interface)->get_position (interface, lat, lon, horiz_accuracy,
vert_accuracy);
+}
+
+static void location_callback_set_interval (guint interval_ms, guint interval_distance) {
+ RetroCore *cb_data = retro_core_get_cb_data ();
+ if (!cb_data)
+ g_return_if_reached ();
+
+ RetroLocation *interface = retro_core_get_location_interface (cb_data);
+ if (!interface)
+ g_return_if_reached ();
+
+ RETRO_LOCATION_GET_INTERFACE (interface)->set_interval (interface, interval_ms, interval_distance);
+}
+
+static void location_callback_initialized () {
+ RetroCore *cb_data = retro_core_get_cb_data ();
+ if (!cb_data)
+ g_return_if_reached ();
+
+ RetroLocation *interface = retro_core_get_location_interface (cb_data);
+ if (!interface)
+ g_return_if_reached ();
+
+ RETRO_LOCATION_GET_INTERFACE (interface)->initialized (interface);
+}
+
+static void location_callback_deinitialized () {
+ RetroCore *cb_data = retro_core_get_cb_data ();
+ if (!cb_data)
+ g_return_if_reached ();
+
+ RetroLocation *interface = retro_core_get_location_interface (cb_data);
+ if (!interface)
+ g_return_if_reached ();
+
+ RETRO_LOCATION_GET_INTERFACE (interface)->deinitialized (interface);
+}
+
+static gboolean get_camera_callback (RetroCore *self, RetroCameraCallback *cb) {
+ void *interface_exists = retro_core_get_camera_interface (self);
+ if (!interface_exists)
+ return FALSE;
+
+ RetroCamera *interface = retro_core_get_camera_interface (self);
+
+ cb->caps = RETRO_CAMERA_GET_INTERFACE (interface)->get_caps (interface);
+ cb->width = RETRO_CAMERA_GET_INTERFACE (interface)->get_width (interface);
+ cb->height = RETRO_CAMERA_GET_INTERFACE (interface)->get_height (interface);
+ cb->start = camera_callback_start;
+ cb->stop = camera_callback_stop;
+ cb->frame_raw_framebuffer = camera_callback_frame_raw_framebuffer;
+ cb->frame_opengl_texture = camera_callback_frame_opengl_texture;
+ cb->initialized = camera_callback_initialized;
+ cb->deinitialized = camera_callback_deinitialized;
+
+ return TRUE;
+}
+
static gboolean get_can_dupe (RetroVideo *self, gboolean *can_dupe) {
*can_dupe = retro_video_get_can_dupe (self);
@@ -34,18 +378,80 @@ static gboolean get_libretro_path (RetroCore *self, const gchar* *libretro_direc
return TRUE;
}
+static gboolean get_location_callback (RetroCore *self, RetroLocationCallback *cb) {
+ void *interface_exists = retro_core_get_location_interface (self);
+ if (!interface_exists)
+ return FALSE;
+
+ cb->start = location_callback_start;
+ cb->stop = location_callback_stop;
+ cb->get_position = location_callback_get_position;
+ cb->set_interval = location_callback_set_interval;
+ cb->initialized = location_callback_initialized;
+ cb->deinitialized = location_callback_deinitialized;
+
+ return TRUE;
+}
+
+static gboolean get_log_callback (RetroCore *self, RetroLogCallback *cb) {
+ void *interface_exists = retro_core_get_log_interface (self);
+ if (!interface_exists)
+ return FALSE;
+
+ cb->log = log_callback_log;
+
+ return TRUE;
+}
+
static gboolean get_overscan (RetroVideo *self, gboolean *overcan) {
*overcan = retro_video_get_overscan (self);
return TRUE;
}
+static gboolean get_performance_callback (RetroCore *self, RetroPerformanceCallback *cb) {
+ void *interface_exists = retro_core_get_performance_interface (self);
+ if (!interface_exists)
+ return FALSE;
+
+ cb->get_time_usec = performance_callback_get_time_usec;
+ cb->get_cpu_features = performance_callback_get_cpu_features;
+ cb->get_perf_counter = performance_callback_get_perf_counter;
+ cb->perf_register = performance_callback_perf_register;
+ cb->perf_start = performance_callback_perf_start;
+ cb->perf_stop = performance_callback_perf_stop;
+ cb->perf_log = performance_callback_perf_log;
+
+ return TRUE;
+}
+
+static gboolean get_rumble_callback (RetroCore *self, RetroRumbleCallback *cb) {
+ void *interface_exists = retro_core_get_rumble_interface (self);
+ if (!interface_exists)
+ return FALSE;
+
+ cb->set_rumble_state = rumble_callback_set_rumble_state;
+
+ return TRUE;
+}
+
static gboolean get_save_directory (RetroCore *self, const gchar* *save_directory) {
*(save_directory) = retro_core_get_save_directory (self);
return TRUE;
}
+static gboolean get_sensor_callback (RetroCore *self, RetroSensorCallback *cb) {
+ void *interface_exists = retro_core_get_sensor_interface (self);
+ if (!interface_exists)
+ return FALSE;
+
+ cb->set_sensor_state = sensor_callback_set_sensor_state;
+ cb->get_sensor_input = sensor_callback_get_sensor_input;
+
+ return TRUE;
+}
+
static gboolean get_system_directory (RetroCore *self, const gchar* *system_directory) {
*(system_directory) = retro_core_get_system_directory (self);
@@ -262,6 +668,34 @@ static gboolean environment_variables_command (RetroVariables *self, unsigned cm
}
}
+static gboolean environment_interfaces_command (RetroCore *self, unsigned cmd, gpointer data) {
+ if (!self)
+ return FALSE;
+
+ switch (cmd) {
+ case RETRO_ENVIRONMENT_GET_CAMERA_INTERFACE:
+ return get_camera_callback (self, (RetroCameraCallback *) data);
+
+ case RETRO_ENVIRONMENT_GET_LOCATION_INTERFACE:
+ return get_location_callback (self, (RetroLocationCallback *) data);
+
+ case RETRO_ENVIRONMENT_GET_LOG_INTERFACE:
+ return get_log_callback (self, (RetroLogCallback *) data);
+
+ case RETRO_ENVIRONMENT_GET_PERF_INTERFACE:
+ return get_performance_callback (self, (RetroPerformanceCallback *) data);
+
+ case RETRO_ENVIRONMENT_GET_RUMBLE_INTERFACE:
+ return get_rumble_callback (self, (RetroRumbleCallback *) data);
+
+ case RETRO_ENVIRONMENT_GET_SENSOR_INTERFACE:
+ return get_sensor_callback (self, (RetroSensorCallback *) data);
+
+ default:
+ return FALSE;
+ }
+}
+
gpointer retro_core_get_module_environment_interface (RetroCore *self) {
gboolean real_cb (unsigned cmd, gpointer data) {
RetroCore *cb_data = retro_core_get_cb_data ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]