8#define BS_THREAD_POOL_NATIVE_EXTENSIONS
13#include <BS_thread_pool.hpp>
14#include <entt/locator/locator.hpp>
15#include <entt/signal/dispatcher.hpp>
32using namespace std::chrono_literals;
87 constexpr const auto dt = std::chrono::duration<long long, std::ratio<1, 60>> {1};
90 using clock = std::chrono::steady_clock;
91 using duration =
decltype(clock::duration {} + dt);
92 using time_point = std::chrono::time_point<clock, duration>;
95 time_point prev = clock::now();
96 time_point now = clock::now();
105 ray::PollInputEvents();
114 ray::ClearBackground(RAY_WHITE);
119 ray::SwapScreenBuffer();
123 while (!ray::WindowShouldClose())
126 auto elapsed = now - prev;
154 ray::SetWindowTitle(std::format(
" | UPS: {0}, FPS: {1}", updates, frames).c_str());
179 auto system_cores = std::thread::hardware_concurrency();
180 if (system_cores < 6)
182 system_cores = std::thread::hardware_concurrency();
186 BS::set_os_process_priority(BS::os_process_priority::high);
187 entt::locator<BS::priority_thread_pool>::emplace(system_cores, [](
const std::size_t idx) {
188 BS::this_thread::set_os_thread_priority(BS::os_thread_priority::highest);
194 platform::configure_terminal();
199 entt::locator<Log>::emplace();
210 auto& config = entt::locator<Config>::emplace(config_file);
222 entt::locator<VirtualFileSystem>::emplace();
229 ray::SetConfigFlags(ray::FLAG_VSYNC_HINT);
234 ray::SetConfigFlags(ray::FLAG_WINDOW_RESIZABLE);
239 ray::SetConfigFlags(ray::FLAG_FULLSCREEN_MODE);
244 ray::SetConfigFlags(ray::FLAG_BORDERLESS_WINDOWED_MODE);
249 ray::SetConfigFlags(ray::FLAG_WINDOW_UNDECORATED);
254 ray::SetConfigFlags(ray::FLAG_WINDOW_TOPMOST);
257 ray::SetConfigFlags(ray::FLAG_WINDOW_HIGHDPI);
258 ray::SetConfigFlags(ray::FLAG_WINDOW_HIDDEN);
259 ray::SetConfigFlags(ray::FLAG_WINDOW_TRANSPARENT);
261 ray::SetExitKey(ray::KEY_NULL);
265 ray::SetWindowState(ray::FLAG_WINDOW_MAXIMIZED);
270 ray::SetWindowState(ray::FLAG_WINDOW_MINIMIZED);
275 auto& fs = entt::locator<VirtualFileSystem>::value();
278 if (image.has_value())
280 ray::SetWindowIcon(image.value());
281 ray::UnloadImage(image.value());
285 ray::ClearWindowState(ray::FLAG_WINDOW_HIDDEN);
286 ray::SetWindowFocused();
299 ray::DisableCursor();
380 auto& lua = entt::locator<sol::state>::emplace();
381 lua.open_libraries(sol::lib::base, sol::lib::package, sol::lib::coroutine, sol::lib::string, sol::lib::os, sol::lib::math, sol::lib::table, sol::lib::io, sol::lib::utf8);
#define GALAXY_ADD_SINK(sink,...)
#define GALAXY_INFO
Log.hpp galaxy.
#define GALAXY_LOG(level, msg,...)
void setup_config(std::string_view config_file)
void run()
Main game loop.
App(const std::string &config_file="config.json")
Default constructor.
void load()
Loads the default appdata file.
void set_render_func(LoopFunc &&render)
Use a custom rendering step in game loop.
std::move_only_function< void(App *app)> LoopFunc
Defines a callback for update() or render() loops in app.run().
void set_update_func(LoopFunc &&update)
Use a custom update step in game loop.
LoopFunc m_render
Render step in gameloop.
LoopFunc m_update
Update step in gameloop.
Logs a message to the console.
static void inject() noexcept
Inject everything into Lua.
double dt() noexcept
Get galaxy delta time.
auto now() noexcept -> std::chrono::local_time< std::chrono::system_clock::duration >
Current local time.
static auto window_icon() noexcept -> const std::string &
Window icon file in vfs.
static auto window_height() noexcept -> int
Window creation height.
static auto log_dir() noexcept -> const std::string &
Current root directory of application, unless it has been changed.
static auto fullscreen() noexcept -> bool
Is window started fullscreen.
static auto vsync() noexcept -> bool
Vsync control.
static auto minimized() noexcept -> bool
Is window started minimized?
static auto cursor_locked() noexcept -> bool
Is the cursor grabbed.
static auto window_width() noexcept -> int
Window creation width.
static auto set_settings_from_config() -> void
Set all our settings using the provided config file.
static auto window_resizable() noexcept -> bool
Is the window resizable.
static auto maximized() noexcept -> bool
Is window started maximized?
static auto title() noexcept -> const std::string &
Game title.
static auto cursor_show() noexcept -> bool
Is the mouse cursor visible or not.
static auto ontop() noexcept -> bool
Should the window always be on top.
static auto borderless_fullscreen() noexcept -> bool
Is window in borderless fullscreen?
static auto set_config_to_default() -> void
Restore all config settings to default.
static auto decoration() noexcept -> bool
Controls if a window has a border around it (including titlebar).