sandbox
Loading...
Searching...
No Matches
scenes_module.hpp
1// SPDX-License-Identifier: MIT
2#ifndef LIBSBX_SCENES_SCENE_MODULE_HPP_
3#define LIBSBX_SCENES_SCENE_MODULE_HPP_
4
5#include <memory>
6#include <optional>
7#include <utility>
8#include <filesystem>
9
10#include <libsbx/memory/tracking_allocator.hpp>
11
12#include <libsbx/math/vector4.hpp>
13#include <libsbx/math/color.hpp>
14
15#include <libsbx/core/module.hpp>
16
17#include <libsbx/scenes/scene.hpp>
18
19namespace sbx::scenes {
20
21class scenes_module final : public core::module<scenes_module> {
22
23 friend class scene;
24
25 inline static const auto is_registered = register_module(stage::normal);
26
27public:
28
29 struct line {
30 sbx::math::vector4 position;
31 sbx::math::color color;
32 }; // struct line
33
35
36 ~scenes_module() override;
37
38 auto update() -> void override;
39
40 auto load_scene(const std::filesystem::path& path) -> scenes::scene&;
41
42 auto scene() -> scenes::scene&;
43
44 auto save_scene(const std::filesystem::path& path) -> void {
45 if (_scene) {
46 _scene->save(path);
47 }
48 }
49
50 template<typename Type, std::invocable<YAML::Node&, const Type&> Save, std::invocable<YAML::Node&> Load>
51 auto register_component(const std::string& name, Save&& save, Load&& load) -> void {
52 _component_io_registry.register_component<Type>(name, std::forward<Save>(save), std::forward<Load>(load));
53 }
54
55 auto component_io(const std::uint32_t id) -> component_io&;
56
57 auto has_component_io(const std::uint32_t id) -> bool;
58
59 auto debug_lines() const -> const std::vector<line>&;
60
61 auto clear_debug_lines() -> void;
62
63 auto add_debug_line(const sbx::math::vector3& start, const sbx::math::vector3& end, const sbx::math::color& color) -> void;
64
65 auto add_coordinate_arrows(const math::matrix4x4& transform, std::float_t length = 2.0f) -> void;
66
67 auto add_debug_plane(const sbx::math::vector3& origin, const sbx::math::vector3& v1, const sbx::math::vector3& v2, std::uint32_t n1, std::uint32_t n2, std::float_t s1, std::float_t s2, const sbx::math::color& color, const sbx::math::color& outline) -> void;
68
69 auto add_debug_volume(const math::matrix4x4& matrix, const math::volume& volume, const sbx::math::color& color) -> void;
70
71 auto add_debug_box(const math::matrix4x4& matrix, const math::volume& volume, const sbx::math::color& color) -> void;
72
73 auto add_debug_circle(const math::vector3& center, const std::float_t radius, const math::vector3& normal, const math::color& color, const std::uint32_t segments = 32) -> void;
74
75 auto add_debug_sphere(const math::vector3& center, const std::float_t radius, const math::color& color, const std::uint32_t segments = 32) -> void;
76
77 auto add_debug_frustum(const math::matrix4x4& view, const math::matrix4x4& projection, const sbx::math::color& color) -> void;
78
79private:
80
81 std::optional<scenes::scene> _scene;
82
83 component_io_registry _component_io_registry;
84
85 std::vector<line> _debug_lines{};
86
87}; // class scene_modules
88
89} // namespace sbx::scenes
90
91#endif // LIBSBX_SCENES_SCENE_MODULE_HPP_
Definition: module.hpp:92
Definition: vector4.hpp:24
RGBA color value type.
Definition: color.hpp:48
Definition: scene.hpp:70
Definition: scenes_module.hpp:21
RGBA color representation and utilities.
Definition: scenes_module.hpp:29