Skip to content

Commit

Permalink
update main, engine, window and presenter to get window arguments pas…
Browse files Browse the repository at this point in the history
…sed from py
  • Loading branch information
ZzzhHe authored and heinezen committed Dec 7, 2024
1 parent b034608 commit a4335be
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 18 deletions.
7 changes: 4 additions & 3 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,7 +16,8 @@ namespace openage::engine {
Engine::Engine(mode mode,
const util::Path &root_dir,
const std::vector<std::string> &mods,
bool debug_graphics) :
bool debug_graphics,
const renderer::window_settings &window_settings) :
running{true},
run_mode{mode},
root_dir{root_dir},
Expand Down Expand Up @@ -56,7 +57,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->presenter->run(debug_graphics);
this->presenter->run(debug_graphics, window_settings);

// Make sure that the presenter gets destructed in the same thread
// otherwise OpenGL complains about missing contexts
Expand Down
6 changes: 5 additions & 1 deletion libopenage/engine/engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

#include "util/path.h"

#include <renderer/window.h>

// TODO: Remove custom jthread definition when clang/libc++ finally supports it
#if __llvm__
#if !__cpp_lib_jthread
Expand Down Expand Up @@ -72,11 +74,13 @@ class Engine {
* @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
*/
Engine(mode mode,
const util::Path &root_dir,
const std::vector<std::string> &mods,
bool debug_graphics = false);
bool debug_graphics = false,
const renderer::window_settings &window_settings = {});

// engine should not be copied or moved
Engine(const Engine &) = delete;
Expand Down
22 changes: 20 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,25 @@ 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};
// convert window arguments to window settings
renderer::window_settings win_settings = {};
win_settings.width = args.window_args.width;
win_settings.height = args.window_args.height;
win_settings.vsync = args.window_args.vsync;

renderer::window_mode wmode;
if (args.window_args.mode == "fullscreen") {
wmode = renderer::window_mode::FULLSCREEN;
}
else if (args.window_args.mode == "borderless") {
wmode = renderer::window_mode::BORDERLESS;
}
else {
wmode = renderer::window_mode::WINDOWED;
}
win_settings.mode = wmode;

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

engine.loop();

Expand Down
22 changes: 21 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 All @@ -16,6 +16,24 @@

namespace openage {

/**
* Window parameters struct.
*
* pxd:
*
* cppclass window_arguments:
* int width
* int height
* bool vsync
* string mode
*/
struct window_arguments {
int width;
int height;
bool vsync;
std::string mode;
};

/**
* Used for passing arguments to run_game.
*
Expand All @@ -26,12 +44,14 @@ namespace openage {
* bool gl_debug
* bool headless
* vector[string] mods
* window_arguments window_args
*/
struct main_arguments {
util::Path root_path;
bool gl_debug;
bool headless;
std::vector<std::string> mods;
window_arguments window_args;
};


Expand Down
13 changes: 4 additions & 9 deletions libopenage/presenter/presenter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
#include "renderer/stages/skybox/render_stage.h"
#include "renderer/stages/terrain/render_stage.h"
#include "renderer/stages/world/render_stage.h"
#include "renderer/window.h"
#include "time/time_loop.h"
#include "util/path.h"

Expand All @@ -48,10 +47,10 @@ Presenter::Presenter(const util::Path &root_dir,
time_loop{time_loop} {}


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

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

this->init_input();

Expand Down Expand Up @@ -93,18 +92,14 @@ 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, const renderer::window_settings &window_settings) {
log::log(INFO << "Presenter: Initializing graphics subsystems...");

// Start up rendering framework
this->gui_app = this->init_window_system();

// Window and renderer
renderer::window_settings settings;
settings.width = 1024;
settings.height = 768;
settings.debug = debug;
this->window = renderer::Window::create("openage presenter test", settings);
this->window = renderer::Window::create("openage presenter test", window_settings);
this->renderer = this->window->make_renderer();

// Asset mangement
Expand Down
8 changes: 6 additions & 2 deletions libopenage/presenter/presenter.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@

#include "util/path.h"

#include <renderer/window.h>


namespace qtgui {
class GuiApplication;
}
Expand Down Expand Up @@ -88,8 +91,9 @@ class Presenter {
* Start the presenter and initialize subsystems.
*
* @param debug_graphics If true, enable OpenGL debug logging.
* @param window_settings window display setting
*/
void run(bool debug_graphics = false);
void run(bool debug_graphics = false, const renderer::window_settings &window_settings = {});

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

/**
* Initialize the GUI.
Expand Down
15 changes: 15 additions & 0 deletions libopenage/renderer/opengl/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,21 @@ GlWindow::GlWindow(const std::string &title,
this->window->setFormat(format);
this->window->create();

// set display mode
switch (settings.mode) {
case window_mode::FULLSCREEN:
this->window->showFullScreen();
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();
break;
}

this->context = std::make_shared<GlContext>(this->window, settings.debug);
if (not this->context->get_raw_context()->isValid()) {
throw Error{MSG(err) << "Failed to create Qt OpenGL context."};
Expand Down
11 changes: 11 additions & 0 deletions libopenage/renderer/window.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ namespace openage::renderer {

class WindowEventHandler;

/**
* Modes for window display.
*/
enum class window_mode {
FULLSCREEN,
BORDERLESS,
WINDOWED
};

/**
* Settings for creating a window.
*/
Expand All @@ -35,6 +44,8 @@ struct window_settings {
bool vsync = true;
// If true, enable debug logging for the selected backend.
bool debug = false;
// Display mode for the window.
window_mode mode = window_mode::FULLSCREEN;
};


Expand Down

0 comments on commit a4335be

Please sign in to comment.