From 933ed978a21d5ffefc376d66f0dc9f5354292ca7 Mon Sep 17 00:00:00 2001 From: untodesu Date: Sun, 16 Mar 2025 12:24:03 +0500 Subject: Update threading command line arguments --- game/client/main.cc | 4 +--- game/server/main.cc | 2 +- game/shared/threading.cc | 24 +++++++++++++++++++++--- 3 files changed, 23 insertions(+), 7 deletions(-) (limited to 'game') diff --git a/game/client/main.cc b/game/client/main.cc index 2fadb9f..6fabaa3 100644 --- a/game/client/main.cc +++ b/game/client/main.cc @@ -149,7 +149,7 @@ int main(int argc, char **argv) shared_game::init(argc, argv); - spdlog::info("Voxelius {}", PROJECT_VERSION_STRING); + spdlog::info("Voxelius Client {}", PROJECT_VERSION_STRING); glfwSetErrorCallback(&on_glfw_error); @@ -165,8 +165,6 @@ int main(int argc, char **argv) std::terminate(); } - spdlog::info("GLFW {}", glfwGetVersionString()); - glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_API); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); diff --git a/game/server/main.cc b/game/server/main.cc index 64bca10..0eff05f 100644 --- a/game/server/main.cc +++ b/game/server/main.cc @@ -30,7 +30,7 @@ int main(int argc, char **argv) shared_game::init(argc, argv); - spdlog::info("Voxelius {} server", PROJECT_VERSION_STRING); + spdlog::info("Voxelius Server {}", PROJECT_VERSION_STRING); globals::fixed_frametime = 0.0f; globals::fixed_frametime_avg = 0.0f; diff --git a/game/shared/threading.cc b/game/shared/threading.cc index 06a9411..7e6f652 100644 --- a/game/shared/threading.cc +++ b/game/shared/threading.cc @@ -4,6 +4,8 @@ #include "core/cmdline.hh" #include "core/constexpr.hh" +constexpr static const char *DEFAULT_POOL_SIZE_ARG = "4"; + static BS::light_thread_pool *thread_pool; static std::deque task_deque; @@ -31,9 +33,25 @@ void Task::set_status(task_status status) void threading::init(void) { - auto threads_arg = cmdline::get("threads", "4"); - auto threads_num = cxpr::clamp(std::strtoul(threads_arg, nullptr, 10), 2U, 4U); - thread_pool = new BS::light_thread_pool(threads_num); + auto argument = cmdline::get("threads", DEFAULT_POOL_SIZE_ARG); + auto num_concurrent_threads = std::thread::hardware_concurrency(); + unsigned int thread_pool_size; + + if(num_concurrent_threads && !std::strcmp(argument, "max")) { + // Use the maximum available number of concurrent + // hardware threads provided by the implementation + thread_pool_size = num_concurrent_threads; + } + else { + if(num_concurrent_threads) + thread_pool_size = cxpr::clamp(std::strtoul(argument, nullptr, 10), 1U, num_concurrent_threads); + else thread_pool_size = cxpr::max(std::strtoul(argument, nullptr, 10), 1U); + } + + spdlog::info("threading: using {} threads for pooling tasks", thread_pool_size); + + thread_pool = new BS::light_thread_pool(thread_pool_size); + task_deque.clear(); } -- cgit