Nymph Game Engine
Chaiscript based Game Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
input_system.h
Go to the documentation of this file.
1 #ifndef INPUT_SYSTEM_H
2 #define INPUT_SYSTEM_H
3 #include <glm/glm.hpp>
4 #include <map>
5 #include <queue>
6 #include <GLFW/glfw3.h>
7 #include "events/subject.h"
8 #include "events/observer.h"
9 #include "events/event.h"
10 //= SCRIPTABLE
11 //= SCRIPTABLE BASES Subject Observer
12 
13 namespace Input {
17  class InputSystem : public Events::Subject, public Events::Observer {
18  private:
19  static std::map<int, int> keys_to_actions;
20  static std::map<int, int> mouse_buttons_to_actions;
21  static glm::dvec2 cursor_position;
22  static glm::dvec2 scroll_offset;
23  static bool cursor_entered;
24  static bool cursor_left;
25  static std::queue<unsigned char> character_typed_buffer;
26  static bool key_input_suspended;
27 
28  std::map<int, int> last_keys_to_actions;
29  std::map<int, int> last_mouse_buttons_to_actions;
30 
31  glm::mat4 camera_transform_matrix;
32  glm::mat4 projection_matrix;
33  int window_width;
34  int window_height;
35  float viewport_width;
36  float viewport_height;
37 
38  static void keyCallback(GLFWwindow* window, int key, int scan_code, int action, int mods);
39  static void characterCallback(GLFWwindow* window, unsigned int key);
40  static void cursorPositionCallback(GLFWwindow* window, double x_pos, double y_pos);
41  static void cursorEnterCallback(GLFWwindow* window, int entered);
42  static void mouseButtonCallback(GLFWwindow* window, int button, int action, int mods);
43  static void mouseScrollCallback(GLFWwindow* window, double x_offset, double y_offset);
44  public:
45  virtual ~InputSystem() = default;
46 
56  InputSystem(GLFWwindow* window, float viewport_width, float viewport_height, glm::mat4 camera_transform_matrix, glm::mat4 projection_matrix);
60  void pollForInput();
61 
62  virtual void onNotifyNow(std::shared_ptr<Events::Event> event) override;
63  virtual void handleQueuedEvent(std::shared_ptr<Events::Event> event) override;
64  //= BEGIN SCRIPTABLE
65  void dummy() {}
66  //= END SCRIPTABLE
67  };
68 }
69 
70 #endif
InputSystem(GLFWwindow *window, float viewport_width, float viewport_height, glm::mat4 camera_transform_matrix, glm::mat4 projection_matrix)
Constructor for input system.
Definition: input_system.cpp:26
void pollForInput()
Polls glfw for new input.
Definition: input_system.cpp:40
Class for a subject that an observer would observe for changes.
Definition: subject.h:13
Interface to be notified of an item's changes.
Definition: observer.h:13
virtual void handleQueuedEvent(std::shared_ptr< Events::Event > event) override
HandleQueuedEvent allows derived classes to define behaviour for when queuedEvents are received...
Definition: input_system.cpp:134
Class for input system.
Definition: input_system.h:17
void dummy()
Definition: input_system.h:65
virtual ~InputSystem()=default
virtual void onNotifyNow(std::shared_ptr< Events::Event > event) override
When receiving an event that is immediate, onNotifyNow is used. It acts as an interrupt to make sure ...
Definition: input_system.cpp:130