Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added cli parameters #1553

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion libopenage/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
#include "engine/engine.h"
#include "util/timer.h"

#include "renderer/window.h"
#include "renderer/enums.h"

namespace openage {

/*
Expand All @@ -30,8 +33,21 @@ int run_game(const main_arguments &args) {
if (args.headless) {
run_mode = openage::engine::Engine::mode::HEADLESS;
}
renderer::WindowConfig window_config;
window_config.width = args.window_config.width;
window_config.height = args.window_config.height;
window_config.vsync = args.window_config.vsync;

// Determine the render mode based on the window-related arguments
if (args.window_config.render_mode == renderer::RenderMode::FULLSCREEN) {
window_config.render_mode = renderer::RenderMode::FULLSCREEN;
} else if (args.window_config.render_mode == renderer::RenderMode::BORDERLESS) {
window_config.render_mode = renderer::RenderMode::BORDERLESS;
} else {
window_config.render_mode = renderer::RenderMode::WINDOWED;
}

openage::engine::Engine engine{run_mode, args.root_path, args.mods, args.gl_debug};
openage::engine::Engine engine{run_mode, args.root_path, args.mods, args.gl_debug, window_config};

engine.loop();

Expand Down
5 changes: 5 additions & 0 deletions libopenage/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <vector>

#include "util/compiler.h"
#include "renderer/enums.h"

namespace openage {

Expand All @@ -32,6 +33,10 @@ struct main_arguments {
bool gl_debug;
bool headless;
std::vector<std::string> mods;
int window_width;
int window_height;
bool vsync;
renderer::RenderMode render_mod
};


Expand Down
33 changes: 32 additions & 1 deletion openage/game/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,30 @@ def init_subparser(cli: ArgumentParser) -> None:
cli.add_argument(
"--modpacks", nargs="+", required=True,
help="list of modpacks to load")

cli.add_argument(
"--window-width", type=int, default=800,
help="Window width")

cli.add_argument(
"--window-height", type=int, default=600,
help="Window height")

cli.add_argument(
"--vsync", action='store_true',
help="Enable V-Sync")

cli.add_argument(
"--fullscreen", action='store_true',
help="Run in fullscreen mode")

cli.add_argument(
"--borderless", action='store_true',
help="Run in borderless mode")

cli.add_argument(
"--windowed", action='store_true',
help="Run in windowed mode")

def main(args, error):
"""
Expand Down Expand Up @@ -88,5 +111,13 @@ def main(args, error):

args.modpacks = mods

window_args = {
"width": args.window_width,
"height": args.window_height,
"vsync": args.vsync,
"fullscreen": args.fullscreen,
"borderless": args.borderless,
"windowed": args.windowed
}
# start the game, continue in main_cpp.pyx!
return run_game(args, root)
return run_game(args, root,window_args)
10 changes: 9 additions & 1 deletion openage/game/main_cpp.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ from libopenage.pyinterface.pyobject cimport PyObj
from libopenage.error.handlers cimport set_exit_ok


def run_game(args, root_path):
def run_game(args, root_path,window_args):
"""
Launches the game after arguments were translated.
"""
Expand All @@ -36,7 +36,15 @@ def run_game(args, root_path):
args_cpp.mods = args.modpacks
else:
args_cpp.mods = vector[string]()

if window_args['fullscreen']:
window_config.render_mode = RenderMode.FULLSCREEN
elif window_args['borderless']:
window_config.render_mode = RenderMode.BORDERLESS
else:
window_config.render_mode = RenderMode.WINDOWED

args_cpp.window_config = window_config
# run the game!
with nogil:
result = run_game_cpp(args_cpp)
Expand Down
35 changes: 33 additions & 2 deletions openage/main/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,30 @@ def init_subparser(cli: ArgumentParser):
cli.add_argument(
"--modpacks", nargs="+",
help="list of modpacks to load")

cli.add_argument(
"--window-width", type=int, default=800,
help="Window width")

cli.add_argument(
"--window-height", type=int, default=600,
help="Window height")

cli.add_argument(
"--vsync", action='store_true',
help="Enable V-Sync")

cli.add_argument(
"--fullscreen", action='store_true',
help="Run in fullscreen mode")

cli.add_argument(
"--borderless", action='store_true',
help="Run in borderless mode")

cli.add_argument(
"--windowed", action='store_true',
help="Run in windowed mode")


def main(args, error):
Expand Down Expand Up @@ -93,6 +117,13 @@ def main(args, error):
from ..convert.service.init.modpack_search import enumerate_modpacks, query_modpack
avail_modpacks = enumerate_modpacks(asset_path / "converted")
args.modpacks = [query_modpack(avail_modpacks).encode("utf-8")]

window_args = {
"width": args.window_width,
"height": args.window_height,
"vsync": args.vsync,
"fullscreen": args.fullscreen,
"borderless": args.borderless,
"windowed": args.windowed
}
# start the game, continue in main_cpp.pyx!
return run_game(args, root)
return run_game(args, root, window_args)
20 changes: 18 additions & 2 deletions openage/main/main_cpp.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ from libopenage.main cimport main_arguments, run_game as run_game_cpp
from libopenage.util.path cimport Path as Path_cpp
from libopenage.pyinterface.pyobject cimport PyObj
from libopenage.error.handlers cimport set_exit_ok
from libopenage.renderer.window cimport WindowConfig
from libopenage.renderer.enums cimport RenderMode


def run_game(args, root_path):
def run_game(args, root_path,window_args):
"""
Launches the game after arguments were translated.
"""
Expand All @@ -37,6 +38,21 @@ def run_game(args, root_path):
else:
args_cpp.mods = vector[string]()

cdef WindowConfig window_config
window_config.width = window_args['width']
window_config.height = window_args['height']
window_config.vsync = window_args['vsync']

# Determine the render mode based on window-related arguments
if window_args['fullscreen']:
window_config.render_mode = RenderMode.FULLSCREEN
elif window_args['borderless']:
window_config.render_mode = RenderMode.BORDERLESS
else:
window_config.render_mode = RenderMode.WINDOWED

# Set the window configuration in args_cpp
args_cpp.window_config = window_config
# run the game!
with nogil:
result = run_game_cpp(args_cpp)
Expand Down