aboutsummaryrefslogtreecommitdiff
path: root/src/peripheral/inc
diff options
context:
space:
mode:
authorXavier Del Campo Romero <xavi.dcr@tutanota.com>2022-06-12 22:34:23 +0200
committerXavier Del Campo Romero <xavi.dcr@tutanota.com>2022-06-12 23:18:57 +0200
commit0f9e2d89589f05847fb7dc808da1594f0961b5b4 (patch)
treef80da866fdf50aae44009ccd1c858d2013b0a3d0 /src/peripheral/inc
parent5794dbf40364ae442a22b6ac6c4732edd0e61f84 (diff)
downloadrts-0f9e2d89589f05847fb7dc808da1594f0961b5b4.tar.gz
Split peripheral-related logic into its own component
This has several advantages: - `camera` no longer needs to define public functions for each peripheral type. - Peripheral-related is now no longer tighly coupled to human_player, so peripheral logic can be reused elsewhere e.g.: on menus. - Makes camera_update_touch consistent compared to equivalent functions, since now `pan` has now been moved to `camera` (as it should be).
Diffstat (limited to 'src/peripheral/inc')
-rw-r--r--src/peripheral/inc/peripheral.h64
1 files changed, 64 insertions, 0 deletions
diff --git a/src/peripheral/inc/peripheral.h b/src/peripheral/inc/peripheral.h
new file mode 100644
index 0000000..c405c3c
--- /dev/null
+++ b/src/peripheral/inc/peripheral.h
@@ -0,0 +1,64 @@
+#ifndef PERIPHERAL_H
+#define PERIPHERAL_H
+
+#include <pad.h>
+#include <keyboard.h>
+#include <mouse.h>
+#include <util.h>
+#include <stddef.h>
+#include <stdbool.h>
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+enum peripheral_type
+{
+ PERIPHERAL_TYPE_PAD,
+ PERIPHERAL_TYPE_TOUCH,
+ PERIPHERAL_TYPE_KEYBOARD_MOUSE
+};
+
+union peripheral
+{
+ struct peripheral_common
+ {
+ enum peripheral_type type;
+ } common;
+
+ struct peripheral_pad
+ {
+ struct peripheral_common common;
+ struct pad pad;
+ } pad;
+
+ struct peripheral_kbm
+ {
+ struct peripheral_common common;
+ struct mouse mouse;
+ struct keyboard keyboard;
+ bool long_press;
+ unsigned int lp_t;
+ } kbm;
+};
+
+struct peripheral_cfg
+{
+ enum peripheral_type type;
+ int padn;
+};
+
+UTIL_STATIC_ASSERT(!offsetof(struct peripheral_pad, common),
+ "unexpected offsetof for struct peripheral_pad");
+UTIL_STATIC_ASSERT(!offsetof(struct peripheral_kbm, common),
+ "unexpected offsetof for struct peripheral_kbm");
+
+void peripheral_init(const struct peripheral_cfg *cfg, union peripheral *p);
+void peripheral_update(union peripheral *p);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* PERIPHERAL_H */