18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-12-01 09:27:10 +01:00
Files
maszyna/application/driveruipanels.cpp
T
Hirek 04f76951f5 refactor(physics): the diesel engine, the torque converter and the retarder are components of their own
TMoverParameters held some 80 fields of the diesel engine and its hydraulic
transmission among its other 600, named dizel_*, hydro_TC_* and hydro_R_*.
They are now three structures of physics/components/dieselengine.h, with
English names:

- DieselEngine diesel: the definition (maxMoment, maxRevolutions,
  minRevolutions, the governor, the clutch, the fuel consumption, the tables)
  and the state (fill, clutchState, clutchPressure, torque, power, the start
  up, the fuel consumed) and its heat (EngineHeat, heat_data before)
- TorqueConverter torqueConverter: present, the ratios, the lockup, the
  fill rates, the table, and its state (fill, lockedUp, torqueRatio, the
  revolutions in and out)
- Retarder retarder: present, its placement, torque, power, fill rates,
  clutch, and its state

The .fiz keywords, the keys of the dictionaries of the Python screens and the
names of the golden channels (dizel_fill...) are unchanged; only the C++
names changed. The functions of the engine (dizel_Update, dizel_Momentum...)
stay members of TMoverParameters for now.

No change in behaviour: 1144/1144 tests, golden traces exact against staging
62f7a29b.
2026-11-28 15:23:36 +01:00

1924 lines
81 KiB
C++

/*
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/.
*/
#include "stdafx.h"
#include "application/driveruipanels.h"
#include "application/editoruipanels.h"
#include "utilities/Globals.h"
#include "application/application.h"
#include "utilities/translation.h"
#include "simulation/simulation.h"
#include "simulation/simulationtime.h"
#include "simulation/simulationenvironment.h"
#include "utilities/Timer.h"
#include "world/Event.h"
#include "world/TractionPower.h"
#include "world/catenary_span.h"
#include "vehicle/Camera.h"
#include "world/mtable.h"
#include "world/stationnames.h"
#include "vehicle/Train.h"
#include "vehicle/Driver.h"
#include "vehicle/drivingaid.h"
#include "model/AnimModel.h"
#include "vehicle/DynObj.h"
#include "model/Model3d.h"
#include "rendering/renderer.h"
#include "utilities/Logs.h"
#include "widgets/vehicleparams.h"
#include "utilities/U8.h"
#include "physics/mover.h"
#define DRIVER_HINT_CONTENT
#include "application/driverhints.h"
#ifdef WITH_UART
#include "utilities/uart.h"
#endif
#include <format>
#include <string_view>
#include <vector>
#include "audio/audiorenderer.h"
namespace {
// how close to a broken coupler the camera has to be for the driving aid to offer its repair [m]
constexpr float coupler_repair_radius { 5.f };
// the broken coupler nearest to the camera, within reach: the vehicle and its end, or no vehicle
std::pair<TDynamicObject const *, int> broken_coupler_nearby( glm::dvec3 const &Camera ) {
auto const *vehicle { std::get<TDynamicObject *>( simulation::Region->find_vehicle( Camera, coupler_repair_radius, false, true ) ) };
if( vehicle == nullptr || vehicle->MoverParameters == nullptr ) { return { nullptr, end::front }; }
auto const front { glm::distance( vehicle->CouplerPosition( end::front ), Camera ) };
auto const rear { glm::distance( vehicle->CouplerPosition( end::rear ), Camera ) };
auto const nearest { front <= rear ? end::front : end::rear };
if( std::min( front, rear ) > coupler_repair_radius || false == vehicle->MoverParameters->Couplers[ nearest ].broken ) { return { nullptr, end::front }; }
return { vehicle, nearest };
}
} // namespace
void
drivingaid_panel::update() {
if( false == is_open ) { return; }
text_lines.clear();
std::tie( m_brokenvehicle, m_brokenend ) = broken_coupler_nearby( Global.pCamera.Pos );
auto const *train { simulation::Train };
auto const *controlled { ( train ? train->Dynamic() : nullptr ) };
if( controlled == nullptr
|| controlled->Mechanik == nullptr ) { return; }
auto const *mover = controlled->MoverParameters;
auto const *vehicledriver = controlled->Mechanik;
auto const *owner = controlled->ctOwner != nullptr ? controlled->ctOwner : controlled->Mechanik;
// the numbers of the throttle and brakes lines, with the controls of the cab the driver is in
auto const readout { drivingaid::compute( drivingaid::from_movers(
*mover,
*vehicledriver->Controlling(),
drivingaid::cab_controls {
train->ggLocalBrake.SubModel != nullptr,
train->ggJointCtrl.SubModel != nullptr } ) ) };
{ // throttle, velocity, speed limits and grade
std::string expandedtext;
if( is_expanded ) {
// grade
std::string gradetext;
auto const reverser { ( mover->DirActive > 0 ? 1 : -1 ) };
if( auto const grade { controlled->VectorFront().y * 100 * ( controlled->DirectionGet() == reverser ? 1 : -1 ) * reverser }; std::abs( grade ) >= 0.25 ) {
std::snprintf(
m_buffer.data(), m_buffer.size(),
STR_C(" Grade: %.1f%%%%"),
grade );
gradetext = m_buffer.data();
}
// next speed limit
auto const speedlimit { static_cast<int>( owner->VelDesired ) };
auto const [ nextspeedlimit, nextspeedlimitdistance ] { owner->next_speed_limit() };
std::string nextspeedlimittext;
if( nextspeedlimit != speedlimit ) {
std::snprintf(
m_buffer.data(), m_buffer.size(),
STR_C(", new limit: %d km/h in %.1f km"),
nextspeedlimit,
nextspeedlimitdistance * 0.001 );
nextspeedlimittext = m_buffer.data();
}
// current speed and limit
std::snprintf(
m_buffer.data(), m_buffer.size(),
STR_C(" Speed: %d km/h (limit %d km/h%s)%s"),
static_cast<int>( std::floor( mover->Vel ) ),
speedlimit,
nextspeedlimittext.c_str(),
gradetext.c_str() );
expandedtext = m_buffer.data();
}
// base data and optional bits put together
std::snprintf(
m_buffer.data(), m_buffer.size(),
STR_C("Throttle: %3d+%d %c%s"),
readout.throttle_first,
readout.throttle_second,
mover->SpeedCtrlUnit.IsActive ? 'T' :
mover->DirActive > 0 ? 'D' :
mover->DirActive < 0 ? 'R' :
'N',
expandedtext.c_str());
text_lines.emplace_back( m_buffer.data(), Global.UITextColor );
}
{ // brakes, air pressure
std::string expandedtext;
if( is_expanded ) {
std::snprintf (
m_buffer.data(), m_buffer.size(),
STR_C(" Pressure: %.2f kPa (train pipe: %.2f kPa)"),
mover->BrakePress * 100,
mover->PipePress * 100 );
expandedtext = m_buffer.data();
}
if( readout.ed_percent ) {
// the ED braking demand, ahead of the expanded data (eu07/maszyna#558)
std::snprintf(
m_buffer.data(), m_buffer.size(),
STR_C(" ED brake: %d%%%%"),
*readout.ed_percent );
expandedtext.insert( 0, m_buffer.data() );
}
if( readout.show_local_brake ) {
std::snprintf(
m_buffer.data(), m_buffer.size(),
STR_C("Brakes: %5.1f+%-2.0f%c%s"),
readout.brake_first,
readout.local_brake,
mover->SlippingWheels ? '!' : ' ',
expandedtext.c_str() );
}
else {
// the cab has no local brake control: its setting is left out (eu07/maszyna#555)
std::snprintf(
m_buffer.data(), m_buffer.size(),
STR_C("Brakes: %5.1f%c%s"),
readout.brake_first,
mover->SlippingWheels ? '!' : ' ',
expandedtext.c_str() );
}
text_lines.emplace_back( m_buffer.data(), Global.UITextColor );
}
{ // alerter, hints
std::string expandedtext;
if( is_expanded ) {
auto const stoptime { static_cast<int>( owner->ExchangeTime ) };
if( stoptime > 0 ) {
std::snprintf(
m_buffer.data(), m_buffer.size(),
STR_C(" Loading/unloading in progress (%d s left)"),
stoptime );
expandedtext = m_buffer.data();
}
else {
auto const trackobstacledistance { std::abs( owner->TrackObstacle() ) };
if( trackobstacledistance <= 75.0 ) {
std::snprintf(
m_buffer.data(), m_buffer.size(),
STR_C(" Another vehicle ahead (distance: %.1f m)"),
trackobstacledistance );
expandedtext = m_buffer.data();
}
}
}
std::string textline =
mover->SecuritySystem.is_vigilance_blinking() && (train != nullptr ? train->fBlinkTimer > 0 : true) ? STR("!ALERTER! ") : " ";
textline +=
mover->SecuritySystem.is_cabsignal_blinking() ? STR("!SHP!") : " ";
text_lines.emplace_back( textline + " " + expandedtext, Global.UITextColor );
}
}
void
drivingaid_panel::render_contents() {
ImGui::Checkbox(STR_C("expand"), &is_expanded);
ImGui::SameLine();
auto const *driver = (simulation::Train && simulation::Train->Dynamic()) ? simulation::Train->Dynamic()->Mechanik : nullptr;
if (driver && (false == Global.RealisticControlMode || DebugModeFlag)) {
bool autopilot = driver->AIControllFlag;
if (ImGui::Checkbox(STR_C("autopilot"), &autopilot)) {
command_relay commandrelay;
commandrelay.post(autopilot ? user_command::aidriverenable : user_command::aidriverdisable, 0.0, 0.0, GLFW_PRESS, 0);
}
}
// only the coupler the camera is next to, and the one of the vehicle it was coupled with
if( m_brokenvehicle != nullptr && ImGui::Button( STR_C( "Repair coupler" ) ) ) {
command_relay commandrelay;
commandrelay.post( user_command::repaircoupler, m_brokenend, 0.0, GLFW_PRESS, 0, glm::vec3( 0.0f ), &m_brokenvehicle->name() );
}
ui_panel::render_contents();
}
void
scenario_panel::update() {
if( false == is_open ) { return; }
text_lines.clear();
auto const *train { simulation::Train };
auto const *controlled { ( train ? train->Dynamic() : nullptr ) };
auto const &camera { Global.pCamera };
m_nearest = false == FreeFlyModeFlag ? controlled :
camera.m_owner != nullptr ? camera.m_owner :
std::get<TDynamicObject *>(simulation::Region->find_vehicle(camera.Pos, 20, false, false)); // w trybie latania lokalizujemy wg mapy
if( m_nearest == nullptr ) { return; }
auto const *owner { (
m_nearest->Mechanik != nullptr && m_nearest->Mechanik->primary() ?
m_nearest->Mechanik :
m_nearest->ctOwner ) };
if( owner == nullptr ) { return; }
std::string textline =
STR("Current task:") + "\n "
+ owner->OrderCurrent();
text_lines.emplace_back( textline, Global.UITextColor );
}
void
scenario_panel::render() {
if( false == is_open ) { return; }
if( true == text_lines.empty() ) { return; }
if( m_nearest == nullptr ) { return; } // possibly superfluous given the above but, eh
auto flags =
ImGuiWindowFlags_NoFocusOnAppearing
| ImGuiWindowFlags_NoCollapse
| ( size.x > 0 ? ImGuiWindowFlags_NoResize : 0 );
if( size.x > 0 ) {
ImGui::SetNextWindowSize( ImVec2S( size.x, size.y ) );
}
if( size_min.x > 0 ) {
ImGui::SetNextWindowSizeConstraints( ImVec2S( size_min.x, size_min.y ), ImVec2S( size_max.x, size_max.y ) );
}
if( auto const panelname { ( title.empty() ? m_name : title ) + "###" + m_name }; true == ImGui::Begin( panelname.c_str(), &is_open, flags ) ) {
// potential assignment section
auto const *owner { (
m_nearest->Mechanik != nullptr && m_nearest->Mechanik->primary() ?
m_nearest->Mechanik :
m_nearest->ctOwner ) };
if( owner != nullptr ) {
auto const assignmentheader { STR("Assignment") };
if( false == owner->assignment().empty()
&& true == ImGui::CollapsingHeader(assignmentheader.c_str()) ) {
ImGui::TextWrapped( "%s", owner->assignment().c_str() );
ImGui::Separator();
}
}
// current task
for( auto const &line : text_lines ) {
ImGui::TextColored( ImVec4( line.color.r, line.color.g, line.color.b, line.color.a ), "%s", line.data.c_str() );
}
// hints
if (owner != nullptr && true == ImGui::CollapsingHeader( STR_C("Hints"), ImGuiTreeNodeFlags_DefaultOpen )) {
for( auto const &hint : owner->m_hints ) {
auto const isdone { std::get<TController::hintpredicate>( hint )( std::get<float>( hint ) ) };
auto const hintcolor{ (
isdone ?
colors::uitextgreen :
Global.UITextColor ) };
ImGui::PushStyleColor( ImGuiCol_Text, { hintcolor.r, hintcolor.g, hintcolor.b, hintcolor.a } );
ImGui::TextWrapped( Translations.lookup_c(driver_hints_texts[(size_t)std::get<driver_hint>( hint )], true), std::get<float>( hint ) );
ImGui::PopStyleColor();
}
}
}
ImGui::End();
}
void
timetable_panel::update() {
if( false == is_open ) { return; }
text_lines.clear();
m_tablelines.clear();
auto const *train { simulation::Train };
auto const *controlled { ( train ? train->Dynamic() : nullptr ) };
auto const &camera { Global.pCamera };
auto const &time { simulation::Time.data() };
{ // current time
std::snprintf(
m_buffer.data(), m_buffer.size(),
STR_C("%-*.*s Time: %d:%02d:%02d"),
37, 37,
STR_C("Timetable"),
time.wHour,
time.wMinute,
time.wSecond );
title = m_buffer.data();
}
auto *vehicle { (
false == FreeFlyModeFlag ? controlled :
camera.m_owner != nullptr ? camera.m_owner :
std::get<TDynamicObject *>( simulation::Region->find_vehicle( camera.Pos, 20, false, false ) ) ) }; // w trybie latania lokalizujemy wg mapy
if( vehicle == nullptr ) { return; }
// if the nearest located vehicle doesn't have a direct driver, try to query its owner
auto const *owner = vehicle->Mechanik != nullptr && vehicle->Mechanik->primary() ? vehicle->Mechanik : vehicle->ctOwner;
if( owner == nullptr ) { return; }
auto const &table = owner->TrainTimetable();
// destination
{
// the names with the letters their files have, in utf-8 as the user interface takes it
auto textline = table.relation_caption();
if( false == textline.empty() ) {
textline += " (" + data_name_to_utf8( owner->TrainName(), true ) + ")";
}
text_lines.emplace_back( textline, Global.UITextColor );
}
if( false == is_expanded ) {
// next station
auto const nextstation = owner->NextStop();
if( false == nextstation.empty() ) {
// jeśli jest podana relacja, to dodajemy punkt następnego zatrzymania
auto textline = " -> " + nextstation;
text_lines.emplace_back( textline, Global.UITextColor );
}
}
if( is_expanded ) {
if( owner->is_train() ) {
// consist data
auto consistmass { owner->fMass };
auto consistlength { owner->fLength };
if( false == owner->is_dmu()
&& false == owner->is_emu() ) {
//odejmij lokomotywy czynne, a przynajmniej aktualną
consistmass -= owner->pVehicle->MoverParameters->TotalMass;
// subtract potential other half of a two-part vehicle
if( auto const *previous { owner->pVehicle->Prev( Coupling::permanent ) }; previous != nullptr ) { consistmass -= previous->MoverParameters->TotalMass; }
auto const *next { owner->pVehicle->Next( Coupling::permanent ) };
if( next != nullptr ) { consistmass -= next->MoverParameters->TotalMass; }
}
std::snprintf(
m_buffer.data(), m_buffer.size(),
STR_C("Consist weight: %d t (specified) %d t (actual)\nConsist length: %d m"),
static_cast<int>( table.LocLoad ),
static_cast<int>( consistmass / 1000 ),
static_cast<int>( consistlength ) );
text_lines.emplace_back( m_buffer.data(), Global.UITextColor );
text_lines.emplace_back( "", Global.UITextColor );
}
if( 0 == table.StationCount ) {
// only bother if there's stations to list
text_lines.emplace_back( STR("(no timetable)"), Global.UITextColor );
}
else {
// header
m_tablelines.emplace_back(U8("┌─────┬────────────────────────────────────┬─────────┬─────┐"), Global.UITextColor);
TMTableLine const *tableline;
for( int i = table.StationStart; i <= table.StationCount; ++i ) {
// wyświetlenie pozycji z rozkładu
tableline = table.TimeTable + i; // linijka rozkładu
bool vmaxchange { true };
if( i > table.StationStart ) {
auto const *previoustableline { tableline - 1 };
if( tableline->vmax == previoustableline->vmax ) {
vmaxchange = false;
}
}
std::string vmax { " " };
if( true == vmaxchange ) {
vmax += to_string( tableline->vmax, 0 );
vmax = vmax.substr( vmax.size() - 3, 3 ); // z wyrównaniem do prawej
}
// the name as the timetable spells it; in utf-8 a letter can take more than one byte, the column is
// 34 characters wide
auto const station { utf8_fit( timetable::station_caption( tableline->StationLabel ), 34 ) };
auto const location { (
( tableline->km > 0.0 ?
to_string( tableline->km, 2 ) :
"" )
+ " " )
.substr( 0, 34 - tableline->StationWare.size() ) };
auto const arrival { (
tableline->Ah >= 0 ?
std::to_string( int( 100 + tableline->Ah ) ).substr( 1, 2 ) + ":" + to_minutes_str( tableline->Am, true, 3 ) :
U8(" │ ") ) };
auto const departure { (
tableline->Dh >= 0 ?
std::to_string( int( 100 + tableline->Dh ) ).substr( 1, 2 ) + ":" + to_minutes_str( tableline->Dm, true, 3 ) :
U8(" │ ") ) };
auto const candepart { (
table.StationStart < table.StationIndex
&& i < table.StationIndex
&& ( tableline->Ah < 0 // pass-through, always valid
|| tableline->is_maintenance // maintenance stop, always valid
|| time.wHour * 60 + time.wMinute + time.wSecond * 0.0167 >= static_cast<float>(tableline->Dh * 60) + tableline->Dm ) ) };
auto const loadchangeinprogress { ( static_cast<int>(std::ceil(-1.0 * owner->fStopTime)) > 0 ) };
auto const isatpassengerstop { true == owner->IsAtPassengerStop && vehicle->MoverParameters->Vel < 1.0 };
auto const traveltime { (
i < 2 ? " " :
tableline->Ah >= 0 ? to_minutes_str( static_cast<float>(CompareTime( table.TimeTable[ i - 1 ].Dh, table.TimeTable[ i - 1 ].Dm, tableline->Ah, tableline->Am )), false, 3 ) :
to_minutes_str( static_cast<float>(std::max( 0.0, CompareTime( table.TimeTable[ i - 1 ].Dh, table.TimeTable[ i - 1 ].Dm, tableline->Dh, tableline->Dm ) - 0.5 )), false, 3 ) ) };
auto const linecolor { (
i != table.StationStart ? Global.UITextColor :
loadchangeinprogress ? colors::uitextred :
candepart ? colors::uitextgreen : // czas minął i odjazd był, to nazwa stacji będzie na zielono
isatpassengerstop ? colors::uitextorange :
Global.UITextColor ) };
std::string const trackcount{ ( tableline->TrackNo == 1 ? U8(" ┃ ") : U8(" ║ " )) };
m_tablelines.emplace_back(U8("│ ") + vmax + U8(" │ ") + station + trackcount + arrival + U8(" │ ") + traveltime + U8(" │"),
linecolor );
m_tablelines.emplace_back(U8("│ │ ") + location + tableline->StationWare + trackcount + departure + U8(" │ │"),
linecolor );
// divider/footer
if( i < table.StationCount ) {
auto const *nexttableline { tableline + 1 };
std::string const vmaxnext{ ( tableline->vmax == nexttableline->vmax ? U8("│ ├") : U8("├─────┼") ) };
auto const trackcountnext{ ( nexttableline->TrackNo == 1 ? U8("╂") : U8("╫") ) };
m_tablelines.emplace_back(
vmaxnext + U8("────────────────────────────────────") + trackcountnext + U8("─────────┼─────┤"),
Global.UITextColor );
}
else {
m_tablelines.emplace_back(
U8("└─────┴────────────────────────────────────┴─────────┴─────┘"),
Global.UITextColor );
}
}
}
} // is_expanded
}
void
timetable_panel::render() {
if( false == is_open ) { return; }
if( true == text_lines.empty() ) { return; }
ImGui::PushFont(ui_layer::font_mono);
auto flags =
ImGuiWindowFlags_NoFocusOnAppearing
| ImGuiWindowFlags_NoCollapse
| ( size.x > 0 ? ImGuiWindowFlags_NoResize : 0 );
// HACK: Make sure the timetable window is of correct width when using a larger font size.
float horizontalScale = Global.ui_fontsize / 13;
if( size.x > 0 ) {
ImGui::SetNextWindowSize( ImVec2S( size.x * horizontalScale, size.y ) );
}
if( size_min.x > 0 ) {
ImGui::SetNextWindowSizeConstraints( ImVec2S( size_min.x * horizontalScale, size_min.y ), ImVec2S( size_max.x * horizontalScale, size_max.y ) );
}
if( auto const panelname { ( title.empty() ? m_name : title ) + "###" + m_name }; true == ImGui::Begin( panelname.c_str(), &is_open, flags ) ) {
for( auto const &line : text_lines ) {
ImGui::TextColored( ImVec4( line.color.r, line.color.g, line.color.b, line.color.a ), "%s", line.data.c_str() );
}
if( is_expanded ) {
ImGui::PushStyleVar( ImGuiStyleVar_ItemSpacing, ImVec2( 1, 0 ) );
for( auto const &line : m_tablelines ) {
ImGui::TextColored( ImVec4( line.color.r, line.color.g, line.color.b, line.color.a ), "%s", line.data.c_str() );
}
ImGui::PopStyleVar();
}
}
ImGui::End();
ImGui::PopFont();
}
void debug_panel::update()
{
if( false == is_open ) { return; }
// input item bindings
m_input.train = simulation::Train;
m_input.controlled = m_input.train ? m_input.train->Dynamic() : nullptr;
m_input.camera = &Global.pCamera;
m_input.vehicle = false == FreeFlyModeFlag ? m_input.controlled :
m_input.camera->m_owner != nullptr ? m_input.camera->m_owner :
std::get<TDynamicObject *>(simulation::Region->find_vehicle(m_input.camera->Pos, 20, false, false)); // w trybie latania lokalizujemy wg mapy
m_input.mover =
m_input.vehicle != nullptr ? m_input.vehicle->MoverParameters : nullptr;
m_input.mechanik = m_input.vehicle != nullptr ? m_input.vehicle->Mechanik : nullptr;
// header section
text_lines.clear();
auto textline = "Version " + Global.asVersion;
text_lines.emplace_back( textline, Global.UITextColor );
// sub-sections
m_vehiclelines.clear();
m_enginelines.clear();
m_ailines.clear();
m_scantablelines.clear();
m_scenariolines.clear();
m_eventqueuelines.clear();
m_powergridlines.clear();
m_cameralines.clear();
m_rendererlines.clear();
m_couplerlines.clear();
#ifdef WITH_UART
m_uartlines.clear();
#endif
update_section_vehicle( m_vehiclelines );
update_section_engine( m_enginelines );
update_section_ai( m_ailines );
update_section_scantable( m_scantablelines );
update_section_scenario( m_scenariolines );
update_section_eventqueue( m_eventqueuelines );
update_section_powergrid( m_powergridlines );
update_section_camera( m_cameralines );
update_section_renderer( m_rendererlines );
update_section_coupler( m_couplerlines );
#ifdef WITH_UART
update_section_uart(m_uartlines);
#endif
}
namespace {
// memory cells of the scenery, to look into and play with while the simulation runs
bool render_section_memcells() {
if( false == ImGui::CollapsingHeader( "Memory Cells" ) ) { return false; }
static memcells_panel memcells { "Memory cells", true };
memcells.listheight = ImGui::GetTextLineHeightWithSpacing() * 12.f;
ImGui::PushID( "memcells" );
memcells.render_body();
ImGui::PopID();
return true;
}
} // namespace
void
debug_panel::render() {
if( false == is_open ) { return; }
ImGui::PushFont(ui_layer::font_mono);
auto flags =
ImGuiWindowFlags_NoFocusOnAppearing
| ImGuiWindowFlags_NoCollapse
| ( size.x > 0 ? ImGuiWindowFlags_NoResize : 0 );
if( size.x > 0 ) {
ImGui::SetNextWindowSize( ImVec2S( size.x, size.y ) );
}
if( size_min.x > 0 ) {
ImGui::SetNextWindowSizeConstraints( ImVec2S( size_min.x, size_min.y ), ImVec2S( size_max.x, size_max.y ) );
}
if( auto const panelname { ( title.empty() ? m_name : title ) + "###" + m_name }; true == ImGui::Begin( panelname.c_str(), &is_open, flags ) ) {
// header section
for( auto const &line : text_lines ) {
ImGui::TextColored( ImVec4( line.color.r, line.color.g, line.color.b, line.color.a ), "%s", line.data.c_str() );
}
// sections
ImGui::Separator();
if (true == render_section( "Vehicle", m_vehiclelines ) && DebugModeFlag && m_input.mover && false == m_input.mover->DamageFlag.Empty() && true == ImGui::Button( "Stop and repair consist" )) {
command_relay commandrelay;
commandrelay.post(user_command::resetconsist, 0.0, 0.0, GLFW_PRESS, 0, glm::vec3(0.0f), &m_input.vehicle->name());
}
render_section_coupler();
render_section( "Vehicle Engine", m_enginelines );
render_section( "Vehicle AI", m_ailines );
render_section( "Vehicle Scan Table", m_scantablelines );
render_section_scenario();
render_section_eventqueue();
render_section_memcells();
if( true == render_section( "Power Grid", m_powergridlines ) ) {
// traction state debug
ImGui::Checkbox( "Debug Traction", &DebugTractionFlag );
}
render_section( "Camera", m_cameralines );
render_section_renderer();
render_section_settings();
render_section_developer(); // Developer tools
#ifdef WITH_UART
if(true == render_section( "UART", m_uartlines)) {
auto ports_num = static_cast<int>(UartStatus.available_ports.size());
auto avlports = new char*[ports_num];
for (int i=0; i < ports_num; i++) {
avlports[i] = (char *) UartStatus.available_ports[i].c_str();
}
ImGui::Combo("Port", &UartStatus.selected_port_index, avlports, ports_num);
ImGui::Combo("Baud", &UartStatus.selected_baud_index, uart_baudrates_list, static_cast<int>(uart_baudrates_list_num));
ImGui::Checkbox("Enabled", &UartStatus.enabled);
}
#endif
// toggles
ImGui::Separator();
bool flag = DebugModeFlag;
if (ImGui::Checkbox("Debug Mode", &flag)) {
command_relay commandrelay;
commandrelay.post(user_command::debugtoggle, 0.0, 0.0, GLFW_RELEASE, 0);
}
}
ImGui::End();
ImGui::PopFont();
}
bool
debug_panel::render_section_scenario() {
if( false == render_section( "Scenario", m_scenariolines ) ) { return false; }
if( Application.is_client() ) {
// NOTE: simulation clients can't adjust scenarion state, this is reserved for the server/standalone instance
return true;
}
// fog slider
{
auto fogrange = std::log( Global.fFogEnd );
if( ImGui::SliderFloat(
( to_string( std::exp( fogrange ), 0, 5 ) + " m###fogend" ).c_str(), &fogrange, std::log( 10.0f ), std::log( 50000.0f ), "Fog distance" ) ) {
command_relay commandrelay;
commandrelay.post(
user_command::setweather,
std::clamp( std::exp( fogrange ), 10.0f, 50000.0f ),
Global.Overcast,
GLFW_PRESS, 0 );
}
}
{
auto Airtemperature = Global.AirTemperature;
if (ImGui::SliderFloat(
(to_string(Airtemperature, 1) + " deg C###Airtemperature").c_str(),
&Airtemperature, -35.0f, 40.0f, "Air Temperature"))
{
command_relay commandrelay;
commandrelay.post(
user_command::settemperature,
std::clamp(Airtemperature, -35.0f, 40.0f),
Global.Overcast,
GLFW_PRESS, 0 );
}
}
// cloud cover slider
{
if( ImGui::SliderFloat(
( to_string( Global.Overcast, 2, 5 ) + " (" + Global.Weather + ")###overcast" ).c_str(), &Global.Overcast, 0.0f, 2.0f, "Cloud cover" ) ) {
command_relay commandrelay;
commandrelay.post(
user_command::setweather,
Global.fFogEnd,
std::clamp( Global.Overcast, 0.0f, 2.0f ),
GLFW_PRESS, 0 );
}
}
// day of year slider
{
if( ImGui::SliderFloat(
( to_string( Global.fMoveLight, 0, 5 ) + " (" + Global.Season + ")###movelight" ).c_str(), &Global.fMoveLight, 0.0f, 364.0f, "Day of year" ) ) {
command_relay commandrelay;
commandrelay.post(
user_command::setdatetime,
std::clamp( Global.fMoveLight, 0.0f, 365.0f ),
simulation::Time.data().wHour * 60 + simulation::Time.data().wMinute,
GLFW_PRESS, 0 );
}
}
// dynamic material update checkbox
ImGui::Checkbox( "Update Item Materials", &Global.UpdateMaterials );
if (DebugModeFlag && ImGui::Checkbox( "Force Daylight", &Global.FakeLight )) {
simulation::Environment.on_daylight_change();
}
// advanced options, only visible in debug mode
if( DebugModeFlag ) {
// time of day slider
{
ImGui::PushStyleColor( ImGuiCol_Text, { Global.UITextColor.r, Global.UITextColor.g, Global.UITextColor.b, Global.UITextColor.a } );
ImGui::TextUnformatted( "CAUTION: time change will affect simulation state" );
ImGui::PopStyleColor();
auto time = simulation::Time.data().wHour * 60 + simulation::Time.data().wMinute;
auto const timestring {
std::string( std::to_string( int( 100 + simulation::Time.data().wHour ) ).substr( 1, 2 )
+ ":"
+ std::string( std::to_string( int( 100 + simulation::Time.data().wMinute ) ).substr( 1, 2 ) ) ) };
if( ImGui::SliderInt( ( timestring + " (" + Global.Period + ")###simulationtime" ).c_str(), &time, 0, 1439, "Time of day" ) ) {
command_relay commandrelay;
commandrelay.post(
user_command::setdatetime,
Global.fMoveLight,
std::clamp( time, 0, 1439 ),
GLFW_PRESS, 0 );
}
}
// time acceleration
{
auto timerate { ( Global.fTimeSpeed == 60 ? 4 : Global.fTimeSpeed == 20 ? 3 : Global.fTimeSpeed == 5 ? 2 : 1 ) };
if( ImGui::SliderInt( ( "x " + to_string( Global.fTimeSpeed, 0 ) + "###timeacceleration" ).c_str(), &timerate, 1, 4, "Time acceleration" ) ) {
Global.fTimeSpeed = timerate == 4 ? 60 : timerate == 3 ? 20 : timerate == 2 ? 5 : 1;
}
}
// base draw range slider
{
ImGui::TextUnformatted("CAUTION: drawing range change can affect FPS badly");
auto drawrange = std::log(Global.BaseDrawRange);
if (ImGui::SliderFloat(
(to_string(std::exp(drawrange), 0, 5) + " m###drawrange").c_str(), &drawrange, std::log(100.0f), std::log(50000.0f), "Base drawing range")) {
Global.BaseDrawRange = std::clamp(std::exp(drawrange), 100.0f, 50000.0f);
}
}
}
return true;
}
bool
debug_panel::render_section_eventqueue() {
if( false == ImGui::CollapsingHeader( "Scenario Event Queue" ) ) { return false; }
// event queue name filter
ImGui::PushItemWidth( -1 );
ImGui::InputTextWithHint( "", "Search event queue", m_eventsearch.data(), m_eventsearch.size() );
ImGui::PopItemWidth();
// event queue
render_section( m_eventqueuelines );
// event queue activator filter
ImGui::Checkbox( "By This Vehicle Only", &m_eventqueueactivevehicleonly );
return true;
}
void
debug_panel::update_section_vehicle( std::vector<text_line> &Output ) {
if( m_input.vehicle == nullptr ) { return; }
if( m_input.mover == nullptr ) { return; }
auto const &vehicle { *m_input.vehicle };
auto const &mover { *m_input.mover };
auto const isowned { /* ( vehicle.Mechanik == nullptr ) && */ vehicle.ctOwner != nullptr && vehicle.ctOwner->Vehicle() != m_input.vehicle };
auto const isdieselenginepowered { mover.EngineType == TEngineType::DieselElectric || mover.EngineType == TEngineType::DieselEngine };
auto const isdieselinshuntmode { mover.ShuntMode && mover.EngineType == TEngineType::DieselElectric };
std::snprintf(
m_buffer.data(), m_buffer.size(),
STR_C("Name: %s%s\nLoad: %.0f %s\nStatus: %s%s\nCouplers:\n front: %s\n rear: %s"),
mover.Name.c_str(),
std::string( isowned ? STR(", owned by: ") + vehicle.ctOwner->OwnerName() : "" ).c_str(),
mover.LoadAmount,
mover.LoadType.name.c_str(),
mover.EngineDescription( 0 ).c_str(),
// TODO: put wheel flat reporting in the enginedescription()
std::string( mover.WheelFlat > 0.01 ? " Flat: " + to_string( mover.WheelFlat, 1 ) + " mm" : "" ).c_str(),
update_vehicle_coupler( end::front ).c_str(),
update_vehicle_coupler( end::rear ).c_str() );
Output.emplace_back( std::string{ m_buffer.data() }, Global.UITextColor );
std::snprintf(
m_buffer.data(), m_buffer.size(),
STR_C("Devices: %c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%s%s\nPower transfers: %.0f@%.0f%s[%.0f]%s%.0f@%.0f :: %.0f@%.0f%s[%.0f]%s%.0f@%.0f"),
// devices
mover.Battery ? 'B' : '.',
mover.PantsValve.is_active ? '+' : '.',
mover.Pantographs[end::rear].valve.is_active ? 'O' :
mover.Pantographs[end::rear].valve.is_enabled ? 'o' :
'.',
mover.Pantographs[end::front].valve.is_active ? 'P' :
mover.Pantographs[end::front].valve.is_enabled ? 'p' :
'.',
mover.PantPressLockActive ? '!' :
mover.PantPressSwitchActive ? '*' :
'.',
mover.WaterPump.is_active ? 'W' :
false == mover.WaterPump.breaker ? '-' :
mover.WaterPump.is_enabled ? 'w' :
'.',
mover.WaterHeater.is_damaged ? '!' :
mover.WaterHeater.is_active ? 'H' :
false == mover.WaterHeater.breaker ? '-' :
mover.WaterHeater.is_enabled ? 'h' :
'.',
mover.FuelPump.is_active ? 'F' :
mover.FuelPump.is_enabled ? 'f' :
'.',
mover.OilPump.is_active ? 'O' :
mover.OilPump.is_enabled ? 'o' :
'.',
mover.Mains ? 'M' : '.',
mover.FuseFlag ? '!' : '.',
mover.ConverterFlag ? 'X' :
false == mover.ConverterAllowLocal ? '-' :
mover.ConverterAllow ? 'x' :
'.',
mover.ConvOvldFlag ? '!' : '.',
mover.CompressorFlag ? 'C' :
false == mover.CompressorAllowLocal ? '-' :
mover.CompressorAllow || (mover.CompressorStart == start_t::automatic && mover.CompressorSpeed > 0.0) ? 'c' :
'.',
mover.CompressorGovernorLock ? '!' : '.',
mover.StLinSwitchOff ? '-' :
mover.ControlPressureSwitch ? '!' :
mover.StLinFlag ? '+' :
'.',
mover.Heating ? 'H' :
mover.HeatingAllow ? 'h' :
'.',
mover.Hamulec->Releaser() ? '^' : '.',
std::string( m_input.mechanik ? STR(" R") + ( mover.Radio && mover.RadioFuse ? std::to_string( m_input.mechanik->iRadioChannel ) : "-" ) : "" ).c_str(),
std::string( isdieselenginepowered ? STR(" oil pressure: ") + to_string( mover.OilPump.pressure, 2 ) : "" ).c_str(),
// power transfers
// 3000v
mover.Couplers[ end::front ].power_high.voltage,
mover.Couplers[ end::front ].power_high.current,
std::string( mover.Couplers[ end::front ].power_high.is_local ? ":" : ":=" ).c_str(),
mover.EngineVoltage,
std::string( mover.Couplers[ end::rear ].power_high.is_local ? ":" : "=:" ).c_str(),
mover.Couplers[ end::rear ].power_high.voltage,
mover.Couplers[ end::rear ].power_high.current,
// 110v
mover.Couplers[ end::front ].power_110v.voltage,
mover.Couplers[ end::front ].power_110v.current,
std::string( mover.Couplers[ end::front ].power_110v.is_local ? ":" : ":=" ).c_str(),
mover.PowerCircuits[ 1 ].first,
std::string( mover.Couplers[ end::rear ].power_110v.is_local ? ":" : "=:" ).c_str(),
mover.Couplers[ end::rear ].power_110v.voltage,
mover.Couplers[ end::rear ].power_110v.current );
Output.emplace_back( m_buffer.data(), Global.UITextColor );
std::snprintf(
m_buffer.data(), m_buffer.size(),
STR_C("Controllers:\n master: %d(%d), secondary: %s\nEngine output: %.1f, current: %.0f\nRevolutions:\n engine: %.0f, motors: %.0f\n engine fans: %.0f, motor fans: %.0f+%.0f, cooling fans: %.0f+%.0f"),
// controllers
mover.MainCtrlPos,
mover.MainCtrlActualPos,
std::string( isdieselinshuntmode ? to_string( mover.AnPos, 2 ) + STR(" (shunt mode)") : std::to_string( mover.ScndCtrlPos ) + "(" + std::to_string( mover.ScndCtrlActualPos ) + ")" ).c_str(),
// engine
mover.EnginePower,
std::abs( mover.TrainType == train_type::emu ? mover.ShowCurrent( 0 ) : mover.Im ),
// revolutions
std::abs( mover.enrot ) * 60,
std::abs( mover.nrot ) * mover.Transmision.Ratio * 60,
mover.RventRot * 60,
std::abs( mover.MotorBlowers[end::front].revolutions ),
std::abs( mover.MotorBlowers[end::rear].revolutions ),
mover.diesel.heat.rpmw,
mover.diesel.heat.rpmw2 );
std::string textline { m_buffer.data() };
if( isdieselenginepowered ) {
std::snprintf(
m_buffer.data(), m_buffer.size(),
STR_C("\nTemperatures:\n engine: %.2f, oil: %.2f, water: %.2f%c%.2f"),
mover.diesel.heat.Ts,
mover.diesel.heat.To,
mover.diesel.heat.temperatura1,
mover.WaterCircuitsLink ? '-' : '|',
mover.diesel.heat.temperatura2 );
textline += m_buffer.data();
}
Output.emplace_back( textline, Global.UITextColor );
std::snprintf(
m_buffer.data(), m_buffer.size(),
STR_C("Brakes:\n train: %.2f (mode: %d, delay: %s, load flag: %d)\n independent: %.2f (%.2f), manual: %.2f, spring: %.2f\nBrake cylinder pressures:\n train: %.2f, independent: %.2f, status: 0x%.2x\nPipe pressures:\n brake: %.2f (hat: %.2f), main: %.2f, control: %.2f\nTank pressures:\n auxiliary: %.2f, main: %.2f, control: %.2f"),
// brakes
mover.fBrakeCtrlPos,
mover.BrakeOpModeFlag,
update_vehicle_brake().c_str(),
mover.LoadFlag,
mover.LocalBrakePosA,
mover.LocalBrakePosAEIM,
static_cast<float>(mover.ManualBrakePos) / static_cast<float>(ManualBrakePosNo),
mover.SpringBrake.Activate ? 1.f : 0.f,
// cylinders
mover.BrakePress,
mover.LocBrakePress,
mover.Hamulec->GetBrakeStatus(),
// pipes
mover.PipePress,
mover.BrakeCtrlPos2,
mover.ScndPipePress,
mover.CntrlPipePress,
// tanks
mover.Hamulec->GetBRP(),
mover.Compressor,
mover.Hamulec->GetCRP() );
textline = m_buffer.data();
if( mover.EnginePowerSource.SourceType == TPowerSource::CurrentCollector ) {
std::snprintf(
m_buffer.data(), m_buffer.size(),
STR_C(" pantograph: %.2f%cMT"),
mover.PantPress,
mover.bPantKurek3 ? '-' : '|' );
textline += m_buffer.data();
}
Output.emplace_back( textline, Global.UITextColor );
std::snprintf(
m_buffer.data(), m_buffer.size(),
STR_C("Forces:\n tractive: %.1f, brake: %.1f, drag: %.2f%s\nAcceleration:\n tangential: %.2f, normal: %.2f (path radius: %s)\nVelocity: %.2f, distance traveled: %.2f\nPosition: [%.2f, %.2f, %.2f]"),
// forces
mover.Ft * 0.001f * ( mover.CabOccupied ? mover.CabOccupied : vehicle.ctOwner ? vehicle.ctOwner->Controlling()->CabOccupied : 1 ) + 0.001f,
mover.Fb * 0.001f,
mover.FrictionForce() * 0.001f,
mover.SlippingWheels ? " (!)" : "",
// acceleration
mover.AccSVBased,
mover.AccN + 0.001f,
std::string( std::abs( mover.RunningShape.R ) > 15000.0 ? "~0" : to_string( mover.RunningShape.R, 0 ) ).c_str(),
// velocity
vehicle.GetVelocity(),
mover.DistCounter,
// position
vehicle.GetPosition().x,
vehicle.GetPosition().y,
vehicle.GetPosition().z );
Output.emplace_back( m_buffer.data(), Global.UITextColor );
if( mover.EnginePowerSource.SourceType == TPowerSource::CurrentCollector ) {
std::snprintf(m_buffer.data(), m_buffer.size(), STR_C("Power use:\n drawn: %.1f kWh\n returned: %.1f kWh\n balance: %.1f kWh"),
mover.EnergyMeter.first, -mover.EnergyMeter.second, mover.EnergyMeter.first + mover.EnergyMeter.second);
textline = m_buffer.data();
if( DebugTractionFlag ) {
for( int i = 0; i < vehicle.iAnimType[ ANIM_PANTS ]; ++i ) { // pętla po wszystkich pantografach
auto const *p { vehicle.pants[ i ].fParamPants };
if( p && p->hvPowerWire ) {
auto const *powerwire { p->hvPowerWire };
std::snprintf(
m_buffer.data(), m_buffer.size(),
STR_C("\n pantograph %d: drawing from: [%s, %s] through: [%.2f, %.2f, %.2f]"),
i,
powerwire->psPower[ 0 ] ? powerwire->psPower[ 0 ]->name().c_str() : "none",
powerwire->psPower[ 1 ] ? powerwire->psPower[ 1 ]->name().c_str() : "none",
powerwire->pPoint1[ 0 ],
powerwire->pPoint1[ 1 ],
powerwire->pPoint1[ 2 ] );
textline += m_buffer.data();
}
}
}
Output.emplace_back( textline, Global.UITextColor );
}
if (!std::isnan(last_time)) {
double dt = Timer::GetTime() - last_time;
AccN_jerk_graph.update(static_cast<float>((mover.AccN - last_AccN) / dt));
AccN_acc_graph.update(static_cast<float>(mover.AccN));
}
last_AccN = static_cast<float>(mover.AccN);
last_time = Timer::GetTime();
}
void debug_panel::graph_data::update(float val) {
data[pos] = val;
pos++;
if (pos >= data.size())
pos = 0;
last_val = val;
}
void debug_panel::graph_data::render() {
ImGui::PushID(this);
ImGui::SliderFloat(STR_C("##Range"), &range, 0.5f, 60.0f, "%.1f");
ImGui::PlotLines("##plot", data.data(), static_cast<int>(data.size()), static_cast<int>(pos), nullptr, 0.0f, range, ImVec2(0, 100));
ImGui::PopID();
}
std::string
debug_panel::update_vehicle_coupler( int const Side ) {
// NOTE: mover and vehicle are guaranteed to be valid by the caller
auto const &mover { *m_input.mover };
std::string const controltype{ ( mover.Couplers[ Side ].control_type.empty() ? "[*]" : "[" + mover.Couplers[ Side ].control_type + "]" ) };
std::string couplerstatus { STR("none") };
std::string const adapterstatus { ( mover.Couplers[ Side ].adapter_type == TCouplerType::NoCoupler ? "" : "[A]" ) };
auto const *connected { m_input.vehicle->MoverParameters->Neighbours[ Side ].vehicle };
if( connected == nullptr ) {
return controltype + " " + couplerstatus + " " + adapterstatus;
}
std::snprintf(
m_buffer.data(), m_buffer.size(),
"%s %s %s[%d] (%.1f m)",
controltype.c_str(),
connected->name().c_str(),
adapterstatus.c_str(),
mover.Couplers[ Side ].CouplingFlag,
mover.Neighbours[ Side ].distance );
return { m_buffer.data() };
}
std::string
debug_panel::update_vehicle_brake() const {
// NOTE: mover is guaranteed to be valid by the caller
auto const &mover { *m_input.mover };
std::string brakedelay;
std::vector<std::pair<int, std::string>> delays {
{ bdelay_G, "G" },
{ bdelay_P, "P" },
{ bdelay_R, "R" },
{ bdelay_M, "+Mg" } };
for( auto const &[delayflag, delayname] : delays ) {
if( ( mover.BrakeDelayFlag & delayflag ) == delayflag ) {
brakedelay += delayname;
}
}
return brakedelay;
}
void
debug_panel::update_section_engine( std::vector<text_line> &Output ) const {
if( m_input.vehicle == nullptr ) { return; }
if( m_input.mover == nullptr ) { return; }
auto const &vehicle{ *m_input.vehicle };
auto const &mover{ *m_input.mover };
// induction motor data
if( mover.EngineType == TEngineType::ElectricInductionMotor ) {
Output.emplace_back( " eimc: eimv: press:", Global.UITextColor );
for( int i = 0; i <= 20; ++i ) {
std::string parameters =
TMoverParameters::eimc_labels[ i ] + to_string( mover.eimc[ i ], 2, 9 )
+ " | "
+ TMoverParameters::eimv_labels[ i ] + to_string( mover.eimv[ i ], 2, 9 );
if( i < 10 ) {
parameters +=
m_input.train != nullptr && m_input.train->Dynamic() == m_input.vehicle ? " | " + TTrain::fPress_labels[i] + to_string(m_input.train->fPress[i][0], 2, 9) : "";
}
else if( i == 12 ) {
parameters += " med:";
}
else if( i >= 13 ) {
parameters += " | " + TDynamicObject::MED_labels[ i - 13 ] + to_string( vehicle.MED[ 0 ][ i - 13 ], 2, 9 );
}
Output.emplace_back( parameters, Global.UITextColor );
}
Output.emplace_back( "Inverter:\n frequency: " + to_string( mover.InverterFrequency, 2 ), Global.UITextColor );
}
// diesel engine data
if( mover.EngineType == TEngineType::DieselEngine ) {
double fuel_mean = 0.0;
if (mover.DistCounter > 0.5) {
fuel_mean = 100 * mover.diesel.fuelConsumedTotal / mover.DistCounter;
}
std::string parameterstext = "param value";
std::vector< std::pair <std::string, double> > const paramvalues {
{ " rpm: ", mover.enrot * 60.0 },
{ "efill: ", mover.diesel.fill },
{ "etorq: ", mover.diesel.torque },
{ "power: ", mover.diesel.power },
{ "f_act: ", mover.diesel.fuelConsumptionActual },
{ "f_tot: ", mover.diesel.fuelConsumedTotal },
{ "fmean: ", fuel_mean },
{ "creal: ", mover.diesel.clutchPressure },
{ "cdesi: ", mover.diesel.clutchState },
{ "cdelt: ", mover.diesel.clutchSlip },
{ "gears: ", mover.diesel.automaticGearShift} };
for( auto const &[parametername, parametervalue] : paramvalues ) {
parameterstext += "\n" + parametername + to_string( parametervalue, 2, 9 );
}
Output.emplace_back( parameterstext, Global.UITextColor );
parameterstext = "hydro value";
std::vector< std::pair <std::string, double> > const hydrovalues {
{ "hTCnI: ", mover.torqueConverter.revolutionsIn },
{ "hTCnO: ", mover.torqueConverter.revolutionsOut },
{ "hTCTM: ", mover.torqueConverter.torqueRatio },
{ "hTCTI: ", mover.torqueConverter.torqueIn },
{ "hTCTO: ", mover.torqueConverter.torqueOut },
{ "hTCfl: ", mover.torqueConverter.fill },
{ "hRtFl: ", mover.retarder.fill } ,
{ " hRtn: ", mover.retarder.revolutions } ,
{ "hRtTq: ", mover.retarder.torque }
};
for( auto const &[parametername, parametervalue] : hydrovalues ) {
parameterstext += "\n" + parametername + to_string( parametervalue, 2, 9 );
}
Output.emplace_back( parameterstext, Global.UITextColor );
}
}
void
debug_panel::update_section_ai( std::vector<text_line> &Output ) const {
if( m_input.mover == nullptr ) { return; }
if( m_input.mechanik == nullptr ) { return; }
auto const &mover{ *m_input.mover };
auto const &mechanik{ *m_input.mechanik };
// biezaca komenda dla AI
auto textline =
"Current order: [" + std::to_string( mechanik.OrderPos ) + "] "
+ mechanik.Order2Str( mechanik.OrderCurrentGet() );
if( mechanik.fStopTime < 0.0 ) {
textline += "\n stop time: " + to_string( std::abs( mechanik.fStopTime ), 1 );
}
if( mechanik.fActionTime < 0.0 ) {
textline += "\n action time: " + to_string( std::abs( mechanik.fActionTime ), 1 );
}
Output.emplace_back( textline, Global.UITextColor );
if( mechanik.VelNext == 0.0
&& mechanik.eSignNext ) {
// jeśli ma zapamiętany event semafora, nazwa eventu semafora
Output.emplace_back( "Current signal: " + data_name_to_utf8( mechanik.eSignNext->m_name ), Global.UITextColor );
}
// distances
textline =
"Distances:\n proximity: " + to_string( mechanik.ActualProximityDist, 0 )
+ ", braking: " + to_string( mechanik.fBrakeDist, 0 );
if( mechanik.VelLimitLastDist.second > 0 ) {
textline += ", last limit: " + (
mechanik.VelLimitLastDist.second < EU07_AI_SPEEDLIMITEXTENDSBEYONDSCANRANGE ?
to_string( mechanik.VelLimitLastDist.second, 0 ) :
"???" );
}
if( mechanik.SwitchClearDist > 0 ) {
textline += ", switches: " + to_string( mechanik.SwitchClearDist, 0 );
}
if( mechanik.Obstacle.distance < 5000 ) {
textline +=
"\n obstacle: " + to_string( mechanik.Obstacle.distance, 0 )
+ " (" + mechanik.Obstacle.vehicle->asName + ")";
}
Output.emplace_back( textline, Global.UITextColor );
// velocity factors
textline =
"Velocity:\n desired: " + to_string( mechanik.VelDesired, 0 )
+ ", next: " + to_string( mechanik.VelNext, 0 )
+ "\n current: " + to_string( mover.Vel + 0.001f, 2 );
std::vector< std::pair< double, std::string > > const restrictions{
{ mechanik.VelSignalLast, "signal" },
{ mechanik.VelLimitLast, "limit" },
{ mechanik.VelRoad, "road" },
{ mechanik.VelRestricted, "restricted" },
{ mover.RunningTrack.Velmax, "track" } };
std::string restrictionstext;
for( auto const &[restrictionspeed, restrictionsource] : restrictions ) {
if( restrictionspeed < 0.0 ) { continue; }
if( false == restrictionstext.empty() ) {
restrictionstext += ", ";
}
restrictionstext +=
to_string( restrictionspeed, 0 )
+ " (" + restrictionsource + ")";
}
if( false == restrictionstext.empty() ) {
textline += "\n restrictions: " + restrictionstext;
}
Output.emplace_back( textline, Global.UITextColor );
// acceleration
textline =
"Acceleration:\n desired: " + to_string( mechanik.AccDesired, 2 )
+ ", corrected: " + to_string( mechanik.AccDesired * mechanik.BrakeAccFactor(), 2 )
+ "\n current: " + to_string( mechanik.AbsAccS + 0.001f, 2 )
+ ", slope: " + to_string( mechanik.fAccGravity + 0.001f, 2 ) + " (" + ( mechanik.fAccGravity > 0.01 ? "\\" : mechanik.fAccGravity < -0.01 ? "/" :
"-" ) + ")"
+ "\n desired diesel percentage: " + std::to_string(mechanik.DizelPercentage)
+ "/" + std::to_string(mechanik.DizelPercentage_Speed)
+ "/" + to_string(100.4*mechanik.mvControlling->eimic_real, 0);
Output.emplace_back( textline, Global.UITextColor );
// brakes
textline =
"Brakes:\n highest pressure: " + to_string( mechanik.fReady, 2 ) + ( mechanik.Ready ? " (all brakes released)" : "" )
+ "\n activation threshold: " + to_string( mechanik.fAccThreshold, 2 )
+ ", delays: " + to_string( mechanik.fBrake_a0[ 0 ], 2 ) + " + " + to_string( mechanik.fBrake_a1[ 0 ], 2 )
+ "\n virtual brake position: " + to_string( mechanik.BrakeCtrlPosition, 2 )
+ "\n test stage: " + std::to_string( mechanik.DynamicBrakeTest )
+ ", applied at: " + to_string( mechanik.DBT_VelocityBrake, 0 )
+ ", release at: " + to_string( mechanik.DBT_VelocityRelease, 0 )
+ ", done at: " + to_string( mechanik.DBT_VelocityFinish, 0 );
Output.emplace_back( textline, Global.UITextColor );
// ai driving flags
textline = "Driving flags:";
for( auto const name : mechanik.DrivingFlagsState().ActiveNames() ) {
textline += "\n ";
textline += name;
}
Output.emplace_back( textline, Global.UITextColor );
}
void
debug_panel::update_section_scantable( std::vector<text_line> &Output ) const {
if( m_input.mechanik == nullptr ) { return; }
Output.emplace_back( "Flags: Dist: Vel: Name:", Global.UITextColor );
auto const &mechanik{ *m_input.mechanik };
std::size_t i = 0; std::size_t const speedtablesize = std::clamp( static_cast<int>( mechanik.TableSize() ) - 1, 0, 30 );
do {
auto const scanline = mechanik.TableText( i );
if( scanline.empty() ) { break; }
Output.emplace_back( data_name_to_utf8( scanline ), Global.UITextColor );
++i;
} while( i < speedtablesize );
if( Output.size() == 1 ) {
Output.front().data = "(no points of interest)";
}
}
#ifdef WITH_UART
void
debug_panel::update_section_uart( std::vector<text_line> &Output ) const {
uart_status const *status = &UartStatus;
Output.emplace_back(
("Port: " + status->port_name).c_str(),
Global.UITextColor
);
Output.emplace_back(
("Baud: " + std::to_string(status->baud)).c_str(),
Global.UITextColor
);
if(status->is_connected) {
std::string synctext = status->is_synced ? "SYNCED" : "NOT SYNCED";
Output.emplace_back(("CONNECTED, " + synctext).c_str(), Global.UITextColor);
} else {
Output.emplace_back("* NOT CONNECTED *", Global.UITextColor);
}
Output.emplace_back(
(
"Packets sent: "+std::to_string(status->packets_sent)
+" Packets received: "+std::to_string(status->packets_received)
).c_str(),
Global.UITextColor
);
}
#endif
void
debug_panel::update_section_scenario( std::vector<text_line> &Output ) const {
auto textline =
"vehicles: " + to_string( Timer::subsystem.sim_dynamics.average(), 2 ) + " msec"
+ " update total: " + to_string( Timer::subsystem.sim_total.average(), 2 ) + " msec";
Output.emplace_back( textline, Global.UITextColor );
// current luminance level
textline = "Light level: " + to_string( Global.fLuminance, 3 ) + ( Global.FakeLight ? "(*)" : "" )+ to_string(Global.SunAngle,2);
textline +=
"\nWind: azimuth "
+ to_string( simulation::Environment.wind_azimuth(), 0 ) // ma być azymut, czyli 0 na północy i rośnie na wschód
+ " "
+ std::string( "N NEE SES SWW NW" )
.substr( static_cast<std::size_t>( 2 * std::floor( std::fmod( 8 + ( glm::radians( simulation::Environment.wind_azimuth() ) + 0.5 * M_PI_4 ) / M_PI_4, 8 ) ) ), 2 )
+ ", " + to_string( glm::length( simulation::Environment.wind() ), 1 ) + " m/s";
textline += "\nAir temperature: " + to_string( Global.AirTemperature, 1 ) + " deg C";
Output.emplace_back( textline, Global.UITextColor );
}
void
debug_panel::update_section_eventqueue( std::vector<text_line> &Output ) {
std::string textline;
// current event queue
auto const time { Timer::GetTime() };
auto const *queuedevent { simulation::Events.begin() };
auto const searchfilter { std::string( m_eventsearch.data() ) };
Output.emplace_back( "Delay: Event:", Global.UITextColor );
while( queuedevent != nullptr
&& Output.size() < 30 ) {
if( false == queuedevent->m_ignored
&& false == queuedevent->m_passive
&& ( false == m_eventqueueactivevehicleonly
|| queuedevent->m_activator == m_input.vehicle ) ) {
auto const label { queuedevent->m_name + ( queuedevent->m_activator ? " (by: " + queuedevent->m_activator->asName + ")" : "" ) };
if( false == searchfilter.empty()
&& false == contains(label, searchfilter) ) {
queuedevent = queuedevent->m_next;
continue;
}
auto const delay { " " + to_string( std::max( 0.0, queuedevent->m_launchtime - time ), 1 ) };
textline =
delay.substr( delay.length() - 6 )
+ " "
+ label + ( queuedevent->m_sibling ? " (joint event)" : "" );
Output.emplace_back( textline, Global.UITextColor );
}
queuedevent = queuedevent->m_next;
}
if( Output.size() == 1 ) {
// event queue can be empty either because no event got through active filters, or because it is genuinely empty
Output.front().data = simulation::Events.begin() == nullptr ? "(no queued events)" : "(no matching events)";
}
}
void
debug_panel::update_section_powergrid( std::vector<text_line> &Output ) const {
auto const lowpowercolor { glm::vec4( 164.0f / 255.0f, 132.0f / 255.0f, 84.0f / 255.0f, 1.f ) };
auto const nopowercolor { glm::vec4( 164.0f / 255.0f, 84.0f / 255.0f, 84.0f / 255.0f, 1.f ) };
Output.emplace_back( "Name: Output: Current: Timeout:", Global.UITextColor );
std::string textline;
for( auto const *powerstation : simulation::Powergrid.sequence() ) {
if( true == powerstation->IsAutogenerated ) { continue; }
if( true == powerstation->bSection ) { continue; }
auto const name { (
powerstation->m_name.empty() ?
"(unnamed)" :
powerstation->m_name )
+ " " };
textline =
name.substr( 0, 20 )
+ " " + to_string( powerstation->OutputVoltage, 0, 5 )
+ " " + to_string( powerstation->TotalCurrent, 1, 8 )
+ " " + to_string( powerstation->FuseTimer, 1, 8 )
+ ( powerstation->FuseCounter == 0 ?
"" :
" (x" + std::to_string( powerstation->FuseCounter ) + ")" );
Output.emplace_back(
textline,
powerstation->FastFuse || powerstation->SlowFuse ? nopowercolor :
powerstation->OutputVoltage < 0.8 * powerstation->NominalVoltage ? lowpowercolor :
Global.UITextColor );
}
if( Output.size() == 1 ) {
Output.front().data = "(no power stations)";
}
}
void
debug_panel::update_section_camera( std::vector<text_line> &Output ) const {
if( m_input.camera == nullptr ) { return; }
auto const &camera{ *m_input.camera };
// camera data
auto textline =
"Position: ["
+ to_string( camera.Pos.x, 2 ) + ", "
+ to_string( camera.Pos.y, 2 ) + ", "
+ to_string( camera.Pos.z, 2 ) + "]";
Output.emplace_back( textline, Global.UITextColor );
textline =
"Azimuth: "
+ to_string( 180.0 - glm::degrees( camera.Angle.y ), 0 ) // ma być azymut, czyli 0 na północy i rośnie na wschód
+ " "
+ std::string( "S SEE NEN NWW SW" )
.substr( static_cast<std::size_t>( 2 * floor( fmod( 8 + ( camera.Angle.y + 0.5 * M_PI_4 ) / M_PI_4, 8 ) ) ), 2 );
Output.emplace_back( textline, Global.UITextColor );
}
void
debug_panel::update_section_renderer( std::vector<text_line> &Output ) {
// gfx renderer data
auto textline =
"FoV: " + to_string( Global.FieldOfView / Global.ZoomFactor, 1 )
+ ", Draw range: " + to_string( Global.BaseDrawRange * Global.fDistanceFactor, 0 ) + "m"
// + "; sectors: " + std::to_string( GfxRenderer->m_drawcount )
// + ", FPS: " + to_string( Timer::GetFPS(), 2 );
+ ", FPS: " + std::to_string( static_cast<int>(std::round(GfxRenderer->Framerate())) )
+ ( Global.VSync ? " (vsync on)" : "" );
if( Global.iSlowMotion ) {
textline += " (slowmotion " + std::to_string( Global.iSlowMotion ) + ")";
}
Output.emplace_back( textline, Global.UITextColor );
textline += "\nRendering mode: ";
if (Global.GfxRenderer == "default")
{
textline += "Shaders";
}
else if (Global.GfxRenderer == "vulkan")
{
textline += "Vulkan";
}
textline += " ";
if( false == Global.LastGLError.empty() ) {
textline +=
"Last openGL error: "
+ Global.LastGLError;
}
Output.emplace_back( textline, Global.UITextColor );
// renderer stats, in sections when the renderer has them (render_section_renderer())
m_renderersections = GfxRenderer->info_sections();
if( m_renderersections.empty() ) {
Output.emplace_back( GfxRenderer->info_times(), Global.UITextColor );
Output.emplace_back( GfxRenderer->info_stats(), Global.UITextColor );
}
// CPU related
Output.emplace_back("CPU:", Global.UITextColor);
// thread counter
textline = "Running threads: " + std::to_string(Global.threads.size() + 1);
Output.emplace_back(textline, Global.UITextColor);
}
namespace {
// how far from the camera a coupler shows in the coupler section [m]
constexpr float coupler_pick_radius { 10.f };
std::string_view coupler_type_name( TCouplerType const Type ) {
switch( Type ) {
case TCouplerType::Articulated: { return "articulated"; }
case TCouplerType::Bare: { return "bare"; }
case TCouplerType::Chain: { return "chain"; }
case TCouplerType::Screw: { return "screw"; }
case TCouplerType::Automatic: { return "automatic"; }
default: { return "none"; }
}
}
// the couplerphysics setting of eu07.ini
std::string_view coupler_physics_setting() {
if( Global.coupler_physics_all ) { return "all"; }
return Global.coupler_physics ? "yes" : "no";
}
std::string_view coupler_stop_name( int const Stop ) {
if( Stop > 0 ) { return "draw gear solid"; }
if( Stop < 0 ) { return "buffers solid"; }
return "none";
}
// a value shown in the Scale of its unit (1000 for kN, 0.001 for mm), dragged within Min and Max of that unit
bool edit_value( char const *Label, double &Value, double const Scale, double const Min, double const Max, char const *Format ) {
auto shown { Value / Scale };
if( false == ImGui::DragScalar( Label, ImGuiDataType_Double, &shown, static_cast<float>( ( Max - Min ) / 1000.0 ), &Min, &Max, Format ) ) {
return false;
}
Value = std::clamp( shown, Min, Max ) * Scale;
return true;
}
bool edit_spring( char const *Name, coupler_physics::spring_curve &Curve, double &Unloading ) {
ImGui::PushID( Name );
ImGui::TextUnformatted( Name );
auto changed { edit_value( "Stiffness [kN/m]", Curve.stiffness, 1000.0, 100.0, 50000.0, "%.0f" ) };
changed = edit_value( "Travel [mm]", Curve.travel, 0.001, 5.0, 300.0, "%.0f" ) || changed;
changed = edit_value( "Progression", Curve.progression, 1.0, 0.0, 0.9, "%.2f" ) || changed;
changed = edit_value( "Unloading ratio", Unloading, 1.0, 0.05, 1.0, "%.2f" ) || changed;
ImGui::Text( "End force: %.0f kN", Curve.end_force() / 1000.0 );
ImGui::PopID();
return changed;
}
bool edit_link( coupler_physics::end_parameters &Parameters ) {
auto &link { Parameters.link };
ImGui::PushID( "link" );
ImGui::TextUnformatted( "Link" );
auto changed { ImGui::Checkbox( "Breakable", &link.breakable ) };
changed = edit_value( "Ultimate force [kN]", link.ultimate, 1000.0, 10.0, 5000.0, "%.0f" ) || changed;
changed = edit_value( "Yield force [kN]", link.yield, 1000.0, 10.0, 5000.0, "%.0f" ) || changed;
link.yield = std::min( link.yield, link.ultimate );
// the permanent stretch at which the link breaks, which is what the hardening gives
auto stretch { ( link.ultimate - link.yield ) / link.hardening };
if( edit_value( "Stretch to break [mm]", stretch, 0.001, 1.0, 200.0, "%.1f" ) ) {
link.hardening = std::max( ( link.ultimate - link.yield ) / stretch, 1.0 );
changed = true;
}
changed = edit_value( "Link stiffness [kN/m]", Parameters.link_stiffness, 1000.0, 1000.0, 2000000.0, "%.0f" ) || changed;
changed = edit_value( "Buffers crush force [kN]", Parameters.crush_force, 1000.0, 100.0, 10000.0, "%.0f" ) || changed;
changed = edit_value( "Restitution of a solid hit", Parameters.solid_restitution, 1.0, 0.05, 0.95, "%.2f" ) || changed;
ImGui::PopID();
return changed;
}
bool edit_coupler_parameters( coupler_physics::end_parameters &Parameters ) {
auto changed { edit_value( "Slack [mm]", Parameters.slack, 0.001, -100.0, 300.0, "%.1f" ) };
changed = edit_value( "Damping [kN s/m]", Parameters.damping, 1000.0, 0.0, 1000.0, "%.1f" ) || changed;
changed = edit_spring( "Buffers", Parameters.buffers, Parameters.buffers_unloading ) || changed;
changed = edit_spring( "Draw gear", Parameters.draw_gear, Parameters.draw_gear_unloading ) || changed;
changed = edit_link( Parameters ) || changed;
return changed;
}
} // namespace
void
debug_panel::update_section_coupler( std::vector<text_line> &Output ) {
m_coupler = {};
if( m_input.camera == nullptr ) { return; }
auto const &camera { m_input.camera->Pos };
auto const *vehicle { std::get<TDynamicObject *>( simulation::Region->find_vehicle( camera, coupler_pick_radius, false, true ) ) };
if( vehicle == nullptr || vehicle->MoverParameters == nullptr ) {
Output.emplace_back( std::format( "No coupler within {:.0f} m of the camera", coupler_pick_radius ), Global.UITextColor );
return;
}
auto const nearerfront { glm::distance( vehicle->CouplerPosition( end::front ), camera ) <= glm::distance( vehicle->CouplerPosition( end::rear ), camera ) };
m_coupler = { vehicle, nearerfront ? end::front : end::rear };
auto const &mover { *vehicle->MoverParameters };
auto const &coupler { mover.Couplers[ m_coupler.end ] };
auto const &neighbour { mover.Neighbours[ m_coupler.end ] };
auto const &state { coupler.physics_state };
Output.emplace_back(
std::format( "{}, {} end, {} coupler{}", vehicle->name(), nearerfront ? "front" : "rear", coupler_type_name( coupler.type() ), coupler.has_adapter() ? " (adapter)" : "" ),
Global.UITextColor );
Output.emplace_back(
std::format(
"Model: {} (couplerphysics {}, vehicle {}covered), crash damage {}",
mover.coupler_physics_at( m_coupler.end ) ? "physical" : "legacy",
coupler_physics_setting(),
mover.CouplerPhysics ? "" : "not ",
Global.crash_damage ? "on" : "off" ),
Global.UITextColor );
if( neighbour.vehicle != nullptr ) {
Output.emplace_back(
std::format( "Neighbour: {} ({} end), coupling [{}], gap {:.1f} mm", neighbour.vehicle->name(), neighbour.vehicle_end == end::front ? "front" : "rear", coupler.CouplingFlag.Bits(), neighbour.distance * 1000.0 ),
Global.UITextColor );
}
else {
Output.emplace_back( "Neighbour: none", Global.UITextColor );
}
Output.emplace_back( std::format( "Force: {:.1f} kN", coupler.CForce / 1000.0 ), Global.UITextColor );
Output.emplace_back(
std::format( "Draw gear: {:.1f} mm, {:.1f} kN Buffers: {:.1f} mm, {:.1f} kN", state.draw_gear.deflection * 1000.0, state.draw_gear.force / 1000.0, state.buffers.deflection * 1000.0, state.buffers.force / 1000.0 ),
Global.UITextColor );
Output.emplace_back(
std::format( "Stretch: {:.1f} mm, stop: {}, overloaded for {:.1f} s", state.elongation * 1000.0, coupler_stop_name( state.stop ), coupler.stretch_duration ),
Global.UITextColor );
if( coupler.broken ) {
Output.emplace_back( "Coupler broken (repair it in the driving aid, F1)", glm::vec4( 1.f, 0.25f, 0.25f, 1.f ) );
}
}
bool
debug_panel::render_section_coupler() {
if( false == render_section( "Coupler", m_couplerlines ) ) { return false; }
// the parameters to try out, in the debug mode, on the simulation itself
if( false == DebugModeFlag || m_coupler.vehicle == nullptr || Application.is_client() ) { return true; }
ImGui::Separator();
ImGui::Checkbox( "Physical coupler model", &Global.coupler_physics );
ImGui::Checkbox( "Physical model for every train", &Global.coupler_physics_all );
ImGui::Checkbox( "Crash damage", &Global.crash_damage );
ImGui::Checkbox( "Apply to the other end of the pair too", &m_couplerbothends );
auto &mover { *m_coupler.vehicle->MoverParameters };
auto &coupler { mover.Couplers[ m_coupler.end ] };
auto const &neighbour { mover.Neighbours[ m_coupler.end ] };
auto *othercoupler { neighbour.vehicle != nullptr ? &neighbour.vehicle->MoverParameters->Couplers[ neighbour.vehicle_end ] : nullptr };
if( auto parameters { coupler.physics }; edit_coupler_parameters( parameters ) ) {
coupler.physics = parameters;
if( m_couplerbothends && othercoupler != nullptr ) {
othercoupler->physics = parameters;
}
}
if( ImGui::Button( "Reset the stretch of the coupling" ) ) {
// both vehicles keep the state of the pair alike
coupler.physics_state.elongation = 0.0;
if( othercoupler != nullptr ) {
othercoupler->physics_state.elongation = 0.0;
}
}
return true;
}
bool
debug_panel::render_section( std::string const &Header, std::vector<text_line> const &Lines ) {
if( true == Lines.empty() ) { return false; }
if( false == ImGui::CollapsingHeader( Header.c_str() ) ) { return false; }
return render_section( Lines );
}
// the lines of the renderer, then its data in sections which fold, the long lines wrapped to the width of the panel
bool
debug_panel::render_section_renderer() {
if( false == render_section( "Gfx Renderer / Statistics", m_rendererlines ) ) { return false; }
ImGui::PushStyleColor( ImGuiCol_Text, { Global.UITextColor.r, Global.UITextColor.g, Global.UITextColor.b, Global.UITextColor.a } );
ImGui::PushTextWrapPos( 0.f );
for( auto const &section : m_renderersections ) {
ImGui::SetNextItemOpen( section.open, ImGuiCond_Once );
if( true == ImGui::TreeNode( section.title.c_str() ) ) {
ImGui::TextUnformatted( section.text.c_str() );
ImGui::TreePop();
}
}
ImGui::PopTextWrapPos();
ImGui::PopStyleColor();
// the physics of the vehicles, timed in the section of the main loop
ImGui::Checkbox( "let vehicles standing still and held by their brakes sleep (physics.sleepheld)", &Global.physics_sleepheld );
ImGui::Checkbox( "one step of the physics in a frame for road vehicles farther than 1 km (physics.roadlod)", &Global.physics_roadlod );
ImGui::SliderFloat( "bar: change of the pressure in a pipe which wakes the physics of a vehicle, 0 any (physics.pipewake)", &Global.physics_pipewake, 0.f, 0.05f, "%.4f" );
return true;
}
bool
debug_panel::render_section( std::vector<text_line> const &Lines ) const {
for( auto const &line : Lines ) {
ImGui::PushStyleColor( ImGuiCol_Text, { line.color.r, line.color.g, line.color.b, line.color.a } );
ImGui::TextUnformatted( line.data.c_str() );
ImGui::PopStyleColor();
// ImGui::TextColored( ImVec4( line.color.r, line.color.g, line.color.b, line.color.a ), line.data.c_str() );
}
return true;
}
bool debug_panel::render_section_developer() const
{
if (false == ImGui::CollapsingHeader("Developer tools"))
return false;
ImGui::PushStyleColor(ImGuiCol_Text, {Global.UITextColor.r, Global.UITextColor.g, Global.UITextColor.b, Global.UITextColor.a});
ImGui::TextUnformatted("Warning! These tools are only for developers.\nDo not use them if you are NOT sure what they do!");
ImGui::TextColored(ImVec4(1.0f, 0.0f, 0.0f, 1.0f), "These settings may crash your simulator!");
if (ImGui::Button("Reload current vehicle .fiz") == true)
{
m_input.vehicle->MoverParameters->reload_FIZ(); // reload fiz
}
ImGui::PopStyleColor();
return true;
}
namespace {
// a combo choosing one of the names, the first entry standing for the library's own choice. the names are asked for
// each time the list opens, as devices come and go. returns: true if the choice changed
template <class Names_>
bool name_combo( char const *Label, std::string &Value, Names_ const &Names, char const *Defaultlabel, std::string_view const Defaultvalue ) {
auto const preview { Value == Defaultvalue ? std::string{ Defaultlabel } : Value };
if( false == ImGui::BeginCombo( Label, preview.c_str() ) ) { return false; }
static std::vector<std::string> names; // one list per call site, as each passes its own lambda
if( ImGui::IsWindowAppearing() ) {
names = Names();
}
auto changed { false };
if( ImGui::Selectable( Defaultlabel, Value == Defaultvalue ) ) {
Value = Defaultvalue;
changed = true;
}
for( auto const &name : names ) {
if( ImGui::Selectable( name.c_str(), name == Value ) ) {
Value = name;
changed = true;
}
}
ImGui::EndCombo();
return changed;
}
// options of the audio device, applied by reopening it: output device, output mode, HRTF, limiter, mixing rate, sources
void render_audio_device_settings() {
auto changed { false };
changed |= name_combo( "Output device###audiodevice", Global.AudioRenderer,
[] { return audio::renderer.output_devices(); }, "System default", "" );
changed |= name_combo( "Output mode###audiooutputmode", Global.AudioOutputMode,
[] { return std::vector<std::string>{ "mono", "stereo", "stereo-basic", "uhj", "headphones", "quad", "5.1", "6.1", "7.1" }; },
"Automatic", "auto" );
changed |= name_combo( "HRTF###audiohrtf", Global.AudioHrtf,
[] { return std::vector<std::string>{ "on", "off" }; }, "Automatic", "auto" );
changed |= name_combo( "HRTF data set###audiohrtfprofile", Global.AudioHrtfProfile,
[] { return audio::renderer.hrtf_profiles(); }, "Library's choice", "" );
changed |= name_combo( "Limiter###audiolimiter", Global.AudioLimiter,
[] { return std::vector<std::string>{ "on", "off" }; }, "Automatic", "auto" );
auto frequency { Global.AudioFrequency > 0 ? std::to_string( Global.AudioFrequency ) : std::string{} };
if( name_combo( "Mixing rate###audiofrequency", frequency,
[] { return std::vector<std::string>{ "22050", "32000", "44100", "48000", "96000" }; }, "Device's", "" ) ) {
Global.AudioFrequency = ( frequency.empty() ? 0 : std::stoi( frequency ) );
changed = true;
}
if( changed ) {
audio::renderer.apply_device_settings();
}
}
// options of the sources, applied to the playing ones right away: resampler, Doppler effect, EFX
void render_audio_source_settings() {
auto changed { false };
changed |= name_combo( "Resampler###audioresampler", Global.AudioResampler,
[] { return audio::renderer.resamplers(); }, "Library's default", "" );
changed |= ImGui::SliderFloat( ( to_string( Global.AudioDoppler, 2 ) + "###audiodoppler" ).c_str(), &Global.AudioDoppler, 0.0f, 1.0f, "Doppler effect" );
changed |= ImGui::Checkbox( "Soundproofing muffles high frequencies###audiolowpass", &Global.AudioLowpass );
changed |= ImGui::SliderFloat( ( to_string( Global.AudioAirAbsorption, 1 ) + "###audioairabsorption" ).c_str(), &Global.AudioAirAbsorption, 0.0f, 10.0f, "Air absorption" );
if( changed ) {
audio::renderer.apply_source_settings();
}
ImGui::TextWrapped( "%s", audio::renderer.device_status().c_str() );
}
} // namespace
bool
debug_panel::render_section_settings() const {
if( false == ImGui::CollapsingHeader( "Settings" ) ) { return false; }
ImGui::PushStyleColor( ImGuiCol_Text, { Global.UITextColor.r, Global.UITextColor.g, Global.UITextColor.b, Global.UITextColor.a } );
ImGui::TextUnformatted( "Graphics" );
ImGui::PopStyleColor();
// screen space reflections
{
char const *ssrlevels[] { "off", "low", "medium", "high" };
ImGui::SliderInt( ( std::string( ssrlevels[ std::clamp( Global.gfx_ssr, 0, 3 ) ] ) + "###screenreflections" ).c_str(), &Global.gfx_ssr, 0, 3, "Reflections" );
}
ImGui::SliderInt( ( std::to_string( Global.gfx_shadow_rank_cutoff ) + "###shadowrankcutoff" ).c_str(), &Global.gfx_shadow_rank_cutoff, 1, 3, "Shadow ranks" );
if( ImGui::SliderFloat( ( to_string( std::abs( Global.gfx_shadow_angle_min ), 2 ) + "###shadowanglecutoff" ).c_str(), &Global.gfx_shadow_angle_min, -1.0, -0.2f, "Shadow angle cutoff" ) ) {
Global.gfx_shadow_angle_min = quantize( Global.gfx_shadow_angle_min, 0.05f );
}
// sieć trakcyjna: zasięg rysowania przewodów, lin i uchwytów jako brył; 0 wyłącza bryły
if( ImGui::SliderFloat( ( to_string( CatenarySettings.solid_range, 0 ) + " m###catenarysolidrange" ).c_str(), &CatenarySettings.solid_range, 0.0f, 500.0f, "3D overhead wires range" ) ) {
CatenarySettings.solid_range = quantize( CatenarySettings.solid_range, 10.0f );
}
if( DebugModeFlag ) {
// sky sliders
{
ImGui::SliderFloat(
( to_string( Global.m_skysaturationcorrection, 2, 5 ) + "###skysaturation" ).c_str(), &Global.m_skysaturationcorrection, 0.0f, 3.0f, "Sky saturation" );
}
{
ImGui::SliderFloat(
( to_string( Global.m_skyhuecorrection, 2, 5 ) + "###skyhue" ).c_str(), &Global.m_skyhuecorrection, 0.0f, 1.0f, "Sky hue correction" );
}
}
ImGui::PushStyleColor( ImGuiCol_Text, { Global.UITextColor.r, Global.UITextColor.g, Global.UITextColor.b, Global.UITextColor.a } );
ImGui::TextUnformatted( "Sound" );
ImGui::PopStyleColor();
// audio volume sliders
ImGui::SliderFloat( ( std::to_string( static_cast<int>( Global.AudioVolume * 100 ) ) + "%###volumemain" ).c_str(), &Global.AudioVolume, 0.0f, 2.0f, "Main audio volume" );
if( ImGui::SliderFloat( ( std::to_string( static_cast<int>( Global.VehicleVolume * 100 ) ) + "%###volumevehicle" ).c_str(), &Global.VehicleVolume, 0.0f, 1.0f, "Vehicle sounds" ) ) {
audio::event_volume_change = true;
}
if( ImGui::SliderFloat( ( std::to_string( static_cast<int>( Global.EnvironmentPositionalVolume * 100 ) ) + "%###volumepositional" ).c_str(), &Global.EnvironmentPositionalVolume, 0.0f, 1.0f, "Positional sounds" ) ) {
audio::event_volume_change = true;
}
if( ImGui::SliderFloat( ( std::to_string( static_cast<int>( Global.EnvironmentAmbientVolume * 100 ) ) + "%###volumeambient" ).c_str(), &Global.EnvironmentAmbientVolume, 0.0f, 1.0f, "Ambient sounds" ) ) {
audio::event_volume_change = true;
}
if (simulation::Train) {
float val = simulation::Train->get_radiovolume();
if( ImGui::SliderFloat( ( std::to_string( static_cast<int>( val * 100 ) ) + "%###volumeradio" ).c_str(), &val, 0.0f, 1.0f, "Vehicle radio volume" ) ) {
command_relay commandrelay;
commandrelay.post(user_command::radiovolumeset, val, 0.0, GLFW_PRESS, 0);
}
}
if( Global.bSoundEnabled ) {
render_audio_device_settings();
render_audio_source_settings();
}
return true;
}
void
transcripts_panel::update() {
if( false == is_open ) { return; }
text_lines.clear();
for( auto const &transcript : ui::Transcripts.aLines ) {
if( Global.fTimeAngleDeg + ( transcript.fShow - Global.fTimeAngleDeg > 180 ? 360 : 0 ) < transcript.fShow ) { continue; }
std::string text = transcript.asText;
std::ranges::replace(text, '|', ' ');
text_lines.emplace_back( text, colors::white );
}
}
void
transcripts_panel::render() {
if( false == is_open ) { return; }
if( true == text_lines.empty() ) { return; }
auto flags =
ImGuiWindowFlags_NoFocusOnAppearing
| ImGuiWindowFlags_NoCollapse
| ( size.x > 0 ? ImGuiWindowFlags_NoResize : 0 );
if( size.x > 0 ) {
ImGui::SetNextWindowSize( ImVec2S( size.x, size.y ) );
}
if( size_min.x > 0 ) {
ImGui::SetNextWindowSizeConstraints( ImVec2S( size_min.x, size_min.y ), ImVec2S( size_max.x, size_max.y ) );
}
if( auto const panelname { ( title.empty() ? m_name : title ) + "###" + m_name }; true == ImGui::Begin( panelname.c_str(), &is_open, flags ) ) {
// header section
for( auto const &line : text_lines ) {
ImGui::TextWrapped( "%s", line.data.c_str() );
}
}
ImGui::End();
}