61 entt::locator<scene::SceneManager>::reset();
62 entt::locator<sol::state>::reset();
63 entt::locator<meta::EntityFactory>::reset();
64 entt::locator<meta::SystemFactory>::reset();
65 entt::locator<entt::dispatcher>::reset();
66 entt::locator<sf::RenderWindow>::reset();
67 entt::locator<fs::VirtualFileSystem>::reset();
68 entt::locator<Config>::reset();
69 entt::locator<BS::light_thread_pool>::reset();
72 entt::locator<logging::Log>::reset();
87 auto& window = entt::locator<sf::RenderWindow>::value();
88 auto& dispatcher = entt::locator<entt::dispatcher>::value();
89 auto& manager = entt::locator<scene::SceneManager>::value();
91 using clock = std::chrono::high_resolution_clock;
92 using duration = std::chrono::duration<double>;
93 using time_point = std::chrono::time_point<clock, duration>;
95 constexpr const auto one_second = std::chrono::seconds {1};
99 const auto dt = one_second / settings::ups();
100 settings::set_delta_time(dt / one_second);
103 duration elapsed {0};
105 time_point now = clock::now();
106 time_point previous = now;
108 unsigned int frames = 0u;
109 unsigned int updates = 0u;
110 duration perf_counter {0};
112 while (window.isOpen())
115 elapsed = now - previous;
119 perf_counter += elapsed;
133 window.clear(sf::Color::White);
139 if (perf_counter >= one_second)
141 window.setTitle(std::format(
"{0} | UPS: {1}, FPS: {2}", settings::window_title(), updates, frames));
145 perf_counter = std::chrono::nanoseconds {0};
162 const auto now = std::chrono::zoned_time {std::chrono::current_zone(), std::chrono::system_clock::now()}.get_local_time();
163 const std::string log_path = std::format(
"{0}{1}{2}", log_dir, std::format(
"{0:%d-%m-%Y-[%H-%M]}", now),
".log");
164 if (!std::filesystem::exists(log_dir))
166 std::filesystem::create_directory(log_dir);
169 entt::locator<logging::Log>::emplace();
202 auto& window = entt::locator<sf::RenderWindow>::emplace();
203 window.setVisible(
false);
206 mode.bitsPerPixel = sf::VideoMode::getDesktopMode().bitsPerPixel;
207 mode.size.x = settings::window_width();
208 mode.size.y = settings::window_height();
210 sf::ContextSettings context;
211 context.antiAliasingLevel = settings::msaa();
212 context.attributeFlags = sf::ContextSettings::Default;
213 context.depthBits = 24;
214 context.majorVersion = 3;
215 context.minorVersion = 2;
216 context.sRgbCapable =
false;
217 context.stencilBits = 8;
219 const auto state = settings::fullscreen() ? sf::State::Fullscreen : sf::State::Windowed;
220 window.create(mode, settings::window_title(), sf::Style::Default, state, context);
222 if (!settings::window_icon().empty())
224 auto& fs = entt::locator<fs::VirtualFileSystem>::value();
225 auto data = fs.read_binary(settings::window_icon());
228 if (image.loadFromMemory(data.data(), data.size()))
231 window.setIcon(image);
239 if (!settings::cursor_icon().empty())
241 window.setMouseCursorVisible(
true);
243 if (settings::cursor_icon_size().x == 0 || settings::cursor_icon_size().y == 0)
245 GALAXY_LOG(
GALAXY_WARNING,
"Did not specify cursor size properly, must be same size as texture. Reverting to system default.");
249 auto& fs = entt::locator<fs::VirtualFileSystem>::value();
250 auto data = fs.read_binary(settings::window_icon());
252 m_cursor = sf::Cursor::createFromPixels(data.data(), settings::cursor_icon_size(), settings::cursor_hotspot());
255 window.setMouseCursor(
m_cursor.value());
265 window.setMouseCursorVisible(settings::cursor_visible());
268 window.setMouseCursorGrabbed(settings::cursor_grabbed());
269 window.setVerticalSyncEnabled(settings::vsync());
271 if (!window.setActive(
true))
276 window.setVisible(
true);
278 if (!window.hasFocus())
280 window.requestFocus();