mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-12-01 18:47:06 +01:00
84f1aa2515
The positions of the master and the secondary controller, of the analog
controller and of the lights selector, the occupied cab, the horns, the radio
and its fuse, the radio-stop, the wipers' switch, the dimmer, the mirrors'
button, the end-of-train signalling and the forced resistor fans: fourteen
fields the cab, the AI, the scenery and the tests wrote straight into
physics::Vehicle are private now. The rest of the simulator reads them through
queries named as the fields were (MainCtrlPos(), Radio(), ...) and changes them
through operations (SetMainCtrlPos(), SetRadio(), ...), so every place that
moves a controller past its own stepping (IncMainCtrl()) is named and can be
found; the compiler keeps anything else out. Inside the vehicle they keep
their meaning under camelCase names. The queries return const references, as
the gauges of the cab bind to them.
The .fiz keys are untouched.
No change in behaviour: the golden traces recorded on dfb43c4f match bit for bit.
1926 lines
82 KiB
C++
1926 lines
82 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/vehicle.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 *, VehicleEnd> 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->physics == nullptr ) { return { nullptr, VehicleEnd::front }; }
|
|
auto const front { glm::distance( vehicle->CouplerPosition( VehicleEnd::front ), Camera ) };
|
|
auto const rear { glm::distance( vehicle->CouplerPosition( VehicleEnd::rear ), Camera ) };
|
|
auto const nearest { front <= rear ? VehicleEnd::front : VehicleEnd::rear };
|
|
if( std::min( front, rear ) > coupler_repair_radius || false == vehicle->physics->Couplers[ nearest ].broken ) { return { nullptr, VehicleEnd::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 *physics = controlled->physics;
|
|
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_vehicles(
|
|
*physics,
|
|
*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 { ( physics->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( physics->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,
|
|
physics->SpeedCtrlUnit.IsActive ? 'T' :
|
|
physics->DirActive > 0 ? 'D' :
|
|
physics->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)"),
|
|
physics->brakes.cylinderPressure * 100,
|
|
physics->brakePipe.Pressure() * 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,
|
|
physics->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,
|
|
physics->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 =
|
|
physics->SecuritySystem.is_vigilance_blinking() && (train != nullptr ? train->fBlinkTimer > 0 : true) ? STR("!ALERTER! ") : " ";
|
|
textline +=
|
|
physics->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, NumberOf( 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->physics->TotalMass;
|
|
// subtract potential other half of a two-part vehicle
|
|
if( auto const *previous { owner->pVehicle->Prev( Coupling::permanent ) }; previous != nullptr ) { consistmass -= previous->physics->TotalMass; }
|
|
auto const *next { owner->pVehicle->Next( Coupling::permanent ) };
|
|
if( next != nullptr ) { consistmass -= next->physics->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->physics->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.physics =
|
|
m_input.vehicle != nullptr ? m_input.vehicle->physics : 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.physics && false == m_input.physics->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.physics == nullptr ) { return; }
|
|
|
|
auto const &vehicle { *m_input.vehicle };
|
|
auto const &physics { *m_input.physics };
|
|
|
|
auto const isowned { /* ( vehicle.Mechanik == nullptr ) && */ vehicle.ctOwner != nullptr && vehicle.ctOwner->Vehicle() != m_input.vehicle };
|
|
auto const isdieselenginepowered { physics.EngineType == TEngineType::DieselElectric || physics.EngineType == TEngineType::DieselEngine };
|
|
auto const isdieselinshuntmode { physics.ShuntMode && physics.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"),
|
|
physics.Name.c_str(),
|
|
std::string( isowned ? STR(", owned by: ") + vehicle.ctOwner->OwnerName() : "" ).c_str(),
|
|
physics.LoadAmount,
|
|
physics.LoadType.name.c_str(),
|
|
physics.EngineDescription( 0 ).c_str(),
|
|
// TODO: put wheel flat reporting in the enginedescription()
|
|
std::string( physics.WheelFlat > 0.01 ? " Flat: " + to_string( physics.WheelFlat, 1 ) + " mm" : "" ).c_str(),
|
|
update_vehicle_coupler( VehicleEnd::front ).c_str(),
|
|
update_vehicle_coupler( VehicleEnd::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
|
|
physics.lowVoltage.IsBatteryOn() ? 'B' : '.',
|
|
physics.pantographAir.valve.is_active ? '+' : '.',
|
|
physics.pantographs[VehicleEnd::rear].valve.is_active ? 'O' :
|
|
physics.pantographs[VehicleEnd::rear].valve.is_enabled ? 'o' :
|
|
'.',
|
|
physics.pantographs[VehicleEnd::front].valve.is_active ? 'P' :
|
|
physics.pantographs[VehicleEnd::front].valve.is_enabled ? 'p' :
|
|
'.',
|
|
physics.pantographAir.IsPressureLockActive() ? '!' :
|
|
physics.pantographAir.IsPressureSwitchPrimed() ? '*' :
|
|
'.',
|
|
physics.WaterPump.is_active ? 'W' :
|
|
false == physics.WaterPump.breaker ? '-' :
|
|
physics.WaterPump.is_enabled ? 'w' :
|
|
'.',
|
|
physics.WaterHeater.is_damaged ? '!' :
|
|
physics.WaterHeater.is_active ? 'H' :
|
|
false == physics.WaterHeater.breaker ? '-' :
|
|
physics.WaterHeater.is_enabled ? 'h' :
|
|
'.',
|
|
physics.FuelPump.is_active ? 'F' :
|
|
physics.FuelPump.is_enabled ? 'f' :
|
|
'.',
|
|
physics.OilPump.is_active ? 'O' :
|
|
physics.OilPump.is_enabled ? 'o' :
|
|
'.',
|
|
physics.lineBreaker.IsClosed() ? 'M' : '.',
|
|
physics.FuseFlag ? '!' : '.',
|
|
physics.converter.IsRunning() ? 'X' :
|
|
false == physics.converter.LocalSwitchOn() ? '-' :
|
|
physics.converter.IsAllowed() ? 'x' :
|
|
'.',
|
|
physics.converter.IsOverloaded() ? '!' : '.',
|
|
physics.air.compressor.IsRunning() ? 'C' :
|
|
false == physics.air.compressor.LocalSwitchOn() ? '-' :
|
|
physics.air.compressor.IsAllowed() || (physics.air.compressor.config.start == start_t::automatic && physics.air.compressor.config.speed > 0.0) ? 'c' :
|
|
'.',
|
|
physics.air.compressor.IsGovernorLocked() ? '!' : '.',
|
|
physics.lineContactors.IsForcedOpen() ? '-' :
|
|
physics.protection.PressureSwitchTripped() ? '!' :
|
|
physics.lineContactors.IsClosed() ? '+' :
|
|
'.',
|
|
physics.trainHeating.IsOn() ? 'H' :
|
|
physics.trainHeating.IsAllowed() ? 'h' :
|
|
'.',
|
|
physics.brakes.distributor->Releaser() ? '^' : '.',
|
|
std::string( m_input.mechanik ? STR(" R") + ( physics.Radio() && physics.RadioFuse() ? std::to_string( m_input.mechanik->iRadioChannel ) : "-" ) : "" ).c_str(),
|
|
std::string( isdieselenginepowered ? STR(" oil pressure: ") + to_string( physics.OilPump.pressure, 2 ) : "" ).c_str(),
|
|
// power transfers
|
|
// 3000v
|
|
physics.Couplers[ VehicleEnd::front ].power_high.voltage,
|
|
physics.Couplers[ VehicleEnd::front ].power_high.current,
|
|
std::string( physics.Couplers[ VehicleEnd::front ].power_high.is_local ? ":" : ":=" ).c_str(),
|
|
physics.EngineVoltage,
|
|
std::string( physics.Couplers[ VehicleEnd::rear ].power_high.is_local ? ":" : "=:" ).c_str(),
|
|
physics.Couplers[ VehicleEnd::rear ].power_high.voltage,
|
|
physics.Couplers[ VehicleEnd::rear ].power_high.current,
|
|
// 110v
|
|
physics.Couplers[ VehicleEnd::front ].power_110v.voltage,
|
|
physics.Couplers[ VehicleEnd::front ].power_110v.current,
|
|
std::string( physics.Couplers[ VehicleEnd::front ].power_110v.is_local ? ":" : ":=" ).c_str(),
|
|
physics.PowerCircuits[ 1 ].first,
|
|
std::string( physics.Couplers[ VehicleEnd::rear ].power_110v.is_local ? ":" : "=:" ).c_str(),
|
|
physics.Couplers[ VehicleEnd::rear ].power_110v.voltage,
|
|
physics.Couplers[ VehicleEnd::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
|
|
physics.MainCtrlPos(),
|
|
physics.MainCtrlActualPos,
|
|
std::string( isdieselinshuntmode ? to_string( physics.AnPos(), 2 ) + STR(" (shunt mode)") : std::to_string( physics.ScndCtrlPos() ) + "(" + std::to_string( physics.ScndCtrlActualPos ) + ")" ).c_str(),
|
|
// engine
|
|
physics.EnginePower,
|
|
std::abs( physics.TrainType == train_type::emu ? physics.ShowCurrent( 0 ) : physics.Im ),
|
|
// revolutions
|
|
std::abs( physics.enrot ) * 60,
|
|
std::abs( physics.nrot ) * physics.Transmision.Ratio * 60,
|
|
physics.RventRot * 60,
|
|
std::abs( physics.MotorBlowers[VehicleEnd::front].revolutions ),
|
|
std::abs( physics.MotorBlowers[VehicleEnd::rear].revolutions ),
|
|
physics.diesel.heat.rpmw,
|
|
physics.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"),
|
|
physics.diesel.heat.Ts,
|
|
physics.diesel.heat.To,
|
|
physics.diesel.heat.temperatura1,
|
|
physics.WaterCircuitsLink ? '-' : '|',
|
|
physics.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
|
|
physics.brakes.handlePositionSmooth,
|
|
physics.brakes.operatingMode,
|
|
update_vehicle_brake().c_str(),
|
|
physics.brakes.loadSetting,
|
|
physics.brakes.independentPosition,
|
|
physics.brakes.independentPositionEim,
|
|
static_cast<float>(physics.brakes.handBrakePosition) / static_cast<float>(ManualBrakePosNo),
|
|
physics.brakes.spring.activate ? 1.f : 0.f,
|
|
// cylinders
|
|
physics.brakes.cylinderPressure,
|
|
physics.brakes.independentCylinderPressure,
|
|
physics.brakes.distributor->GetBrakeStatus(),
|
|
// pipes
|
|
physics.brakePipe.Pressure(),
|
|
physics.brakes.handleCapPosition,
|
|
physics.mainPipe.Pressure(),
|
|
physics.brakes.controlReservoirPressure,
|
|
// tanks
|
|
physics.brakes.distributor->GetBRP(),
|
|
physics.air.MainReservoirPressure(),
|
|
physics.brakes.distributor->GetCRP() );
|
|
|
|
textline = m_buffer.data();
|
|
|
|
if( physics.EnginePowerSource.SourceType == TPowerSource::CurrentCollector ) {
|
|
std::snprintf(
|
|
m_buffer.data(), m_buffer.size(),
|
|
STR_C(" pantograph: %.2f%cMT"),
|
|
physics.pantographAir.Pressure(),
|
|
physics.pantographAir.IsConnectedToMainReservoir() ? '-' : '|' );
|
|
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
|
|
physics.Ft * 0.001f * ( physics.CabOccupied() ? physics.CabOccupied() : vehicle.ctOwner ? vehicle.ctOwner->Controlling()->CabOccupied() : 1 ) + 0.001f,
|
|
physics.Fb * 0.001f,
|
|
physics.FrictionForce() * 0.001f,
|
|
physics.SlippingWheels ? " (!)" : "",
|
|
// acceleration
|
|
physics.AccSVBased,
|
|
physics.AccN + 0.001f,
|
|
std::string( std::abs( physics.RunningShape.R ) > 15000.0 ? "~0" : to_string( physics.RunningShape.R, 0 ) ).c_str(),
|
|
// velocity
|
|
vehicle.GetVelocity(),
|
|
physics.DistCounter,
|
|
// position
|
|
vehicle.GetPosition().x,
|
|
vehicle.GetPosition().y,
|
|
vehicle.GetPosition().z );
|
|
|
|
Output.emplace_back( m_buffer.data(), Global.UITextColor );
|
|
|
|
if( physics.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"),
|
|
physics.EnergyMeter.first, -physics.EnergyMeter.second, physics.EnergyMeter.first + physics.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>((physics.AccN - last_AccN) / dt));
|
|
AccN_acc_graph.update(static_cast<float>(physics.AccN));
|
|
}
|
|
|
|
last_AccN = static_cast<float>(physics.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( VehicleEnd const Side ) {
|
|
// NOTE: physics and vehicle are guaranteed to be valid by the caller
|
|
auto const &physics { *m_input.physics };
|
|
|
|
std::string const controltype{ ( physics.Couplers[ Side ].control_type.empty() ? "[*]" : "[" + physics.Couplers[ Side ].control_type + "]" ) };
|
|
std::string couplerstatus { STR("none") };
|
|
std::string const adapterstatus { ( physics.Couplers[ Side ].adapter_type == TCouplerType::NoCoupler ? "" : "[A]" ) };
|
|
|
|
auto const *connected { m_input.vehicle->physics->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(),
|
|
physics.Couplers[ Side ].CouplingFlag.Bits(),
|
|
physics.Neighbours[ Side ].distance );
|
|
|
|
return { m_buffer.data() };
|
|
}
|
|
|
|
std::string
|
|
debug_panel::update_vehicle_brake() const {
|
|
// NOTE: physics is guaranteed to be valid by the caller
|
|
auto const &physics { *m_input.physics };
|
|
|
|
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( ( physics.brakes.delaySetting & 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.physics == nullptr ) { return; }
|
|
|
|
auto const &vehicle{ *m_input.vehicle };
|
|
auto const &physics{ *m_input.physics };
|
|
|
|
// induction motor data
|
|
if( physics.EngineType == TEngineType::ElectricInductionMotor ) {
|
|
|
|
Output.emplace_back( " eimc: eimv: press:", Global.UITextColor );
|
|
auto const config{ physics.inductionMotor.ConfigListing() };
|
|
auto const state{ physics.inductionMotor.StateListing() };
|
|
for( int i = 0; i <= 20; ++i ) {
|
|
|
|
std::string parameters =
|
|
std::string( config[ i ].first ) + to_string( config[ i ].second, 2, 9 )
|
|
+ " | "
|
|
+ std::string( state[ i ].first ) + to_string( state[ i ].second, 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 += " | " + std::string( physics::ConsistBrakeBlending::Labels[ i - 13 ] ) + to_string( vehicle.brakeBlending.Figures()[ i - 13 ], 2, 9 );
|
|
}
|
|
|
|
Output.emplace_back( parameters, Global.UITextColor );
|
|
}
|
|
Output.emplace_back( "Inverter:\n frequency: " + to_string( physics.inductionMotor.inverterFrequency, 2 ), Global.UITextColor );
|
|
}
|
|
// diesel engine data
|
|
if( physics.EngineType == TEngineType::DieselEngine ) {
|
|
|
|
double fuel_mean = 0.0;
|
|
if (physics.DistCounter > 0.5) {
|
|
fuel_mean = 100 * physics.diesel.fuelConsumedTotal / physics.DistCounter;
|
|
}
|
|
|
|
std::string parameterstext = "param value";
|
|
std::vector< std::pair <std::string, double> > const paramvalues {
|
|
{ " rpm: ", physics.enrot * 60.0 },
|
|
{ "efill: ", physics.diesel.fill },
|
|
{ "etorq: ", physics.diesel.torque },
|
|
{ "power: ", physics.diesel.power },
|
|
{ "f_act: ", physics.diesel.fuelConsumptionActual },
|
|
{ "f_tot: ", physics.diesel.fuelConsumedTotal },
|
|
{ "fmean: ", fuel_mean },
|
|
{ "creal: ", physics.diesel.clutchPressure },
|
|
{ "cdesi: ", physics.diesel.clutchState },
|
|
{ "cdelt: ", physics.diesel.clutchSlip },
|
|
{ "gears: ", physics.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: ", physics.torqueConverter.revolutionsIn },
|
|
{ "hTCnO: ", physics.torqueConverter.revolutionsOut },
|
|
{ "hTCTM: ", physics.torqueConverter.torqueRatio },
|
|
{ "hTCTI: ", physics.torqueConverter.torqueIn },
|
|
{ "hTCTO: ", physics.torqueConverter.torqueOut },
|
|
{ "hTCfl: ", physics.torqueConverter.fill },
|
|
{ "hRtFl: ", physics.retarder.fill } ,
|
|
{ " hRtn: ", physics.retarder.revolutions } ,
|
|
{ "hRtTq: ", physics.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.physics == nullptr ) { return; }
|
|
if( m_input.mechanik == nullptr ) { return; }
|
|
|
|
auto const &physics{ *m_input.physics };
|
|
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( physics.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" },
|
|
{ physics.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( static_cast<int>( mechanik.brakeTest.stage ) )
|
|
+ ", applied at: " + to_string( mechanik.brakeTest.velocityBrake, 0 )
|
|
+ ", release at: " + to_string( mechanik.brakeTest.velocityRelease, 0 )
|
|
+ ", done at: " + to_string( mechanik.brakeTest.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->physics == 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( VehicleEnd::front ), camera ) <= glm::distance( vehicle->CouplerPosition( VehicleEnd::rear ), camera ) };
|
|
m_coupler = { vehicle, nearerfront ? VehicleEnd::front : VehicleEnd::rear };
|
|
|
|
auto const &physics { *vehicle->physics };
|
|
auto const &coupler { physics.Couplers[ m_coupler.end ] };
|
|
auto const &neighbour { physics.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 {}",
|
|
physics.coupler_physics_at( m_coupler.end ) ? "physical" : "legacy",
|
|
coupler_physics_setting(),
|
|
physics.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.FacingEnd() == VehicleEnd::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 &physics { *m_coupler.vehicle->physics };
|
|
auto &coupler { physics.Couplers[ m_coupler.end ] };
|
|
auto const &neighbour { physics.Neighbours[ m_coupler.end ] };
|
|
auto *othercoupler { neighbour.vehicle != nullptr ? &neighbour.vehicle->physics->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 §ion : 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->physics->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();
|
|
}
|