From b0346085291c180dcfb4fa3123703ba85acb3827 Mon Sep 17 00:00:00 2001 From: Alex Zhuohao He Date: Tue, 3 Dec 2024 11:45:49 -0500 Subject: [PATCH] update .py and .pyx by adding new window arguments --- openage/game/main.py | 21 +++++++++++++++++++++ openage/game/main_cpp.pyx | 8 +++++++- openage/main/main.py | 21 +++++++++++++++++++++ openage/main/main_cpp.pyx | 8 +++++++- 4 files changed, 56 insertions(+), 2 deletions(-) diff --git a/openage/game/main.py b/openage/game/main.py index 0fdf007259..44b74ee058 100644 --- a/openage/game/main.py +++ b/openage/game/main.py @@ -36,6 +36,19 @@ def init_subparser(cli: ArgumentParser) -> None: help="Check if the assets are up to date" ) + cli.add_argument( + "--window-size", nargs=2, type=int, default=[1024, 768], + metavar=('WIDTH', 'HEIGHT'), + help="initial window size in pixels, e.g., --window-size 1024 768") + + cli.add_argument( + "--vsync", action='store_true', + help="enable vertical synchronization") + + cli.add_argument( + "--window-mode", choices=["fullscreen", "borderless", "windowed"], default="windowed", + help="set the window mode: fullscreen, borderless, or windowed (default)") + def main(args, error): """ @@ -98,5 +111,13 @@ def main(args, error): # encode modpacks as bytes for the C++ interface args.modpacks = [modpack.encode('utf-8') for modpack in args.modpacks] + # Pass window parameters to engine + args.window_args = { + "width": args.window_size[0], + "height": args.window_size[1], + "vsync": args.vsync, + "window_mode": args.window_mode, + } + # start the game, continue in main_cpp.pyx! return run_game(args, root) diff --git a/openage/game/main_cpp.pyx b/openage/game/main_cpp.pyx index e7697b0ddb..d37545f87c 100644 --- a/openage/game/main_cpp.pyx +++ b/openage/game/main_cpp.pyx @@ -1,4 +1,4 @@ -# Copyright 2015-2023 the openage authors. See copying.md for legal info. +# Copyright 2015-2024 the openage authors. See copying.md for legal info. from cpython.ref cimport PyObject from libcpp.string cimport string @@ -37,6 +37,12 @@ def run_game(args, root_path): else: args_cpp.mods = vector[string]() + # window + args_cpp.window_args.width = args.window_args["width"] + args_cpp.window_args.height = args.window_args["height"] + args_cpp.window_args.vsync = args.window_args["vsync"] + args_cpp.window_args.mode = args.window_args["window_mode"].encode('utf-8') + # run the game! with nogil: result = run_game_cpp(args_cpp) diff --git a/openage/main/main.py b/openage/main/main.py index fbeb527ee4..5fa628c3e5 100644 --- a/openage/main/main.py +++ b/openage/main/main.py @@ -28,6 +28,19 @@ def init_subparser(cli: ArgumentParser): "--modpacks", nargs="+", type=str, help="list of modpacks to load") + cli.add_argument( + "--window-size", nargs=2, type=int, default=[1024, 768], + metavar=('WIDTH', 'HEIGHT'), + help="initial window size in pixels, e.g., --window-size 1024 768") + + cli.add_argument( + "--vsync", action='store_true', + help="enable vertical synchronization") + + cli.add_argument( + "--window-mode", choices=["fullscreen", "borderless", "windowed"], default="windowed", + help="set the window mode: fullscreen, borderless, or windowed (default)") + def main(args, error): """ @@ -106,5 +119,13 @@ def main(args, error): else: args.modpacks = [query_modpack(list(available_modpacks.keys())).encode("utf-8")] + # Pass window parameters to engine + args.window_args = { + "width": args.window_size[0], + "height": args.window_size[1], + "vsync": args.vsync, + "window_mode": args.window_mode, + } + # start the game, continue in main_cpp.pyx! return run_game(args, root) diff --git a/openage/main/main_cpp.pyx b/openage/main/main_cpp.pyx index e7697b0ddb..d37545f87c 100644 --- a/openage/main/main_cpp.pyx +++ b/openage/main/main_cpp.pyx @@ -1,4 +1,4 @@ -# Copyright 2015-2023 the openage authors. See copying.md for legal info. +# Copyright 2015-2024 the openage authors. See copying.md for legal info. from cpython.ref cimport PyObject from libcpp.string cimport string @@ -37,6 +37,12 @@ def run_game(args, root_path): else: args_cpp.mods = vector[string]() + # window + args_cpp.window_args.width = args.window_args["width"] + args_cpp.window_args.height = args.window_args["height"] + args_cpp.window_args.vsync = args.window_args["vsync"] + args_cpp.window_args.mode = args.window_args["window_mode"].encode('utf-8') + # run the game! with nogil: result = run_game_cpp(args_cpp)