16
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-07-23 14:29:18 +02:00

build 190405. autonomous vehicle door mode, door permit cab control type support, random fog range, global light level driven vehicle interior lighting, ogg vorbis multichannel file decoding fix

This commit is contained in:
tmj-fstate
2019-04-06 22:25:12 +02:00
parent e99dc9a02c
commit b9807284fc
9 changed files with 119 additions and 69 deletions

View File

@@ -3585,13 +3585,14 @@ void TController::Doors( bool const Open, int const Side ) {
|| ( false == AIControllFlag ) ) ) { || ( false == AIControllFlag ) ) ) {
// ai doesn't close the door until it's free to depart, but human driver has free reign to do stupid things // ai doesn't close the door until it's free to depart, but human driver has free reign to do stupid things
if( ( pVehicle->MoverParameters->Doors.close_control == control_t::conductor ) if( ( pVehicle->MoverParameters->Doors.close_control == control_t::conductor )
|| ( ( true == AIControllFlag ) || ( ( true == AIControllFlag ) ) ) {
&& ( ( pVehicle->MoverParameters->Doors.close_control == control_t::driver )
|| ( pVehicle->MoverParameters->Doors.close_control == control_t::mixed ) ) ) ) {
// if the door are controlled by the driver, we let the user operate them unless this user is an ai // if the door are controlled by the driver, we let the user operate them unless this user is an ai
// the train conductor, if present, handles door operation also for human-driven trains // the train conductor, if present, handles door operation also for human-driven trains
if( ( pVehicle->MoverParameters->Doors.close_control == control_t::driver )
|| ( pVehicle->MoverParameters->Doors.close_control == control_t::mixed ) ) {
pVehicle->MoverParameters->OperateDoors( side::right, false ); pVehicle->MoverParameters->OperateDoors( side::right, false );
pVehicle->MoverParameters->OperateDoors( side::left, false ); pVehicle->MoverParameters->OperateDoors( side::left, false );
}
if( pVehicle->MoverParameters->Doors.permit_needed ) { if( pVehicle->MoverParameters->Doors.permit_needed ) {
pVehicle->MoverParameters->PermitDoors( side::right, false ); pVehicle->MoverParameters->PermitDoors( side::right, false );
pVehicle->MoverParameters->PermitDoors( side::left, false ); pVehicle->MoverParameters->PermitDoors( side::left, false );

View File

@@ -70,7 +70,6 @@ struct global_settings {
bool bLiveTraction{ true }; bool bLiveTraction{ true };
float Overcast{ 0.1f }; // NOTE: all this weather stuff should be moved elsewhere float Overcast{ 0.1f }; // NOTE: all this weather stuff should be moved elsewhere
glm::vec3 FogColor = { 0.6f, 0.7f, 0.8f }; glm::vec3 FogColor = { 0.6f, 0.7f, 0.8f };
double fFogStart{ 1700 };
double fFogEnd{ 2000 }; double fFogEnd{ 2000 };
std::string Season{}; // season of the year, based on simulation date std::string Season{}; // season of the year, based on simulation date
std::string Weather{ "cloudy:" }; // current weather std::string Weather{ "cloudy:" }; // current weather

View File

@@ -7071,9 +7071,14 @@ TMoverParameters::update_doors( double const Deltatime ) {
door.local_close = door.local_close && ( false == door.is_closed ); door.local_close = door.local_close && ( false == door.is_closed );
door.remote_close = door.remote_close && ( false == door.is_closed ); door.remote_close = door.remote_close && ( false == door.is_closed );
auto const autoopenrequest {
( Doors.open_control == control_t::autonomous )
&& ( ( false == Doors.permit_needed ) || door.open_permit )
};
auto const openrequest { auto const openrequest {
( localopencontrol && door.local_open ) ( localopencontrol && door.local_open )
|| ( remoteopencontrol && door.remote_open ) }; || ( remoteopencontrol && door.remote_open )
|| ( autoopenrequest && ( false == door.is_open ) ) };
auto const autocloserequest { auto const autocloserequest {
( ( Doors.auto_velocity != -1.f ) && ( Vel > Doors.auto_velocity ) ) ( ( Doors.auto_velocity != -1.f ) && ( Vel > Doors.auto_velocity ) )
@@ -8360,12 +8365,6 @@ void TMoverParameters::LoadFIZ_Doors( std::string const &line ) {
lookup != doorcontrols.end() ? lookup != doorcontrols.end() ?
lookup->second : lookup->second :
control_t::passenger; control_t::passenger;
if( Doors.close_control == control_t::autonomous ) {
// convert legacy method
Doors.close_control = control_t::passenger;
Doors.auto_velocity = 10.0;
}
} }
// automatic closing conditions // automatic closing conditions
extract_value( Doors.auto_duration, "DoorStayOpen", line, "" ); extract_value( Doors.auto_duration, "DoorStayOpen", line, "" );

View File

@@ -4289,39 +4289,75 @@ void TTrain::OnCommand_doortoggleleft( TTrain *Train, command_data const &Comman
void TTrain::OnCommand_doorpermitleft( TTrain *Train, command_data const &Command ) { void TTrain::OnCommand_doorpermitleft( TTrain *Train, command_data const &Command ) {
if( Command.action == GLFW_REPEAT ) { return; }
if( Command.action == GLFW_PRESS ) { if( Command.action == GLFW_PRESS ) {
Train->mvOccupied->PermitDoors( auto const side { (
( Train->mvOccupied->ActiveCab == 1 ? Train->mvOccupied->ActiveCab == 1 ?
side::left : side::left :
side::right ) ); side::right ) };
if( Train->ggDoorLeftPermitButton.type() == TGaugeType::push ) {
// impulse switch
Train->mvOccupied->PermitDoors( side );
// visual feedback // visual feedback
Train->ggDoorLeftPermitButton.UpdateValue( 1.0, Train->dsbSwitch ); Train->ggDoorLeftPermitButton.UpdateValue( 1.0, Train->dsbSwitch );
} }
else {
// two-state switch
auto const newstate { !( Train->mvOccupied->Doors.instances[ side ].open_permit ) };
Train->mvOccupied->PermitDoors( side, newstate );
// visual feedback
Train->ggDoorLeftPermitButton.UpdateValue( ( newstate ? 1.0 : 0.0 ), Train->dsbSwitch );
}
}
else if( Command.action == GLFW_RELEASE ) { else if( Command.action == GLFW_RELEASE ) {
if( Train->ggDoorLeftPermitButton.type() == TGaugeType::push ) {
// impulse switch
// visual feedback // visual feedback
Train->ggDoorLeftPermitButton.UpdateValue( 0.0, Train->dsbSwitch ); Train->ggDoorLeftPermitButton.UpdateValue( 0.0, Train->dsbSwitch );
} }
} }
}
void TTrain::OnCommand_doorpermitright( TTrain *Train, command_data const &Command ) { void TTrain::OnCommand_doorpermitright( TTrain *Train, command_data const &Command ) {
if( Command.action == GLFW_REPEAT ) { return; }
if( Command.action == GLFW_PRESS ) { if( Command.action == GLFW_PRESS ) {
Train->mvOccupied->PermitDoors( auto const side { (
( Train->mvOccupied->ActiveCab == 1 ? Train->mvOccupied->ActiveCab == 1 ?
side::right : side::right :
side::left ) ); side::left ) };
if( Train->ggDoorRightPermitButton.type() == TGaugeType::push ) {
// impulse switch
Train->mvOccupied->PermitDoors( side );
// visual feedback // visual feedback
Train->ggDoorRightPermitButton.UpdateValue( 1.0, Train->dsbSwitch ); Train->ggDoorRightPermitButton.UpdateValue( 1.0, Train->dsbSwitch );
} }
else {
// two-state switch
auto const newstate { !( Train->mvOccupied->Doors.instances[ side ].open_permit ) };
Train->mvOccupied->PermitDoors( side, newstate );
// visual feedback
Train->ggDoorRightPermitButton.UpdateValue( ( newstate ? 1.0 : 0.0 ), Train->dsbSwitch );
}
}
else if( Command.action == GLFW_RELEASE ) { else if( Command.action == GLFW_RELEASE ) {
if( Train->ggDoorRightPermitButton.type() == TGaugeType::push ) {
// impulse switch
// visual feedback // visual feedback
Train->ggDoorRightPermitButton.UpdateValue( 0.0, Train->dsbSwitch ); Train->ggDoorRightPermitButton.UpdateValue( 0.0, Train->dsbSwitch );
} }
} }
}
void TTrain::OnCommand_doorpermitpresetactivatenext( TTrain *Train, command_data const &Command ) { void TTrain::OnCommand_doorpermitpresetactivatenext( TTrain *Train, command_data const &Command ) {
@@ -7585,7 +7621,12 @@ void TTrain::set_cab_controls( int const Cab ) {
1.f : 1.f :
0.f ) ); 0.f ) );
// doors // doors
// NOTE: for the time being permit switches are presumed to be impulse switches if( ggDoorLeftPermitButton.type() != TGaugeType::push ) {
ggDoorLeftPermitButton.PutValue( mvOccupied->Doors.instances[ ( mvOccupied->ActiveCab == 1 ? side::left : side::right ) ].open_permit ? 1.f : 0.f );
}
if( ggDoorRightPermitButton.type() != TGaugeType::push ) {
ggDoorRightPermitButton.PutValue( mvOccupied->Doors.instances[ ( mvOccupied->ActiveCab == 1 ? side::right : side::left ) ].open_permit ? 1.f : 0.f );
}
ggDoorPermitPresetButton.PutValue( mvOccupied->Doors.permit_preset ); ggDoorPermitPresetButton.PutValue( mvOccupied->Doors.permit_preset );
ggDoorLeftButton.PutValue( mvOccupied->Doors.instances[ ( mvOccupied->ActiveCab == 1 ? side::left : side::right ) ].is_closed ? 0.f : 1.f ); ggDoorLeftButton.PutValue( mvOccupied->Doors.instances[ ( mvOccupied->ActiveCab == 1 ? side::left : side::right ) ].is_closed ? 0.f : 1.f );
ggDoorRightButton.PutValue( mvOccupied->Doors.instances[ ( mvOccupied->ActiveCab == 1 ? side::right : side::left ) ].is_closed ? 0.f : 1.f ); ggDoorRightButton.PutValue( mvOccupied->Doors.instances[ ( mvOccupied->ActiveCab == 1 ? side::right : side::left ) ].is_closed ? 0.f : 1.f );
@@ -7814,8 +7855,8 @@ bool TTrain::initialize_button(cParser &Parser, std::string const &Label, int co
} }
// TODO: move viable dedicated lights to the automatic light array // TODO: move viable dedicated lights to the automatic light array
std::unordered_map<std::string, bool *> const autolights = { std::unordered_map<std::string, bool *> const autolights = {
{ "i-doorpermit_left:", &mvOccupied->Doors.instances[side::left].open_permit }, { "i-doorpermit_left:", &mvOccupied->Doors.instances[ ( mvOccupied->ActiveCab == 1 ? side::left : side::right ) ].open_permit },
{ "i-doorpermit_right:", &mvOccupied->Doors.instances[ side::right ].open_permit }, { "i-doorpermit_right:", &mvOccupied->Doors.instances[ ( mvOccupied->ActiveCab == 1 ? side::right : side::left ) ].open_permit },
{ "i-doorstep:", &mvOccupied->Doors.step_enabled } { "i-doorstep:", &mvOccupied->Doors.step_enabled }
}; };
{ {

View File

@@ -81,12 +81,12 @@ openal_buffer::openal_buffer( std::string const &Filename ) :
auto const samplecount { stb_vorbis_decode_filename( Filename.c_str(), &channels, &samplerate, &filedata ) }; auto const samplecount { stb_vorbis_decode_filename( Filename.c_str(), &channels, &samplerate, &filedata ) };
if( samplecount > 0 ) { if( samplecount > 0 ) {
rate = samplerate; rate = samplerate;
data.resize( samplecount ); data.resize( samplecount * channels );
std::copy( filedata, filedata + samplecount, std::begin( data ) ); std::copy( filedata, filedata + data.size(), std::begin( data ) );
free( filedata ); free( filedata );
if( channels > 1 ) { if( channels > 1 ) {
narrow_to_mono( channels ); narrow_to_mono( channels );
data.resize( samplecount / channels ); data.resize( samplecount );
} }
} }
else { else {
@@ -109,7 +109,7 @@ void
openal_buffer::narrow_to_mono( std::uint16_t const Channelcount ) { openal_buffer::narrow_to_mono( std::uint16_t const Channelcount ) {
std::size_t monodataindex { 0 }; std::size_t monodataindex { 0 };
std::int32_t accumulator { 0 }; std::int64_t accumulator { 0 };
auto channelcount { Channelcount }; auto channelcount { Channelcount };
for( auto const channeldata : data ) { for( auto const channeldata : data ) {
@@ -117,7 +117,7 @@ openal_buffer::narrow_to_mono( std::uint16_t const Channelcount ) {
accumulator += channeldata; accumulator += channeldata;
if( --channelcount == 0 ) { if( --channelcount == 0 ) {
data[ monodataindex++ ] = accumulator / Channelcount; data[ monodataindex++ ] = static_cast<std::int16_t>( accumulator / Channelcount );
accumulator = 0; accumulator = 0;
channelcount = Channelcount; channelcount = Channelcount;
} }

View File

@@ -21,7 +21,7 @@ http://mozilla.org/MPL/2.0/.
#include "uilayer.h" #include "uilayer.h"
#include "Logs.h" #include "Logs.h"
auto const EU07_CONTROLLER_MOUSESLIDERSIZE{ 0.65 }; auto const EU07_CONTROLLER_MOUSESLIDERSIZE{ 0.6 };
void void
mouse_slider::bind( user_command const &Command ) { mouse_slider::bind( user_command const &Command ) {

View File

@@ -2170,34 +2170,36 @@ opengl_renderer::Render( TDynamicObject *Dynamic ) {
m_renderspecular = true; // vehicles are rendered with specular component. static models without, at least for the time being m_renderspecular = true; // vehicles are rendered with specular component. static models without, at least for the time being
// render // render
if( Dynamic->mdLowPolyInt ) { if( Dynamic->mdLowPolyInt ) {
// low poly interior // HACK: reduce light level for vehicle interior if there's strong global lighting source
/* auto const luminance { static_cast<float>( 0.5 * ( std::max( 0.3, Global.fLuminance - Global.Overcast ) ) ) };
if( ( true == FreeFlyModeFlag ) m_sunlight.apply_intensity(
|| ( ( Dynamic->mdKabina == nullptr ) || ( false == Dynamic->bDisplayCab ) ) ) { clamp( (
*/ Dynamic->fShade > 0.f ?
/* Dynamic->fShade :
// enable cab light if needed 1.f )
if( Dynamic->InteriorLightLevel > 0.0f ) { - luminance,
0.f, 1.f ) );
// crude way to light the cabin, until we have something more complete in place // low poly interior
::glLightModelfv( GL_LIGHT_MODEL_AMBIENT, glm::value_ptr( Dynamic->InteriorLight * Dynamic->InteriorLightLevel ) );
}
*/
Render( Dynamic->mdLowPolyInt, Dynamic->Material(), squaredistance ); Render( Dynamic->mdLowPolyInt, Dynamic->Material(), squaredistance );
/* // HACK: if the model has low poly interior, we presume the load is placed inside and also affected by reduced light level
if( Dynamic->InteriorLightLevel > 0.0f ) { if( Dynamic->mdLoad ) {
// reset the overall ambient // renderowanie nieprzezroczystego ładunku
::glLightModelfv( GL_LIGHT_MODEL_AMBIENT, glm::value_ptr( m_baseambient ) );
}
*/
/*
}
*/
}
if( Dynamic->mdModel )
Render( Dynamic->mdModel, Dynamic->Material(), squaredistance );
if( Dynamic->mdLoad ) // renderowanie nieprzezroczystego ładunku
Render( Dynamic->mdLoad, Dynamic->Material(), squaredistance, { 0.f, Dynamic->LoadOffset, 0.f }, {} ); Render( Dynamic->mdLoad, Dynamic->Material(), squaredistance, { 0.f, Dynamic->LoadOffset, 0.f }, {} );
}
m_sunlight.apply_intensity( Dynamic->fShade > 0.f ? Dynamic->fShade : 1.f );
}
else {
// HACK: if the model lacks low poly interior, we presume the load is placed outside
if( Dynamic->mdLoad ) {
// renderowanie nieprzezroczystego ładunku
Render( Dynamic->mdLoad, Dynamic->Material(), squaredistance, { 0.f, Dynamic->LoadOffset, 0.f }, {} );
}
}
if( Dynamic->mdModel ) {
Render( Dynamic->mdModel, Dynamic->Material(), squaredistance );
}
// post-render cleanup // post-render cleanup
m_renderspecular = false; m_renderspecular = false;
if( Dynamic->fShade > 0.0f ) { if( Dynamic->fShade > 0.0f ) {

View File

@@ -164,16 +164,24 @@ state_serializer::deserialize_atmo( cParser &Input, scene::scratch_data &Scratch
// atmosphere color; legacy parameter, no longer used // atmosphere color; legacy parameter, no longer used
Input.getTokens( 3 ); Input.getTokens( 3 );
// fog range // fog range
{
double fograngestart, fograngeend;
Input.getTokens( 2 ); Input.getTokens( 2 );
Input Input
>> Global.fFogStart >> fograngestart
>> Global.fFogEnd; >> fograngeend;
if( Global.fFogEnd > 0.0 ) { if( Global.fFogEnd != 0.0 ) {
// fog colour; optional legacy parameter, no longer used // fog colour; optional legacy parameter, no longer used
Input.getTokens( 3 ); Input.getTokens( 3 );
} }
Global.fFogEnd =
clamp(
Random( fograngestart, fograngeend ),
100.0, 2000.0 );
}
std::string token { Input.getToken<std::string>() }; std::string token { Input.getToken<std::string>() };
if( token != "endatmo" ) { if( token != "endatmo" ) {
// optional overcast parameter // optional overcast parameter

View File

@@ -1,5 +1,5 @@
#pragma once #pragma once
#define VERSION_MAJOR 19 #define VERSION_MAJOR 19
#define VERSION_MINOR 403 #define VERSION_MINOR 406
#define VERSION_REVISION 0 #define VERSION_REVISION 0