[retro-gtk/wip/aplazas/input: 3/3] WIP Use RetroInput



commit 6e8f953dd0fada4da53eb4def82fcc305eaeda94
Author: Adrien Plazas <kekun plazas laposte net>
Date:   Fri Oct 27 08:27:49 2017 +0200

    WIP Use RetroInput

 retro-gtk/retro-controller.c           |   12 ++++--------
 retro-gtk/retro-controller.h           |   14 +++++---------
 retro-gtk/retro-core-view-controller.c |   12 ++++--------
 retro-gtk/retro-core-view-controller.h |    2 +-
 retro-gtk/retro-core-view.c            |   22 ++++++++++------------
 retro-gtk/retro-core-view.h            |    8 +++-----
 retro-gtk/retro-core.c                 |   20 +++++++-------------
 retro-gtk/retro-core.h                 |   10 ++++------
 retro-gtk/retro-environment.c          |    6 +++++-
 9 files changed, 43 insertions(+), 63 deletions(-)
---
diff --git a/retro-gtk/retro-controller.c b/retro-gtk/retro-controller.c
index 177bdc1..4af5b8d 100644
--- a/retro-gtk/retro-controller.c
+++ b/retro-gtk/retro-controller.c
@@ -32,19 +32,15 @@ retro_controller_poll (RetroController *self)
 /**
  * retro_controller_get_input_state:
  * @self: a #RetroController
- * @controller_type: a #RetroControllerType to query @self
- * @index: an input index to interpret depending on @controller_type
- * @id: an input id to interpret depending on @controller_type
+ * @input: a #RetroInput to query @self
  *
  * Gets the state of an input of @self.
  *
  * Returns: the input's state
  */
 gint16
-retro_controller_get_input_state (RetroController     *self,
-                                  RetroControllerType  controller_type,
-                                  guint                index,
-                                  guint                id)
+retro_controller_get_input_state (RetroController *self,
+                                  RetroInput      *input)
 {
   RetroControllerInterface *iface;
 
@@ -54,7 +50,7 @@ retro_controller_get_input_state (RetroController     *self,
 
   g_return_val_if_fail (iface->get_input_state != NULL, 0);
 
-  return iface->get_input_state (self, controller_type, index, id);
+  return iface->get_input_state (self, input);
 }
 
 /**
diff --git a/retro-gtk/retro-controller.h b/retro-gtk/retro-controller.h
index 32aa2bf..af05154 100644
--- a/retro-gtk/retro-controller.h
+++ b/retro-gtk/retro-controller.h
@@ -8,7 +8,7 @@
 #endif
 
 #include <glib-object.h>
-#include "retro-controller-type.h"
+#include "retro-input.h"
 #include "retro-rumble-effect.h"
 
 G_BEGIN_DECLS
@@ -22,19 +22,15 @@ struct _RetroControllerInterface
   GTypeInterface parent_iface;
 
   void (*poll) (RetroController *self);
-  gint16 (*get_input_state) (RetroController     *self,
-                             RetroControllerType  controller_type,
-                             guint                index,
-                             guint                id);
+  gint16 (*get_input_state) (RetroController *self,
+                             RetroInput      *input);
   RetroControllerType (*get_controller_type) (RetroController *self);
   guint64 (*get_capabilities) (RetroController *self);
 };
 
 void retro_controller_poll (RetroController *self);
-gint16 retro_controller_get_input_state (RetroController     *self,
-                                         RetroControllerType  controller_type,
-                                         guint                index,
-                                         guint                id);
+gint16 retro_controller_get_input_state (RetroController *self,
+                                         RetroInput      *input);
 RetroControllerType retro_controller_get_controller_type (RetroController *self);
 guint64 retro_controller_get_capabilities (RetroController *self);
 gboolean retro_controller_set_rumble_state (RetroController   *self,
diff --git a/retro-gtk/retro-core-view-controller.c b/retro-gtk/retro-core-view-controller.c
index 82329e7..565da17 100644
--- a/retro-gtk/retro-core-view-controller.c
+++ b/retro-gtk/retro-core-view-controller.c
@@ -25,10 +25,8 @@ retro_core_view_controller_poll (RetroController *base)
 }
 
 static gint16
-retro_core_view_controller_get_input_state (RetroController     *base,
-                                            RetroControllerType  controller_type,
-                                            guint                index,
-                                            guint                id)
+retro_core_view_controller_get_input_state (RetroController *base,
+                                            RetroInput      *input)
 {
   RetroCoreViewController *self = RETRO_CORE_VIEW_CONTROLLER (base);
   gpointer view;
@@ -36,7 +34,7 @@ retro_core_view_controller_get_input_state (RetroController     *base,
 
   g_return_val_if_fail (self != NULL, 0);
 
-  if (controller_type != self->controller_type)
+  if (retro_input_get_controller_type (input) != self->controller_type)
     return 0;
 
   view = g_weak_ref_get (&self->view);
@@ -44,9 +42,7 @@ retro_core_view_controller_get_input_state (RetroController     *base,
   if (view == NULL)
     return 0;
 
-  result = retro_core_view_get_input_state (RETRO_CORE_VIEW (view),
-                                            self->controller_type,
-                                            index, id);
+  result = retro_core_view_get_input_state (RETRO_CORE_VIEW (view), input);
 
   g_object_unref (G_OBJECT (view));
 
diff --git a/retro-gtk/retro-core-view-controller.h b/retro-gtk/retro-core-view-controller.h
index 6cf5e24..2a728c4 100644
--- a/retro-gtk/retro-core-view-controller.h
+++ b/retro-gtk/retro-core-view-controller.h
@@ -8,7 +8,7 @@
 #endif
 
 #include <glib-object.h>
-#include "retro-controller-type.h"
+#include "retro-input.h"
 #include "retro-core-view.h"
 
 G_BEGIN_DECLS
diff --git a/retro-gtk/retro-core-view.c b/retro-gtk/retro-core-view.c
index f285db6..4b3b52f 100644
--- a/retro-gtk/retro-core-view.c
+++ b/retro-gtk/retro-core-view.c
@@ -5,10 +5,7 @@
 #include <linux/input-event-codes.h>
 #include "retro-cairo-display.h"
 #include "retro-core-view-controller.h"
-#include "retro-joypad-id.h"
-#include "retro-mouse-id.h"
 #include "retro-pa-player.h"
-#include "retro-pointer-id.h"
 
 static guint16 DEFAULT_KEY_JOYPAD_BUTTON_MAPPING[RETRO_JOYPAD_ID_COUNT] = {
   KEY_S,
@@ -623,30 +620,31 @@ retro_core_view_as_controller (RetroCoreView       *self,
 /**
  * retro_core_view_get_input_state:
  * @self: a #RetroCoreView
- * @controller_type: a #RetroControllerType to query @self
- * @index: an input index to interpret depending on @device
- * @id: an input id to interpret depending on @device
+ * @input: a #RetroInput to query @self
  *
  * Gets the state of an input of @self.
  *
  * Returns: the input's state
  */
 gint16
-retro_core_view_get_input_state (RetroCoreView       *self,
-                                 RetroControllerType  controller_type,
-                                 guint                index,
-                                 guint                id)
+retro_core_view_get_input_state (RetroCoreView *self,
+                                 RetroInput    *input)
 {
+  guint id;
+  guint index;
   gint16 result;
 
   g_return_val_if_fail (RETRO_IS_CORE_VIEW (self), 0);
 
-  switch (controller_type) {
+  id = retro_input_get_id (input);
+  index = retro_input_get_index (input);
+
+  switch (retro_input_get_controller_type (input)) {
   case RETRO_CONTROLLER_TYPE_JOYPAD:
     if (id >= RETRO_JOYPAD_ID_COUNT)
       return 0;
 
-    return retro_core_view_get_joypad_button_state (self, id) ? G_MAXINT16 : 0;
+    return retro_core_view_get_joypad_button_state (self, id ? G_MAXINT16 : 0);
   case RETRO_CONTROLLER_TYPE_MOUSE:
     switch (id) {
     case RETRO_MOUSE_ID_X:
diff --git a/retro-gtk/retro-core-view.h b/retro-gtk/retro-core-view.h
index 785fc10..baaaeb0 100644
--- a/retro-gtk/retro-core-view.h
+++ b/retro-gtk/retro-core-view.h
@@ -10,7 +10,7 @@
 #include <gtk/gtk.h>
 #include "retro-core.h"
 #include "retro-controller.h"
-#include "retro-controller-type.h"
+#include "retro-input.h"
 #include "retro-video-filter.h"
 
 G_BEGIN_DECLS
@@ -30,10 +30,8 @@ void retro_core_view_set_filter (RetroCoreView    *self,
                                  RetroVideoFilter  filter);
 RetroController *retro_core_view_as_controller (RetroCoreView       *self,
                                                 RetroControllerType  controller_type);
-gint16 retro_core_view_get_input_state (RetroCoreView       *self,
-                                        RetroControllerType  controller_type,
-                                        guint                index,
-                                        guint                id);
+gint16 retro_core_view_get_input_state (RetroCoreView *self,
+                                        RetroInput    *input);
 guint64 retro_core_view_get_controller_capabilities (RetroCoreView *self);
 gboolean retro_core_view_get_can_grab_pointer (RetroCoreView *self);
 void retro_core_view_set_can_grab_pointer (RetroCoreView *self,
diff --git a/retro-gtk/retro-core.c b/retro-gtk/retro-core.c
index 3758ce2..28f5600 100644
--- a/retro-gtk/retro-core.c
+++ b/retro-gtk/retro-core.c
@@ -1734,9 +1734,7 @@ retro_core_poll_controllers (RetroCore *self)
  * retro_core_get_controller_input_state:
  * @self: a #RetroCore
  * @port: the port number
- * @controller_type: a #RetroControllerType to query @self
- * @index: an input index to interpret depending on @controller_type
- * @id: an input id to interpret depending on @controller_type
+ * @input: a #RetroInput
  *
  * Gets the state of an input of the controller plugged into the given port of
  * @self.
@@ -1744,11 +1742,9 @@ retro_core_poll_controllers (RetroCore *self)
  * Returns: the input's state
  */
 gint16
-retro_core_get_controller_input_state (RetroCore           *self,
-                                       guint                port,
-                                       RetroControllerType  controller_type,
-                                       guint                index,
-                                       guint                id)
+retro_core_get_controller_input_state (RetroCore  *self,
+                                       guint       port,
+                                       RetroInput *input)
 {
   RetroController *controller;
 
@@ -1762,13 +1758,11 @@ retro_core_get_controller_input_state (RetroCore           *self,
   if (controller == NULL)
     return 0;
 
-  if ((retro_controller_get_capabilities (controller) & (1 << controller_type)) == 0)
+  if ((retro_controller_get_capabilities (controller) &
+      (1 << retro_input_get_controller_type (input))) == 0)
     return 0;
 
-  return retro_controller_get_input_state (controller,
-                                           controller_type,
-                                           index,
-                                           id);
+  return retro_controller_get_input_state (controller, input);
 }
 
 // FIXME documentation
diff --git a/retro-gtk/retro-core.h b/retro-gtk/retro-core.h
index 0f9e111..1ba15d2 100644
--- a/retro-gtk/retro-core.h
+++ b/retro-gtk/retro-core.h
@@ -9,7 +9,7 @@
 
 #include <gtk/gtk.h>
 #include "retro-controller-iterator.h"
-#include "retro-controller-type.h"
+#include "retro-input.h"
 #include "retro-memory-type.h"
 
 G_BEGIN_DECLS
@@ -57,11 +57,9 @@ void retro_core_set_memory (RetroCore       *self,
                             RetroMemoryType  memory_type,
                             GBytes          *bytes);
 void retro_core_poll_controllers (RetroCore *self);
-gint16 retro_core_get_controller_input_state (RetroCore           *self,
-                                              uint                 port,
-                                              RetroControllerType  controller_type,
-                                              guint                index,
-                                              guint                id);
+gint16 retro_core_get_controller_input_state (RetroCore  *self,
+                                              uint        port,
+                                              RetroInput *input);
 guint64 retro_core_get_controller_capabilities (RetroCore *self);
 void retro_core_set_controller (RetroCore       *self,
                                 guint            port,
diff --git a/retro-gtk/retro-environment.c b/retro-gtk/retro-environment.c
index b294b23..645fdc3 100644
--- a/retro-gtk/retro-environment.c
+++ b/retro-gtk/retro-environment.c
@@ -3,6 +3,7 @@
 #include "retro-core-private.h"
 
 #include "libretro-environment.h"
+#include "retro-input-private.h"
 #include "retro-pixdata-private.h"
 
 void retro_core_set_system_av_info (RetroCore         *self,
@@ -500,13 +501,16 @@ on_input_state (guint port,
                 guint id)
 {
   RetroCore *self;
+  RetroInput input;
 
   self = retro_core_get_cb_data ();
 
   if (self == NULL)
     g_return_val_if_reached (0);
 
-  return retro_core_get_controller_input_state (self, port, device, index, id);
+  retro_input_init (&input, device, id, index);
+
+  return retro_core_get_controller_input_state (self, port, &input);
 }
 
 // TODO This is internal, make it private as soon as possible.


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