mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-07-23 09:49:19 +02:00
electro-pneumatic brake operation ai logic tweak, pantograph compressor valve state commands, automatic material update switch, train lights state readout for python scripts, minor bug fixes
This commit is contained in:
22
Driver.cpp
22
Driver.cpp
@@ -2961,6 +2961,16 @@ bool TController::IncBrake()
|
||||
OK = IncBrakeEIM();
|
||||
}
|
||||
}
|
||||
else if( mvOccupied->Handle->TimeEP == false ) {
|
||||
auto const initialbrakeposition { mvOccupied->fBrakeCtrlPos };
|
||||
auto const AccMax { std::min( fBrake_a0[ 0 ] + 12 * fBrake_a1[ 0 ], mvOccupied->MED_amax ) };
|
||||
mvOccupied->BrakeLevelSet(
|
||||
interpolate(
|
||||
mvOccupied->Handle->GetPos( bh_EPR ),
|
||||
mvOccupied->Handle->GetPos( bh_EPB ),
|
||||
clamp( -AccDesired / AccMax * mvOccupied->AIHintLocalBrakeAccFactor, 0.0, 1.0 ) ) );
|
||||
OK = ( mvOccupied->fBrakeCtrlPos != initialbrakeposition );
|
||||
}
|
||||
else if( mvOccupied->fBrakeCtrlPos != mvOccupied->Handle->GetPos( bh_EPB ) ) {
|
||||
mvOccupied->BrakeLevelSet( mvOccupied->Handle->GetPos( bh_EPB ) );
|
||||
if( mvOccupied->Handle->GetPos( bh_EPR ) - mvOccupied->Handle->GetPos( bh_EPN ) < 0.1 )
|
||||
@@ -3076,6 +3086,16 @@ bool TController::DecBrake()
|
||||
OK = DecBrakeEIM();
|
||||
}
|
||||
}
|
||||
else if( mvOccupied->Handle->TimeEP == false ) {
|
||||
auto const initialbrakeposition { mvOccupied->fBrakeCtrlPos };
|
||||
auto const AccMax { std::min(fBrake_a0[ 0 ] + 12 * fBrake_a1[ 0 ], mvOccupied->MED_amax) };
|
||||
mvOccupied->BrakeLevelSet(
|
||||
interpolate(
|
||||
mvOccupied->Handle->GetPos( bh_EPR ),
|
||||
mvOccupied->Handle->GetPos( bh_EPB ),
|
||||
clamp( -AccDesired / AccMax * mvOccupied->AIHintLocalBrakeAccFactor, 0.0, 1.0 ) ) );
|
||||
OK = ( mvOccupied->fBrakeCtrlPos != initialbrakeposition );
|
||||
}
|
||||
else if (mvOccupied->fBrakeCtrlPos != mvOccupied->Handle->GetPos(bh_EPR))
|
||||
{
|
||||
mvOccupied->BrakeLevelSet(mvOccupied->Handle->GetPos(bh_EPR));
|
||||
@@ -3462,7 +3482,7 @@ bool TController::IncSpeedEIM() {
|
||||
bool OK = false; // domyślnie false, aby wyszło z pętli while
|
||||
switch( mvControlling->EIMCtrlType ) {
|
||||
case 0:
|
||||
OK = mvControlling->IncMainCtrl( std::max( 1, mvOccupied->MainCtrlPosNo / 10 ) );
|
||||
OK = mvControlling->IncMainCtrl( 1 );
|
||||
break;
|
||||
case 1:
|
||||
OK = mvControlling->MainCtrlPos < 6;
|
||||
|
||||
@@ -1442,7 +1442,7 @@ TDynamicObject::couple( int const Side ) {
|
||||
auto const &coupler { MoverParameters->Couplers[ Side ] };
|
||||
auto *othervehicle { neighbour.vehicle };
|
||||
auto *othervehicleparams{ othervehicle->MoverParameters };
|
||||
auto const &othercoupler { othervehicleparams->Couplers[ Side ] };
|
||||
auto const &othercoupler { othervehicleparams->Couplers[ neighbour.vehicle_end ] };
|
||||
|
||||
if( coupler.CouplingFlag == coupling::faux ) {
|
||||
// najpierw hak
|
||||
|
||||
@@ -57,6 +57,7 @@ struct global_settings {
|
||||
std::string asCurrentDynamicPath;
|
||||
int CurrentMaxTextureSize{ 4096 };
|
||||
bool GfxFramebufferSRGB { true };
|
||||
bool UpdateMaterials { true };
|
||||
// settings
|
||||
// filesystem
|
||||
bool bLoadTraction{ true };
|
||||
|
||||
@@ -345,7 +345,7 @@ struct TLocation
|
||||
double Y;
|
||||
double Z;
|
||||
};
|
||||
/*rotacja*/
|
||||
|
||||
struct TRotation
|
||||
{
|
||||
double Rx;
|
||||
@@ -1594,7 +1594,10 @@ public:
|
||||
bool DirectionBackward( void );/*! kierunek ruchu*/
|
||||
bool EIMDirectionChangeAllow( void ) const;
|
||||
inline double IsVehicleEIMBrakingFactor() {
|
||||
return eimv[ eimv_Ipoj ] < 0 ? -1.0 : 1.0; }
|
||||
return (
|
||||
( DynamicBrakeFlag && ResistorsFlag ) ? 0.0 :
|
||||
eimv[ eimv_Ipoj ] < 0 ? -1.0 :
|
||||
1.0 ); }
|
||||
void BrakeLevelSet(double b);
|
||||
bool BrakeLevelAdd(double b);
|
||||
bool IncBrakeLevel(); // wersja na użytek AI
|
||||
|
||||
@@ -4240,8 +4240,12 @@ void TMoverParameters::UpdatePipePressure(double dt)
|
||||
temp = Handle->GetCP();
|
||||
else
|
||||
temp = 0.0;
|
||||
if (temp < 0.001)
|
||||
DynamicBrakeEMUStatus = true;
|
||||
|
||||
DynamicBrakeEMUStatus = (
|
||||
temp > 0.001 ?
|
||||
ConverterFlag :
|
||||
true );
|
||||
|
||||
double temp1 = temp;
|
||||
if ((DCEMUED_EP_max_Vel > 0.001) && (Vel > DCEMUED_EP_max_Vel) && (DynamicBrakeEMUStatus))
|
||||
temp1 = 0;
|
||||
@@ -8063,8 +8067,9 @@ TMoverParameters::update_doors( double const Deltatime ) {
|
||||
// revoke permit if...
|
||||
door.open_permit =
|
||||
( true == door.open_permit ) // ...we already have one...
|
||||
&& ( false == Doors.is_locked ) // ...and the door lock is engaged...
|
||||
&& ( false == door.remote_close );// ...or about to be closed
|
||||
&& ( ( false == Doors.permit_presets.empty() ) // ...there's no preset switch controlling permit state...
|
||||
|| ( ( false == Doors.is_locked ) // ...and the door lock is engaged...
|
||||
&& ( false == door.remote_close ) ) );// ...or the door is about to be closed
|
||||
|
||||
door.is_open =
|
||||
( door.position >= Doors.range )
|
||||
|
||||
106
Train.cpp
106
Train.cpp
@@ -239,6 +239,8 @@ TTrain::commandhandler_map const TTrain::m_commandhandlers = {
|
||||
{ user_command::batteryenable, &TTrain::OnCommand_batteryenable },
|
||||
{ user_command::batterydisable, &TTrain::OnCommand_batterydisable },
|
||||
{ user_command::pantographcompressorvalvetoggle, &TTrain::OnCommand_pantographcompressorvalvetoggle },
|
||||
{ user_command::pantographcompressorvalveenable, &TTrain::OnCommand_pantographcompressorvalveenable },
|
||||
{ user_command::pantographcompressorvalvedisable, &TTrain::OnCommand_pantographcompressorvalvedisable },
|
||||
{ user_command::pantographcompressoractivate, &TTrain::OnCommand_pantographcompressoractivate },
|
||||
{ user_command::pantographtogglefront, &TTrain::OnCommand_pantographtogglefront },
|
||||
{ user_command::pantographtogglerear, &TTrain::OnCommand_pantographtogglerear },
|
||||
@@ -496,13 +498,20 @@ bool TTrain::Init(TDynamicObject *NewDynamicObject, bool e3d)
|
||||
|
||||
{
|
||||
Global.CurrentMaxTextureSize = Global.iMaxCabTextureSize;
|
||||
auto const result{ LoadMMediaFile( DynamicObject->asBaseDir + DynamicObject->MoverParameters->TypeName + ".mmd" ) };
|
||||
auto const filename{ DynamicObject->asBaseDir + DynamicObject->MoverParameters->TypeName + ".mmd" };
|
||||
auto const result { LoadMMediaFile( filename ) };
|
||||
Global.CurrentMaxTextureSize = Global.iMaxTextureSize;
|
||||
/*
|
||||
if( false == result ) {
|
||||
return false;
|
||||
}
|
||||
*/
|
||||
InitializeCab( mvOccupied->CabOccupied, filename );
|
||||
|
||||
if( DynamicObject->Controller == Humandriver ) {
|
||||
// McZapkie-030303: mozliwosc wyswietlania kabiny, w przyszlosci dac opcje w mmd
|
||||
DynamicObject->bDisplayCab = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Ra: taka proteza - przesłanie kierunku do członów connected
|
||||
@@ -547,6 +556,24 @@ dictionary_source *TTrain::GetTrainState() {
|
||||
dict->insert( "lights_front", mvOccupied->iLights[ end::front ] );
|
||||
dict->insert( "lights_rear", mvOccupied->iLights[ end::rear ] );
|
||||
dict->insert( "lights_compartments", mvOccupied->CompartmentLights.is_active || mvOccupied->CompartmentLights.is_disabled );
|
||||
if( Dynamic()->Mechanik ) {
|
||||
auto const *controller { Dynamic()->Mechanik };
|
||||
auto const cabmodifier { cab_to_end() == end::front ? 1 : -1 };
|
||||
auto const traindirection { controller->Direction() * cabmodifier };
|
||||
auto const *frontvehicle { controller->Vehicle( traindirection >= 0 ? end::front : end::rear ) };
|
||||
auto const *rearvehicle { controller->Vehicle( traindirection >= 0 ? end::rear : end::front ) };
|
||||
auto const frontvehicledirection { ( frontvehicle->DirectionGet() == controller->Vehicle()->DirectionGet() ? 1 : -1 ) };
|
||||
auto const rearvehicledirection { ( rearvehicle->DirectionGet() == controller->Vehicle()->DirectionGet() ? 1 : -1 ) };
|
||||
auto const fronttrainlights { frontvehicle->MoverParameters->iLights[ frontvehicledirection * cabmodifier >= 0 ? end::front : end::rear ] };
|
||||
auto const reartrainlights{ rearvehicle->MoverParameters->iLights[ rearvehicledirection * cabmodifier >= 0 ? end::rear : end::front ] };
|
||||
dict->insert( "lights_train_front", fronttrainlights );
|
||||
dict->insert( "lights_train_rear", reartrainlights );
|
||||
}
|
||||
else {
|
||||
// fallback, in the unlikely case we lose the controller
|
||||
dict->insert( "lights_train_front", mvOccupied->iLights[ end::front ] );
|
||||
dict->insert( "lights_train_rear", mvOccupied->iLights[ end::rear ] );
|
||||
}
|
||||
// reverser
|
||||
dict->insert( "direction", mvOccupied->DirActive );
|
||||
// throttle
|
||||
@@ -2112,7 +2139,7 @@ void TTrain::OnCommand_pantographtogglefront( TTrain *Train, command_data const
|
||||
auto const &pantograph { Train->mvControlled->Pantographs[ end::front ] };
|
||||
auto const state {
|
||||
pantograph.valve.is_enabled
|
||||
| pantograph.is_active }; // fallback for impulse switches
|
||||
|| pantograph.is_active }; // fallback for impulse switches
|
||||
if( state ) {
|
||||
OnCommand_pantographlowerfront( Train, Command );
|
||||
}
|
||||
@@ -2138,7 +2165,7 @@ void TTrain::OnCommand_pantographtogglerear( TTrain *Train, command_data const &
|
||||
auto const &pantograph { Train->mvControlled->Pantographs[ end::rear ] };
|
||||
auto const state {
|
||||
pantograph.valve.is_enabled
|
||||
| pantograph.is_active }; // fallback for impulse switches
|
||||
|| pantograph.is_active }; // fallback for impulse switches
|
||||
if( state ) {
|
||||
OnCommand_pantographlowerrear( Train, Command );
|
||||
}
|
||||
@@ -2403,31 +2430,58 @@ void TTrain::change_pantograph_selection( int const Change ) {
|
||||
|
||||
void TTrain::OnCommand_pantographcompressorvalvetoggle( TTrain *Train, command_data const &Command ) {
|
||||
|
||||
if( Command.action == GLFW_PRESS ) {
|
||||
// only react to press
|
||||
if( Train->mvControlled->bPantKurek3 == false ) {
|
||||
// connect pantographs with primary tank
|
||||
OnCommand_pantographcompressorvalveenable( Train, Command );
|
||||
}
|
||||
else {
|
||||
// connect pantograps with pantograph compressor
|
||||
OnCommand_pantographcompressorvalvedisable( Train, Command );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TTrain::OnCommand_pantographcompressorvalveenable( TTrain *Train, command_data const &Command ) {
|
||||
|
||||
auto const valveispresent {
|
||||
( Train->ggPantCompressorValve.SubModel != nullptr )
|
||||
|| ( ( Train->iCabn == 0 )
|
||||
&& ( Train->mvControlled == Train->mvOccupied ) ) };
|
||||
|
||||
if( false == valveispresent )
|
||||
{
|
||||
if( false == valveispresent ) {
|
||||
// tylko w maszynowym, unless actual device is present
|
||||
return;
|
||||
}
|
||||
|
||||
if( Command.action == GLFW_PRESS ) {
|
||||
// only react to press
|
||||
if( Train->mvControlled->bPantKurek3 == false ) {
|
||||
// connect pantographs with primary tank
|
||||
Train->mvControlled->bPantKurek3 = true;
|
||||
// visual feedback:
|
||||
Train->ggPantCompressorValve.UpdateValue( 0.0 );
|
||||
}
|
||||
else {
|
||||
// connect pantograps with pantograph compressor
|
||||
Train->mvControlled->bPantKurek3 = false;
|
||||
// visual feedback:
|
||||
Train->ggPantCompressorValve.UpdateValue( 1.0 );
|
||||
}
|
||||
// connect pantographs with primary tank
|
||||
Train->mvControlled->bPantKurek3 = true;
|
||||
// visual feedback:
|
||||
Train->ggPantCompressorValve.UpdateValue( 0.0 );
|
||||
}
|
||||
}
|
||||
|
||||
void TTrain::OnCommand_pantographcompressorvalvedisable( TTrain *Train, command_data const &Command ) {
|
||||
|
||||
auto const valveispresent {
|
||||
( Train->ggPantCompressorValve.SubModel != nullptr )
|
||||
|| ( ( Train->iCabn == 0 )
|
||||
&& ( Train->mvControlled == Train->mvOccupied ) ) };
|
||||
|
||||
if( false == valveispresent ) {
|
||||
// tylko w maszynowym, unless actual device is present
|
||||
return;
|
||||
}
|
||||
|
||||
if( Command.action == GLFW_PRESS ) {
|
||||
// only react to press
|
||||
// connect pantograps with pantograph compressor
|
||||
Train->mvControlled->bPantKurek3 = false;
|
||||
// visual feedback:
|
||||
Train->ggPantCompressorValve.UpdateValue( 1.0 );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7594,25 +7648,13 @@ bool TTrain::LoadMMediaFile(std::string const &asFileName)
|
||||
|
||||
} while (token != "");
|
||||
}
|
||||
/*
|
||||
else
|
||||
{
|
||||
return false;
|
||||
} // nie znalazl sekcji internal
|
||||
|
||||
if (!InitializeCab(mvOccupied->CabOccupied, asFileName))
|
||||
{
|
||||
// zle zainicjowana kabina
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (DynamicObject->Controller == Humandriver)
|
||||
{
|
||||
// McZapkie-030303: mozliwosc wyswietlania kabiny, w przyszlosci dac opcje w mmd
|
||||
DynamicObject->bDisplayCab = true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
*/
|
||||
return true;
|
||||
}
|
||||
|
||||
bool TTrain::InitializeCab(int NewCabNo, std::string const &asFileName)
|
||||
|
||||
2
Train.h
2
Train.h
@@ -262,6 +262,8 @@ class TTrain {
|
||||
static void OnCommand_batteryenable( TTrain *Train, command_data const &Command );
|
||||
static void OnCommand_batterydisable( TTrain *Train, command_data const &Command );
|
||||
static void OnCommand_pantographcompressorvalvetoggle( TTrain *Train, command_data const &Command );
|
||||
static void OnCommand_pantographcompressorvalveenable( TTrain *Train, command_data const &Command );
|
||||
static void OnCommand_pantographcompressorvalvedisable( TTrain *Train, command_data const &Command );
|
||||
static void OnCommand_pantographcompressoractivate( TTrain *Train, command_data const &Command );
|
||||
static void OnCommand_pantographtogglefront( TTrain *Train, command_data const &Command );
|
||||
static void OnCommand_pantographtogglerear( TTrain *Train, command_data const &Command );
|
||||
|
||||
@@ -177,6 +177,8 @@ commanddescription_sequence Commands_descriptions = {
|
||||
{ "departureannounce", command_target::vehicle },
|
||||
{ "doorlocktoggle", command_target::vehicle },
|
||||
{ "pantographcompressorvalvetoggle", command_target::vehicle },
|
||||
{ "pantographcompressorvalveenable", command_target::vehicle },
|
||||
{ "pantographcompressorvalvedisable", command_target::vehicle },
|
||||
{ "pantographcompressoractivate", command_target::vehicle },
|
||||
{ "pantographtogglefront", command_target::vehicle },
|
||||
{ "pantographtogglerear", command_target::vehicle },
|
||||
|
||||
@@ -168,6 +168,8 @@ enum class user_command {
|
||||
departureannounce,
|
||||
doorlocktoggle,
|
||||
pantographcompressorvalvetoggle,
|
||||
pantographcompressorvalveenable,
|
||||
pantographcompressorvalvedisable,
|
||||
pantographcompressoractivate,
|
||||
pantographtogglefront,
|
||||
pantographtogglerear,
|
||||
|
||||
@@ -177,6 +177,8 @@ driverkeyboard_input::default_bindings() {
|
||||
{ user_command::departureannounce, GLFW_KEY_SLASH },
|
||||
{ user_command::doorlocktoggle, GLFW_KEY_S | keymodifier::control },
|
||||
{ user_command::pantographcompressorvalvetoggle, GLFW_KEY_V | keymodifier::control },
|
||||
// pantographcompressorvalveenable,
|
||||
// pantographcompressorvalvedisable,
|
||||
{ user_command::pantographcompressoractivate, GLFW_KEY_V | keymodifier::shift },
|
||||
{ user_command::pantographtogglefront, GLFW_KEY_P },
|
||||
{ user_command::pantographtogglerear, GLFW_KEY_O },
|
||||
|
||||
@@ -625,6 +625,7 @@ debug_panel::render_section_scenario() {
|
||||
GLFW_PRESS, 0 );
|
||||
}
|
||||
}
|
||||
ImGui::Checkbox( "Update Item Materials", &Global.UpdateMaterials );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -4034,17 +4034,19 @@ void opengl33_renderer::Update(double const Deltatime)
|
||||
}
|
||||
}
|
||||
|
||||
// update resources if there was environmental change
|
||||
simulation_state simulationstate {
|
||||
Global.Weather,
|
||||
Global.Season
|
||||
};
|
||||
std::swap( m_simulationstate, simulationstate );
|
||||
if( ( m_simulationstate.season != simulationstate.season ) && ( false == simulationstate.season.empty() ) ) {
|
||||
m_materials.on_season_change();
|
||||
}
|
||||
if( ( m_simulationstate.weather != simulationstate.weather ) && ( false == simulationstate.weather.empty() ) ) {
|
||||
m_materials.on_weather_change();
|
||||
if( Global.UpdateMaterials ) {
|
||||
// update resources if there was environmental change
|
||||
simulation_state simulationstate {
|
||||
Global.Weather,
|
||||
Global.Season
|
||||
};
|
||||
std::swap( m_simulationstate, simulationstate );
|
||||
if( ( m_simulationstate.season != simulationstate.season ) && ( false == simulationstate.season.empty() ) ) {
|
||||
m_materials.on_season_change();
|
||||
}
|
||||
if( ( m_simulationstate.weather != simulationstate.weather ) && ( false == simulationstate.weather.empty() ) ) {
|
||||
m_materials.on_weather_change();
|
||||
}
|
||||
}
|
||||
|
||||
if ((true == Global.ResourceSweep) && (true == simulation::is_ready))
|
||||
|
||||
@@ -4078,17 +4078,19 @@ opengl_renderer::Update( double const Deltatime ) {
|
||||
}
|
||||
}
|
||||
|
||||
if( Global.UpdateMaterials ) {
|
||||
// update resources if there was environmental change
|
||||
simulation_state simulationstate {
|
||||
Global.Weather,
|
||||
Global.Season
|
||||
};
|
||||
std::swap( m_simulationstate, simulationstate );
|
||||
if( ( m_simulationstate.season != simulationstate.season ) && ( false == simulationstate.season.empty() ) ) {
|
||||
m_materials.on_season_change();
|
||||
}
|
||||
if( ( m_simulationstate.weather != simulationstate.weather ) && ( false == simulationstate.weather.empty() ) ) {
|
||||
m_materials.on_weather_change();
|
||||
simulation_state simulationstate{
|
||||
Global.Weather,
|
||||
Global.Season
|
||||
};
|
||||
std::swap( m_simulationstate, simulationstate );
|
||||
if( ( m_simulationstate.season != simulationstate.season ) && ( false == simulationstate.season.empty() ) ) {
|
||||
m_materials.on_season_change();
|
||||
}
|
||||
if( ( m_simulationstate.weather != simulationstate.weather ) && ( false == simulationstate.weather.empty() ) ) {
|
||||
m_materials.on_weather_change();
|
||||
}
|
||||
}
|
||||
|
||||
if( ( true == Global.ResourceSweep )
|
||||
|
||||
Reference in New Issue
Block a user