From c2a09e48d05b4364dfebc5fb31e8a5dbf76cb255 Mon Sep 17 00:00:00 2001 From: Trevor Slocum Date: Fri, 22 Sep 2023 20:39:11 -0700 Subject: [PATCH] Add CLI parameter for running without graphics Resolves #1547. --- libopenage/main.cpp | 6 +++++- libopenage/main.h | 2 ++ openage/game/main.py | 4 ++++ openage/game/main_cpp.pyx | 3 +++ openage/main/main.py | 4 ++++ openage/main/main_cpp.pyx | 3 +++ 6 files changed, 21 insertions(+), 1 deletion(-) diff --git a/libopenage/main.cpp b/libopenage/main.cpp index 7c80689a25f..6e7aa0de510 100644 --- a/libopenage/main.cpp +++ b/libopenage/main.cpp @@ -25,8 +25,12 @@ int run_game(const main_arguments &args) { auto cvar_manager = std::make_shared(args.root_path["cfg"]); cvar_manager->load_all(); - // TODO: select run_mode by launch argument + // set engine run_mode openage::engine::Engine::mode run_mode = openage::engine::Engine::mode::FULL; + if (args.headless) { + run_mode = openage::engine::Engine::mode::HEADLESS; + } + openage::engine::Engine engine{run_mode, args.root_path, args.mods}; engine.loop(); diff --git a/libopenage/main.h b/libopenage/main.h index 7eb33177116..36d7cae6926 100644 --- a/libopenage/main.h +++ b/libopenage/main.h @@ -27,12 +27,14 @@ namespace openage { * Path root_path * int32_t fps_limit * bool gl_debug + * bool headless * vector[string] mods */ struct main_arguments { util::Path root_path; int32_t fps_limit; bool gl_debug; + bool headless; std::vector mods; }; diff --git a/openage/game/main.py b/openage/game/main.py index d9dd9923be2..be658d50ab6 100644 --- a/openage/game/main.py +++ b/openage/game/main.py @@ -28,6 +28,10 @@ def init_subparser(cli: ArgumentParser) -> None: "--gl-debug", action='store_true', help="throw exceptions directly from the OpenGL calls") + cli.add_argument( + "--headless", action='store_true', + help="run without displaying graphics") + cli.add_argument( "--modpacks", nargs="+", type=bytes, help="list of modpacks to load") diff --git a/openage/game/main_cpp.pyx b/openage/game/main_cpp.pyx index 76fe9c82268..d34b22bf5c9 100644 --- a/openage/game/main_cpp.pyx +++ b/openage/game/main_cpp.pyx @@ -32,6 +32,9 @@ def run_game(args, root_path): # opengl debugging args_cpp.gl_debug = args.gl_debug + # headless mode + args_cpp.headless = args.headless + # run the game! with nogil: result = run_game_cpp(args_cpp) diff --git a/openage/main/main.py b/openage/main/main.py index 0340bc2a11d..e5036357950 100644 --- a/openage/main/main.py +++ b/openage/main/main.py @@ -24,6 +24,10 @@ def init_subparser(cli: ArgumentParser): "--gl-debug", action='store_true', help="throw exceptions directly from the OpenGL calls") + cli.add_argument( + "--headless", action='store_true', + help="run without displaying graphics") + cli.add_argument( "--modpacks", nargs="+", help="list of modpacks to load") diff --git a/openage/main/main_cpp.pyx b/openage/main/main_cpp.pyx index a7970762cfd..dd64aa57541 100644 --- a/openage/main/main_cpp.pyx +++ b/openage/main/main_cpp.pyx @@ -35,6 +35,9 @@ def run_game(args, root_path): # opengl debugging args_cpp.gl_debug = args.gl_debug + # headless mode + args_cpp.headless = args.headless + # mods if args.modpacks is not None: args_cpp.mods = args.modpacks