[retro-gtk] retro-controller-type: Add functions for getting id and index count



commit 3b2a773cdc077b3dec705095df8c47cedc2ac50a
Author: Alexander Mikhaylenko <alexm gnome org>
Date:   Wed Jan 8 02:01:40 2020 +0500

    retro-controller-type: Add functions for getting id and index count
    
    Runner process will need to have a complete input state, so it will need
    to know how many ids and indices each controller type has to allocate
    memory.

 shared/retro-controller-type.c | 49 ++++++++++++++++++++++++++++++++++++++++++
 shared/retro-controller-type.h |  3 +++
 2 files changed, 52 insertions(+)
---
diff --git a/shared/retro-controller-type.c b/shared/retro-controller-type.c
index a65b02d..22f48ac 100644
--- a/shared/retro-controller-type.c
+++ b/shared/retro-controller-type.c
@@ -2,6 +2,9 @@
 
 #include "retro-controller-type.h"
 
+#include "retro-controller-codes.h"
+#include "retro-keyboard-key-private.h"
+
 GType
 retro_controller_type_get_type (void)
 {
@@ -29,3 +32,49 @@ retro_controller_type_get_type (void)
 
   return retro_controller_type_type;
 }
+
+int
+retro_controller_type_get_id_count (RetroControllerType type)
+{
+  switch (type) {
+  case RETRO_CONTROLLER_TYPE_JOYPAD:
+    return RETRO_JOYPAD_ID_COUNT;
+
+  case RETRO_CONTROLLER_TYPE_MOUSE:
+    return RETRO_MOUSE_ID_COUNT;
+
+  case RETRO_CONTROLLER_TYPE_KEYBOARD:
+    return RETRO_KEYBOARD_KEY_LAST;
+
+  case RETRO_CONTROLLER_TYPE_LIGHTGUN:
+    return RETRO_LIGHTGUN_ID_COUNT;
+
+  case RETRO_CONTROLLER_TYPE_ANALOG:
+    return RETRO_ANALOG_ID_COUNT;
+
+  case RETRO_CONTROLLER_TYPE_POINTER:
+    return RETRO_POINTER_ID_COUNT;
+
+  default:
+    g_assert_not_reached ();
+  }
+}
+
+int
+retro_controller_type_get_index_count (RetroControllerType type)
+{
+  switch (type) {
+  case RETRO_CONTROLLER_TYPE_ANALOG:
+    return RETRO_ANALOG_INDEX_COUNT;
+
+  case RETRO_CONTROLLER_TYPE_JOYPAD:
+  case RETRO_CONTROLLER_TYPE_MOUSE:
+  case RETRO_CONTROLLER_TYPE_KEYBOARD:
+  case RETRO_CONTROLLER_TYPE_LIGHTGUN:
+  case RETRO_CONTROLLER_TYPE_POINTER:
+    return 1;
+
+  default:
+    g_assert_not_reached ();
+  }
+}
diff --git a/shared/retro-controller-type.h b/shared/retro-controller-type.h
index ac17046..f327e00 100644
--- a/shared/retro-controller-type.h
+++ b/shared/retro-controller-type.h
@@ -41,4 +41,7 @@ typedef enum
   RETRO_CONTROLLER_TYPE_TYPE_MASK = 0xff,
 } RetroControllerType;
 
+int retro_controller_type_get_id_count (RetroControllerType type);
+int retro_controller_type_get_index_count (RetroControllerType type);
+
 G_END_DECLS


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