galaxy 1.0.0
Real-Time C++23 Game Programming Framework. Built on data-driven design principles and agile software engineering.
Loading...
Searching...
No Matches
Loader.cpp
Go to the documentation of this file.
1
7
8#include <BS_thread_pool.hpp>
9#include <zip.h>
10
12#include "galaxy/core/ServiceLocator.hpp"
13#include "galaxy/core/Window.hpp"
15#include "galaxy/graphics/Renderer.hpp"
16#include "galaxy/input/Input.hpp"
17#include "galaxy/media/AudioEngine.hpp"
26
27#include "Loader.hpp"
28
29using namespace std::chrono_literals;
30
31namespace galaxy
32{
33 namespace core
34 {
36 {
37 }
38
40 {
41 }
42
44 {
45 auto& tp = ServiceLocator<BS::thread_pool>::ref();
46 auto& config = ServiceLocator<Config>::ref();
47 auto& nui = ServiceLocator<ui::NuklearUI>::ref();
48
49 nk_size current = 0;
50 constexpr const nk_size total = 11;
51
52 tp.detach_task([this]() -> void {
53 this->load_user_config();
54 });
55
56 tp.detach_task([this]() -> void {
57 this->load_window();
58 });
59
61
62 do
63 {
64 current = total - tp.get_tasks_total();
65
66 nui.poll_input();
67
68 graphics::Renderer::ref().begin_default();
69 graphics::Renderer::ref().clear_active();
70
71 nui.new_frame();
72 nui.show_loading_bar("Loading Assets...", total, current);
73 nui.render();
74
75 graphics::Renderer::ref().end_default();
76 std::this_thread::sleep_for(1ms);
77 } while (tp.get_tasks_total() > 0);
78
79 nui.poll_input();
80 nui.new_frame();
81 nui.show_building_atlas();
82
83 graphics::Renderer::ref().begin_default();
84 graphics::Renderer::ref().clear_active();
85 nui.render();
86 graphics::Renderer::ref().end_default();
87
89 }
90
92 {
93 auto& tp = ServiceLocator<BS::thread_pool>::ref();
94
95 tp.detach_task([]() -> void {
96 ServiceLocator<resource::SoundCache>::ref().load_folder(GALAXY_SFX_DIR);
97 });
98
99 tp.detach_task([]() -> void {
100 ServiceLocator<resource::MusicCache>::ref().load_folder(GALAXY_MUSIC_DIR);
101 });
102
103 tp.detach_task([]() -> void {
104 ServiceLocator<resource::VoiceCache>::ref().load_folder(GALAXY_VOICE_DIR);
105 });
106
107 tp.detach_task([]() -> void {
108 ServiceLocator<resource::VideoCache>::ref().load_folder(GALAXY_VIDEO_DIR);
109 });
110
111 tp.detach_task([]() -> void {
112 ServiceLocator<resource::Animations>::ref().load_folder(GALAXY_ANIM_DIR);
113 });
114
115 tp.detach_task([]() -> void {
116 ServiceLocator<resource::Shaders>::ref().load_folder(GALAXY_SHADER_DIR);
117 });
118
119 tp.detach_task([]() -> void {
120 ServiceLocator<resource::Fonts>::ref().load_folder(GALAXY_FONT_DIR);
121 });
122
123 tp.detach_task([]() -> void {
124 ServiceLocator<resource::Scripts>::ref().load_folder(GALAXY_SCRIPT_DIR);
125 });
126
127 tp.detach_task([]() -> void {
128 ServiceLocator<resource::Prefabs>::ref().load_folder(GALAXY_PREFABS_DIR);
129 });
130 }
131
133 {
134 auto& config = core::ServiceLocator<core::Config>::ref();
135 auto& window = core::ServiceLocator<core::Window>::ref();
136
137 input::CameraKeys::FORWARD = input::int_to_key(config.get<int>("camera_foward", "input"));
138 input::CameraKeys::BACKWARD = input::int_to_key(config.get<int>("camera_backward", "input"));
139 input::CameraKeys::LEFT = input::int_to_key(config.get<int>("camera_left", "input"));
140 input::CameraKeys::RIGHT = input::int_to_key(config.get<int>("camera_right", "input"));
141 input::CameraKeys::ROTATE_LEFT = input::int_to_key(config.get<int>("camera_rotate_left", "input"));
142 input::CameraKeys::ROTATE_RIGHT = input::int_to_key(config.get<int>("camera_rotate_right", "input"));
143
144 auto& se = core::ServiceLocator<media::SoundEngine>::ref();
145 auto& me = core::ServiceLocator<media::MusicEngine>::ref();
146 auto& de = core::ServiceLocator<media::VoiceEngine>::ref();
147
148 se.set_volume(config.get<float>("sfx_volume", "audio"));
149 me.set_volume(config.get<float>("music_volume", "audio"));
150 de.set_volume(config.get<float>("dialogue_volume", "audio"));
151 }
152
154 {
155 auto& config = core::ServiceLocator<core::Config>::ref();
156 auto& window = core::ServiceLocator<core::Window>::ref();
157
158 auto icon = config.get<std::string>("icon", "window");
159 window.set_icon(icon);
160
161 auto& cursor = window.get_input<input::Cursor>();
162 cursor.toggle(config.get<bool>("visible_cursor", "window"));
163
164 auto cursor_icon = config.get<std::string>("cursor_icon", "window");
165 if (!cursor_icon.empty())
166 {
167 cursor.load_custom(cursor_icon);
168 cursor.use_custom_else_pointer();
169 }
170 else
171 {
172 cursor.use_pointer();
173 }
174 }
175
177 {
178 auto& shaders = core::ServiceLocator<resource::Shaders>::ref();
179
180 auto rtt = std::make_unique<graphics::Shader>();
182 {
183 shaders.insert("render_to_texture", rtt);
184 }
185
186 for (const auto& [key, value] : shaders.cache())
187 {
188 value->compile();
189 }
190
191 for (const auto& [key, value] : core::ServiceLocator<resource::Fonts>::ref().cache())
192 {
193 value->build();
194 }
195
196 for (auto&& [key, value] : core::ServiceLocator<resource::VideoCache>::ref().cache())
197 {
198 value->build();
199 }
200
201 auto& tex = ServiceLocator<resource::Textures>::ref();
202 tex.load_folder(GALAXY_TEXTURE_DIR);
203 for (auto&& [key, value] : tex.cache())
204 {
205 value->make_bindless();
206 }
207 }
208 } // namespace core
209} // namespace galaxy
void load_resources()
Load game resources.
Definition Loader.cpp:91
~Loader()
Destructor.
Definition Loader.cpp:39
void build_resources()
Builds opengl resources on the main thread.
Definition Loader.cpp:176
void load_all()
Loads resources, user config and window settings.
Definition Loader.cpp:43
void load_user_config()
Only loads user config.
Definition Loader.cpp:132
Loader()
Constructor.
Definition Loader.cpp:35
void load_window()
Only loads the window settings.
Definition Loader.cpp:153
constexpr const auto render_texture_shader_frag
Render To Texture fragment shader.
constexpr const auto render_texture_shader_vert
Render To Texture vertex shader.
Timer.hpp galaxy.
Definition Async.hpp:17