ST_engine  0.3-ALPHA
input_manager.hpp
1 /* This file is part of the "ST" project.
2  * You may use, distribute or modify this code under the terms
3  * of the GNU General Public License version 2.
4  * See LICENCE.txt in the root directory of the project.
5  *
6  * Author: Maxim Atanasov
7  * E-mail: maxim.atanasov@protonmail.com
8  */
9 
10 #ifndef INPUT_DEF
11 #define INPUT_DEF
12 
13 #include <key_definitions.hpp>
14 #include <key_event.hpp>
15 #include <message_bus.hpp>
16 #include <task_manager.hpp>
17 #include <SDL_events.h>
18 #include <SDL_haptic.h>
19 
22 private:
23 
24  struct controller_analog_inputs {
25  int16_t left_trigger = 0;
26  int16_t right_trigger = 0;
27  int16_t right_stick_vertical = 0;
28  int16_t right_stick_horizontal = 0;
29  int16_t left_stick_vertical = 0;
30  int16_t left_stick_horizontal = 0;
31  };
32 
33  struct button_and_mouse_controls {
34  int32_t mouse_x = 0, mouse_y = 0;
35  int16_t mouse_scroll = 0;
36  bool *buttons{};
37  };
38  bool *keyboard_sdl_raw{};
39 
40  uint32_t v_width = 1, v_height = 1;
41  uint32_t r_width = 1, r_height = 1;
42 
43  float ratio_w = 1, ratio_h = 1;
44 
45  int16_t left_stick_horizontal_threshold = 0;
46  int16_t left_stick_vertical_threshold = 0;
47 
48  int16_t right_stick_horizontal_threshold = 0;
49  int16_t right_stick_vertical_threshold = 0;
50 
51  int16_t left_trigger_threshold = 0;
52  int16_t right_trigger_threshold = 0;
53 
54  SDL_Event event{};
55 
56  message_bus &gMessage_bus;
57  task_manager &gTask_manager;
58  subscriber msg_sub{};
59  std::vector<SDL_GameController *> controllers;
60  std::vector<SDL_Haptic *> controllers_haptic;
61  struct button_and_mouse_controls controls{};
62  struct button_and_mouse_controls controls_prev_frame;
63  struct controller_analog_inputs controller_analog_inputs;
64  struct controller_analog_inputs controller_analog_inputs_prev_frame;
65 
66  //Store ST::keys and the amount of times the have been registered as values;
67  ska::bytell_hash_map<ST::key, uint8_t> registered_keys;
68 
69  //this is where we save the text stream from our input manager
70  std::string composition;
71  bool text_input = false;
72 
73  bool key_event(ST::key, ST::key_event k_event) const;
74 
75  void handle_messages();
76 
77  void take_input();
78 
79  void take_controller_input();
80 
81  void take_mouse_input();
82 
83 #ifndef _MSC_VER
84  static void update_task(void* mngr);
85 #endif
86 
87 public:
88 
89  input_manager(task_manager &gTask_manager, message_bus &gMessageBus);
90 
91  ~input_manager();
92 
93  void update();
94 };
95 
96 #endif //INPUT_DEF
This object is responsible for taking input.
input_manager(task_manager &gTask_manager, message_bus &gMessageBus)
The central messaging system of the engine. All subsystem make extensive use of it.
Definition: message_bus.hpp:29
This class handles a small queue for messages.
Definition: subscriber.hpp:20
The Task Manager handles all things multi-threaded in the engine.