sandbox
Loading...
Searching...
No Matches
devices_module.hpp
1#ifndef LIBSBX_DEVICES_DEVICES_MODULE_HPP_
2#define LIBSBX_DEVICES_DEVICES_MODULE_HPP_
3
4#include <cinttypes>
5
6#include <memory>
7#include <vector>
8#include <unordered_map>
9
10#include <fmt/format.h>
11
12#include <GLFW/glfw3.h>
13
14#include <libsbx/core/module.hpp>
15#include <libsbx/core/engine.hpp>
16
17#include <libsbx/units/time.hpp>
18
19#include <libsbx/memory/aligned_storage.hpp>
20
21#include <libsbx/devices/window.hpp>
22#include <libsbx/devices/input.hpp>
23
24namespace sbx::devices {
25
26class devices_module final : public core::module<devices_module> {
27
28 inline static const auto is_registered = register_module(stage::pre);
29
30public:
31
33 if (!glfwInit()) {
34 throw std::runtime_error{"Could not initialize glfw"};
35 }
36
37 if (!glfwVulkanSupported()) {
38 throw std::runtime_error{"Glfw does not support vulkan"};
39 }
40
41 // _window = std::make_unique<devices::window>(window_create_info{"Demo", 1280, 720});
42 // std::construct_at(std::launder(reinterpret_cast<devices::window*>(&_window)), window_create_info{"Demo", 1280, 720});
43 // _window.construct(window_create_info{"Demo", 1280, 720});
44 _window.construct(window_create_info{"Demo", 1280, 720});
45 }
46
47 ~devices_module() override {
48 _window.destroy();
49
50 glfwTerminate();
51 }
52
53 auto update() -> void override {
54 input::_transition_pressed_keys();
55 input::_transition_pressed_mouse_buttons();
56 input::_transition_scroll_delta();
57
58 glfwPollEvents();
59 }
60
61 auto window() -> devices::window& {
62 return *_window;
63 }
64
65 auto required_instance_extensions() const -> std::vector<const char*> {
66 auto extension_count = std::uint32_t{0};
67 auto extensions = glfwGetRequiredInstanceExtensions(&extension_count);
68
69 return std::vector<const char*>{extensions, extensions + extension_count};
70 }
71
72private:
73
75
76}; // class devices_module
77
78} // namespace sbx::devices
79
80#endif // LIBSBX_DEVICES_DEVICES_MODULE_HPP_
Definition: module.hpp:72
Definition: devices_module.hpp:26
Definition: window.hpp:33
A class that allows for the manual construction and destruction of an object of type Type.
Definition: aligned_storage.hpp:40
Definition: window.hpp:27