Support Windows Server GUI startup with Direct3D and WARP (by Codex)

This commit is contained in:
Codex committed 2026-10-23 08:52:10 +02:00
1 parent d9d05f83b4
commit 856d38cc0c
20 files changed
+532 -172

No files matched your search

+6
View File
@@ -66,6 +66,12 @@ jobs:
run: cmake --build build --config Release --parallel 2
- name: Run synthetic tests and report data tests as skipped
run: ctest --test-dir build -C Release --output-on-failure --output-junit test-results.xml
- name: Windows Server launcher with WARP software graphics
if: runner.os == 'Windows'
env:
SDL_VIDEODRIVER: windows
OPENBMH_RML_DRIVER: warp
run: build/launcher_gui_smoke.exe
- name: Package products and licenses
run: python3 tools/package/make_package.py --build build --out dist --platform ${{ matrix.platform }}
- name: Package corresponding source and pinned dependencies
+5 -1
View File
@@ -49,7 +49,7 @@ jobs:
if [[ "$RUNNER_OS" == "macOS" ]]; then args+=(-DCMAKE_OSX_ARCHITECTURES=arm64 -DCMAKE_OSX_DEPLOYMENT_TARGET=11.0); fi
cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Release -DOPENBMH_BUILD_EDITOR=ON -DBMH_DATA= "${args[@]}"
- name: Build editor and synthetic tests
run: cmake --build build --target openbmh_editor editor_core_tests editor_comparison_tests editor_regulations_tests --parallel 2
run: cmake --build build --target openbmh_editor launcher_gui_smoke editor_core_tests editor_comparison_tests editor_regulations_tests --parallel 2
- name: Native editor core and MCP tests
run: ctest --test-dir build -C Release -R "^editor_(core_tests|comparison_tests|regulations_tests|version)$" --output-on-failure --output-junit editor-tests.xml
- name: Linux native GUI smoke
@@ -57,6 +57,10 @@ jobs:
run: |
xvfb-run -a -s '-screen 0 1600x1000x24' python3 tests/editor_gui_smoke.py build/OpenBMHEditor
xvfb-run -a -s '-screen 0 1600x1000x24' build/OpenBMHEditor --demo --page players --settings build/test-options.json --screenshot build/editor.png --quit-after-ms 1800
xvfb-run -a -s '-screen 0 1600x1000x24' python3 tests/editor_startup_smoke.py build/OpenBMHEditor --launcher build/launcher_gui_smoke
- name: Windows Server native GUI and WARP fallback
if: runner.os == 'Windows'
run: python3 tests/editor_startup_smoke.py build/OpenBMHEditor.exe --launcher build/launcher_gui_smoke.exe
- name: Package editor
shell: bash
run: |
+1 -1
View File
@@ -1,6 +1,6 @@
# SPDX-License-Identifier: GPL-3.0-only
cmake_minimum_required(VERSION 3.24)
project(OpenBMH VERSION 0.2.0 LANGUAGES CXX C)
project(OpenBMH VERSION 0.2.1 LANGUAGES CXX C)
if(APPLE)
enable_language(OBJC OBJCXX)
set(CMAKE_OBJCXX_STANDARD 20)
+3 -3
View File
@@ -1,8 +1,8 @@
# OpenBMH
The separate [OpenBMH Editor 0.5.2](docs/EDITOR.md) uses native RmlUI,
The separate [OpenBMH Editor 0.5.3](docs/EDITOR.md) uses native RmlUI,
supports German/English, three themes, image editing and a local MCP server.
Download its own `editor-v0.5.2` release or build with
Download its own `editor-v0.5.3` release or build with
`-DOPENBMH_BUILD_EDITOR=ON`. Edited worlds are independent of the Classic runtime.
A modern and faithful open source rebuild of the *Bundesliga Manager Hattrick* engine.
@@ -36,7 +36,7 @@ For direct startup or the console:
Both frontends use native content and saves. Use **Add** to migrate older files rather than passing an original executable or `.FBM` to the running game. The starting year changes the Classic year display; original weekday and scheduling rules are preserved. Modern worlds are reserved for a later version.
The launcher uses SDL2, RmlUI and OpenGL 3.3 (macOS: OpenGL 4.1); keep its `assets` directory next to the executable. Folder selection uses the operating system's dialog. See the [0.2 migration contract](docs/formats/obw/runtime-0.2.md) for compatibility and validation limits. Platform builds and automated tests are separate from human interactive acceptance on Windows and macOS.
The launcher uses SDL2 and RmlUI, with Direct3D 11 and automatic WARP software fallback on Windows, OpenGL 3.3 on Linux and OpenGL 4.1 on macOS; keep its `assets` directory next to the executable. Folder selection uses the operating system's dialog. See the [0.2 migration contract](docs/formats/obw/runtime-0.2.md) for compatibility and validation limits. Platform builds and automated tests are separate from human interactive acceptance on Windows and macOS.
## Features and direction
+18 -5
View File
@@ -1,10 +1,23 @@
# OpenBMH Editor 0.5.2
# OpenBMH Editor 0.5.3
Der eigenständige, native Editor verwendet **RmlUI, SDL2 und OpenGL**. Er bearbeitet Startdatenbanken, keine laufenden Spielstände. Das Spiel und seine Classic-Prüfung bleiben unverändert. Editor 0.5.2 hat eine eigene Versionsreihe und den Release-Tag `editor-v0.5.2`; die Spielversion ist 0.2.0.
Der eigenständige, native Editor verwendet **RmlUI, SDL2 und OpenGL**. Er bearbeitet Startdatenbanken, keine laufenden Spielstände. Das Spiel und seine Classic-Prüfung bleiben unverändert. Editor 0.5.3 hat eine eigene Versionsreihe und den Release-Tag `editor-v0.5.3`; die Spielversion ist 0.2.1.
## Windows-Start und Diagnose
Windows verwendet Direct3D 11 und wechselt bei fehlender Hardware automatisch auf
den integrierten WARP-Renderer. Der Editor und der Spiel-Launcher benötigen dort
keinen OpenGL-Treiber. Dieser Start wird auch mit erzwungenem WARP auf Windows
Server 2022 geprüft. Zum gezielten Testen lässt sich `OPENBMH_RML_DRIVER=warp`
setzen; die normale Auswahl erfolgt automatisch.
Startfehler erscheinen in einem nativen Dialog und werden zusätzlich unter
`%LOCALAPPDATA%\OpenBMH\OpenBMHEditor-startup.log` protokolliert. Bei einem
Aufruf aus PowerShell/CMD kann auch stderr umgeleitet werden. Headless- und
MCP-Aufrufe zeigen keinen modalen Fehlerdialog und behalten ihre Prozesscodes.
## Starten und Daten öffnen
Das vollständige Paket `OpenBMHEditor-0.5.2-<plattform>.zip` entpacken und `OpenBMHEditor.exe` (Windows) beziehungsweise `OpenBMHEditor` (Linux/macOS) starten. `assets/editor` muss beim Programm bleiben. Auf macOS kann die unsignierte Anwendung über **Rechtsklick → Öffnen** gestartet werden. Eine Signatur/Notarisierung ist nicht Bestandteil dieser Version. `OpenBMHEditor --version` zeigt die Editorversion ohne Grafikstart.
Das vollständige Paket `OpenBMHEditor-0.5.3-<plattform>.zip` entpacken und `OpenBMHEditor.exe` (Windows) beziehungsweise `OpenBMHEditor` (Linux/macOS) starten. `assets/editor` muss beim Programm bleiben. Auf macOS kann die unsignierte Anwendung über **Rechtsklick → Öffnen** gestartet werden. Eine Signatur/Notarisierung ist nicht Bestandteil dieser Version. `OpenBMHEditor --version` zeigt die Editorversion ohne Grafikstart.
**Öffnen** bietet OBW-Dateien und entpackte Welten an. **BMH / FLTD importieren** liest einen Ordner mit einer unterstützten BMH- oder Football-Limited-Installation durch den bestehenden Konverter. Das Original wird nicht überschrieben. Eine bestehende Classic-OBW wird zunächst überprüft und dann in eine bearbeitbare Editorwelt übernommen.
@@ -84,7 +97,7 @@ Das sind keine heutigen UEFA-Regeln und kein neuer Saison-Simulator.
## Kompilieren
Voraussetzungen entsprechen dem Hauptprojekt: C++20-Compiler, Git, CMake ≥ 3.24 und Ninja. Windows: Visual Studio 2022 C++ Build Tools / x64 Native Tools Prompt; macOS ARM: Xcode Command Line Tools, CMake und Ninja; Linux: GTK3-, X11- und OpenGL-Entwicklungspakete wie im Haupt-README. Die Grafikausgabe benötigt OpenGL 3.3, auf macOS OpenGL 4.1.
Voraussetzungen entsprechen dem Hauptprojekt: C++20-Compiler, Git, CMake ≥ 3.24 und Ninja. Windows: Visual Studio 2022 C++ Build Tools / x64 Native Tools Prompt; macOS ARM: Xcode Command Line Tools, CMake und Ninja; Linux: GTK3-, X11- und OpenGL-Entwicklungspakete wie im Haupt-README. Windows nutzt Direct3D 11 mit automatischem WARP-Software-Fallback; Linux benötigt OpenGL 3.3, macOS OpenGL 4.1.
```sh
cmake -S . -B build-editor -G Ninja -DCMAKE_BUILD_TYPE=Release -DOPENBMH_BUILD_EDITOR=ON
@@ -118,4 +131,4 @@ The editor retains full squads, original image data, source claims and unknown e
In **Options**, switch the interface to **English**, choose one of the three themes, and enable/disable the integrated local MCP server. **Copy connection** provides the authenticated configuration. The server defaults to loopback port 8765; use port 0 for a free port. GUI and MCP share the same world, validation and undo history. It supports MCP Streamable HTTP 2025-11-25/2025-06-18 and optional stdio mode. Use `expected_revision` for concurrent edits.
Build with the three commands above, including `-DOPENBMH_BUILD_EDITOR=ON`. The native application requires OpenGL 3.3 (macOS 4.1) and the platform development dependencies documented in the main README. Editor 0.5.2 is unsigned and does not bundle any real-world dataset or proprietary game assets.
Build with the three commands above, including `-DOPENBMH_BUILD_EDITOR=ON`. Windows uses Direct3D 11 with automatic WARP software fallback. Linux requires OpenGL 3.3; macOS requires OpenGL 4.1, plus the documented platform development dependencies. Editor 0.5.3 is unsigned and does not bundle any real-world dataset or proprietary game assets.
+5 -2
View File
@@ -57,8 +57,11 @@ of `OpenBMH`, keeping edition-specific process globals isolated. Portable mod co
personal files have independent lifetimes. See [runtime-0.2](formats/obw/runtime-0.2.md).
The launcher layout and theme live in `assets/launcher/launcher.rml` and `theme.rcss`.
They share the same RmlUI core, FreeType font engine and upstream SDL2/OpenGL renderer
on all desktop platforms. The C++ view translates events into the existing launcher
They share the same RmlUI core, FreeType font engine and SDL2 platform layer.
Windows uses the pinned upstream Direct3D 11 renderer with hardware-to-WARP
fallback, while Linux/macOS keep the upstream OpenGL renderer. Both the editor
and launcher share window/device lifetime, resizing and capture through
`src/launch/rml_video.*`. The C++ view translates events into the existing launcher
interface; it does not own conversion rules or mod storage. This presentation layer
can be reused by future modern screens. Classic game screens retain their current UI.
The operating system supplies the folder picker through nativefiledialog-extended.
+10 -1
View File
@@ -1,5 +1,14 @@
<!-- SPDX-License-Identifier: GPL-3.0-only -->
# OpenBMH v0.2.0
# OpenBMH v0.2.1
Fixes the launcher startup on Windows Server / Remote Desktop and computers
without an OpenGL 3.3 driver. The Windows RmlUI launcher uses Direct3D 11, with
automatic WARP software fallback; Linux and macOS keep their existing OpenGL
renderer. Launch errors use a native Windows dialog and a diagnostic log under
`%LOCALAPPDATA%/OpenBMH/OpenBMH-startup.log`. Game rules, saves and OBW content
remain compatible with 0.2.0.
## Version 0.2.0
Version 0.2 makes the original-style game independent of the original installation
after import. It supports Bundesliga Manager Hattrick and Football Limited Classic
+15 -1
View File
@@ -1,5 +1,19 @@
<!-- SPDX-License-Identifier: GPL-3.0-only -->
# OpenBMH Editor 0.5.2
# OpenBMH Editor 0.5.3
Fixes the Windows graphical startup on machines without an OpenGL 3.3 driver,
including Windows Server / Remote Desktop. The editor and game launcher use the
pinned RmlUI Direct3D 11 renderer with automatic WARP software fallback. No
additional graphics runtime download is needed on the supported Windows systems.
Linux/macOS retain their existing OpenGL rendering.
Windows startup failures now produce a native dialog and a log in
`%LOCALAPPDATA%/OpenBMH/OpenBMHEditor-startup.log`. Console redirection is
retained and headless/MCP errors remain nonmodal. Native GUI startup, screenshots,
Unicode paths and the actual launcher are now tested on Windows Server 2022
with WARP forced, in addition to the existing core/MCP tests.
## Editor 0.5.2
Adds **Regulations / Regelwerk**, a read-only view of game and league rules.
Inspect promotion/relegation places and destinations, playoff conditions,
+3 -21
View File
@@ -31,6 +31,7 @@
#include "launch/file_dialog.hpp"
#include "launch/game_data.hpp"
#include "launch/launcher.hpp"
#include "launch/rml_video.hpp"
#include "content/package.hpp"
#include "version.hpp"
#include "app/live_matchday_events.hpp"
@@ -75,8 +76,7 @@ using namespace bmh;
// Why the game cannot start: a message box, and the same text on stderr.
static void show_start_error(const std::string& text) {
std::fprintf(stderr, "%s\n", text.c_str());
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "OpenBMH", text.c_str(), nullptr);
rml::report_start_error("OpenBMH", text);
}
// Reattach the native editor when an in-game filename field takes focus. Cocoa
@@ -91,26 +91,8 @@ static void focus_filename_input(SDL_Renderer* renderer) {
SDL_StartTextInput();
}
#ifdef _WIN32
// The game is a Windows GUI program (no console window on double-click). Started from a
// console, it writes --version, --help and start errors there (kernel32 AttachConsole).
extern "C" __declspec(dllimport) int __stdcall AttachConsole(unsigned long process_id);
static void attach_parent_console() {
// (an output redirected to a file or pipe stays there; a GUI program without one has no
// valid stream, fileno < 0)
const bool out_free = _fileno(stdout) < 0, err_free = _fileno(stderr) < 0;
if ((out_free || err_free) && AttachConsole(static_cast<unsigned long>(-1))) { // ATTACH_PARENT_PROCESS
std::FILE* f = nullptr;
if (out_free) freopen_s(&f, "CONOUT$", "w", stdout);
if (err_free) freopen_s(&f, "CONOUT$", "w", stderr);
}
}
#else
static void attach_parent_console() {}
#endif
int main(int argc, char** argv) {
attach_parent_console();
rml::attach_parent_console();
const std::vector<std::string> args = launch::utf8_arguments(argc, argv); // (file names beyond the code page)
fs::path data, save_directory;
uint32_t seed = uint32_t(std::chrono::system_clock::now().time_since_epoch().count());
+1 -1
View File
@@ -1,6 +1,6 @@
# SPDX-License-Identifier: GPL-3.0-only
include(FetchContent)
set(OPENBMH_EDITOR_VERSION "0.5.2")
set(OPENBMH_EDITOR_VERSION "0.5.3")
file(WRITE "${CMAKE_BINARY_DIR}/editor-version.json" "{\"version\": \"${OPENBMH_EDITOR_VERSION}\"}\n")
set(JSON_BuildTests OFF CACHE BOOL "" FORCE)
FetchContent_Declare(editor_json GIT_REPOSITORY https://github.com/nlohmann/json.git
+12 -2
View File
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: GPL-3.0-only
#include "editor/ui.hpp"
#include "editor/version.hpp"
#include "launch/rml_video.hpp"
#include <SDL.h>
#include <atomic>
#include <chrono>
@@ -14,7 +15,14 @@ void stop(int) { stopped = true; }
} // namespace
int main(int argc, char **argv) {
using namespace bmh::editor;
bmh::rml::attach_parent_console();
std::string language = "de";
bool graphical = true;
for (int i = 1; i < argc; ++i)
if (std::string_view(argv[i]) == "--headless" || std::string_view(argv[i]) == "--serve" ||
std::string_view(argv[i]) == "--stdio-mcp" || std::string_view(argv[i]) == "--version" ||
std::string_view(argv[i]) == "--help")
graphical = false;
try {
bool headless = false, serve = false, stdio = false, demo = false, blank = false, validate = false,
print = false;
@@ -153,10 +161,12 @@ int main(int argc, char **argv) {
}
return has_errors ? 2 : 0;
} catch (const Error &e) {
std::cerr << Json{{"error", e.code}, {"message", tr(language, e.code)}, {"details", e.details}}.dump() << '\n';
const auto message =
Json{{"error", e.code}, {"message", tr(language, e.code)}, {"details", e.details}}.dump();
bmh::rml::report_start_error("OpenBMHEditor", message, graphical);
return 1;
} catch (const std::exception &e) {
std::cerr << tr(language, "error") << ": " << e.what() << '\n';
bmh::rml::report_start_error("OpenBMHEditor", tr(language, "error") + ": " + e.what(), graphical);
return 1;
}
}
+3 -2
View File
@@ -4,7 +4,9 @@
#include <map>
#include <random>
#ifdef _WIN32
#ifndef NOMINMAX
#define NOMINMAX
#endif
#include <windows.h>
#else
#include <sys/stat.h>
@@ -268,8 +270,7 @@ std::string tr(const std::string &language, const std::string &key) {
"Drag a rectangle on the image or enter crop values. Without cropping, "
"the original resolution is retained."}},
{"video_failed",
{"Die Grafikausgabe benötigt OpenGL 3.3 (macOS: 4.1).",
"The interface requires OpenGL 3.3 (macOS: 4.1)."}},
{"Die Grafikausgabe konnte nicht initialisiert werden.", "Graphics initialization failed."}},
{"ui_assets_missing",
{"Editor-Oberfläche fehlt. Bitte das vollständige Paket entpacken.",
"Editor interface files are missing. Please extract the complete "
+15 -66
View File
@@ -3,11 +3,11 @@
#include "editor/images.hpp"
#include "editor/version.hpp"
#include "launch/rml_path.hpp"
#include "launch/rml_video.hpp"
#include <RmlUi/Core.h>
#include <RmlUi/Core/Elements/ElementFormControl.h>
#include <RmlUi/Core/Elements/ElementFormControlInput.h>
#include <RmlUi_Platform_SDL.h>
#include <RmlUi_Renderer_GL3.h>
#include <algorithm>
#include <chrono>
#include <cmath>
@@ -31,58 +31,13 @@ std::string button(const std::string &action, const std::string &label, const st
return "<button data-action=\"" + escaped(action) + "\" class=\"" + css + "\" " + attributes + ">" +
escaped(label) + "</button>";
}
struct Video {
SDL_Window *window = nullptr;
SDL_GLContext gl = nullptr;
bool loader = false;
Video() {
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS | SDL_INIT_TIMER) != 0)
throw Error("video_failed");
SDL_SetHint(SDL_HINT_MOUSE_FOCUS_CLICKTHROUGH, "1");
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
#ifdef __APPLE__
SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_FORWARD_COMPATIBLE_FLAG);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 4);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);
#else
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3);
#endif
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
window =
SDL_CreateWindow("OpenBMH Editor", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 1440, 900,
SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI | SDL_WINDOW_HIDDEN);
if (!window)
throw Error("video_failed");
SDL_SetWindowMinimumSize(window, 1080, 720);
gl = SDL_GL_CreateContext(window);
if (!gl)
throw Error("video_failed");
SDL_GL_MakeCurrent(window, gl);
SDL_GL_SetSwapInterval(1);
std::string error;
if (!RmlGL3::Initialize(&error))
throw Error("video_failed", {{"detail", error}});
loader = true;
SDL_StartTextInput();
}
~Video() {
if (loader)
RmlGL3::Shutdown();
if (gl)
SDL_GL_DeleteContext(gl);
if (window)
SDL_DestroyWindow(window);
SDL_Quit();
}
};
class Renderer final : public RenderInterface_GL3 {
class Renderer final : public bmh::rml::Renderer {
public:
Session &session;
std::map<std::string, std::pair<std::string, std::string>> memory;
std::map<std::string, std::string> logical;
uint64_t serial = 0;
explicit Renderer(Session &s) : session(s) {}
Renderer(Session &s, bmh::rml::Video &video) : bmh::rml::Renderer(video), session(s) {}
std::string asset(const std::string &key) {
auto token = "world-image-" + std::to_string(serial++) + ".png";
logical[token] = key;
@@ -101,7 +56,7 @@ class Renderer final : public RenderInterface_GL3 {
Rml::TextureHandle LoadTexture(Rml::Vector2i &dimensions, const Rml::String &source) override {
const auto token = utf8(path(source).filename());
if (!memory.contains(token) && !logical.contains(token))
return RenderInterface_GL3::LoadTexture(dimensions, source);
return bmh::rml::Renderer::LoadTexture(dimensions, source);
try {
auto value = memory.contains(token) ? memory.at(token) : session.asset_bytes(logical.at(token));
auto raster = images::decode(value.first, value.second, token.starts_with("icon-") ? 64 : 512);
@@ -129,7 +84,7 @@ class EditorUi final : public Rml::EventListener {
Options &options_;
McpServer &server_;
UiConfig config_;
Video video_;
bmh::rml::Video video_{"OpenBMH Editor", 1440, 900, 1080, 720};
bmh::rml::AssetFiles files_;
SystemInterface_SDL system_{video_.window};
Renderer renderer_;
@@ -299,7 +254,7 @@ class EditorUi final : public Rml::EventListener {
void resize() {
int w, h, pw, ph;
SDL_GetWindowSize(video_.window, &w, &h);
SDL_GL_GetDrawableSize(video_.window, &pw, &ph);
video_.drawable_size(pw, ph);
if (!w || !h)
return;
renderer_.SetViewport(pw, ph);
@@ -1775,23 +1730,16 @@ class EditorUi final : public Rml::EventListener {
if (config_.screenshot.empty())
return;
int w, h;
SDL_GL_GetDrawableSize(video_.window, &w, &h);
images::Raster raster{w, h, std::vector<uint8_t>(size_t(w) * h * 4)};
using ReadPixels = void (*)(int, int, int, int, unsigned, unsigned, void *);
auto read = reinterpret_cast<ReadPixels>(SDL_GL_GetProcAddress("glReadPixels"));
if (!read)
throw Error("video_failed");
read(0, 0, w, h, 0x1908 /* RGBA */, 0x1401 /* UNSIGNED_BYTE */, raster.pixels.data());
for (int y = 0; y < h / 2; ++y)
for (int x = 0; x < w * 4; ++x)
std::swap(raster.pixels[size_t(y) * w * 4 + x], raster.pixels[size_t(h - y - 1) * w * 4 + x]);
auto pixels = video_.capture(w, h);
images::Raster raster{w, h, std::move(pixels)};
write_atomic(config_.screenshot, images::encode_png(raster));
config_.screenshot.clear();
}
public:
EditorUi(Session &s, Options &o, McpServer &server, UiConfig config)
: session_(s), options_(o), server_(server), config_(std::move(config)), renderer_(s) {
: session_(s), options_(o), server_(server), config_(std::move(config)), renderer_(s, video_) {
SDL_StartTextInput();
page_ = config_.page;
Rml::SetSystemInterface(&system_);
Rml::SetFileInterface(&files_);
@@ -1801,10 +1749,11 @@ class EditorUi final : public Rml::EventListener {
if (!initialized_)
throw Error("video_failed");
for (auto weight : {"Regular", "Bold"})
if (!Rml::LoadFontFace(utf8(config_.assets / (std::string("LatoLatin-") + weight + ".ttf"))))
if (!Rml::LoadFontFace(
bmh::rml::asset_path(config_.assets / (std::string("LatoLatin-") + weight + ".ttf"))))
throw Error("ui_assets_missing");
context_ = Rml::CreateContext("editor", {1440, 900});
doc_ = context_->LoadDocument(utf8(config_.assets / "editor.rml"));
doc_ = context_->LoadDocument(bmh::rml::asset_path(config_.assets / "editor.rml"));
if (!doc_)
throw Error("ui_assets_missing");
for (auto event : {"click", "change", "mousedown", "mouseup", "mousemove"})
@@ -1915,7 +1864,7 @@ class EditorUi final : public Rml::EventListener {
ime_.HandleEdit(event.edit);
int w, h, pw, ph;
SDL_GetWindowSize(video_.window, &w, &h);
SDL_GL_GetDrawableSize(video_.window, &pw, &ph);
video_.drawable_size(pw, ph);
if (w && h) {
if (event.type == SDL_MOUSEMOTION) {
event.motion.x = int(double(event.motion.x) * pw / w);
@@ -1978,7 +1927,7 @@ class EditorUi final : public Rml::EventListener {
auto elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(now - start_).count();
if (!busy_ && elapsed > 1200 && !config_.screenshot.empty())
screenshot();
SDL_GL_SwapWindow(video_.window);
video_.present();
SDL_Delay(10);
if (config_.quit_after_ms > 0 && elapsed >= config_.quit_after_ms)
closed_ = true;
+3
View File
@@ -33,6 +33,9 @@ target_link_libraries(bmh_launcher PUBLIC bmh_content)
include(../launch/rmlui.cmake)
target_sources(bmh_launcher PRIVATE ../launch/launcher_rmlui.cpp)
target_link_libraries(bmh_launcher PRIVATE bmh_rmlui nfd)
add_executable(launcher_gui_smoke ../../tests/launcher_gui_smoke.cpp)
target_link_libraries(launcher_gui_smoke PRIVATE bmh_launcher bmh_rmlui)
set_target_properties(launcher_gui_smoke PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}")
add_executable(launcher_document_tests ../../tests/launcher_document_tests.cpp)
target_include_directories(launcher_document_tests PRIVATE ..)
target_link_libraries(launcher_document_tests PRIVATE RmlUi::Core)
+11 -64
View File
@@ -1,18 +1,18 @@
// SPDX-License-Identifier: GPL-3.0-only
#include "launch/launcher_ui.hpp"
#include "launch/rml_path.hpp"
#include "launch/archive.hpp"
#include "launch/launcher_ui.hpp"
#include "launch/process.hpp"
#include "launch/rml_path.hpp"
#include "launch/rml_video.hpp"
#include "version.hpp"
#include <RmlUi/Core.h>
#include <RmlUi/Core/Elements/ElementFormControl.h>
#include <RmlUi/Core/Elements/ElementFormControlInput.h>
#include <RmlUi_Platform_SDL.h>
#include <RmlUi_Renderer_GL3.h>
#include <nfd.hpp>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <nfd.hpp>
#include <stdexcept>
namespace bmh::launch {
@@ -41,9 +41,6 @@ std::string escape(std::string_view value) {
}
return result;
}
[[noreturn]] void sdl_error(const char *operation) {
throw std::runtime_error(std::string(operation) + ": " + SDL_GetError());
}
int modifiers(Uint16 state) {
int result = 0;
if (state & KMOD_CTRL)
@@ -65,62 +62,11 @@ int modifiers(Uint16 state) {
result |= Rml::Input::KM_NUMLOCK;
return result;
}
struct Video {
SDL_Window *window = nullptr;
SDL_GLContext gl = nullptr;
bool loader = false;
Video() {
try {
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS | SDL_INIT_TIMER) != 0)
sdl_error("Launcher video initialization");
SDL_SetHint(SDL_HINT_MOUSE_FOCUS_CLICKTHROUGH, "1");
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
#ifdef __APPLE__
SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_FORWARD_COMPATIBLE_FLAG);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 4);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);
#else
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3);
#endif
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
window = SDL_CreateWindow("OpenBMH", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 1100, 688,
SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI |
SDL_WINDOW_HIDDEN);
if (!window)
sdl_error("Launcher window");
SDL_SetWindowMinimumSize(window, 800, 540);
gl = SDL_GL_CreateContext(window);
if (!gl)
sdl_error("Launcher requires OpenGL 3.3 (macOS: 4.1)");
SDL_GL_MakeCurrent(window, gl);
SDL_GL_SetSwapInterval(1);
std::string error;
if (!RmlGL3::Initialize(&error))
throw std::runtime_error("Launcher graphics initialization: " + error);
loader = true;
SDL_StopTextInput();
} catch (...) {
close();
throw;
}
}
void close() {
if (loader)
RmlGL3::Shutdown();
if (gl)
SDL_GL_DeleteContext(gl);
if (window)
SDL_DestroyWindow(window);
SDL_QuitSubSystem(SDL_INIT_VIDEO | SDL_INIT_EVENTS | SDL_INIT_TIMER);
}
~Video() { close(); }
};
class RmlLauncher final : public LauncherUI, public Rml::EventListener {
Video video_;
rml::Video video_{"OpenBMH", 1100, 688, 800, 540};
rml::AssetFiles files_;
SystemInterface_SDL system_{video_.window};
RenderInterface_GL3 renderer_;
rml::Renderer renderer_{video_};
TextInputMethodEditor_SDL ime_;
Rml::Context *context_ = nullptr;
Rml::ElementDocument *document_ = nullptr;
@@ -165,7 +111,7 @@ class RmlLauncher final : public LauncherUI, public Rml::EventListener {
void resize() {
int w = 0, h = 0, pixels_w = 0, pixels_h = 0;
SDL_GetWindowSize(video_.window, &w, &h);
SDL_GL_GetDrawableSize(video_.window, &pixels_w, &pixels_h);
video_.drawable_size(pixels_w, pixels_h);
if (w <= 0 || h <= 0 || pixels_w <= 0 || pixels_h <= 0)
return;
renderer_.SetViewport(pixels_w, pixels_h);
@@ -350,7 +296,7 @@ class RmlLauncher final : public LauncherUI, public Rml::EventListener {
// SDL2 reports mouse coordinates in window units on Retina/HiDPI.
int w = 0, h = 0, pw = 0, ph = 0;
SDL_GetWindowSize(video_.window, &w, &h);
SDL_GL_GetDrawableSize(video_.window, &pw, &ph);
video_.drawable_size(pw, ph);
if (w > 0 && h > 0) {
if (event.type == SDL_MOUSEMOTION) {
event.motion.x = int(double(event.motion.x) * pw / w);
@@ -377,7 +323,7 @@ class RmlLauncher final : public LauncherUI, public Rml::EventListener {
renderer_.Clear();
context_->Render();
renderer_.EndFrame();
SDL_GL_SwapWindow(video_.window);
video_.present();
dirty_ = false;
}
}
@@ -390,8 +336,9 @@ class RmlLauncher final : public LauncherUI, public Rml::EventListener {
public:
RmlLauncher() {
SDL_StopTextInput();
if (!renderer_)
throw std::runtime_error("RmlUI could not create the OpenGL renderer");
throw std::runtime_error("RmlUI could not create the graphics renderer");
try {
Rml::SetSystemInterface(&system_);
Rml::SetFileInterface(&files_);
+233
View File
@@ -0,0 +1,233 @@
// SPDX-License-Identifier: GPL-3.0-only
#include "launch/rml_video.hpp"
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <filesystem>
#include <fstream>
#include <stdexcept>
#include <string_view>
#ifdef _WIN32
#include <SDL_syswm.h>
#endif
namespace bmh::rml {
namespace {
[[noreturn]] void sdl_error(const char *operation) {
throw std::runtime_error(std::string(operation) + ": " + SDL_GetError());
}
#ifdef _WIN32
void check(HRESULT result, const char *operation) {
if (FAILED(result)) {
char code[24];
std::snprintf(code, sizeof(code), "0x%08lX", static_cast<unsigned long>(result));
throw std::runtime_error(std::string(operation) + ": " + code);
}
}
std::wstring wide(const std::string &text) {
const int length = MultiByteToWideChar(CP_UTF8, 0, text.data(), int(text.size()), nullptr, 0);
std::wstring result(size_t(length), L' ');
MultiByteToWideChar(CP_UTF8, 0, text.data(), int(text.size()), result.data(), length);
return result;
}
#endif
} // namespace
Video::Video(const char *title, int width, int height, int minimum_width, int minimum_height) {
try {
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS | SDL_INIT_TIMER) != 0)
sdl_error("Video initialization");
SDL_SetHint(SDL_HINT_MOUSE_FOCUS_CLICKTHROUGH, "1");
Uint32 flags = SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI | SDL_WINDOW_HIDDEN;
#ifndef _WIN32
flags |= SDL_WINDOW_OPENGL;
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
#ifdef __APPLE__
SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_FORWARD_COMPATIBLE_FLAG);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 4);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);
#else
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3);
#endif
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
#endif
window =
SDL_CreateWindow(title, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, width, height, flags);
if (!window)
sdl_error("Window creation");
SDL_SetWindowMinimumSize(window, minimum_width, minimum_height);
#ifdef _WIN32
SDL_SysWMinfo info{};
SDL_VERSION(&info.version);
if (!SDL_GetWindowWMInfo(window, &info))
sdl_error("Native window handle");
DXGI_SWAP_CHAIN_DESC desc{};
desc.BufferCount = 2;
desc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
desc.OutputWindow = info.info.win.window;
desc.SampleDesc.Count = 1;
desc.Windowed = TRUE;
desc.SwapEffect = DXGI_SWAP_EFFECT_FLIP_DISCARD;
const D3D_FEATURE_LEVEL levels[] = {D3D_FEATURE_LEVEL_11_0};
auto create = [&](D3D_DRIVER_TYPE driver) {
return D3D11CreateDeviceAndSwapChain(nullptr, driver, nullptr, 0, levels, 1, D3D11_SDK_VERSION,
&desc, swapchain_.ReleaseAndGetAddressOf(),
device_.ReleaseAndGetAddressOf(), nullptr,
context_.ReleaseAndGetAddressOf());
};
const auto mode = std::getenv("OPENBMH_RML_DRIVER");
const bool force_warp = mode && std::string_view(mode) == "warp";
HRESULT result = force_warp ? E_FAIL : create(D3D_DRIVER_TYPE_HARDWARE);
bool software = false;
if (FAILED(result)) {
result = create(D3D_DRIVER_TYPE_WARP);
software = true;
}
check(result, "Direct3D 11 initialization (hardware and WARP)");
// Upstream's full-featured renderer requires the 11.1 runtime interfaces.
Microsoft::WRL::ComPtr<ID3D11Device1> device1;
Microsoft::WRL::ComPtr<ID3D11DeviceContext1> context1;
check(device_.As(&device1), "Direct3D 11.1 device");
check(context_.As(&context1), "Direct3D 11.1 context");
std::fprintf(stderr, "RmlUI renderer: Direct3D 11 (%s)\n", software ? "WARP software" : "hardware");
int pw, ph;
drawable_size(pw, ph);
resize(pw, ph);
#else
gl_ = SDL_GL_CreateContext(window);
if (!gl_)
sdl_error("OpenGL 3.3 initialization (macOS: 4.1)");
if (SDL_GL_MakeCurrent(window, gl_) != 0)
sdl_error("OpenGL context activation");
SDL_GL_SetSwapInterval(1);
std::string error;
if (!RmlGL3::Initialize(&error))
throw std::runtime_error("OpenGL renderer initialization: " + error);
loader_ = true;
#endif
} catch (...) {
close();
throw;
}
}
Video::~Video() { close(); }
void Video::close() noexcept {
#ifdef _WIN32
if (context_)
context_->ClearState();
target_.Reset();
swapchain_.Reset();
context_.Reset();
device_.Reset();
#else
if (loader_)
RmlGL3::Shutdown();
if (gl_)
SDL_GL_DeleteContext(gl_);
#endif
if (window)
SDL_DestroyWindow(window);
SDL_QuitSubSystem(SDL_INIT_VIDEO | SDL_INIT_EVENTS | SDL_INIT_TIMER);
}
void Video::drawable_size(int &width, int &height) const {
#ifdef _WIN32
SDL_GetWindowSizeInPixels(window, &width, &height);
#else
SDL_GL_GetDrawableSize(window, &width, &height);
#endif
}
#ifdef _WIN32
void Video::resize(int width, int height) {
if (width < 1 || height < 1 || (width == width_ && height == height_ && target_))
return;
context_->OMSetRenderTargets(0, nullptr, nullptr);
target_.Reset();
check(swapchain_->ResizeBuffers(0, UINT(width), UINT(height), DXGI_FORMAT_UNKNOWN, 0),
"Swapchain resize");
Microsoft::WRL::ComPtr<ID3D11Texture2D> buffer;
check(swapchain_->GetBuffer(0, IID_PPV_ARGS(&buffer)), "Swapchain buffer");
check(device_->CreateRenderTargetView(buffer.Get(), nullptr, &target_), "Render target");
width_ = width;
height_ = height;
}
#endif
void Video::present() {
#ifdef _WIN32
check(swapchain_->Present(1, 0), "Direct3D presentation");
#else
SDL_GL_SwapWindow(window);
#endif
}
std::vector<uint8_t> Video::capture(int &width, int &height) {
drawable_size(width, height);
std::vector<uint8_t> pixels(size_t(width) * size_t(height) * 4);
#ifdef _WIN32
Microsoft::WRL::ComPtr<ID3D11Texture2D> buffer, staging;
check(swapchain_->GetBuffer(0, IID_PPV_ARGS(&buffer)), "Screenshot buffer");
D3D11_TEXTURE2D_DESC desc{};
buffer->GetDesc(&desc);
desc.Usage = D3D11_USAGE_STAGING;
desc.BindFlags = 0;
desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
desc.MiscFlags = 0;
check(device_->CreateTexture2D(&desc, nullptr, &staging), "Screenshot staging texture");
context_->CopyResource(staging.Get(), buffer.Get());
D3D11_MAPPED_SUBRESOURCE data{};
check(context_->Map(staging.Get(), 0, D3D11_MAP_READ, 0, &data), "Screenshot readback");
for (int row = 0; row < height; ++row)
std::memcpy(pixels.data() + size_t(row) * width * 4,
static_cast<const uint8_t *>(data.pData) + size_t(row) * data.RowPitch,
size_t(width) * 4);
context_->Unmap(staging.Get(), 0);
#else
using ReadPixels = void (*)(int, int, int, int, unsigned, unsigned, void *);
auto read = reinterpret_cast<ReadPixels>(SDL_GL_GetProcAddress("glReadPixels"));
if (!read)
sdl_error("Screenshot readback");
read(0, 0, width, height, 0x1908, 0x1401, pixels.data());
for (int row = 0; row < height / 2; ++row)
for (int col = 0; col < width * 4; ++col)
std::swap(pixels[size_t(row) * width * 4 + col],
pixels[size_t(height - row - 1) * width * 4 + col]);
#endif
return pixels;
}
void report_start_error(const char *product, const std::string &message, bool dialog) noexcept {
std::fprintf(stderr, "%s: %s\n", product, message.c_str());
#ifdef _WIN32
try {
wchar_t directory[32768]{};
const auto length = GetEnvironmentVariableW(L"LOCALAPPDATA", directory, 32768);
auto root = (length > 0 && length < 32768 ? std::filesystem::path(directory)
: std::filesystem::temp_directory_path()) /
L"OpenBMH";
std::filesystem::create_directories(root);
std::ofstream log(root / (std::string(product) + "-startup.log"), std::ios::app);
log << message << '\n';
if (dialog && !std::getenv("OPENBMH_NO_ERROR_DIALOG"))
MessageBoxW(nullptr, wide(message).c_str(), wide(product).c_str(), MB_OK | MB_ICONERROR);
} catch (...) {
if (dialog && !std::getenv("OPENBMH_NO_ERROR_DIALOG"))
MessageBoxW(nullptr, L"The application could not start.", L"OpenBMH", MB_OK | MB_ICONERROR);
}
#else
if (dialog && !std::getenv("OPENBMH_NO_ERROR_DIALOG"))
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, product, message.c_str(), nullptr);
#endif
}
void attach_parent_console() noexcept {
#ifdef _WIN32
const bool out_free = _fileno(stdout) < 0, err_free = _fileno(stderr) < 0;
if ((out_free || err_free) && AttachConsole(ATTACH_PARENT_PROCESS)) {
FILE *stream = nullptr;
if (out_free)
freopen_s(&stream, "CONOUT$", "w", stdout);
if (err_free)
freopen_s(&stream, "CONOUT$", "w", stderr);
}
#endif
}
} // namespace bmh::rml
+74
View File
@@ -0,0 +1,74 @@
// SPDX-License-Identifier: GPL-3.0-only
#pragma once
#include <SDL.h>
#include <cstdint>
#include <string>
#include <vector>
#ifdef _WIN32
#ifndef NOMINMAX
#define NOMINMAX
#endif
#include <RmlUi_Renderer_DX11.h>
#include <wrl/client.h>
#else
#include <RmlUi_Renderer_GL3.h>
#endif
namespace bmh::rml {
// The native Windows renderer needs no OpenGL ICD in a Remote Desktop session.
// The device falls back to Microsoft's built-in WARP when hardware is absent.
class Video {
public:
SDL_Window *window = nullptr;
Video(const char *title, int width, int height, int minimum_width, int minimum_height);
~Video();
Video(const Video &) = delete;
Video &operator=(const Video &) = delete;
void drawable_size(int &width, int &height) const;
void present();
// RGBA rows in top-to-bottom order, independent of the graphics API.
std::vector<uint8_t> capture(int &width, int &height);
#ifdef _WIN32
ID3D11Device *device() const { return device_.Get(); }
ID3D11RenderTargetView *target() const { return target_.Get(); }
void resize(int width, int height);
#endif
private:
void close() noexcept;
#ifdef _WIN32
Microsoft::WRL::ComPtr<ID3D11Device> device_;
Microsoft::WRL::ComPtr<ID3D11DeviceContext> context_;
Microsoft::WRL::ComPtr<IDXGISwapChain> swapchain_;
Microsoft::WRL::ComPtr<ID3D11RenderTargetView> target_;
int width_ = 0, height_ = 0;
#else
SDL_GLContext gl_ = nullptr;
bool loader_ = false;
#endif
};
#ifdef _WIN32
class Renderer : public RenderInterface_DX11 {
Video &video_;
public:
explicit Renderer(Video &video) : RenderInterface_DX11(video.device()), video_(video) {}
void SetViewport(int width, int height) {
video_.resize(width, height);
RenderInterface_DX11::SetViewport(width, height);
}
void Clear() { RenderInterface_DX11::Clear(video_.target()); }
void EndFrame() { RenderInterface_DX11::EndFrame(video_.target()); }
explicit operator bool() const { return video_.device() != nullptr; }
};
#else
class Renderer : public RenderInterface_GL3 {
public:
explicit Renderer(Video &) {}
};
#endif
// Also used before SDL initialization, so an unavailable graphics driver cannot
// prevent reporting the actual startup error. No preferences or tokens are logged.
void report_start_error(const char *product, const std::string &message, bool dialog = true) noexcept;
void attach_parent_console() noexcept;
} // namespace bmh::rml
+9 -2
View File
@@ -22,8 +22,15 @@ FetchContent_Declare(rmlui
FetchContent_MakeAvailable(rmlui)
add_library(bmh_rmlui STATIC
${rmlui_SOURCE_DIR}/Backends/RmlUi_Platform_SDL.cpp
${rmlui_SOURCE_DIR}/Backends/RmlUi_Renderer_GL3.cpp)
target_include_directories(bmh_rmlui PUBLIC ${rmlui_SOURCE_DIR}/Backends)
${CMAKE_SOURCE_DIR}/src/launch/rml_video.cpp)
if(WIN32)
target_sources(bmh_rmlui PRIVATE ${rmlui_SOURCE_DIR}/Backends/RmlUi_Renderer_DX11.cpp)
target_link_libraries(bmh_rmlui PUBLIC d3d11 dxgi d3dcompiler)
target_compile_definitions(bmh_rmlui PUBLIC NUM_MSAA_SAMPLES=1 NOMINMAX)
else()
target_sources(bmh_rmlui PRIVATE ${rmlui_SOURCE_DIR}/Backends/RmlUi_Renderer_GL3.cpp)
endif()
target_include_directories(bmh_rmlui PUBLIC ${rmlui_SOURCE_DIR}/Backends ${CMAKE_SOURCE_DIR}/src)
target_compile_definitions(bmh_rmlui PUBLIC RMLUI_SDL_VERSION_MAJOR=2 RMLUI_NUM_MSAA_SAMPLES=0)
target_link_libraries(bmh_rmlui PUBLIC RmlUi::Core ${BMH_SDL_TARGET} PRIVATE ${CMAKE_DL_LIBS})
+72
View File
@@ -0,0 +1,72 @@
#!/usr/bin/env python3
# SPDX-License-Identifier: GPL-3.0-only
"""Native graphics startup, including Windows Server/WARP and missing assets.
Use an actual display (Xvfb on Linux). Never reads a user profile or game data.
Optionally opens the actual launcher UI too. Windows CI runs on Server 2022.
"""
import argparse
import json
import os
from pathlib import Path
import shutil
import struct
import subprocess
import tempfile
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('editor', type=Path)
parser.add_argument('--launcher', type=Path)
args = parser.parse_args()
# Non-ASCII + spaces exercise UTF-8 native loading and RmlUI URL paths.
with tempfile.TemporaryDirectory(prefix='OpenBMH Pr\u00fcfung ') as temporary:
root = Path(temporary)
executable = args.editor.resolve()
env = {**os.environ, 'OPENBMH_RML_DRIVER': 'warp', 'OPENBMH_NO_ERROR_DIALOG': '1',
'LIBGL_ALWAYS_SOFTWARE': '1', 'SDL_AUDIODRIVER': 'dummy'}
if os.name == 'nt':
env['SDL_VIDEODRIVER'] = 'windows'
# Copy the GUI and its own assets, rather than finding files via cwd.
installed = root / 'Programme'; installed.mkdir()
exe = installed / executable.name
shutil.copy2(executable, exe)
shutil.copytree(executable.parent / 'assets/editor', installed / 'assets/editor')
for dll in executable.parent.glob('*.dll'):
shutil.copy2(dll, installed / dll.name)
settings = root / 'settings.json'
settings.write_text(json.dumps({'language': 'de', 'theme': 'midnight', 'mcp_enabled': False}))
for name, options in [('first-start', []), ('demo', ['--demo', '--page', 'regulations'])]:
screenshot = root / (name + '.png')
result = subprocess.run([str(exe), '--settings', str(settings), '--quit-after-ms', '1800',
'--screenshot', str(screenshot), *options],
cwd=root, env=env, capture_output=True, timeout=35)
assert result.returncode == 0, (name, result.returncode, result.stderr.decode(errors='replace'))
image = screenshot.read_bytes()
assert image[:8] == b'\x89PNG\r\n\x1a\n' and len(image) > 15000, name
width, height = struct.unpack_from('>II', image, 16)
assert width >= 1080 and height >= 720, (width, height)
if os.name == 'nt':
assert b'Direct3D 11 (WARP software)' in result.stderr, result.stderr
result = subprocess.run([str(exe), '--settings', str(settings), '--assets', str(root / 'missing-assets')],
cwd=root, env=env, capture_output=True, timeout=20)
assert result.returncode == 1 and b'ui_assets_missing' in result.stderr, result.stderr
# Also render and close the real launcher, without needing installed mods.
if args.launcher:
original = args.launcher.resolve()
launcher = installed / original.name
shutil.copy2(original, launcher)
shutil.copytree(original.parent / 'assets/launcher', installed / 'assets/launcher')
for dll in original.parent.glob('*.dll'):
shutil.copy2(dll, installed / dll.name)
result = subprocess.run([str(launcher)], cwd=root, env=env, capture_output=True, timeout=25)
assert result.returncode == 0, result.stderr
assert b'Native launcher rendered' in result.stdout, result.stdout
if os.name == 'nt':
assert b'Direct3D 11 (WARP software)' in result.stderr, result.stderr
print('Native first start, demo, Unicode asset paths, failure reporting and launcher startup passed')
if __name__ == '__main__':
main()
+33
View File
@@ -0,0 +1,33 @@
// SPDX-License-Identifier: GPL-3.0-only
#include "launch/launcher_ui.hpp"
#include <SDL.h>
#include <cstdio>
#include <stdexcept>
// Run explicitly on a real display (Windows CI also forces the WARP device),
// outside the dummy-video CTest suite. This constructs the actual launcher UI.
int main(int, char **) {
try {
auto ui = bmh::launch::make_launcher_ui();
const auto timer = SDL_AddTimer(
1600,
[](Uint32, void *) -> Uint32 {
SDL_Event event{};
event.type = SDL_QUIT;
SDL_PushEvent(&event);
return 0;
},
nullptr);
if (!timer)
throw std::runtime_error(SDL_GetError());
const auto result = ui->next({});
SDL_RemoveTimer(timer);
if (result.action != bmh::launch::LauncherAction::end)
return 1;
std::puts("Native launcher rendered and exited successfully");
return 0;
} catch (const std::exception &error) {
std::fprintf(stderr, "%s\n", error.what());
return 1;
}
}