FastEngine 0.9.3
A multiplayer oriented 2D engine made with Vulkan.
Loading...
Searching...
No Matches
C_event.hpp
1/*
2 * Copyright 2024 Guillaume Guillet
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef _FGE_C_EVENT_HPP_INCLUDED
18#define _FGE_C_EVENT_HPP_INCLUDED
19
20#include "FastEngine/fge_extern.hpp"
21#include "C_vector.hpp"
22#include "FastEngine/C_callback.hpp"
23#include "SDL_events.h"
24
25#define FGE_EVENT_KEYCODES_SIZE 12
26#define FGE_EVENT_DEFAULT_MAXEVENTCOUNT 20
27
28namespace fge
29{
30
31class RenderWindow;
32
33namespace vulkan
34{
35
36class SurfaceWindow;
37
38} // namespace vulkan
39
40namespace net
41{
42
43class Packet;
44
45} // namespace net
46
58class FGE_API Event
59{
60public:
61 Event() = default;
68 explicit Event(fge::Vector2i const& windowSize, fge::Vector2i const& windowPosition) :
69 g_windowSize(windowSize),
70 g_windowPosition(windowPosition)
71 {}
77#ifndef FGE_DEF_SERVER
78 explicit Event(fge::vulkan::SurfaceWindow const& surfaceWindow);
79 explicit Event(fge::RenderWindow const& renderWindow);
80#endif //FGE_DEF_SERVER
81 ~Event() = default;
82
86 void clear();
87
99 void start();
100#ifndef FGE_DEF_SERVER
110 void process(SDL_Event const& evt);
119 void process(unsigned int maxEventCount = FGE_EVENT_DEFAULT_MAXEVENTCOUNT);
120#endif //FGE_DEF_SERVER
121
122 void pushType(SDL_EventType type);
123 void popType(SDL_EventType type);
124
131 bool isKeyPressed(uint32_t keycode) const;
137 uint32_t getKeyUnicode() const;
138
144 fge::Vector2i const& getWindowSize() const;
150 fge::Vector2i const& getWindowPos() const;
151
158 bool isEventType(uint32_t type) const;
159
165 fge::Vector2i const& getMousePixelPos() const;
172 bool isMouseButtonPressed(uint8_t mouseButton) const;
173
186
201
207 std::string getBinaryKeysString() const;
213 std::string getBinaryTypesString() const;
219 std::string getBinaryMouseButtonsString() const;
220
221 //Callbacks
223
230
233
239
244
252
259
263
267
269
274
277
280
281private:
282 static uint64_t EventTypeToBitMask(uint32_t type);
283 static std::size_t KeycodeToBitIndex(uint32_t keyCode);
284 static uint32_t UTF8ToUTF32(char const* utf8);
285
286 //Event type
287 uint64_t g_types = 0;
288
289 //Keyboard
290 uint32_t g_keyCodes[FGE_EVENT_KEYCODES_SIZE] = {0};
291 uint32_t g_keyUnicode = 0;
292
293 //Mouse
294 fge::Vector2i g_mouseRelativeMotion = {0, 0};
295 fge::Vector2i g_mousePixelPosition = {0, 0};
296 uint8_t g_mouseButtons = 0;
297
298 int g_mouseWheelHorizontalDelta = 0;
299 int g_mouseWheelVerticalDelta = 0;
300
301 //Window size
302 fge::Vector2i g_windowSize;
303 fge::Vector2i g_windowPosition;
304};
305
306} // namespace fge
307
308#endif // _FGE_C_EVENT_HPP_INCLUDED
This class is used to handle callbacks in a safe way.
Definition C_callback.hpp:189
This class is a wrapper for SDL events.
Definition C_event.hpp:59
std::string getBinaryTypesString() const
Get a binary representation of all SDL event types into a string.
std::string getBinaryMouseButtonsString() const
Get a binary representation of all mouse buttons into a string.
bool isKeyPressed(uint32_t keycode) const
Check if a key is pressed.
bool isMouseButtonPressed(uint8_t mouseButton) const
Check if the specified mouse button is pressed.
std::string getBinaryKeysString() const
Get a binary representation of all keys into a string.
bool isEventType(uint32_t type) const
Check if the specified SDL event is active.
void clear()
Clear all the events.
void popType(SDL_EventType type)
TODO: add comments.
void start()
Start the event loop.
fge::Vector2i const & getWindowPos() const
Get the window position.
fge::Vector2i const & getMousePixelPos() const
Get the mouse pixel position.
uint32_t getKeyUnicode() const
Get the unicode of the last key pressed.
Event(fge::Vector2i const &windowSize, fge::Vector2i const &windowPosition)
Constructor to apply to size of the window and the position.
Definition C_event.hpp:68
fge::Vector2i const & getWindowSize() const
Get the window size.
int getMouseWheelHorizontalDelta() const
Get the horizontal mouse wheel delta.
fge::net::Packet & unpack(fge::net::Packet &pck)
Unpack events data from a network packet.
fge::net::Packet & pack(fge::net::Packet &pck)
Pack events data into a network packet.
void process(unsigned int maxEventCount=20)
Process automatically SDL events.
Event(fge::vulkan::SurfaceWindow const &surfaceWindow)
Constructor to apply window data.
void process(SDL_Event const &evt)
Process an SDL event.
int getMouseWheelVerticalDelta() const
Get the vertical mouse wheel delta.
Definition C_renderWindow.hpp:51
Definition C_packet.hpp:70
Vulkan OS window surface.
Definition vulkan/C_surface.hpp:97