summaryrefslogtreecommitdiffstats
path: root/src/game/server/main.cc
diff options
context:
space:
mode:
authoruntodesu <kirill@untode.su>2025-06-29 22:24:42 +0500
committeruntodesu <kirill@untode.su>2025-06-29 22:24:42 +0500
commit6cd00aacfa22fed6a54a9b812f6b069ad16feec0 (patch)
treeb77f4e665da3dd235cdb01e7e6ea78c1c02ecf2e /src/game/server/main.cc
parentf440914e1ae453768d09383f332bc7844e0a700e (diff)
downloadvoxelius-6cd00aacfa22fed6a54a9b812f6b069ad16feec0.tar.bz2
voxelius-6cd00aacfa22fed6a54a9b812f6b069ad16feec0.zip
Move game sources into src subdirectory
Diffstat (limited to 'src/game/server/main.cc')
-rw-r--r--src/game/server/main.cc103
1 files changed, 103 insertions, 0 deletions
diff --git a/src/game/server/main.cc b/src/game/server/main.cc
new file mode 100644
index 0000000..734ae6a
--- /dev/null
+++ b/src/game/server/main.cc
@@ -0,0 +1,103 @@
+#include "server/pch.hh"
+
+#include "core/binfile.hh"
+#include "core/cmdline.hh"
+#include "core/config.hh"
+#include "core/constexpr.hh"
+#include "core/epoch.hh"
+#include "core/image.hh"
+#include "core/resource.hh"
+#include "core/version.hh"
+
+#include "shared/game.hh"
+#include "shared/protocol.hh"
+#include "shared/threading.hh"
+
+#include "server/game.hh"
+#include "server/globals.hh"
+
+static ConfigUnsigned server_tickrate(protocol::TICKRATE, 10U, 300U);
+
+static void on_termination_signal(int)
+{
+ spdlog::warn("server: received termination signal");
+ globals::is_running = false;
+}
+
+int main(int argc, char** argv)
+{
+ cmdline::create(argc, argv);
+
+ shared_game::init(argc, argv);
+
+ spdlog::info("Voxelius Server {}", project_version_string);
+
+ globals::fixed_frametime = 0.0f;
+ globals::fixed_frametime_avg = 0.0f;
+ globals::fixed_frametime_us = 0;
+ globals::fixed_framecount = 0;
+
+ globals::curtime = epoch::microseconds();
+
+ globals::is_running = true;
+
+ std::signal(SIGINT, &on_termination_signal);
+ std::signal(SIGTERM, &on_termination_signal);
+
+ server_game::init();
+
+ threading::init();
+
+ globals::server_config.add_value("server.tickrate", server_tickrate);
+ globals::server_config.load_file("server.conf");
+ globals::server_config.load_cmdline();
+
+ globals::tickrate = server_tickrate.get_value();
+ globals::tickrate_dt = static_cast<std::uint64_t>(1000000.0f / static_cast<float>(globals::tickrate));
+
+ server_game::init_late();
+
+ std::uint64_t last_curtime = globals::curtime;
+
+ while(globals::is_running) {
+ globals::curtime = epoch::microseconds();
+
+ globals::fixed_frametime_us = globals::curtime - last_curtime;
+ globals::fixed_frametime = static_cast<float>(globals::fixed_frametime_us) / 1000000.0f;
+ globals::fixed_frametime_avg += globals::fixed_frametime;
+ globals::fixed_frametime_avg *= 0.5f;
+
+ last_curtime = globals::curtime;
+
+ server_game::fixed_update();
+ server_game::fixed_update_late();
+
+ globals::dispatcher.update();
+
+ globals::fixed_framecount += 1;
+
+ std::this_thread::sleep_for(std::chrono::microseconds(globals::tickrate_dt));
+
+ resource::soft_cleanup<BinFile>();
+ resource::soft_cleanup<Image>();
+
+ threading::update();
+ }
+
+ server_game::deinit();
+
+ resource::hard_cleanup<BinFile>();
+ resource::hard_cleanup<Image>();
+
+ threading::deinit();
+
+ spdlog::info("server: shutdown after {} frames", globals::fixed_framecount);
+ spdlog::info("server: average framerate: {:.03f} TPS", 1.0f / globals::fixed_frametime_avg);
+ spdlog::info("server: average frametime: {:.03f} MSPT", 1000.0f * globals::fixed_frametime_avg);
+
+ globals::server_config.save_file("server.conf");
+
+ shared_game::deinit();
+
+ return EXIT_SUCCESS;
+}