summaryrefslogtreecommitdiffstats
path: root/game/shared/game.cc
diff options
context:
space:
mode:
authoruntodesu <kirill@untode.su>2025-09-11 15:48:53 +0500
committeruntodesu <kirill@untode.su>2025-09-11 15:48:53 +0500
commitd0fbd68055e3f4a796330cc8acc6c0954b5327ff (patch)
treee581014ea02711efa5e71f00f9862e5bca58f2ed /game/shared/game.cc
parentcbd823aa2154a956e7da4319eecbf7afc10441ae (diff)
downloadvoxelius-d0fbd68055e3f4a796330cc8acc6c0954b5327ff.tar.bz2
voxelius-d0fbd68055e3f4a796330cc8acc6c0954b5327ff.zip
Run clang-format across the project
Diffstat (limited to 'game/shared/game.cc')
-rw-r--r--game/shared/game.cc246
1 files changed, 123 insertions, 123 deletions
diff --git a/game/shared/game.cc b/game/shared/game.cc
index 94c2c1f..f7b9da4 100644
--- a/game/shared/game.cc
+++ b/game/shared/game.cc
@@ -1,123 +1,123 @@
-#include "shared/pch.hh"
-
-#include "shared/game.hh"
-
-#include "core/io/cmdline.hh"
-
-static std::filesystem::path get_gamepath(void)
-{
- if(auto gamepath = io::cmdline::get_cstr("gamepath")) {
- // Allow users and third-party launchers to override
- // content location. Perhaps this would work to allow
- // for a Minecraft-like versioning approach?
- return std::filesystem::path(gamepath);
- }
-
- return std::filesystem::current_path() / "data";
-}
-
-static std::filesystem::path get_userpath(void)
-{
- if(auto userpath = io::cmdline::get_cstr("userpath")) {
- // Allow users and third-party launchers to override
- // user data location. Perhaps this would work to allow
- // for a Minecraft-like versioning approach?
- return std::filesystem::path(userpath);
- }
-
- if(auto win_appdata = std::getenv("APPDATA")) {
- // On pre-seven Windows systems it's just AppData
- // On post-seven Windows systems it's AppData/Roaming
- return std::filesystem::path(win_appdata) / "voxelius";
- }
-
- if(auto xdg_home = std::getenv("XDG_DATA_HOME")) {
- // Systems with an active X11/Wayland session
- // theoretically should have this defined, and
- // it can be different from ${HOME} (I think).
- return std::filesystem::path(xdg_home) / ".voxelius";
- }
-
- if(auto unix_home = std::getenv("HOME")) {
- // Any spherical UNIX/UNIX-like system in vacuum
- // has this defined for every single user process.
- return std::filesystem::path(unix_home) / ".voxelius";
- }
-
- // Give up and save stuff into CWD
- return std::filesystem::current_path();
-}
-
-void shared_game::init(int argc, char** argv)
-{
- auto logger = spdlog::default_logger();
- auto& logger_sinks = logger->sinks();
-
- logger_sinks.clear();
- logger_sinks.push_back(std::make_shared<spdlog::sinks::stderr_color_sink_mt>());
- logger_sinks.push_back(std::make_shared<spdlog::sinks::basic_file_sink_mt>("voxelius.log", false));
-
-#if defined(NDEBUG)
- constexpr auto default_loglevel = spdlog::level::info;
-#else
- constexpr auto default_loglevel = spdlog::level::trace;
-#endif
-
- if(io::cmdline::contains("quiet")) {
- logger->set_level(spdlog::level::warn);
- }
- else if(io::cmdline::contains("verbose")) {
- logger->set_level(spdlog::level::trace);
- }
- else {
- logger->set_level(default_loglevel);
- }
-
- logger->set_pattern("%H:%M:%S.%e %^[%L]%$ %v");
- logger->flush();
-
- if(!PHYSFS_init(argv[0])) {
- spdlog::critical("physfs: init failed: {}", PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode()));
- std::terminate();
- }
-
- auto gamepath = get_gamepath();
- auto userpath = get_userpath();
-
- spdlog::info("shared_game: set gamepath to {}", gamepath.string());
- spdlog::info("shared_game: set userpath to {}", userpath.string());
-
- std::error_code ignore_error = {};
- std::filesystem::create_directories(gamepath, ignore_error);
- std::filesystem::create_directories(userpath, ignore_error);
-
- if(!PHYSFS_mount(gamepath.string().c_str(), nullptr, false)) {
- spdlog::critical("physfs: mount {} failed: {}", gamepath.string(), PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode()));
- std::terminate();
- }
-
- if(!PHYSFS_mount(userpath.string().c_str(), nullptr, false)) {
- spdlog::critical("physfs: mount {} failed: {}", userpath.string(), PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode()));
- std::terminate();
- }
-
- if(!PHYSFS_setWriteDir(userpath.string().c_str())) {
- spdlog::critical("physfs: setwritedir {} failed: {}", userpath.string(), PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode()));
- std::terminate();
- }
-
- if(enet_initialize()) {
- spdlog::critical("enet: init failed");
- std::terminate();
- }
-}
-
-void shared_game::shutdown(void)
-{
- enet_deinitialize();
-
- if(!PHYSFS_deinit()) {
- spdlog::critical("physfs: deinit failed: {}", PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode()));
- std::terminate();
- }
-}
+#include "shared/pch.hh"
+
+#include "shared/game.hh"
+
+#include "core/io/cmdline.hh"
+
+static std::filesystem::path get_gamepath(void)
+{
+ if(auto gamepath = io::cmdline::get_cstr("gamepath")) {
+ // Allow users and third-party launchers to override
+ // content location. Perhaps this would work to allow
+ // for a Minecraft-like versioning approach?
+ return std::filesystem::path(gamepath);
+ }
+
+ return std::filesystem::current_path() / "data";
+}
+
+static std::filesystem::path get_userpath(void)
+{
+ if(auto userpath = io::cmdline::get_cstr("userpath")) {
+ // Allow users and third-party launchers to override
+ // user data location. Perhaps this would work to allow
+ // for a Minecraft-like versioning approach?
+ return std::filesystem::path(userpath);
+ }
+
+ if(auto win_appdata = std::getenv("APPDATA")) {
+ // On pre-seven Windows systems it's just AppData
+ // On post-seven Windows systems it's AppData/Roaming
+ return std::filesystem::path(win_appdata) / "voxelius";
+ }
+
+ if(auto xdg_home = std::getenv("XDG_DATA_HOME")) {
+ // Systems with an active X11/Wayland session
+ // theoretically should have this defined, and
+ // it can be different from ${HOME} (I think).
+ return std::filesystem::path(xdg_home) / ".voxelius";
+ }
+
+ if(auto unix_home = std::getenv("HOME")) {
+ // Any spherical UNIX/UNIX-like system in vacuum
+ // has this defined for every single user process.
+ return std::filesystem::path(unix_home) / ".voxelius";
+ }
+
+ // Give up and save stuff into CWD
+ return std::filesystem::current_path();
+}
+
+void shared_game::init(int argc, char** argv)
+{
+ auto logger = spdlog::default_logger();
+ auto& logger_sinks = logger->sinks();
+
+ logger_sinks.clear();
+ logger_sinks.push_back(std::make_shared<spdlog::sinks::stderr_color_sink_mt>());
+ logger_sinks.push_back(std::make_shared<spdlog::sinks::basic_file_sink_mt>("voxelius.log", false));
+
+#if defined(NDEBUG)
+ constexpr auto default_loglevel = spdlog::level::info;
+#else
+ constexpr auto default_loglevel = spdlog::level::trace;
+#endif
+
+ if(io::cmdline::contains("quiet")) {
+ logger->set_level(spdlog::level::warn);
+ }
+ else if(io::cmdline::contains("verbose")) {
+ logger->set_level(spdlog::level::trace);
+ }
+ else {
+ logger->set_level(default_loglevel);
+ }
+
+ logger->set_pattern("%H:%M:%S.%e %^[%L]%$ %v");
+ logger->flush();
+
+ if(!PHYSFS_init(argv[0])) {
+ spdlog::critical("physfs: init failed: {}", PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode()));
+ std::terminate();
+ }
+
+ auto gamepath = get_gamepath();
+ auto userpath = get_userpath();
+
+ spdlog::info("shared_game: set gamepath to {}", gamepath.string());
+ spdlog::info("shared_game: set userpath to {}", userpath.string());
+
+ std::error_code ignore_error = {};
+ std::filesystem::create_directories(gamepath, ignore_error);
+ std::filesystem::create_directories(userpath, ignore_error);
+
+ if(!PHYSFS_mount(gamepath.string().c_str(), nullptr, false)) {
+ spdlog::critical("physfs: mount {} failed: {}", gamepath.string(), PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode()));
+ std::terminate();
+ }
+
+ if(!PHYSFS_mount(userpath.string().c_str(), nullptr, false)) {
+ spdlog::critical("physfs: mount {} failed: {}", userpath.string(), PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode()));
+ std::terminate();
+ }
+
+ if(!PHYSFS_setWriteDir(userpath.string().c_str())) {
+ spdlog::critical("physfs: setwritedir {} failed: {}", userpath.string(), PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode()));
+ std::terminate();
+ }
+
+ if(enet_initialize()) {
+ spdlog::critical("enet: init failed");
+ std::terminate();
+ }
+}
+
+void shared_game::shutdown(void)
+{
+ enet_deinitialize();
+
+ if(!PHYSFS_deinit()) {
+ spdlog::critical("physfs: deinit failed: {}", PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode()));
+ std::terminate();
+ }
+}