mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-07-18 03:09:18 +02:00
normal derivatives graph, global crash derail/coupler damage switch
This commit is contained in:
@@ -928,6 +928,10 @@ global_settings::ConfigParse(cParser &Parser) {
|
||||
Parser >> exec_on_exit;
|
||||
std::replace(std::begin(exec_on_exit), std::end(exec_on_exit), '_', ' ');
|
||||
}
|
||||
else if (token == "crashdamage") {
|
||||
Parser.getTokens(1);
|
||||
Parser >> crash_damage;
|
||||
}
|
||||
} while ((token != "") && (token != "endconfig")); //(!Parser->EndOfFile)
|
||||
// na koniec trochę zależności
|
||||
if (!bLoadTraction) // wczytywanie drutów i słupów
|
||||
|
||||
@@ -188,6 +188,7 @@ struct global_settings {
|
||||
bool dds_upper_origin = false;
|
||||
bool captureonstart = true;
|
||||
bool render_cab = true;
|
||||
bool crash_damage = true;
|
||||
|
||||
#ifdef USE_EXTCAM_CAMERA
|
||||
std::string extcam_cmd;
|
||||
|
||||
@@ -1144,31 +1144,33 @@ void TMoverParameters::CollisionDetect(int const End, double const dt)
|
||||
}
|
||||
}
|
||||
|
||||
if( ( coupler.Dist < 0 )
|
||||
&& ( FuzzyLogic( std::abs( CCF ), 5.0 * ( coupler.FmaxC + 1.0 ), p_coupldmg ) ) ) {
|
||||
// small chance to smash the coupler if it's hit with excessive force
|
||||
damage_coupler( End );
|
||||
}
|
||||
if (Global.crash_damage) {
|
||||
if( ( coupler.Dist < 0 )
|
||||
&& ( FuzzyLogic( std::abs( CCF ), 5.0 * ( coupler.FmaxC + 1.0 ), p_coupldmg ) ) ) {
|
||||
// small chance to smash the coupler if it's hit with excessive force
|
||||
damage_coupler( End );
|
||||
}
|
||||
|
||||
auto const safevelocitylimit { 15.0 };
|
||||
auto const velocitydifference {
|
||||
glm::length(
|
||||
glm::angleAxis( Rot.Rz, glm::dvec3{ 0, 1, 0 } ) * V
|
||||
- glm::angleAxis( othervehicle->Rot.Rz, glm::dvec3{ 0, 1, 0 } ) * othervehicle->V )
|
||||
* 3.6 }; // m/s -> km/h
|
||||
auto const safevelocitylimit { 15.0 };
|
||||
auto const velocitydifference {
|
||||
glm::length(
|
||||
glm::angleAxis( Rot.Rz, glm::dvec3{ 0, 1, 0 } ) * V
|
||||
- glm::angleAxis( othervehicle->Rot.Rz, glm::dvec3{ 0, 1, 0 } ) * othervehicle->V )
|
||||
* 3.6 }; // m/s -> km/h
|
||||
|
||||
if( velocitydifference > safevelocitylimit ) {
|
||||
// HACK: crude estimation for potential derail, will take place with velocity difference > 15 km/h adjusted for vehicle mass ratio
|
||||
WriteLog( "Bad driving: " + Name + " and " + othervehicle->Name + " collided with velocity " + to_string( velocitydifference, 0 ) + " km/h" );
|
||||
if( velocitydifference > safevelocitylimit ) {
|
||||
// HACK: crude estimation for potential derail, will take place with velocity difference > 15 km/h adjusted for vehicle mass ratio
|
||||
WriteLog( "Bad driving: " + Name + " and " + othervehicle->Name + " collided with velocity " + to_string( velocitydifference, 0 ) + " km/h" );
|
||||
|
||||
if( velocitydifference > safevelocitylimit * ( TotalMass / othervehicle->TotalMass ) ) {
|
||||
derail( 5 );
|
||||
}
|
||||
if( velocitydifference > safevelocitylimit * ( othervehicle->TotalMass / TotalMass ) ) {
|
||||
othervehicle->derail( 5 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( velocitydifference > safevelocitylimit * ( TotalMass / othervehicle->TotalMass ) ) {
|
||||
derail( 5 );
|
||||
}
|
||||
if( velocitydifference > safevelocitylimit * ( othervehicle->TotalMass / TotalMass ) ) {
|
||||
othervehicle->derail( 5 );
|
||||
}
|
||||
}
|
||||
|
||||
// adjust velocity and acceleration of affected vehicles
|
||||
if( false == TestFlag( DamageFlag, dtrain_out ) ) {
|
||||
auto const accelerationchange{ ( velocity - V ) / dt };
|
||||
@@ -1191,8 +1193,8 @@ void TMoverParameters::CollisionDetect(int const End, double const dt)
|
||||
|
||||
void
|
||||
TMoverParameters::damage_coupler( int const End ) {
|
||||
if( SetFlag( DamageFlag, dtrain_coupling ) )
|
||||
EventFlag = true;
|
||||
if( SetFlag( DamageFlag, dtrain_coupling ) )
|
||||
EventFlag = true;
|
||||
|
||||
auto &coupler { Couplers[ End ] };
|
||||
|
||||
@@ -1201,8 +1203,6 @@ TMoverParameters::damage_coupler( int const End ) {
|
||||
AlarmChainFlag = true;
|
||||
}
|
||||
|
||||
// M7TMP: disable coupler breaking because consist cannot be teleported to starting place in one piece
|
||||
/*
|
||||
coupler.CouplingFlag = 0;
|
||||
|
||||
if( coupler.Connected != nullptr ) {
|
||||
@@ -1221,7 +1221,6 @@ TMoverParameters::damage_coupler( int const End ) {
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
WriteLog( "Bad driving: " + Name + " broke a coupler" );
|
||||
}
|
||||
@@ -4647,7 +4646,7 @@ double TMoverParameters::CouplerForce( int const End, double dt ) {
|
||||
coupler.stretch_duration += dt;
|
||||
// give coupler 1 sec of leeway to account for simulation glitches, before checking whether it breaks
|
||||
// (arbitrary) chance to break grows from 10-100% over 10 sec period
|
||||
if( ( coupler.stretch_duration > 1.f )
|
||||
if( Global.crash_damage && ( coupler.stretch_duration > 1.f )
|
||||
&& ( Random() < ( coupler.stretch_duration * 0.1f * dt ) ) ) {
|
||||
damage_coupler( End );
|
||||
}
|
||||
|
||||
@@ -533,6 +533,13 @@ debug_panel::render() {
|
||||
&GfxRenderer.settings.traction_debug );
|
||||
}
|
||||
render_section( "Camera", m_cameralines );
|
||||
if (m_input.vehicle && ImGui::CollapsingHeader(STR_C("Normal forces graph"))) {
|
||||
ImGui::Text("Normal acceleration: %.2f m/s^2", AccN_acc_graph.last_val);
|
||||
AccN_acc_graph.render();
|
||||
|
||||
ImGui::Text("Normal jerk: %.2f m/s^3", AccN_jerk_graph.last_val);
|
||||
AccN_jerk_graph.render();
|
||||
}
|
||||
render_section( "Gfx Renderer", m_rendererlines );
|
||||
// toggles
|
||||
ImGui::Separator();
|
||||
@@ -673,13 +680,7 @@ debug_panel::update_section_vehicle( std::vector<text_line> &Output ) {
|
||||
textline += m_buffer.data();
|
||||
}
|
||||
|
||||
Output.emplace_back( textline, Global.UITextColor );
|
||||
|
||||
if( tprev != simulation::Time.data().wSecond ) {
|
||||
tprev = simulation::Time.data().wSecond;
|
||||
Acc = ( mover.Vel - VelPrev ) / 3.6;
|
||||
VelPrev = mover.Vel;
|
||||
}
|
||||
Output.emplace_back( textline, Global.UITextColor );
|
||||
|
||||
std::snprintf(
|
||||
m_buffer.data(), m_buffer.size(),
|
||||
@@ -690,8 +691,8 @@ debug_panel::update_section_vehicle( std::vector<text_line> &Output ) {
|
||||
mover.Adhesive( mover.RunningTrack.friction ),
|
||||
( mover.SlippingWheels ? " (!)" : "" ),
|
||||
// acceleration
|
||||
Acc,
|
||||
mover.AccN + 0.001f,
|
||||
mover.AccSVBased,
|
||||
mover.AccN,
|
||||
std::string( std::abs( mover.RunningShape.R ) > 10000.0 ? "~0" : to_string( mover.RunningShape.R, 0 ) ).c_str(),
|
||||
// velocity
|
||||
vehicle.GetVelocity(),
|
||||
@@ -703,6 +704,31 @@ debug_panel::update_section_vehicle( std::vector<text_line> &Output ) {
|
||||
|
||||
Output.emplace_back( m_buffer.data(), Global.UITextColor );
|
||||
|
||||
if (!std::isnan(last_time)) {
|
||||
double dt = Timer::GetTime() - last_time;
|
||||
AccN_jerk_graph.update((mover.AccN - last_AccN) / dt);
|
||||
AccN_acc_graph.update(mover.AccN);
|
||||
}
|
||||
|
||||
last_AccN = 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(), data.size(), pos, nullptr, 0.0f, range, ImVec2(0, 100));
|
||||
ImGui::PopID();
|
||||
}
|
||||
|
||||
std::string
|
||||
|
||||
@@ -106,9 +106,23 @@ private:
|
||||
m_eventqueuelines,
|
||||
m_powergridlines,
|
||||
m_rendererlines;
|
||||
int tprev { 0 }; // poprzedni czas
|
||||
double VelPrev { 0.0 }; // poprzednia prędkość
|
||||
double Acc { 0.0 }; // przyspieszenie styczne
|
||||
|
||||
double last_time = std::numeric_limits<double>::quiet_NaN();
|
||||
|
||||
struct graph_data
|
||||
{
|
||||
double last_val = 0.0;
|
||||
std::array<float, 150> data = { 0.0f };
|
||||
size_t pos = 0;
|
||||
float range = 25.0f;
|
||||
|
||||
void update(float data);
|
||||
void render();
|
||||
};
|
||||
graph_data AccN_jerk_graph;
|
||||
graph_data AccN_acc_graph;
|
||||
float last_AccN;
|
||||
|
||||
bool m_eventqueueactivevehicleonly { false };
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user