18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-12-01 04:47:06 +01:00

Merge MaSzyna-EU07/maszyna master into feat/vat-people

master as of 9fecba82: the test mode (--test, null renderer), the AI braking
and passenger stops, the ESt3 brake, the SOD lamp, the 401Da oil pump lamp,
smoke of vehicles taken off the tracks, text displays with national
characters, the scenario picker drag and drop, the log written to the end of
the closing, unit and scenario tests, and the small fixes.

How the conflicts went:
- the OpenGL 3.3 and legacy renderers stay removed; what master changed in
  them is carried over where this branch has a counterpart: the opaque
  characters of text displays in scene_walk::Render_text(). The instancing
  range of master is covered by the instance records of this branch, the
  sizes of the sun and the moon are its own.
- test mode: the null backend picked in select_gfx_backend(), the window
  hidden, no crash gui; settings of the removed renderers left out.
- materials: the matte and tinted copies of this branch (the tint in the
  slot of the weathering), made again on a change of the season or the
  weather (update_variants), before the track blends.
- tracks: this branch's Segment, Track and TrackUneven, with master's
  replaced_shake(), uneven_underway(), rail_joints_moved(),
  switch_followers() and the editor's add_followers(); tributary and unknown
  track types stay as this branch loads them.
- the log service stops by StopLogService(), the exit paths of EU07.cpp too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GXgG7F4L42c2F9sDSAJbT2
This commit is contained in:
lcddisplay
2026-11-08 21:17:00 +01:00
230 changed files with 15522 additions and 821 deletions
+119 -21
View File
@@ -31,8 +31,10 @@ http://mozilla.org/MPL/2.0/.
#include "utilities/memorystats.h"
#include "utilities/dictionary.h"
#include "version_info.h"
#include "simulation/simulationtest.h"
#include <chrono>
#include <format>
#include <vector>
#include "utilities/translation.h"
#if WITH_DISCORD_RPC
@@ -295,7 +297,7 @@ void eu07_application::DiscordRPCService()
if (currentMode != mode::driver)
{
// the editor and the other modes: nothing to tell, without spinning a core on it
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
std::this_thread::sleep_for(std::chrono::milliseconds(250));
continue;
}
@@ -343,6 +345,9 @@ int eu07_application::init(int Argc, char *Argv[])
{
int result{0};
// a test run is known before anything is logged: whoever started it reads its result on the standard output,
// which the log isn't written to then (eu07/maszyna#541)
Global.test.enabled = simulation::parse_test_command_line(std::vector<char const *>(Argv, Argv + Argc)).enabled;
// start logging service
std::thread sLoggingService(LogService);
Global.threads.emplace("LogService", std::move(sLoggingService));
@@ -409,7 +414,7 @@ int eu07_application::init(int Argc, char *Argv[])
ErrorLog("Failed to init UI!");
return result;
}
if (crashreport_is_pending())
if (crashreport_is_pending() && false == Global.test.enabled)
{ // run crashgui as early as possible: it's drawn by the renderer
if ((result = run_crashgui()) != 0)
{
@@ -441,8 +446,12 @@ int eu07_application::init(int Argc, char *Argv[])
#if WITH_DISCORD_RPC
// Run DiscordRPC service
std::thread sDiscordRPC(&eu07_application::DiscordRPCService, this);
Global.threads.emplace("DiscordRPC", std::move(sDiscordRPC));
// not for a test run: it would show the test scenery as the player's presence, and hold up the closing
if (false == Global.test.enabled)
{
std::thread sDiscordRPC(&eu07_application::DiscordRPCService, this);
Global.threads.emplace("DiscordRPC", std::move(sDiscordRPC));
}
#endif
if (!init_network())
@@ -715,19 +724,29 @@ void eu07_application::release_python_lock()
void eu07_application::exit()
{
Global.applicationQuitOrder = true;
// each step of the closing in the log, to tell from it where a closing that hangs stops
auto const closing{std::chrono::steady_clock::now()};
auto const step = [closing](char const *What) {
WriteLog(std::format("Closing: {} at {} ms", What, std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::steady_clock::now() - closing).count()));
};
step("the modes");
for (auto &mode : m_modes)
mode.reset();
step("the renderer");
GfxRenderer->Shutdown();
m_network.reset();
// SafeDelete( simulation::Train );
step("the scenery");
SafeDelete(simulation::Region);
step("the ui and the python workers");
ui_layer::shutdown();
// the python workers detach their GL context on the way out, so they have to be done before the windows they use are destroyed
m_taskqueue.exit();
step("the windows");
for (auto *window : m_windows)
{
glfwDestroyWindow(window);
@@ -738,6 +757,8 @@ void eu07_application::exit()
if (!Global.exec_on_exit.empty())
system(Global.exec_on_exit.c_str());
step("done");
StopLogService();
auto it = Global.threads.find("LogService");
if (it != Global.threads.end())
{
@@ -965,14 +986,17 @@ GLFWwindow *eu07_application::window(int const Windowindex, bool visible, int wi
}
// for index -1 create a new child window
auto const *vmode{glfwGetVideoMode(monitor ? monitor : glfwGetPrimaryMonitor())};
// match requested video mode to current to allow for
// fullwindow creation when resolution is the same
glfwWindowHint(GLFW_RED_BITS, vmode->redBits);
glfwWindowHint(GLFW_GREEN_BITS, vmode->greenBits);
glfwWindowHint(GLFW_BLUE_BITS, vmode->blueBits);
glfwWindowHint(GLFW_REFRESH_RATE, vmode->refreshRate);
auto *videomonitor{monitor ? monitor : glfwGetPrimaryMonitor()};
// a machine without a display (e.g. a test runner) has no monitor to match
if (auto const *vmode{videomonitor ? glfwGetVideoMode(videomonitor) : nullptr})
{
// match requested video mode to current to allow for
// fullwindow creation when resolution is the same
glfwWindowHint(GLFW_RED_BITS, vmode->redBits);
glfwWindowHint(GLFW_GREEN_BITS, vmode->greenBits);
glfwWindowHint(GLFW_BLUE_BITS, vmode->blueBits);
glfwWindowHint(GLFW_REFRESH_RATE, vmode->refreshRate);
}
glfwWindowHint(GLFW_VISIBLE, visible);
@@ -1055,6 +1079,13 @@ void eu07_application::init_debug()
void eu07_application::init_console()
{
#ifdef _WIN32
if (Global.test.enabled)
{
// a test is started by whoever waits for its result, often reading its output: no console of its own
// (showsystemconsole) pops up and takes stdout away from them, and a console it was started from isn't hidden
return;
}
HWND consoleWnd = ::GetConsoleWindow();
const bool hadConsole = consoleWnd != nullptr;
@@ -1155,9 +1186,30 @@ int eu07_application::init_settings(int Argc, char *Argv[])
{
Global.asVersion = VERSION_INFO;
// a test run is known before the rest of the command line is read (Global.test.enabled, see init()), so a
// command line it can't take ends with the error code of the test, not with 0, which would pass it
auto const testcommandline{simulation::parse_test_command_line(std::vector<char const *>(Argv, Argv + Argc))};
if (false == testcommandline.error.empty())
{
simulation::test().conclude(simulation::test_result::error, testcommandline.error);
return -1;
}
if (testcommandline.timeout.has_value())
{
Global.test.timeout = *testcommandline.timeout;
Global.test.timeout_from_command_line = true;
}
if (testcommandline.wall_timeout.has_value())
{
Global.test.wall_timeout = testcommandline.wall_timeout;
Global.test.wall_timeout_from_command_line = true;
}
fs::path iniPath = user_config_path("eu07.ini");
if (!iniPath.empty() && fs::exists(iniPath))
// a test reads the settings of the game folder only (and those given with -ini), not the player's own
// (%APPDATA%/MaSzyna, ~/.config/MaSzyna), so it runs the same for whoever runs it
if (false == Global.test.enabled && !iniPath.empty() && fs::exists(iniPath))
{
Global.LoadIniFile(iniPath.string().c_str());
}
@@ -1216,18 +1268,51 @@ int eu07_application::init_settings(int Argc, char *Argv[])
WriteLog(std::format("seed given on the command line: {} -> {}", Argv[i], Global.random_seed));
}
}
else if (token == "--test")
{
// integration test: the scenery runs unattended and the exit code is the result (eu07/maszyna#541),
// taken from the command line above
}
else if (token == "--test-timeout" || token == "--test-wall-timeout")
{
// taken from the command line above, with its value
++i;
}
else if (token == "-ini")
{
// extra settings file read on top of eu07.ini, so a run can override a few keys
// (window size, physicslog...) without touching the user's own config
if (i + 1 < Argc)
{
Global.LoadIniFile(Argv[++i]);
}
}
else
{
std::cout << "usage: " << std::string(Argv[0]) << " [-s sceneryfilepath]"
// a test's standard output carries its result only
(Global.test.enabled ? std::cerr : std::cout) << "usage: " << std::string(Argv[0]) << " [-s sceneryfilepath]"
<< " [-v vehiclename]"
<< " [-edit [sceneryfilepath]]"
<< " [-seed number|word]" << std::endl;
<< " [-seed number|word]"
<< " [-ini settingsfile]"
<< " [--test [--test-timeout seconds] [--test-wall-timeout seconds]]" << std::endl;
simulation::test().conclude(simulation::test_result::error, std::format("unknown command line argument {}", token));
return -1;
}
}
if (editwithoutscenery && false == sceneryfromcommandline)
Global.SceneryFile.clear();
if (Global.test.enabled)
{
if (false == sceneryfromcommandline || Global.SceneryFile.empty())
{
simulation::test().conclude(simulation::test_result::error, "--test needs a scenery given with -s");
return -1;
}
simulation::apply_test_mode_settings();
}
return 0;
}
@@ -1268,7 +1353,12 @@ void eu07_application::select_gfx_backend()
auto *factory{gfx_renderer_factory::get_instance()};
m_gfxbackend = nullptr;
if (Global.GfxRenderer == "vulkan")
if (Global.GfxRenderer == "null")
{
// draws nothing and loads no textures (test mode)
m_gfxbackend = factory->backend("null");
}
else if (Global.GfxRenderer == "vulkan")
{
// a renderer which can't run here falls back to opengl, so a setting in eu07.ini doesn't leave the user with a black screen
std::string reason;
@@ -1325,8 +1415,9 @@ int eu07_application::create_main_window()
Global.bFullScreen = true;
}
// a selftest of the editor run while the computer is in use for something else draws into a window never shown nor focused
bool const shown{std::getenv("EU07_EDITOR_SELFTEST_HIDDEN") == nullptr};
// a selftest of the editor run while the computer is in use for something else draws into a window never shown nor focused;
// test mode keeps its window hidden too: glfw, the ui and the input still need one, but nothing is shown in it
bool const shown{(std::getenv("EU07_EDITOR_SELFTEST_HIDDEN") == nullptr) && (false == Global.test.enabled)};
auto *mainwindow = window(-1, shown, Global.window_size.x, Global.window_size.y, Global.bFullScreen && shown ? monitor : nullptr, true, false);
if (mainwindow == nullptr)
@@ -1358,7 +1449,9 @@ int eu07_application::create_main_window()
#ifdef _WIN32
// setup wrapper for base glfw window proc, to handle copydata messages
Hwnd = glfwGetWin32Window(mainwindow);
BaseWindowProc = (WNDPROC)::SetWindowLongPtr(Hwnd, GWLP_WNDPROC, (LONG_PTR)WndProc);
// commands sent by other programs are input from outside, which a test doesn't take
if (false == Global.test.enabled)
BaseWindowProc = (WNDPROC)::SetWindowLongPtr(Hwnd, GWLP_WNDPROC, (LONG_PTR)WndProc);
// switch off the topmost flag
::SetWindowPos(Hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
#endif
@@ -1389,13 +1482,18 @@ void eu07_application::init_callbacks()
auto *window{m_windows.front()};
glfwSetWindowSizeCallback(window, window_resize_callback);
glfwSetFramebufferSizeCallback(window, framebuffer_resize_callback);
glfwSetWindowFocusCallback(window, focus_callback);
glfwSetCursorEnterCallback(window, cursor_enter_callback);
if (Global.test.enabled)
{
// a test takes no input: keys and clicks sent to its hidden window would change the run
return;
}
glfwSetCursorPosCallback(window, cursor_pos_callback);
glfwSetMouseButtonCallback(window, mouse_button_callback);
glfwSetKeyCallback(window, key_callback);
glfwSetScrollCallback(window, scroll_callback);
glfwSetCharCallback(window, char_callback);
glfwSetWindowFocusCallback(window, focus_callback);
glfwSetCursorEnterCallback(window, cursor_enter_callback);
}
int eu07_application::init_ui()