summaryrefslogtreecommitdiff
path: root/lib/nes/app/input/input-device.hh
diff options
context:
space:
mode:
authorHannes Schulze <haschu0103@outlook.de>2025-01-30 16:43:06 +0100
committerHannes Schulze <haschu0103@outlook.de>2025-01-31 00:02:26 +0100
commit307e07d6513f9524b7fcab5134494bd175465cd1 (patch)
treece025db2ea998bdcd8980a0ed443083f0daf8d35 /lib/nes/app/input/input-device.hh
parent5959349f341a2380c0c3f41ec40a1e8e0d969d00 (diff)
handle input devices in the c++ application
Diffstat (limited to 'lib/nes/app/input/input-device.hh')
-rw-r--r--lib/nes/app/input/input-device.hh44
1 files changed, 44 insertions, 0 deletions
diff --git a/lib/nes/app/input/input-device.hh b/lib/nes/app/input/input-device.hh
new file mode 100644
index 0000000..9ac7423
--- /dev/null
+++ b/lib/nes/app/input/input-device.hh
@@ -0,0 +1,44 @@
+#pragma once
+
+#include "nes/sys/types/button-mask.hh"
+
+namespace nes
+{
+ /// An abstract input device which can be used to play games.
+ class input_device
+ {
+ public:
+ virtual ~input_device() = default;
+
+ input_device(input_device const&) = delete;
+ input_device(input_device&&) = delete;
+ auto operator=(input_device const&) -> input_device& = delete;
+ auto operator=(input_device&&) -> input_device& = delete;
+
+ virtual auto read_key_up() -> bool = 0;
+ virtual auto read_key_down() -> bool = 0;
+ virtual auto read_key_left() -> bool = 0;
+ virtual auto read_key_right() -> bool = 0;
+ virtual auto read_key_a() -> bool = 0;
+ virtual auto read_key_b() -> bool = 0;
+ virtual auto read_key_select() -> bool = 0;
+ virtual auto read_key_start() -> bool = 0;
+
+ auto read_mask() -> button_mask
+ {
+ auto res = button_mask{};
+ if (read_key_up()) { res.add(buttons::up); }
+ if (read_key_down()) { res.add(buttons::down); }
+ if (read_key_left()) { res.add(buttons::left); }
+ if (read_key_right()) { res.add(buttons::right); }
+ if (read_key_a()) { res.add(buttons::a); }
+ if (read_key_b()) { res.add(buttons::b); }
+ if (read_key_select()) { res.add(buttons::select); }
+ if (read_key_start()) { res.add(buttons::start); }
+ return res;
+ }
+
+ protected:
+ explicit input_device() = default;
+ };
+} // namespace nes \ No newline at end of file