Fling Engine  0.00.1
Fling Engine is a game engine written in Vulkan
Input.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "NonCopyable.hpp"
4 #include "Input/Key.h"
5 
6 namespace Fling
7 {
11  struct MousePos
12  {
13  float X;
14  float Y;
15  };
16 
20  class Input : public NonCopyable
21  {
22  public:
23 
25  static void Init() { m_Instace->InitImpl(); }
26 
31  static void Shutdown()
32  {
33  m_Instace->ShutdownImpl();
34  delete m_Instace;
35  }
36 
40  static void Poll() { m_Instace->PollImpl(); }
41 
42  static bool IsKeyDown(const std::string& t_KeyName) { return m_Instace->IsKeyDownImpl(t_KeyName); }
43  static bool IsKeyHeld(const std::string& t_KeyName) { return m_Instace->IsKeyHelpImpl(t_KeyName); }
44 
45  static bool IsMouseButtonPressed(const std::string& t_KeyName) { return m_Instace->IsMouseButtonPressedImpl(t_KeyName); }
46  static bool IsMouseDown(const std::string& t_KeyName) { return m_Instace->IsMouseDownImpl(t_KeyName); }
47 
48 
52  static MousePos GetMousePos() { return m_Instace->GetMousePosImpl(); }
53 
54  typedef std::map<std::string, Fling::Key> KeyMap;
55  typedef std::pair<std::string, Fling::Key> KeyPair;
56 
57  protected:
58 
60  static KeyMap m_KeyMap;
61 
63  static Input* m_Instace;
64 
71  static void AddKeyMap(const std::string& t_Name, UINT32 t_KeyCode)
72  {
73  m_KeyMap.insert( KeyPair(t_Name, Fling::Key(t_Name, t_KeyCode)) );
74  }
75 
76  virtual void InitImpl() = 0;
77  virtual void ShutdownImpl() = 0;
78 
80  virtual void PollImpl() = 0;
81 
82  virtual void InitKeyMap() = 0;
83 
84  virtual bool IsKeyDownImpl(const std::string& t_KeyName) = 0;
85  virtual bool IsKeyHelpImpl(const std::string& t_KeyName) = 0;
86 
87  virtual bool IsMouseButtonPressedImpl(const std::string& t_KeyName) = 0;
88  virtual bool IsMouseDownImpl(const std::string& t_KeyName) = 0;
89  virtual MousePos GetMousePosImpl() = 0;
90  };
91 
92 } // namespace Fling
static void Shutdown()
Shuts down input manager.
Definition: Input.h:31
static Input * m_Instace
Created by the implementation class.
Definition: Input.h:63
represents the current mouse position in screen space
Definition: Input.h:11
static bool IsMouseDown(const std::string &t_KeyName)
Definition: Input.h:46
static bool IsKeyHeld(const std::string &t_KeyName)
Definition: Input.h:43
static void Init()
Initialize the input instance on this platform.
Definition: Input.h:25
float Y
Definition: Input.h:14
Base input class for polling input in the Fling Engine.
Definition: Input.h:20
static bool IsKeyDown(const std::string &t_KeyName)
Definition: Input.h:42
Definition: Key.h:9
Class that removes the copy operator and constructor.
Definition: NonCopyable.hpp:10
static KeyMap m_KeyMap
The actual key map.
Definition: Input.h:60
static bool IsMouseButtonPressed(const std::string &t_KeyName)
Definition: Input.h:45
static MousePos GetMousePos()
Get the current mouse position in screen space.
Definition: Input.h:52
std::pair< std::string, Fling::Key > KeyPair
Definition: Input.h:55
std::map< std::string, Fling::Key > KeyMap
Definition: Input.h:54
uint32_t UINT32
Definition: FlingTypes.h:10
Definition: Engine.h:13
float X
Definition: Input.h:13
static void AddKeyMap(const std::string &t_Name, UINT32 t_KeyCode)
Add a key mapping to this platform.
Definition: Input.h:71
static void Poll()
Update any input polling that needs to happen on this platform.
Definition: Input.h:40