[retro-gtk/c-port: 29/39] Merge Rumble into Core and InputDevice



commit 4bef85a76b9895b25953c5fd321c6d9e34e84b7e
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 |   25 +++++++++++++++++++++++++
 retro-gtk/rumble.vala           |   15 ---------------
 7 files changed, 61 insertions(+), 40 deletions(-)
---
diff --git a/retro-gtk/Makefile.am b/retro-gtk/Makefile.am
index cce4ab4..321535d 100644
--- a/retro-gtk/Makefile.am
+++ b/retro-gtk/Makefile.am
@@ -51,7 +51,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 \
        libretro-environment.h \
@@ -132,6 +131,7 @@ retro_gtkinclude_HEADERS = \
        retro-pa-player.h \
        retro-pixel-format.h \
        retro-pointer-id.h \
+       retro-rumble-effect.h \
        retro-variable.h \
        retro-video-filter.h \
        $(NULL)
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 3a3f52e..0ea1aa9 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 a2a2acd..6f38c6c 100644
--- a/retro-gtk/retro-input-device.h
+++ b/retro-gtk/retro-input-device.h
@@ -5,6 +5,7 @@
 
 #include <glib-object.h>
 #include "retro-device-type.h"
+#include "retro-rumble-effect.h"
 
 G_BEGIN_DECLS
 
@@ -33,6 +34,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..f05b7f1
--- /dev/null
+++ b/retro-gtk/retro-rumble-effect.h
@@ -0,0 +1,25 @@
+// This file is part of retro-gtk. License: GPL-3.0+.
+
+#ifndef RETRO_RUMBLE_EFFECT_H
+#define RETRO_RUMBLE_EFFECT_H
+
+#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]