| 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 #include <entt/signal/delegate.hpp>
6 #include <entt/signal/sigh.hpp>
7
8 namespace Fling
9 {
13 struct MousePos
14 {
15 float X;
16 float Y;
17 };
18
22 class Input : public NonCopyable
23 {
24 public:
25
27 static void Init() { m_Instance->InitImpl(); }
28
33 static void PreUpdate() { m_Instance->PreUpdateImpl(); };
34
39 static void Shutdown()
40 {
41 m_Instance->ShutdownImpl();
42 delete m_Instance;
43 }
44
48 static void Poll() { m_Instance->PollImpl(); }
49
50 static bool IsKeyDown(const std::string& t_KeyName) { return m_Instance->IsKeyDownImpl(t_KeyName); }
51 static bool IsKeyHeld(const std::string& t_KeyName) { return m_Instance->IsKeyHelpImpl(t_KeyName); }
52
53 static bool IsMouseButtonPressed(const std::string& t_KeyName) { return m_Instance->IsMouseButtonPressedImpl(t_KeyName); }
54 static bool IsMouseDown(const std::string& t_KeyName) { return m_Instance->IsMouseDownImpl(t_KeyName); }
55
59 static MousePos GetMousePos() { return m_Instance->GetMousePosImpl(); }
60
70 template<auto Candidate, typename Type>
71 static void BindKeyPress(const std::string& t_KeyName, Type& t_Instance);
72
74 typedef std::map<std::string, Fling::Key> KeyMap;
75 typedef std::pair<std::string, Fling::Key> KeyPair;
76
78 typedef std::map<std::string, entt::delegate<void()>> KeyDownMap;
79 typedef std::pair<std::string, entt::delegate<void()>> KeyDownMapPair;
80
81 protected:
82
84 static KeyMap m_KeyMap;
85
86 static KeyDownMap m_KeyDownMap;
87
89 static Input* m_Instance;
90
97 static void AddKeyMap(const std::string& t_Name, UINT32 t_KeyCode)
98 {
99 m_KeyMap.insert( KeyPair(t_Name, Fling::Key(t_Name, t_KeyCode)) );
100 }
101
102 virtual void InitImpl() = 0;
103 virtual void PreUpdateImpl() = 0;
104 virtual void ShutdownImpl() = 0;
105
107 virtual void PollImpl() = 0;
108
109 virtual void InitKeyMap() = 0;
110
111 virtual bool IsKeyDownImpl(const std::string& t_KeyName) = 0;
112 virtual bool IsKeyHelpImpl(const std::string& t_KeyName) = 0;
113
114 virtual bool IsMouseButtonPressedImpl(const std::string& t_KeyName) = 0;
115 virtual bool IsMouseDownImpl(const std::string& t_KeyName) = 0;
116 virtual MousePos GetMousePosImpl() = 0;
117 };
118
119 } // namespace Fling
120
121 #include "Input.inl"
Fling::Input::Shutdown
static void Shutdown()
Shuts down input manager.
Definition: Input.h:39
Fling::MousePos
represents the current mouse position in screen space
Definition: Input.h:13
Fling::Input::IsMouseDown
static bool IsMouseDown(const std::string &t_KeyName)
Definition: Input.h:54
Fling::Input::m_KeyDownMap
static KeyDownMap m_KeyDownMap
Definition: Input.h:86
Fling::Input::IsKeyHeld
static bool IsKeyHeld(const std::string &t_KeyName)
Definition: Input.h:51
Key.h
Fling::Input::PreUpdate
static void PreUpdate()
PreUpdate is called before polling of input, and after Init.
Definition: Input.h:33
Fling::Input::Init
static void Init()
Initialize the input instance on this platform.
Definition: Input.h:27
Fling::Input::KeyDownMap
std::map< std::string, entt::delegate< void()> > KeyDownMap
Key press delegate mappings.
Definition: Input.h:78
Fling::MousePos::Y
float Y
Definition: Input.h:16
NonCopyable.hpp
Fling::Input::m_Instance
static Input * m_Instance
Created by the implementation class.
Definition: Input.h:89
Fling::Input
Base input class for polling input in the Fling Engine.
Definition: Input.h:22
Fling::Input::IsKeyDown
static bool IsKeyDown(const std::string &t_KeyName)
Definition: Input.h:50
Fling::Key
Definition: Key.h:9
Fling::NonCopyable
Class that removes the copy operator and constructor.
Definition: NonCopyable.hpp:10
Fling::Input::m_KeyMap
static KeyMap m_KeyMap
The actual key map.
Definition: Input.h:84
Fling::Input::IsMouseButtonPressed
static bool IsMouseButtonPressed(const std::string &t_KeyName)
Definition: Input.h:53
Fling::Input::GetMousePos
static MousePos GetMousePos()
Get the current mouse position in screen space.
Definition: Input.h:59
Fling::Input::KeyPair
std::pair< std::string, Fling::Key > KeyPair
Definition: Input.h:75
Fling::Input::KeyMap
std::map< std::string, Fling::Key > KeyMap
Input Key mappings.
Definition: Input.h:74
Input.inl
UINT32
uint32_t UINT32
Definition: FlingTypes.h:13
Fling::Input::KeyDownMapPair
std::pair< std::string, entt::delegate< void()> > KeyDownMapPair
Definition: Input.h:79
Fling
Definition: Engine.h:29
Fling::MousePos::X
float X
Definition: Input.h:15
Fling::Input::AddKeyMap
static void AddKeyMap(const std::string &t_Name, UINT32 t_KeyCode)
Add a key mapping to this platform.
Definition: Input.h:97
Fling::Input::Poll
static void Poll()
Update any input polling that needs to happen on this platform.
Definition: Input.h:48