16
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-07-24 03:09:18 +02:00

ai acceleration logic tweak, minor audio tweaks, minor bug fixes

This commit is contained in:
tmj-fstate
2019-11-27 23:55:08 +01:00
parent e3cc06af23
commit fa42655808
12 changed files with 122 additions and 63 deletions

View File

@@ -2194,6 +2194,14 @@ bool TController::CheckVehicles(TOrders user)
p = p->Next(); // pojazd podłączony od tyłu (licząc od czoła)
}
if( ( user == Connect ) && ( true == main ) ) {
// HACK: with additional vehicles in the consist ensure all linked vehicles are set to move in the same direction
if( ( pVehicle->PrevC( coupling::control ) != nullptr )
|| ( pVehicle->NextC( coupling::control ) != nullptr ) ) {
sync_consist_reversers();
}
}
if (AIControllFlag)
{ // jeśli prowadzi komputer
if( true == TestFlag( OrderCurrentGet(), Obey_train ) ) {
@@ -2248,6 +2256,14 @@ bool TController::CheckVehicles(TOrders user)
AutoRewident();
// enable door locks
mvOccupied->LockDoors( true );
// enable train heating
// HACK: to account for su-45/-46 shortcomings diesel-powered engines only activate heating in cold conditions
// TODO: take instead into account presence of converters in attached cars, once said presence is possible to specify
mvControlling->HeatingAllow = (
IsCargoTrain ? false :
( ( mvControlling->EngineType == TEngineType::DieselElectric )
|| ( mvControlling->EngineType == TEngineType::DieselEngine ) ) ? ( Global.AirTemperature < 10 ) :
true );
}
}
else { // gdy człowiek i gdy nastąpiło połącznie albo rozłączenie
@@ -2597,14 +2613,6 @@ bool TController::PrepareEngine()
if( lookup != brakepositions.end() ) {
BrakeLevelSet( lookup->second ); // GBH
}
// enable train heating
// HACK: to account for su-45/-46 shortcomings diesel-powered engines only activate heating in cold conditions
// TODO: take instead into account presence of converters in attached cars, once said presence is possible to specify
mvControlling->HeatingAllow = (
( ( mvControlling->EngineType == TEngineType::DieselElectric )
|| ( mvControlling->EngineType == TEngineType::DieselEngine ) ) ?
( Global.AirTemperature < 10 ) :
true );
}
}
else
@@ -3213,7 +3221,7 @@ bool TController::IncSpeed()
}
break;
}
else
else {
if( true == Ready ) {
if( ( mvControlling->Vel > mvControlling->dizel_minVelfullengage )
&& ( mvControlling->RList[ mvControlling->MainCtrlPos ].Mn > 0 ) ) {
@@ -3223,6 +3231,7 @@ bool TController::IncSpeed()
OK = mvControlling->IncMainCtrl( 1 );
}
}
}
if( false == mvControlling->Mains ) {
SpeedCntrl(0.0);
mvControlling->MainSwitch( true );
@@ -4464,9 +4473,14 @@ TController::UpdateSituation(double dt) {
if (bp < 0) bp = 0;
if (Ready) {
// bo jak coś nie odhamowane, to dalej nie ma co sprawdzać
if( bp >= (
vehicle->EngineType == TEngineType::ElectricSeriesMotor ? 0.4 : // motor relay activation threshold
mvOccupied->Vel > 5.0 ? 0.5 : // a bit of leeway if already in motion
0.4 ) ) {
Ready = false;
}
if (bp >= 0.4) // wg UIC określone sztywno na 0.04
{
Ready = false; // nie gotowy
// Ra: odluźnianie przeładowanych lokomotyw, ciągniętych na zimno - prowizorka...
if (AIControllFlag) // skład jak dotąd był wyluzowany
{
@@ -6975,6 +6989,40 @@ void TController::ZeroDirection() {
while( ( mvOccupied->ActiveDir < 0 ) && ( mvOccupied->DirectionForward() ) ) { ; }
}
void TController::sync_consist_reversers() {
auto const currentdirection { mvOccupied->ActiveDir };
auto const fastforward { (
( mvOccupied->TrainType == dt_EZT )
&& ( mvOccupied->EngineType != TEngineType::ElectricInductionMotor ) )
&& ( mvOccupied->Imin == mvOccupied->IminHi ) };
// move reverser all way in the opposite direction...
for( auto idx = 0; idx < 3; ++idx ) {
if( currentdirection >= 0 ) {
mvOccupied->DirectionBackward();
}
else {
mvOccupied->DirectionForward();
}
}
// ...then restore original setting
while( mvOccupied->ActiveDir != currentdirection ) {
if( false == (
currentdirection >= 0 ?
mvOccupied->DirectionForward() :
mvOccupied->DirectionBackward() ) ) {
// sanity check for potential endless loop
break;
}
}
// potentially restore 'fast forward' setting
if( ( currentdirection > 0 ) && ( true == fastforward ) ) {
mvOccupied->DirectionForward();
}
}
Mtable::TTrainParameters const &
TController::TrainTimetable() const {
return TrainParams;

View File

@@ -249,6 +249,7 @@ private:
void DirectionForward(bool forward);
void ZeroDirection();
int OrderDirectionChange(int newdir, TMoverParameters *Vehicle);
void sync_consist_reversers();
void Lights(int head, int rear);
std::string StopReasonText() const;
double BrakeAccFactor() const;

View File

@@ -2719,7 +2719,6 @@ bool TDynamicObject::Update(double dt, double dt1)
if( ts.R != 0.0 ) {
// sin(0) results in division by zero
// ts.R=fabs(0.5*MoverParameters->BDist/sin(ts.R*0.5));
ts.R = -0.5 * MoverParameters->BDist / sin( ts.R * 0.5 );
}
}
@@ -5284,7 +5283,7 @@ void TDynamicObject::LoadMMediaFile( std::string const &TypeName, std::string co
else if( token == "departuresignal:" ) {
// pliki z sygnalem odjazdu
sound_source soundtemplate { sound_placement::general, 25.f };
sound_source soundtemplate { sound_placement::general };
soundtemplate.deserialize( parser, sound_type::multipart, sound_parameters::range );
soundtemplate.owner( this );
for( auto &departuresignalsound : m_departuresignalsounds ) {
@@ -5296,7 +5295,7 @@ void TDynamicObject::LoadMMediaFile( std::string const &TypeName, std::string co
}
else if( token == "dooropen:" ) {
sound_source soundtemplate { sound_placement::general, 25.f };
sound_source soundtemplate { sound_placement::general };
soundtemplate.deserialize( parser, sound_type::single );
soundtemplate.owner( this );
for( auto &door : m_doorsounds ) {
@@ -5308,7 +5307,7 @@ void TDynamicObject::LoadMMediaFile( std::string const &TypeName, std::string co
}
else if( token == "doorclose:" ) {
sound_source soundtemplate { sound_placement::general, 25.f };
sound_source soundtemplate { sound_placement::general };
soundtemplate.deserialize( parser, sound_type::single );
soundtemplate.owner( this );
for( auto &door : m_doorsounds ) {
@@ -5320,7 +5319,7 @@ void TDynamicObject::LoadMMediaFile( std::string const &TypeName, std::string co
}
else if( token == "doorlock:" ) {
sound_source soundtemplate { sound_placement::general, 12.5f };
sound_source soundtemplate { sound_placement::general };
soundtemplate.deserialize( parser, sound_type::single );
soundtemplate.owner( this );
for( auto &door : m_doorsounds ) {
@@ -5332,7 +5331,7 @@ void TDynamicObject::LoadMMediaFile( std::string const &TypeName, std::string co
}
else if( token == "doorunlock:" ) {
sound_source soundtemplate { sound_placement::general, 12.5f };
sound_source soundtemplate { sound_placement::general };
soundtemplate.deserialize( parser, sound_type::single );
soundtemplate.owner( this );
for( auto &door : m_doorsounds ) {
@@ -5344,7 +5343,7 @@ void TDynamicObject::LoadMMediaFile( std::string const &TypeName, std::string co
}
else if( token == "doorstepopen:" ) {
sound_source soundtemplate { sound_placement::general, 20.f };
sound_source soundtemplate { sound_placement::general };
soundtemplate.deserialize( parser, sound_type::single );
soundtemplate.owner( this );
for( auto &door : m_doorsounds ) {
@@ -5356,7 +5355,7 @@ void TDynamicObject::LoadMMediaFile( std::string const &TypeName, std::string co
}
else if( token == "doorstepclose:" ) {
sound_source soundtemplate { sound_placement::general, 20.f };
sound_source soundtemplate { sound_placement::general };
soundtemplate.deserialize( parser, sound_type::single );
soundtemplate.owner( this );
for( auto &door : m_doorsounds ) {

View File

@@ -1543,7 +1543,7 @@ public:
bool RunCommand( std::string Command, double CValue1, double CValue2, int const Couplertype = ctrain_controll );
bool RunInternalCommand();
void PutCommand(std::string NewCommand, double NewValue1, double NewValue2, const TLocation &NewLocation);
bool CabActivisation(void);
bool CabActivisation( bool const Force = false );
bool CabDeactivisation( bool const Force = false );
/*! funkcje zwiekszajace/zmniejszajace nastawniki*/

View File

@@ -2336,11 +2336,11 @@ bool TMoverParameters::DecScndCtrl(int CtrlSpeed)
// Q: 20160710
// załączenie rozrządu
// *************************************************************************************************
bool TMoverParameters::CabActivisation(void)
bool TMoverParameters::CabActivisation( bool const Force )
{
bool OK = false;
OK = (CabNo == 0); // numer kabiny, z której jest sterowanie
OK = Force || (CabNo == 0); // numer kabiny, z której jest sterowanie
if (OK)
{
CabNo = ActiveCab; // sterowanie jest z kabiny z obsadą
@@ -4412,9 +4412,16 @@ void TMoverParameters::ComputeConstans(void)
FrictConst1 += Cx * dragarea;
}
Curvature = abs(RunningShape.R); // zero oznacza nieskończony promień
if (Curvature > 0.0)
Curvature = 1.0 / Curvature;
if( CategoryFlag & 1 ) {
Curvature = (
RunningShape.R == 0.0 ? // zero oznacza nieskończony promień
0.0 :
1.0 / std::abs( RunningShape.R ) );
}
else {
// vehicles other than trains don't experience friction against the rail on curves
Curvature = 0.0;
}
// opór składu na łuku (youBy): +(500*TrackW/R)*TotalMassxg*0.001 do FrictConst2s/d
FrictConst2s = (TotalMassxg * ((500.0 * TrackW * Curvature) + 2.5 - HideModifier +
2 * BearingF / dtrain_bearing)) *
@@ -5082,7 +5089,7 @@ double TMoverParameters::TractionForce( double dt ) {
switch( EngineType ) {
case TEngineType::Dumb: {
PosRatio = ( MainCtrlPos + ScndCtrlPos ) / ( MainCtrlPosNo + ScndCtrlPosNo + 0.01 );
EnginePower = 1000.0 * Power * PosRatio;
EnginePower = /*1000.0 **/ Power * PosRatio;
break;
}
case TEngineType::DieselEngine: {
@@ -5154,14 +5161,16 @@ double TMoverParameters::TractionForce( double dt ) {
{
if (Vel > 0.1)
{
Ft = Min0R(1000.0 * Power / abs(V), Ftmax) * PosRatio;
Ft = std::min(1000.0 * Power / std::abs(V), Ftmax) * PosRatio;
}
else
else {
Ft = Ftmax * PosRatio;
}
Ft = Ft * DirAbsolute; // ActiveDir*CabNo;
}
else
else {
Ft = 0;
}
break;
} // Dumb

View File

@@ -19,10 +19,10 @@ void render_task::run() {
// convert provided input to a python dictionary
auto *input = PyDict_New();
if( input == nullptr ) { goto exit; }
for( auto const &datapair : m_input->floats ) { PyDict_SetItemString( input, datapair.first.c_str(), PyGetFloat( datapair.second ) ); }
for( auto const &datapair : m_input->integers ) { PyDict_SetItemString( input, datapair.first.c_str(), PyGetInt( datapair.second ) ); }
for( auto const &datapair : m_input->bools ) { PyDict_SetItemString( input, datapair.first.c_str(), PyGetBool( datapair.second ) ); }
for( auto const &datapair : m_input->strings ) { PyDict_SetItemString( input, datapair.first.c_str(), PyGetString( datapair.second.c_str() ) ); }
for( auto const &datapair : m_input->floats ) { auto *value{ PyGetFloat( datapair.second ) }; PyDict_SetItemString( input, datapair.first.c_str(), value ); Py_DECREF( value ); }
for( auto const &datapair : m_input->integers ) { auto *value{ PyGetInt( datapair.second ) }; PyDict_SetItemString( input, datapair.first.c_str(), value ); Py_DECREF( value ); }
for( auto const &datapair : m_input->bools ) { auto *value{ PyGetBool( datapair.second ) }; PyDict_SetItemString( input, datapair.first.c_str(), value ); }
for( auto const &datapair : m_input->strings ) { auto *value{ PyGetString( datapair.second.c_str() ) }; PyDict_SetItemString( input, datapair.first.c_str(), value ); Py_DECREF( value ); }
// call the renderer
auto *output { PyObject_CallMethod( m_renderer, "render", "O", input ) };

View File

@@ -460,9 +460,9 @@ bool TTrain::Init(TDynamicObject *NewDynamicObject, bool e3d)
fMainRelayTimer = 0; // Hunter, do k...y nędzy, ustawiaj wartości początkowe zmiennych!
iCabn = (
mvOccupied->ActiveCab < 0 ? 0 :
mvOccupied->ActiveCab > 0 ? 1 :
2 );
mvOccupied->ActiveCab < 0 ? 2 :
0 );
{
Global.CurrentMaxTextureSize = Global.iMaxCabTextureSize;
@@ -474,6 +474,7 @@ bool TTrain::Init(TDynamicObject *NewDynamicObject, bool e3d)
}
// Ra: taka proteza - przesłanie kierunku do członów connected
/*
if (mvControlled->ActiveDir > 0)
{ // było do przodu
mvControlled->DirectionBackward();
@@ -484,6 +485,11 @@ bool TTrain::Init(TDynamicObject *NewDynamicObject, bool e3d)
mvControlled->DirectionForward();
mvControlled->DirectionBackward();
}
*/
if( false == DynamicObject->Mechanik->AIControllFlag ) {
DynamicObject->Mechanik->sync_consist_reversers();
}
return true;
}

View File

@@ -292,6 +292,7 @@ openal_renderer::init() {
return false;
}
::alDistanceModel( AL_INVERSE_DISTANCE_CLAMPED );
::alDopplerFactor( 0.25f );
// all done
m_ready = true;
return true;
@@ -345,20 +346,11 @@ openal_renderer::update( double const Deltatime ) {
glm::vec3() );
*/
auto cameramove{ glm::dvec3{ Global.pCamera.Pos - m_camerapos} };
m_camerapos = Global.pCamera.Pos;
// intercept sudden user-induced camera jumps...
// ...from free fly mode change
if( m_freeflymode != FreeFlyModeFlag ) {
m_freeflymode = FreeFlyModeFlag;
if( true == m_freeflymode ) {
// cache last precipitation vector in the cab
m_cabcameramove = m_cameramove;
// don't carry previous precipitation vector to a new unrelated location
m_cameramove = glm::dvec3{ 0.0 };
}
else {
// restore last cached precipitation vector
m_cameramove = m_cabcameramove;
}
cameramove = glm::dvec3{ 0.0 };
}
// ...from jump between cab and window/mirror view

View File

@@ -152,8 +152,6 @@ private:
*/
glm::vec3 m_listenervelocity;
glm::dvec3 m_camerapos{ 0.0 };
glm::dvec3 m_cameramove{ 0.0 };
glm::dvec3 m_cabcameramove{ 0.0 };
bool m_freeflymode{ true };
bool m_windowopen{ true };
int m_activecab{ 0 };

View File

@@ -791,8 +791,9 @@ driver_mode::OnKeyDown(int cKey) {
}
simulation::Train->Dynamic()->Mechanik->TakeControl( false, true );
if( true == simulation::Train->Dynamic()->Mechanik->primary() ) {
simulation::Train->Dynamic()->MoverParameters->CabDeactivisation( true ); // potentially left active
simulation::Train->Dynamic()->MoverParameters->CabActivisation();
simulation::Train->Occupied()->CabDeactivisation( true ); // potentially left active
// simulation::Train->Occupied()->ActiveCab = simulation::Train->Occupied()->CabNo;
simulation::Train->Occupied()->CabActivisation();
}
InOutKey(); // do kabiny
}
@@ -1168,7 +1169,8 @@ driver_mode::ChangeDynamic() {
if( false == driver->AIControllFlag ) // tylko jeśli ręcznie prowadzony
{
occupied->LimPipePress = occupied->PipePress;
occupied->CabActivisation(); // załączenie rozrządu (wirtualne kabiny)
occupied->ActiveCab = occupied->CabNo;
occupied->CabActivisation( true ); // załączenie rozrządu (wirtualne kabiny)
vehicle->MechInside = true;
vehicle->Controller = Humandriver;
}

View File

@@ -2789,9 +2789,8 @@ void opengl33_renderer::Render(TTrack *Track)
// single path pieces are rendererd in pick scenery mode only
case rendermode::pickscenery:
{
m_picksceneryitems.emplace_back(Track);
model_ubs.param[0] = glm::vec4(pick_color(m_picksceneryitems.size() + 1), 1.0f);
m_pick_shader->bind();
m_picksceneryitems.emplace_back( Track );
draw(std::begin(Track->Geometry1), std::end(Track->Geometry1));
draw(std::begin(Track->Geometry2), std::end(Track->Geometry2));

View File

@@ -886,7 +886,12 @@ sound_source::update_counter( sound_handle const Sound, int const Value ) {
ui::Transcripts.Add( buffer.caption );
}
}
assert( sound( Sound ).playing >= 0 );
// assert( sound( Sound ).playing >= 0 );
if( sound( Sound ).playing < 0 ) {
// HACK: counter can occassionally go into negative values
// TODO: investigate and fix
sound( Sound ).playing = 0;
}
}
void