Skip to content

Commit

Permalink
Address review feedback: fix formatting, remove redundant debug arg, …
Browse files Browse the repository at this point in the history
…and change display mode setting method.
  • Loading branch information
ZzzhHe authored and heinezen committed Dec 7, 2024
1 parent a4335be commit 87da14e
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 31 deletions.
5 changes: 2 additions & 3 deletions libopenage/engine/engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ namespace openage::engine {
Engine::Engine(mode mode,
const util::Path &root_dir,
const std::vector<std::string> &mods,
bool debug_graphics,
const renderer::window_settings &window_settings) :
running{true},
run_mode{mode},
Expand Down Expand Up @@ -56,8 +55,8 @@ 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->presenter->run(debug_graphics, window_settings);
this->threads.emplace_back([&]() {
this->presenter->run(window_settings);

// Make sure that the presenter gets destructed in the same thread
// otherwise OpenGL complains about missing contexts
Expand Down
6 changes: 2 additions & 4 deletions libopenage/engine/engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
#include <thread>
#include <vector>

#include "renderer/window.h"
#include "util/path.h"

#include <renderer/window.h>

// TODO: Remove custom jthread definition when clang/libc++ finally supports it
#if __llvm__
Expand Down Expand Up @@ -73,13 +73,11 @@ class Engine {
* @param mode The run mode to use.
* @param root_dir openage root directory.
* @param mods The mods to load.
* @param debug_graphics If true, enable OpenGL debug logging.
* @param window_settings window display setting
* @param window_settings The settings to customize the display window (e.g. size, display mode, vsync).
*/
Engine(mode mode,
const util::Path &root_dir,
const std::vector<std::string> &mods,
bool debug_graphics = false,
const renderer::window_settings &window_settings = {});

// engine should not be copied or moved
Expand Down
8 changes: 6 additions & 2 deletions libopenage/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,16 @@ int run_game(const main_arguments &args) {
else if (args.window_args.mode == "borderless") {
wmode = renderer::window_mode::BORDERLESS;
}
else {
else if (args.window_args.mode == "windowed") {
wmode = renderer::window_mode::WINDOWED;
}
else {
throw Error(MSG(err) << "Invalid window mode: " << args.window_args.mode);
}
win_settings.mode = wmode;
win_settings.debug = args.gl_debug;

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

engine.loop();

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


void Presenter::run(bool debug_graphics, const renderer::window_settings &window_settings) {
void Presenter::run(const renderer::window_settings &window_settings) {
log::log(INFO << "Presenter: Launching subsystems...");

this->init_graphics(debug_graphics, window_settings);
this->init_graphics(window_settings);

this->init_input();

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

void Presenter::init_graphics(bool debug, const renderer::window_settings &window_settings) {
void Presenter::init_graphics(const renderer::window_settings &window_settings) {
log::log(INFO << "Presenter: Initializing graphics subsystems...");

// Start up rendering framework
Expand Down
10 changes: 4 additions & 6 deletions libopenage/presenter/presenter.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
#include <memory>
#include <vector>

#include "renderer/window.h"
#include "util/path.h"

#include <renderer/window.h>


namespace qtgui {
class GuiApplication;
Expand Down Expand Up @@ -90,10 +89,9 @@ class Presenter {
/**
* Start the presenter and initialize subsystems.
*
* @param debug_graphics If true, enable OpenGL debug logging.
* @param window_settings window display setting
* @param window_settings The settings to customize the display window (e.g. size, display mode, vsync).
*/
void run(bool debug_graphics = false, const renderer::window_settings &window_settings = {});
void run(const renderer::window_settings &window_settings = {});

/**
* Set the game simulation controlled by this presenter.
Expand Down Expand Up @@ -124,7 +122,7 @@ class Presenter {
* - main renderer
* - component renderers (Terrain, Game Entities, GUI)
*/
void init_graphics(bool debug = false, const renderer::window_settings &window_settings = {});
void init_graphics(const renderer::window_settings &window_settings = {});

/**
* Initialize the GUI.
Expand Down
14 changes: 8 additions & 6 deletions libopenage/renderer/opengl/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,20 @@ GlWindow::GlWindow(const std::string &title,
this->window->create();

// set display mode
// Reset to a known state
this->window->setWindowState(Qt::WindowNoState);
switch (settings.mode) {
case window_mode::FULLSCREEN:
this->window->showFullScreen();
case window_mode::WINDOWED:
this->window->setFlags(this->window->flags() & ~Qt::FramelessWindowHint);
break;
case window_mode::BORDERLESS:
this->window->setFlags(this->window->flags() | Qt::FramelessWindowHint);
this->window->show();
break;
case window_mode::WINDOWED:
default:
this->window->showNormal();
case window_mode::FULLSCREEN:
this->window->setWindowState(Qt::WindowFullScreen);
break;
default:
throw Error{MSG(err) << "Invalid window mode."};
}

this->context = std::make_shared<GlContext>(this->window, settings.debug);
Expand Down
2 changes: 1 addition & 1 deletion libopenage/renderer/window.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ struct window_settings {
// If true, enable debug logging for the selected backend.
bool debug = false;
// Display mode for the window.
window_mode mode = window_mode::FULLSCREEN;
window_mode mode = window_mode::WINDOWED;
};


Expand Down
6 changes: 3 additions & 3 deletions openage/game/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ def init_subparser(cli: ArgumentParser) -> None:
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")
help="Initial window size in pixels")

cli.add_argument(
"--vsync", action='store_true',
help="enable vertical synchronization")
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)")
help="Set the window mode")


def main(args, error):
Expand Down
6 changes: 3 additions & 3 deletions openage/main/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ def init_subparser(cli: ArgumentParser):
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")
help="Initial window size in pixels")

cli.add_argument(
"--vsync", action='store_true',
help="enable vertical synchronization")
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)")
help="Set the window mode")


def main(args, error):
Expand Down

0 comments on commit 87da14e

Please sign in to comment.