Skip to content

Commit

Permalink
update .py and .pyx by adding new window arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
ZzzhHe authored and heinezen committed Dec 7, 2024
1 parent dc69f2e commit b034608
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 2 deletions.
21 changes: 21 additions & 0 deletions openage/game/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down Expand Up @@ -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)
8 changes: 7 additions & 1 deletion openage/game/main_cpp.pyx
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)
Expand Down
21 changes: 21 additions & 0 deletions openage/main/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down Expand Up @@ -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)
8 changes: 7 additions & 1 deletion openage/main/main_cpp.pyx
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit b034608

Please sign in to comment.