mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-11-19 16:55:10 +01:00
Merge branch 'master' into feat/renderers-cleanup
This commit is contained in:
@@ -73,6 +73,14 @@ void global_settings::FinalizeConfig()
|
||||
python_enabled = false;
|
||||
#endif
|
||||
|
||||
#ifndef WITH_WASM
|
||||
wasm_enabled = false;
|
||||
#endif
|
||||
|
||||
#ifndef WITH_LUA
|
||||
luascreens_enabled = false;
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
Console::ModeSet(iFeedbackMode, iFeedbackPort);
|
||||
#endif
|
||||
@@ -488,6 +496,66 @@ bool global_settings::ConfigParseInput(cParser& Parser, const std::string& token
|
||||
return false;
|
||||
}
|
||||
|
||||
bool global_settings::ConfigParseTest(cParser& Parser, std::string_view const Token)
|
||||
{
|
||||
// integration test limits, usually given in the config block of a test scenery
|
||||
if (Token == "test.timeout")
|
||||
{
|
||||
double value{ test.timeout };
|
||||
ParseOne(Parser, value);
|
||||
if (false == test.timeout_from_command_line)
|
||||
test.timeout = std::max(0.0, value);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (Token == "test.wall_timeout")
|
||||
{
|
||||
double value{ 0.0 };
|
||||
ParseOne(Parser, value);
|
||||
if (false == test.wall_timeout_from_command_line)
|
||||
test.wall_timeout = std::max(0.0, value);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (Token == "test.vehicle")
|
||||
{
|
||||
// a vehicle of a train under test, by its name in the scenery; the pass and the standstill wait for its
|
||||
// consist only, not for other trains (eu07/maszyna#541). given more than once, for each of them
|
||||
std::string name;
|
||||
ParseOne(Parser, name, 1, true);
|
||||
if (false == name.empty() && std::ranges::find(test.vehicles, name) == test.vehicles.end())
|
||||
test.vehicles.emplace_back(name);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (Token == "test.standstill")
|
||||
{
|
||||
ParseOne(Parser, test.standstill);
|
||||
test.standstill = std::max(0.0, test.standstill);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (Token == "test.pass_on_standstill")
|
||||
{
|
||||
ParseOne(Parser, test.pass_on_standstill);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (Token == "test.fail_if_stop_overran")
|
||||
{
|
||||
ParseOne(Parser, test.fail_if_stop_overran);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (Token == "test.no_movement_before_pass")
|
||||
{
|
||||
ParseOne(Parser, test.no_movement_before_pass);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool global_settings::ConfigParseSimulation(cParser& Parser, const std::string& token)
|
||||
{
|
||||
if (token == "async.trainThreads")
|
||||
@@ -855,6 +923,12 @@ bool global_settings::ConfigParseSimulation(cParser& Parser, const std::string&
|
||||
return true;
|
||||
}
|
||||
|
||||
if (token == "controlcoupling.enginecheck")
|
||||
{
|
||||
ParseOne(Parser, control_coupling_engine_check, 1);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -915,6 +989,42 @@ bool global_settings::ConfigParseUI(cParser& Parser, const std::string& token)
|
||||
return false;
|
||||
}
|
||||
|
||||
bool global_settings::ConfigParseScriptScreens(cParser& Parser, std::string_view const token)
|
||||
{
|
||||
if (token == "luascreens.enabled")
|
||||
{
|
||||
ParseOne(Parser, luascreens_enabled, 1);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (token == "wasm.enabled")
|
||||
{
|
||||
ParseOne(Parser, wasm_enabled, 1);
|
||||
return true;
|
||||
}
|
||||
|
||||
// wasm.cabframes and wasm.externalframes: the first names of the keys, from before the Lua screens
|
||||
if (token == "screens.cabframes" || token == "wasm.cabframes")
|
||||
{
|
||||
ParseOneClamped(Parser, screens_cabframes, 1, 1000);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (token == "screens.externalframes" || token == "wasm.externalframes")
|
||||
{
|
||||
ParseOneClamped(Parser, screens_externalframes, 1, 1000);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (token == "screens.gpupost")
|
||||
{
|
||||
ParseOne(Parser, screens_gpupost, 1);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool global_settings::ConfigParsePython(cParser& Parser, const std::string& token)
|
||||
{
|
||||
if (token == "python.enabled")
|
||||
@@ -1423,6 +1533,9 @@ void global_settings::ConfigParse(cParser& Parser)
|
||||
if (ConfigParsePython(Parser, token))
|
||||
continue;
|
||||
|
||||
if (ConfigParseScriptScreens(Parser, token))
|
||||
continue;
|
||||
|
||||
if (ConfigParseNetwork(Parser, token))
|
||||
continue;
|
||||
|
||||
@@ -1432,6 +1545,9 @@ void global_settings::ConfigParse(cParser& Parser)
|
||||
if (ConfigParseDebug(Parser, token))
|
||||
continue;
|
||||
|
||||
if (ConfigParseTest(Parser, token))
|
||||
continue;
|
||||
|
||||
// WriteLog(std::format("Unknown config token: {}", token), logtype::warning, false);
|
||||
|
||||
} while (true);
|
||||
@@ -2195,6 +2311,7 @@ global_settings::export_as_text( std::ostream &Output ) const {
|
||||
export_as_text( Output, "scenario.time.current", ScenarioTimeCurrent );
|
||||
export_as_text( Output, "scenario.weather.temperature", AirTemperature );
|
||||
export_as_text( Output, "ai.trainman", AITrainman );
|
||||
export_as_text( Output, "controlcoupling.enginecheck", control_coupling_engine_check );
|
||||
export_as_text( Output, "scalespeculars", ScaleSpecularValues );
|
||||
export_as_text( Output, "gfxrenderer", GfxRenderer );
|
||||
export_as_text( Output, "shadows", RenderShadows );
|
||||
@@ -2358,6 +2475,17 @@ global_settings::export_as_text( std::ostream &Output ) const {
|
||||
export_as_text( Output, "gfx.shadowmap.enabled", gfx_shadowmap_enabled );
|
||||
// TODO: export fpslimit
|
||||
export_as_text( Output, "randomseed", Global.random_seed );
|
||||
export_as_text( Output, "test.timeout", test.timeout );
|
||||
if( test.wall_timeout.has_value() ) {
|
||||
export_as_text( Output, "test.wall_timeout", *test.wall_timeout );
|
||||
}
|
||||
export_as_text( Output, "test.standstill", test.standstill );
|
||||
export_as_text( Output, "test.pass_on_standstill", test.pass_on_standstill );
|
||||
export_as_text( Output, "test.fail_if_stop_overran", test.fail_if_stop_overran );
|
||||
export_as_text( Output, "test.no_movement_before_pass", test.no_movement_before_pass );
|
||||
for( auto const &vehicle : test.vehicles ) {
|
||||
export_as_text( Output, "test.vehicle", vehicle );
|
||||
}
|
||||
export_as_text( Output, "gfx.envmap.enabled", gfx_envmap_enabled );
|
||||
export_as_text( Output, "gfx.lights.clustered", gfx_lights_clustered );
|
||||
export_as_text( Output, "gfx.lights.clusterheatmap", gfx_lights_clusterheatmap );
|
||||
@@ -2500,6 +2628,11 @@ global_settings::export_as_text( std::ostream &Output ) const {
|
||||
export_as_text( Output, "python.threadedupload", python_threadedupload );
|
||||
export_as_text( Output, "python.uploadmain", python_uploadmain );
|
||||
export_as_text( Output, "python.mipmaps", python_mipmaps );
|
||||
export_as_text( Output, "luascreens.enabled", luascreens_enabled );
|
||||
export_as_text( Output, "wasm.enabled", wasm_enabled );
|
||||
export_as_text( Output, "screens.cabframes", screens_cabframes );
|
||||
export_as_text( Output, "screens.externalframes", screens_externalframes );
|
||||
export_as_text( Output, "screens.gpupost", screens_gpupost );
|
||||
export_as_text( Output, "async.trainThreads", trainThreads );
|
||||
for( auto const &server : network_servers ) {
|
||||
Output
|
||||
|
||||
@@ -16,6 +16,7 @@ http://mozilla.org/MPL/2.0/.
|
||||
#include "utilities/utilities.h"
|
||||
#include "utilities/motiontelemetry.h"
|
||||
#include <map>
|
||||
#include <optional>
|
||||
|
||||
#ifdef WITH_UART
|
||||
#include "utilities/uart.h"
|
||||
@@ -87,6 +88,20 @@ struct global_settings {
|
||||
std::string local_start_vehicle{ "EU07-424" };
|
||||
std::string editor_enter_vehicle; // vehicle placed in the editor, to be entered when the driving goes on
|
||||
bool editor_session{ false }; // scenery was opened for editing (-edit): loader keeps track of scenery layers and hands over to the editor
|
||||
// integration test mode (--test, eu07/maszyna#541); the limits can be set in the scenery's config block (test.*)
|
||||
struct test_settings {
|
||||
bool enabled{ false };
|
||||
double timeout{ 3600.0 }; // [s] of simulation time; no result by then fails the test
|
||||
double standstill{ 300.0 }; // [s] the tested trains standing still this long ends the test; 0 = never
|
||||
bool pass_on_standstill{ false }; // the standstill end passes the test instead of failing it
|
||||
bool fail_if_stop_overran{ true }; // a train passing a signal at stop ends the test as failed; with false it's only logged
|
||||
bool no_movement_before_pass{ true }; // a pass waits until the tested trains stand still; with false it ends the test at once
|
||||
std::vector<std::string> vehicles; // test.vehicle: the trains under test are the consists of these; none = every vehicle
|
||||
bool timeout_from_command_line{ false }; // --test-timeout given, the scenery doesn't override it
|
||||
std::optional<double> wall_timeout; // [s] of real time since the start; none = test.timeout + time for the loading, 0 = no limit
|
||||
bool wall_timeout_from_command_line{ false }; // --test-wall-timeout given, the scenery doesn't override it
|
||||
};
|
||||
test_settings test;
|
||||
bool editor_tracks{ false }; // F3 track workspace: draw and pick tracks without the scenery draw-range cap
|
||||
int iConvertModels{ 0 }; // tworzenie plików binarnych
|
||||
int iConvertIndexRange{ 1000 }; // range of duplicate vertex scan
|
||||
@@ -306,6 +321,7 @@ struct global_settings {
|
||||
bool captureonstart = true;
|
||||
bool render_cab = true;
|
||||
bool crash_damage = true;
|
||||
bool control_coupling_engine_check = true; // no multiple-unit control between electric and diesel traction vehicles (eu07/maszyna#520)
|
||||
bool gui_defaultwindows = true;
|
||||
bool gui_showtranscripts = true;
|
||||
bool gui_trainingdefault = false;
|
||||
@@ -326,6 +342,11 @@ struct global_settings {
|
||||
bool python_sharectx = true;
|
||||
bool python_uploadmain = true;
|
||||
std::chrono::duration<float> python_minframetime {0.01f};
|
||||
bool luascreens_enabled{true}; // screens drawn by Lua scripts (luascreen:, luadestinationsign: in the .mmd)
|
||||
bool wasm_enabled{true}; // screens drawn by WebAssembly modules (wasmscreen:, wasmdestinationsign: in the .mmd)
|
||||
int screens_cabframes{4}; // the script screens in the cab are refreshed every so many rendered frames
|
||||
int screens_externalframes{30}; // the script screens outside the cab (destination signs) are refreshed every so many rendered frames
|
||||
bool screens_gpupost{true}; // the post-processing of the script screens (image:led_post, image:resize) on the gpu, when the renderer can
|
||||
|
||||
bool gfx_skiprendering = false;
|
||||
// the size of the image the scene of the main window is drawn to: -1 until the renderer works it out from the window and
|
||||
@@ -670,9 +691,11 @@ struct global_settings {
|
||||
bool ConfigParseSimulation(cParser& Parser, const std::string& token);
|
||||
bool ConfigParseUI(cParser& Parser, const std::string& token);
|
||||
bool ConfigParsePython(cParser& Parser, const std::string& token);
|
||||
bool ConfigParseScriptScreens(cParser& Parser, std::string_view token);
|
||||
bool ConfigParseNetwork(cParser& Parser, const std::string& token);
|
||||
bool ConfigParseHardware(cParser& Parser, const std::string& token);
|
||||
bool ConfigParseDebug(cParser& Parser, const std::string& token);
|
||||
bool ConfigParseTest(cParser& Parser, std::string_view Token);
|
||||
bool ConfigParse_gfx( cParser &parser, std::string_view const Token );
|
||||
// sky light and exposure switches of the opengl 4.6 renderer (gfx.ambient.*, gfx.envmap.ggx, gfx.atmosphere*, gfx.postfx.autoexposure*, gfx.postfx.bloom*, gfx.postfx.whitebalance*, gfx.postfx.ao*)
|
||||
bool ConfigParse_gfx_sky( cParser &parser, std::string_view const Token );
|
||||
|
||||
@@ -127,8 +127,8 @@ void LogService()
|
||||
if (log_scrollback.size() > 200)
|
||||
log_scrollback.pop_front();
|
||||
|
||||
// log to console
|
||||
if (Global.iWriteLogEnabled & 2)
|
||||
// log to console; not in test mode, where the standard output carries the result of the test only
|
||||
if ((Global.iWriteLogEnabled & 2) && false == Global.test.enabled)
|
||||
{
|
||||
if (isError)
|
||||
printf("\033[1;37;41m%s\033[0m\n", msg.c_str());
|
||||
|
||||
@@ -27,6 +27,17 @@ double fSoundTimer{ 0.0 };
|
||||
double fSinceStart{ 0.0 };
|
||||
double override_delta = -1.0f;
|
||||
|
||||
namespace {
|
||||
|
||||
// when set (test mode), every frame lasts this long, see set_fixed_step()
|
||||
double &fixed_step()
|
||||
{
|
||||
static double step{0.0};
|
||||
return step;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
double GetTime()
|
||||
{
|
||||
return fSimulationTime;
|
||||
@@ -53,6 +64,11 @@ void set_delta_override(double t)
|
||||
override_delta = t;
|
||||
}
|
||||
|
||||
void set_fixed_step(double t)
|
||||
{
|
||||
fixed_step() = t;
|
||||
}
|
||||
|
||||
void ResetTimers()
|
||||
{
|
||||
UpdateTimers( Global.iPause != 0 );
|
||||
@@ -76,10 +92,16 @@ void UpdateTimers(bool pause)
|
||||
fr = 1000000000;
|
||||
#endif
|
||||
DeltaRenderTime = double(count - oldCount) / double(fr);
|
||||
auto const fixedstep{fixed_step()};
|
||||
if (fixedstep > 0.0)
|
||||
{
|
||||
// the frame lasts exactly as long as said, however long it took to compute; the time speed doesn't apply
|
||||
DeltaRenderTime = fixedstep;
|
||||
}
|
||||
fRenderTime += DeltaRenderTime;
|
||||
if (!pause)
|
||||
{
|
||||
DeltaTime = Global.fTimeSpeed * DeltaRenderTime;
|
||||
DeltaTime = (fixedstep > 0.0 ? 1.0 : Global.fTimeSpeed) * DeltaRenderTime;
|
||||
fSoundTimer += DeltaTime;
|
||||
if (fSoundTimer > 0.1)
|
||||
fSoundTimer = 0.0;
|
||||
|
||||
@@ -25,6 +25,9 @@ double GetDeltaRenderTime();
|
||||
|
||||
void set_delta_override(double v);
|
||||
|
||||
// every frame advances the clocks by this many seconds, whatever the real time; 0 = real time (test mode)
|
||||
void set_fixed_step(double v);
|
||||
|
||||
void ResetTimers();
|
||||
|
||||
void UpdateTimers(bool pause);
|
||||
@@ -244,6 +247,7 @@ struct subsystem_stopwatches {
|
||||
stopwatch loop_renderer_update; // gfx_renderer::Update()
|
||||
stopwatch loop_terrain; // terrain streaming
|
||||
stopwatch loop_tasks; // task queue
|
||||
stopwatch mainloop_period; // start to start, the wait for fpslimit included
|
||||
};
|
||||
|
||||
extern subsystem_stopwatches subsystem;
|
||||
|
||||
@@ -404,7 +404,9 @@ void write_report()
|
||||
std::swprintf(message, std::size(message), L"The simulator has crashed.\n\nIts memory dump could not be written (error %lu), the description of the crash is in:\n%ls_info.txt",
|
||||
static_cast<unsigned long>(data.error), base);
|
||||
}
|
||||
::MessageBoxW(nullptr, message, L"MaSzyna", MB_ICONERROR | MB_OK | MB_TOPMOST | MB_SETFOREGROUND);
|
||||
// in test mode nobody is there to close the box, and the run would wait for it until killed
|
||||
if (false == Global.test.enabled)
|
||||
::MessageBoxW(nullptr, message, L"MaSzyna", MB_ICONERROR | MB_OK | MB_TOPMOST | MB_SETFOREGROUND);
|
||||
::SetEvent(report_done);
|
||||
}
|
||||
|
||||
|
||||
59
utilities/framepacer.h
Normal file
59
utilities/framepacer.h
Normal file
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
This Source Code Form is subject to the
|
||||
terms of the Mozilla Public License, v.
|
||||
2.0. If a copy of the MPL was not
|
||||
distributed with this file, You can
|
||||
obtain one at
|
||||
http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <chrono>
|
||||
#include <optional>
|
||||
|
||||
// paces the main loop to the frame time set by fpslimit in eu07.ini.
|
||||
// the frames are scheduled on a fixed cadence rather than by sleeping off what is left of each frame,
|
||||
// so a sleep that overshoots (the windows timer wakes up in steps of up to ~15.6 ms) is made up by
|
||||
// a shorter wait in the next frame, and the frame rate averages to the limit.
|
||||
// all the time arithmetic is done in the clock's integer ticks: a sleep_for() given a float duration
|
||||
// adds it to now() as float nanoseconds, which after a few hours of system uptime rounds the wake-up
|
||||
// time to tens of milliseconds and lets the limit fall through (eu07/maszyna#416)
|
||||
class frame_pacer {
|
||||
|
||||
public:
|
||||
using clock = std::chrono::steady_clock;
|
||||
|
||||
// called at the end of each frame. returns the point in time the next frame may start at,
|
||||
// or nothing when it may start right away
|
||||
[[nodiscard]] std::optional<clock::time_point> next_frame(clock::time_point const Now, std::chrono::duration<float> const Frametime) {
|
||||
return next_frame(Now, std::chrono::duration_cast<clock::duration>(Frametime));
|
||||
}
|
||||
[[nodiscard]] std::optional<clock::time_point> next_frame(clock::time_point const Now, clock::duration const Minframetime) {
|
||||
if (Minframetime <= clock::duration::zero()) {
|
||||
// no limit
|
||||
m_framestart.reset();
|
||||
return std::nullopt;
|
||||
}
|
||||
if (!m_framestart) {
|
||||
// first paced frame
|
||||
m_framestart = Now;
|
||||
return std::nullopt;
|
||||
}
|
||||
auto const nextframe{*m_framestart + Minframetime};
|
||||
if (Now >= nextframe + Minframetime) {
|
||||
// a whole frame or more behind: start the cadence anew rather than run frames back to back to catch up
|
||||
m_framestart = Now;
|
||||
return std::nullopt;
|
||||
}
|
||||
m_framestart = nextframe;
|
||||
if (Now >= nextframe) {
|
||||
return std::nullopt;
|
||||
}
|
||||
return nextframe;
|
||||
}
|
||||
|
||||
private:
|
||||
// the scheduled start of the current frame
|
||||
std::optional<clock::time_point> m_framestart;
|
||||
};
|
||||
@@ -273,6 +273,10 @@ std::string locale::label_cab_control(std::string const &Label)
|
||||
{ "coolingfans_sw:", STRN("cooling fans") },
|
||||
{ "main_off_bt:", STRN("line breaker") },
|
||||
{ "main_on_bt:", STRN("line breaker") },
|
||||
{ "mainb_off_bt:", STRN("line breaker B") },
|
||||
{ "mainb_on_bt:", STRN("line breaker B") },
|
||||
{ "mainc_off_bt:", STRN("line breaker C") },
|
||||
{ "mainc_on_bt:", STRN("line breaker C") },
|
||||
{ "security_reset_bt:", STRN("alerter") },
|
||||
{ "shp_reset_bt:", STRN("shp") },
|
||||
{ "releaser_bt:", STRN("independent brake releaser") },
|
||||
@@ -318,7 +322,14 @@ std::string locale::label_cab_control(std::string const &Label)
|
||||
{ "converterlocal_sw:", STRN("local converter") },
|
||||
{ "converteroff_sw:", STRN("converter") },
|
||||
{ "main_sw:", STRN("line breaker") },
|
||||
{ "mainb_sw:", STRN("line breaker B") },
|
||||
{ "mainc_sw:", STRN("line breaker C") },
|
||||
{ "radio_sw:", STRN("radio") },
|
||||
{ "radioon_sw:", STRN("radio") },
|
||||
{ "radiooff_sw:", STRN("radio") },
|
||||
{ "radiofuse_sw:", STRN("radio fuse") },
|
||||
{ "radiofuseon_sw:", STRN("radio fuse") },
|
||||
{ "radiofuseoff_sw:", STRN("radio fuse") },
|
||||
{ "radiochannel_sw:", STRN("radio channel") },
|
||||
{ "radiochannelprev_sw:", STRN("radio channel") },
|
||||
{ "radiochannelnext_sw:", STRN("radio channel") },
|
||||
|
||||
Reference in New Issue
Block a user