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 custom resolution size for main and game #1672

Draft
wants to merge 9 commits into
base: master
Choose a base branch
from
3 changes: 2 additions & 1 deletion .mailmap
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ Tobias Feldballe <[email protected]> <[email protected]>
Tobias Feldballe <[email protected]> <[email protected]>
Jonas Borchelt <[email protected]>
Derek Frogget <[email protected]> <[email protected]>
Nikhil Ghosh <[email protected]>
Nikhil Ghosh <[email protected]>
Raul Galvez <[email protected]> <[email protected]>
1 change: 1 addition & 0 deletions copying.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ _the openage authors_ are:
| Haoyang Bi | AyiStar | ayistar à outlook dawt com |
| Michael Seibt | RoboSchmied | github à roboschmie dawt de |
| Nikhil Ghosh | NikhilGhosh75 | nghosh606 à gmail dawt com |
| Raul Galvez | RaulGalvez288 | raul.galvez à outlook dawt com |

If you're a first-time committer, add yourself to the above list. This is not
just for legal reasons, but also to keep an overview of all those nicknames.
Expand Down
14 changes: 10 additions & 4 deletions libopenage/engine/engine.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023-2023 the openage authors. See copying.md for legal info.
// Copyright 2023-2024 the openage authors. See copying.md for legal info.

#include "engine.h"

Expand All @@ -16,14 +16,20 @@ namespace openage::engine {
Engine::Engine(mode mode,
const util::Path &root_dir,
const std::vector<std::string> &mods,
bool debug_graphics) :
bool debug_graphics,
size_t window_width,
size_t window_height) :
running{true},
run_mode{mode},
root_dir{root_dir},
height{window_height},
width{window_width},
threads{} {
log::log(INFO
<< "launching engine with root directory"
<< root_dir);
<< root_dir
<< "width: " << width
<< "height: " << height);

// read and apply the configuration files
this->cvar_manager = std::make_shared<cvar::CVarManager>(this->root_dir["cfg"]);
Expand Down Expand Up @@ -55,7 +61,7 @@ Engine::Engine(mode mode,

// if presenter is used, run it in a separate thread
if (this->run_mode == mode::FULL) {
this->threads.emplace_back([&, debug_graphics]() {
this->threads.emplace_back([&, debug_graphics, window_width, window_height]() {
this->presenter->run(debug_graphics);

// Make sure that the presenter gets destructed in the same thread
Expand Down
16 changes: 15 additions & 1 deletion libopenage/engine/engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,15 @@ class Engine {
* @param root_dir openage root directory.
* @param mods The mods to load.
* @param debug_graphics If true, enable OpenGL debug logging.
* @param wWidth Width of the window.
* @param wHeight Height of the window.
*/
Engine(mode mode,
const util::Path &root_dir,
const std::vector<std::string> &mods,
bool debug_graphics = false);
bool debug_graphics = false,
int wWidth = 1024,
int wHeight = 768);

// engine should not be copied or moved
Engine(const Engine &) = delete;
Expand Down Expand Up @@ -108,6 +112,16 @@ class Engine {
*/
util::Path root_dir;

/**
* The width of the rendering window.
*/
int width;

/**
* The height of the rendering window.
*/
int height;

/**
* The threads used by the engine.
*/
Expand Down
4 changes: 2 additions & 2 deletions libopenage/main.cpp
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.

#include "main.h"

Expand Down Expand Up @@ -31,7 +31,7 @@ int run_game(const main_arguments &args) {
run_mode = openage::engine::Engine::mode::HEADLESS;
}

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, args.width, args.height};

engine.loop();

Expand Down
6 changes: 5 additions & 1 deletion libopenage/main.h
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.

#pragma once

Expand Down Expand Up @@ -26,12 +26,16 @@ namespace openage {
* bool gl_debug
* bool headless
* vector[string] mods
* int width
* int height
*/
struct main_arguments {
util::Path root_path;
bool gl_debug;
bool headless;
std::vector<std::string> mods;
int width;
int height;
};


Expand Down
6 changes: 3 additions & 3 deletions libopenage/presenter/presenter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ Presenter::Presenter(const util::Path &root_dir,
time_loop{time_loop} {}


void Presenter::run(bool debug_graphics) {
void Presenter::run(bool debug_graphics, int width, int height) {
log::log(INFO << "Presenter: Launching subsystems...");

this->init_graphics(debug_graphics);
this->init_graphics(debug_graphics, width, height);

this->init_input();

Expand Down Expand Up @@ -93,7 +93,7 @@ std::shared_ptr<qtgui::GuiApplication> Presenter::init_window_system() {
return std::make_shared<renderer::gui::GuiApplicationWithLogger>();
}

void Presenter::init_graphics(bool debug) {
void Presenter::init_graphics(bool debug, int width, int height) {
log::log(INFO << "Presenter: Initializing graphics subsystems...");

// Start up rendering framework
Expand Down
6 changes: 4 additions & 2 deletions libopenage/presenter/presenter.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,10 @@ class Presenter {
* Start the presenter and initialize subsystems.
*
* @param debug_graphics If true, enable OpenGL debug logging.
* @param width Width of the window rendered.
* @param height height of the window rendered.
*/
void run(bool debug_graphics = false);
void run(bool debug_graphics = false, int width = 1024, int height = 768);

/**
* Set the game simulation controlled by this presenter.
Expand Down Expand Up @@ -120,7 +122,7 @@ class Presenter {
* - main renderer
* - component renderers (Terrain, Game Entities, GUI)
*/
void init_graphics(bool debug = false);
void init_graphics(bool debug = false, int width = 1024, int height = 768);

/**
* Initialize the GUI.
Expand Down
10 changes: 9 additions & 1 deletion openage/game/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,15 @@ def init_subparser(cli: ArgumentParser) -> None:

cli.add_argument(
"--check-updates", action='store_true',
help="Check if the assets are up to date"
help="Check if the assets are up to date")

cli.add_argument(
"--width", type=int, default=1024,
help="width of the game window")

cli.add_argument(
"--height", type=int, default=768,
help="height of the game window"
)


Expand Down
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 width
args_cpp.width = args.width

# window height
args_cpp.height = args.height

# run the game!
with nogil:
result = run_game_cpp(args_cpp)
Expand Down
9 changes: 9 additions & 0 deletions openage/main/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ def init_subparser(cli: ArgumentParser):
"--modpacks", nargs="+", type=str,
help="list of modpacks to load")

cli.add_argument(
"--width", type=int, default=1024,
help="width of the game window")

cli.add_argument(
"--height", type=int, default=768,
help="height of the game window"
)


def main(args, error):
"""
Expand Down
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 width
args_cpp.width = args.width

# window height
args_cpp.height = args.height

# run the game!
with nogil:
result = run_game_cpp(args_cpp)
Expand Down