mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-11-18 21:06:00 +01:00
Merge branch 'master' into feat/renderers-cleanup
This commit is contained in:
@@ -29,10 +29,13 @@ http://mozilla.org/MPL/2.0/.
|
||||
#include "vehicle/Train.h"
|
||||
#include "utilities/Timer.h"
|
||||
#include "utilities/memorystats.h"
|
||||
#include "utilities/framepacer.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
|
||||
@@ -343,6 +346,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 +415,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)
|
||||
{
|
||||
@@ -432,6 +438,16 @@ int eu07_application::init(int Argc, char *Argv[])
|
||||
{
|
||||
m_taskqueue.init();
|
||||
}
|
||||
crashreport_add_info("luascreens_enabled", Global.luascreens_enabled ? "yes" : "no");
|
||||
crashreport_add_info("wasm_enabled", Global.wasm_enabled ? "yes" : "no");
|
||||
if (Global.luascreens_enabled || Global.wasm_enabled)
|
||||
{
|
||||
m_screenqueue.init();
|
||||
if (Global.screens_gpupost)
|
||||
{
|
||||
m_screenqueue.set_post_processor(GfxRenderer->Screen_post_processor());
|
||||
}
|
||||
}
|
||||
if ((result = init_modes()) != 0)
|
||||
{
|
||||
ErrorLog("Failed to initialize game modes");
|
||||
@@ -441,8 +457,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())
|
||||
@@ -492,9 +512,14 @@ bool eu07_application::is_client() const
|
||||
int eu07_application::run()
|
||||
{
|
||||
auto frame{0};
|
||||
frame_pacer framepacer;
|
||||
Timer::subsystem.mainloop_period.start();
|
||||
// main application loop
|
||||
while (!glfwWindowShouldClose(m_windows.front()) && !m_modestack.empty())
|
||||
{
|
||||
// the time from one frame's start to the next, the wait for fpslimit included
|
||||
Timer::subsystem.mainloop_period.stop();
|
||||
Timer::subsystem.mainloop_period.start();
|
||||
Timer::subsystem.mainloop_total.start();
|
||||
GfxRenderer->Frame_Start();
|
||||
Timer::subsystem.loop_input.start();
|
||||
@@ -641,6 +666,7 @@ int eu07_application::run()
|
||||
|
||||
Timer::subsystem.loop_tasks.start();
|
||||
m_taskqueue.update();
|
||||
m_screenqueue.update();
|
||||
Timer::subsystem.loop_tasks.stop();
|
||||
|
||||
if (!GfxRenderer->Render())
|
||||
@@ -662,10 +688,11 @@ int eu07_application::run()
|
||||
if (m_network)
|
||||
m_network->update();
|
||||
|
||||
auto const frametime{Timer::subsystem.mainloop_total.stop()};
|
||||
if (Global.minframetime.count() != 0.0f && (Global.minframetime - frametime).count() > 0.0f)
|
||||
Timer::subsystem.mainloop_total.stop();
|
||||
// fpslimit: wait for the next frame's slot (eu07/maszyna#416)
|
||||
if (auto const nextframe{framepacer.next_frame(frame_pacer::clock::now(), Global.minframetime)})
|
||||
{
|
||||
std::this_thread::sleep_for(Global.minframetime - frametime);
|
||||
std::this_thread::sleep_until(*nextframe);
|
||||
}
|
||||
}
|
||||
// Handled by application.exit
|
||||
@@ -725,6 +752,8 @@ void eu07_application::exit()
|
||||
mode.reset();
|
||||
|
||||
step("the renderer");
|
||||
// the screens' post-processing goes with the renderer
|
||||
m_screenqueue.set_post_processor(nullptr);
|
||||
GfxRenderer->Shutdown();
|
||||
m_network.reset();
|
||||
|
||||
@@ -737,6 +766,7 @@ void eu07_application::exit()
|
||||
|
||||
// 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();
|
||||
m_screenqueue.exit();
|
||||
step("the windows");
|
||||
for (auto *window : m_windows)
|
||||
{
|
||||
@@ -977,14 +1007,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);
|
||||
|
||||
@@ -1067,6 +1100,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;
|
||||
|
||||
@@ -1167,9 +1207,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());
|
||||
}
|
||||
@@ -1228,18 +1289,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;
|
||||
}
|
||||
|
||||
@@ -1300,6 +1394,11 @@ void eu07_application::select_gfx_backend()
|
||||
Global.GfxRenderer = "default";
|
||||
}
|
||||
}
|
||||
else if (Global.GfxRenderer == "null")
|
||||
{
|
||||
// draws nothing and loads no textures (test mode)
|
||||
m_gfxbackend = factory->backend("null");
|
||||
}
|
||||
|
||||
if (m_gfxbackend == nullptr)
|
||||
{
|
||||
@@ -1337,8 +1436,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,
|
||||
// and test mode keeps its window hidden: 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)
|
||||
@@ -1370,7 +1470,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
|
||||
@@ -1401,13 +1503,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()
|
||||
|
||||
Reference in New Issue
Block a user