AnnEventManager.hpp
Go to the documentation of this file.
1 
7 #pragma once
8 
9 #include "systemMacro.h"
10 
11 #include <array>
12 #include <memory>
13 #include <valarray>
14 
15 #include "AnnKeyCode.h"
16 #include "AnnSubsystem.hpp"
17 #include "AnnEvents.hpp"
19 #include "AnnTextInputer.hpp"
20 #include "AnnEventListener.hpp"
21 
23 #define LISTENER \
24 public \
25  Annwvyn::AnnEventListener
26 
28 #define constructListener() AnnEventListener()
29 
30 namespace Annwvyn
31 {
32  class AnnEngine;
33  class AnnDefaultEventListener;
34 
35  //The event manager handles all events that can occur during the gameplay loop. The private 'update()' method is called by
36  //AnnEngine and provide the heartbeat for the event system.
37  //Events can be user inputs or mostly anything else.
38  //AnnEventManager creates AnnEvent (or subclass of AnnEvent) for each kind of event, populate that object with relevant event data
39  //And propagate that event to any declared event listener.
40  //Listeners should subclass AnnEventListener. A listener is registered when a pointer to it is passed as argument to the addListener() method.
41  //You'll crash the engine if you destroy a listener without removing it from the EventManager (the EM will dereference an non-existing pointer)
42 
45  {
46  public:
48  AnnEventManager(Ogre::RenderWindow* w);
50  ~AnnEventManager();
51 
52  //---------------------------- listener management
60  void useDefaultEventListener();
62  AnnEventListenerPtr getDefaultEventListener() const;
65  void addListener(AnnEventListenerPtr listener);
66 
68  template <class ListenerType, class... Args>
69  decltype(auto) addListener(Args&&... args)
70  {
71  auto listener = std::make_shared<ListenerType>(args...);
72  addListener(listener);
73  return listener;
74  }
75 
78  void clearListenerList();
81  void removeListener(AnnEventListenerPtr listener = nullptr);
82  //---------------------------- listener management
83 
84  //---------------------------- timer management
86  AnnTimerID fireTimer(double delay);
88  AnnTimerID fireTimerMillisec(double millisecDelay);
89  //---------------------------- timer management
90 
91  //---------------------------- other
93  size_t getControllerCount() const;
95  AnnTextInputer* getTextInputer() const;
97  void keyboardUsedForText(bool state = true);
98  //---------------------------- other
99 
100  OIS::InputManager* _getOISInputManager() const;
101 
102  private:
107 
108  friend class AnnEngine;
109  friend class AnnPhysicsEngine;
111 
113  void userSpaceDispatchEvent(AnnUserSpaceEventPtr e, AnnUserSpaceEventLauncher* sender);
115  void update() override;
117  void captureEvents();
119  void processKeyboardEvents();
121  void processMouseEvents();
123  void processJoystickEvents();
125  void processHandControllerEvents();
127  void pushEventsToListeners();
129  void processInput();
131  void processTimers();
133  void processTriggerEvents();
135  void processCollisionEvents();
137  void processUserSpaceEvents();
139  void detectedCollision(void* a, void* b, AnnVect3 worldPosition, AnnVect3 normalOnB);
141  void playerCollision(void* object);
142 
151 
152  //----------------------- OIS and other library input objects
154  OIS::InputManager* InputManager;
156  OIS::Keyboard* Keyboard;
158  OIS::Mouse* Mouse;
161  //----------------------- OIS and other library input objects
162 
163  //----------------------- PREVIOUS STATE FOR EVENT DETECTION FROM UNBUFFERED STATE
168  //----------------------- PREVIOUS STATE FOR EVENT DETECTION FROM UNBUFFERED STATE
169 
170  //----------------------- TIMER MANAGEMENT
179  //----------------------- TIMER MANAGEMENT
180 
181  //----------------------- COLLISION MANAGEMENT
186  //----------------------- COLLISION MANAGEMENT
187 
196 
198  bool knowXbox;
201  };
202 
204 }
file for defining macros used for symbol export regarding the way the OS does things.
std::vector< AnnControllerBuffer > Joysticks
Array of poiners to OIS Joystick.
std::vector< std::pair< AnnUserSpaceEventPtr, AnnUserSpaceEventLauncher * > > userSpaceEventBuffer
Using a shared ptr to keep ownership of the event object until the event is dealt with...
int AnnTimerID
Definition: AnnEvents.hpp:339
Class that can send a user space event to the event manager.
std::shared_ptr< AnnDefaultEventListener > defaultEventListener
Default event listener.
Main engine class. Creating an instance of this class make the engine start.
Definition: AnnEngine.hpp:70
Class that abstract the physics engine initialization and collision information queries for Annwvyn...
A 3D Vector.
Definition: AnnVect3.hpp:16
ControllerID xboxID
ID of an eventual Xbox controller.
Namespace containing the totality of Annwvyn components.
Definition: AnnGetter.cpp:8
Translation of OIS keys code to Annwvyn KeyCode.
std::vector< AnnTriggerEvent > triggerEventBuffer
List of trigger event to process.
std::vector< AnnHandControllerEvent > handControllerEventBuffer
Buffer of hand controller events.
bool keyboardIgnore
True if keyboard event should be ignored (keyboard used for "text input")
std::vector< AnnKeyEvent > keyEventBuffer
Buffer of keyboard events.
std::unique_ptr< AnnTextInputer > textInputer
The text inputer object itself.
std::array< bool, KeyCode::SIZE > previousKeyStates
Array for remembering the key states at last update.
int ControllerID
Definition: AnnEvents.hpp:157
AnnTimerID lastTimerCreated
Dynamically sized array for remembering the joystick button state at last update. ...
OIS::Keyboard * Keyboard
Pointer that holds the keyboard.
std::vector< AnnTimer > futureTimers
List of timer that will timeout in a future frame.
Parent class of all Annwvyn SubSystem.
std::array< bool, ButtonCount > previousMouseButtonStates
Array for remembering the button states at last update.
std::vector< AnnControllerEvent > stickEventBuffer
Buffer of stick events.
This class permit to get text input from the keyboard.
OIS::Mouse * Mouse
Pointer that holds the Mouse.
std::vector< std::tuple< void *, void *, AnnVect3, AnnVect3 > > collisionBuffers
Collision reported by the physics engine to consider.
std::vector< AnnMouseEvent > mouseEventBuffer
Buffer of mouse events.
bool knowXbox
True if we detected an xbox controller.
#define AnnDllExport
Definition: systemMacro.h:24
std::vector< AnnGameObject * > playerCollisionBuffer
Player collision reported by the physics engine to consider.
OIS::InputManager * InputManager
OIS Event Manager.
std::vector< AnnEventListenerWeakPtr > listeners
std::vector< AnnTimer > activeTimers
List of timers.
Event Manager : Object that handle the event system.