[retro-gtk/wip/aplazas/c-port: 24/36] Merge Rumble into Core and InputDevice



commit 09ce5afbfe13353b2a7e8531ec47b90784f47e34
Author: Adrien Plazas <kekun plazas laposte net>
Date:   Mon Sep 25 09:16:40 2017 +0200

    Merge Rumble into Core and InputDevice
    
    Port it to C in the process.

 retro-gtk/Makefile.am           |    2 +-
 retro-gtk/core.vala             |    8 --------
 retro-gtk/retro-environment.c   |   34 ++++++++++++++++++----------------
 retro-gtk/retro-input-device.c  |   12 ++++++++++++
 retro-gtk/retro-input-device.h  |    5 +++++
 retro-gtk/retro-rumble-effect.h |   29 +++++++++++++++++++++++++++++
 retro-gtk/rumble.vala           |   15 ---------------
 7 files changed, 65 insertions(+), 40 deletions(-)
---
diff --git a/retro-gtk/Makefile.am b/retro-gtk/Makefile.am
index b566b58..987d82f 100644
--- a/retro-gtk/Makefile.am
+++ b/retro-gtk/Makefile.am
@@ -52,6 +52,7 @@ retro_gtk_public_h_sources = \
        retro-pa-player.h \
        retro-pixel-format.h \
        retro-pointer-id.h \
+       retro-rumble-effect.h \
        retro-video-filter.h \
        $(NULL)
 
@@ -97,7 +98,6 @@ libretro_gtk_la_SOURCES = \
        retro-pa-player.c \
        retro-pixel-format.c \
        retro-video-filter.c \
-       rumble.vala \
        retro-core.c \
        retro-environment.c \
        \
diff --git a/retro-gtk/core.vala b/retro-gtk/core.vala
index 9dae0cc..6dc96d1 100644
--- a/retro-gtk/core.vala
+++ b/retro-gtk/core.vala
@@ -86,14 +86,6 @@ public class Core : Object {
        }
 
        /**
-        * The rumble interface.
-        *
-        * Optional.
-        * If set, it must be set before {@link init} is called.
-        */
-       public Rumble rumble_interface { set; get; }
-
-       /**
         * Asks the frontend to shut down.
         */
        public signal bool shutdown ();
diff --git a/retro-gtk/retro-environment.c b/retro-gtk/retro-environment.c
index 7346db8..0cf5a98 100644
--- a/retro-gtk/retro-environment.c
+++ b/retro-gtk/retro-environment.c
@@ -32,21 +32,27 @@ rumble_callback_set_rumble_state (guint             port,
                                   RetroRumbleEffect effect,
                                   guint16           strength)
 {
-  RetroCore *cb_data;
-  RetroRumble *interface;
+  RetroCore *self;
+  RetroCoreEnvironmentInternal *internal;
+  RetroInputDevice *controller;
+
+  self = retro_core_get_cb_data ();
+
+  g_return_val_if_fail (RETRO_IS_CORE (self), FALSE);
+
+  internal = RETRO_CORE_ENVIRONMENT_INTERNAL (self);
+
+  if (!g_hash_table_contains (internal->controllers, &port))
+    return FALSE;
 
-  cb_data = retro_core_get_cb_data ();
-  if (!cb_data)
-    g_return_val_if_reached (FALSE);
+  controller = g_hash_table_lookup (internal->controllers, &port);
 
-  interface = retro_core_get_rumble_interface (cb_data);
-  if (!interface)
-    g_return_val_if_reached (FALSE);
+  if (controller == NULL)
+    return FALSE;
 
-  return RETRO_RUMBLE_GET_INTERFACE (interface)->set_rumble_state (interface,
-                                                                   port,
-                                                                   effect,
-                                                                   strength);
+  return retro_input_device_set_rumble_state (controller,
+                                              effect,
+                                              strength);
 }
 
 static void
@@ -157,10 +163,6 @@ static gboolean
 get_rumble_callback (RetroCore           *self,
                      RetroRumbleCallback *cb)
 {
-  gpointer interface_exists = retro_core_get_rumble_interface (self);
-  if (!interface_exists)
-    return FALSE;
-
   cb->set_rumble_state = rumble_callback_set_rumble_state;
 
   return TRUE;
diff --git a/retro-gtk/retro-input-device.c b/retro-gtk/retro-input-device.c
index b95ddba..6431893 100644
--- a/retro-gtk/retro-input-device.c
+++ b/retro-gtk/retro-input-device.c
@@ -69,3 +69,15 @@ retro_input_device_get_device_capabilities (RetroInputDevice *self)
 
   return iface->get_device_capabilities (self);
 }
+
+gboolean
+retro_input_device_set_rumble_state (RetroInputDevice  *self,
+                                     RetroRumbleEffect  effect,
+                                     guint16            strength)
+{
+  g_return_val_if_fail (RETRO_IS_INPUT_DEVICE (self), FALSE);
+
+  // TODO
+
+  return FALSE;
+}
diff --git a/retro-gtk/retro-input-device.h b/retro-gtk/retro-input-device.h
index 3b3e6e2..058ba1c 100644
--- a/retro-gtk/retro-input-device.h
+++ b/retro-gtk/retro-input-device.h
@@ -9,6 +9,7 @@
 
 #include <glib-object.h>
 #include "retro-device-type.h"
+#include "retro-rumble-effect.h"
 
 G_BEGIN_DECLS
 
@@ -37,6 +38,10 @@ gint16 retro_input_device_get_input_state (RetroInputDevice *self,
 RetroDeviceType retro_input_device_get_device_type (RetroInputDevice *self);
 guint64 retro_input_device_get_device_capabilities (RetroInputDevice *self);
 
+gboolean retro_input_device_set_rumble_state (RetroInputDevice  *self,
+                                              RetroRumbleEffect  effect,
+                                              guint16            strength);
+
 G_END_DECLS
 
 #endif /* RETRO_INPUT_DEVICE_H */
diff --git a/retro-gtk/retro-rumble-effect.h b/retro-gtk/retro-rumble-effect.h
new file mode 100644
index 0000000..21a29a4
--- /dev/null
+++ b/retro-gtk/retro-rumble-effect.h
@@ -0,0 +1,29 @@
+// This file is part of retro-gtk. License: GPL-3.0+.
+
+#ifndef RETRO_RUMBLE_EFFECT_H
+#define RETRO_RUMBLE_EFFECT_H
+
+#if !defined(__RETRO_GTK_INSIDE__) && !defined(RETRO_GTK_COMPILATION)
+# error "Only <retro-gtk.h> can be included directly."
+#endif
+
+#include <glib.h>
+
+G_BEGIN_DECLS
+
+/**
+ * RetroAnalogIndex:
+ * @RETRO_RUMBLE_EFFECT_STRONG: The strong rumble effect.
+ * @RETRO_RUMBLE_EFFECT_WEAK: The weak rumble effect.
+ *
+ * Represents the strength of the rumble effect.
+ */
+typedef enum
+{
+  RETRO_RUMBLE_EFFECT_STRONG,
+  RETRO_RUMBLE_EFFECT_WEAK,
+} RetroRumbleEffect;
+
+G_END_DECLS
+
+#endif /* RETRO_RUMBLE_EFFECT_H */


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