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



commit 46e007c71be0667bcb6f4f0d3ead2e69749b3a8d
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           |    3 ++-
 retro-gtk/core.vala             |    8 --------
 retro-gtk/retro-environment.c   |   34 ++++++++++++++++++----------------
 retro-gtk/retro-input-device.c  |   22 ++++++++++++++++++++++
 retro-gtk/retro-input-device.h  |    4 ++++
 retro-gtk/retro-rumble-effect.c |   24 ++++++++++++++++++++++++
 retro-gtk/retro-rumble-effect.h |   29 +++++++++++++++++++++++++++++
 retro-gtk/rumble.vala           |   15 ---------------
 8 files changed, 99 insertions(+), 40 deletions(-)
---
diff --git a/retro-gtk/Makefile.am b/retro-gtk/Makefile.am
index 80010ed..890fb2f 100644
--- a/retro-gtk/Makefile.am
+++ b/retro-gtk/Makefile.am
@@ -49,6 +49,7 @@ retro_gtk_public_h_sources = \
        retro-mouse-id.h \
        retro-pixel-format.h \
        retro-pointer-id.h \
+       retro-rumble-effect.h \
        retro-video-filter.h \
        $(NULL)
 
@@ -104,8 +105,8 @@ libretro_gtk_la_SOURCES = \
        retro-pa-player.c \
        retro-pixel-format.c \
        retro-pointer-id.c \
+       retro-rumble-effect.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 1c3d21e..9afdb7e 100644
--- a/retro-gtk/retro-input-device.c
+++ b/retro-gtk/retro-input-device.c
@@ -106,3 +106,25 @@ retro_input_device_get_device_capabilities (RetroInputDevice *self)
 
   return iface->get_device_capabilities (self);
 }
+
+/**
+ * retro_input_device_set_rumble_state:
+ * @self: a #RetroInputDevice
+ * @effect: the rumble effect
+ * @strength: the rumble effect strength
+ *
+ * Sets the rumble state of @self.
+ *
+ * Returns: whether the rumble state has been successfully set.
+ */
+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..8c02513 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
 
@@ -36,6 +37,9 @@ gint16 retro_input_device_get_input_state (RetroInputDevice *self,
                                            guint             id);
 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
 
diff --git a/retro-gtk/retro-rumble-effect.c b/retro-gtk/retro-rumble-effect.c
new file mode 100644
index 0000000..f4ac888
--- /dev/null
+++ b/retro-gtk/retro-rumble-effect.c
@@ -0,0 +1,24 @@
+// This file is part of retro-gtk. License: GPL-3.0+.
+
+#include "retro-rumble-effect.h"
+
+GType
+retro_rumble_effect_get_type (void)
+{
+  static volatile gsize retro_rumble_effect_type = 0;
+
+  if (g_once_init_enter (&retro_rumble_effect_type)) {
+    static const GEnumValue values[] = {
+      { RETRO_RUMBLE_EFFECT_STRONG, "RETRO_RUMBLE_EFFECT_STRONG", "strong" },
+      { RETRO_RUMBLE_EFFECT_WEAK, "RETRO_RUMBLE_EFFECT_WEAK", "weak" },
+      { 0, NULL, NULL },
+    };
+    GType type;
+
+    type = g_enum_register_static ("RetroRumbleEffect", values);
+
+    g_once_init_leave (&retro_rumble_effect_type, type);
+  }
+
+  return retro_rumble_effect_type;
+}
diff --git a/retro-gtk/retro-rumble-effect.h b/retro-gtk/retro-rumble-effect.h
new file mode 100644
index 0000000..93e314d
--- /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
+
+/**
+ * RetroRumbleEffect:
+ * @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]