mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-03-22 15:05:03 +01:00
additional serial port data output, 3d model load failure caching, minor refactoring and bug fixes
This commit is contained in:
@@ -886,6 +886,7 @@ TCommandType TController::TableUpdate(double &fVelDes, double &fDist, double &fN
|
||||
// also ignore any horn cue that may be potentially set below 1 km/h and before the actual full stop
|
||||
iDrivigFlags &= ~( moveStartHorn | moveStartHornNow );
|
||||
}
|
||||
|
||||
// perform loading/unloading
|
||||
auto const platformside = static_cast<int>( std::floor( sSpeedTable[ i ].evEvent->ValueGet( 2 ) ) ) % 10;
|
||||
auto const exchangetime = simulation::Station.update_load( pVehicles[ 0 ], *TrainParams, platformside );
|
||||
@@ -3010,7 +3011,6 @@ void TController::Doors( bool const Open, int const Side ) {
|
||||
// otwieranie drzwi
|
||||
// otwieranie drzwi w składach wagonowych - docelowo wysyłać komendę zezwolenia na otwarcie drzwi
|
||||
// tu będzie jeszcze długość peronu zaokrąglona do 10m (20m bezpieczniej, bo nie modyfikuje bitu 1)
|
||||
// p7=platform side (1:left, 2:right, 3:both)
|
||||
auto *vehicle = pVehicles[0]; // pojazd na czole składu
|
||||
while( vehicle != nullptr ) {
|
||||
// wagony muszą mieć baterię załączoną do otwarcia drzwi...
|
||||
@@ -3020,7 +3020,7 @@ void TController::Doors( bool const Open, int const Side ) {
|
||||
// if the door are controlled by the driver, we let the user operate them...
|
||||
if( true == AIControllFlag ) {
|
||||
// ...unless this user is an ai
|
||||
// p7=platform side (1:left, 2:right, 3:both)
|
||||
// Side=platform side (1:left, 2:right, 3:both)
|
||||
// jeśli jedzie do tyłu, to drzwi otwiera odwrotnie
|
||||
auto const lewe = ( vehicle->DirectionGet() > 0 ) ? 1 : 2;
|
||||
auto const prawe = 3 - lewe;
|
||||
@@ -3052,7 +3052,7 @@ void TController::Doors( bool const Open, int const Side ) {
|
||||
auto *vehicle = pVehicles[ 0 ]; // pojazd na czole składu
|
||||
while( vehicle != nullptr ) {
|
||||
// zamykanie drzwi w pojazdach - flaga zezwolenia była by lepsza
|
||||
if( vehicle->MoverParameters->DoorCloseCtrl != control::passenger ) {
|
||||
if( vehicle->MoverParameters->DoorCloseCtrl != control::autonomous ) {
|
||||
vehicle->MoverParameters->DoorLeft( false, range::local ); // w lokomotywie można by nie zamykać...
|
||||
vehicle->MoverParameters->DoorRight( false, range::local );
|
||||
}
|
||||
|
||||
12
DynObj.cpp
12
DynObj.cpp
@@ -2581,17 +2581,11 @@ void TDynamicObject::LoadUpdate() {
|
||||
|
||||
// try first specialized version of the load model, vehiclename_loadname
|
||||
auto const specializedloadfilename { asBaseDir + MoverParameters->TypeName + "_" + MoverParameters->LoadType };
|
||||
if( ( true == FileExists( specializedloadfilename + ".e3d" ) )
|
||||
|| ( true == FileExists( specializedloadfilename + ".t3d" ) ) ) {
|
||||
mdLoad = TModelsManager::GetModel( specializedloadfilename, true );
|
||||
}
|
||||
mdLoad = TModelsManager::GetModel( specializedloadfilename, true );
|
||||
if( mdLoad == nullptr ) {
|
||||
// if this fails, try generic load model
|
||||
auto const genericloadfilename { asBaseDir + MoverParameters->LoadType };
|
||||
if( ( true == FileExists( genericloadfilename + ".e3d" ) )
|
||||
|| ( true == FileExists( genericloadfilename + ".t3d" ) ) ) {
|
||||
mdLoad = TModelsManager::GetModel( genericloadfilename, true );
|
||||
}
|
||||
mdLoad = TModelsManager::GetModel( genericloadfilename, true );
|
||||
}
|
||||
if( mdLoad != nullptr ) {
|
||||
// TODO: discern from vehicle component which merely uses vehicle directory and has no animations, so it can be initialized outright
|
||||
@@ -4162,6 +4156,7 @@ void TDynamicObject::LoadMMediaFile( std::string BaseDir, std::string TypeName,
|
||||
int skinindex = 0;
|
||||
std::string texturename; nameparser >> texturename;
|
||||
while( ( texturename != "" ) && ( skinindex < 4 ) ) {
|
||||
erase_extension( texturename );
|
||||
m_materialdata.replacable_skins[ skinindex + 1 ] = GfxRenderer.Fetch_Material( Global.asCurrentTexturePath + texturename );
|
||||
++skinindex;
|
||||
texturename = ""; nameparser >> texturename;
|
||||
@@ -4170,6 +4165,7 @@ void TDynamicObject::LoadMMediaFile( std::string BaseDir, std::string TypeName,
|
||||
}
|
||||
else {
|
||||
// otherwise try the basic approach
|
||||
erase_extension( ReplacableSkin );
|
||||
int skinindex = 0;
|
||||
do {
|
||||
material_handle material = GfxRenderer.Fetch_Material( Global.asCurrentTexturePath + ReplacableSkin + "," + std::to_string( skinindex + 1 ), true );
|
||||
|
||||
35
MdlMngr.cpp
35
MdlMngr.cpp
@@ -37,7 +37,7 @@ TMdlContainer::LoadModel(std::string const &Name, bool const Dynamic) {
|
||||
}
|
||||
};
|
||||
|
||||
TModelsManager::modelcontainer_sequence TModelsManager::m_models;
|
||||
TModelsManager::modelcontainer_sequence TModelsManager::m_models { 1, {} };
|
||||
TModelsManager::stringmodelcontainerindex_map TModelsManager::m_modelsmap;
|
||||
|
||||
// wczytanie modelu do tablicy
|
||||
@@ -48,12 +48,12 @@ TModelsManager::LoadModel(std::string const &Name, bool dynamic) {
|
||||
auto model = m_models.back().LoadModel( Name, dynamic );
|
||||
if( model != nullptr ) {
|
||||
m_modelsmap.emplace( Name, m_models.size() - 1 );
|
||||
return model;
|
||||
}
|
||||
else {
|
||||
m_models.pop_back();
|
||||
return nullptr;
|
||||
m_modelsmap.emplace( Name, null_handle );
|
||||
}
|
||||
return model;
|
||||
}
|
||||
|
||||
TModel3d *
|
||||
@@ -87,35 +87,34 @@ TModelsManager::GetModel(std::string const &Name, bool const Dynamic)
|
||||
Global.asCurrentTexturePath.erase( Global.asCurrentTexturePath.rfind( "/" ) + 1 );
|
||||
}
|
||||
|
||||
erase_extension( filename );
|
||||
filename = ToLower( filename );
|
||||
if( ( filename.rfind( '.' ) != std::string::npos )
|
||||
&& ( filename.rfind( '.' ) != filename.rfind( ".." ) + 1 ) ) {
|
||||
// trim extension if there's one, but don't mistake folder traverse for extension
|
||||
filename.erase( filename.rfind( '.' ) );
|
||||
}
|
||||
|
||||
// see if we have it in the databank
|
||||
auto *model { find_in_databank( filename ) };
|
||||
if( model != nullptr ) {
|
||||
auto banklookup { find_in_databank( filename ) };
|
||||
TModel3d *model { banklookup.second };
|
||||
if( true == banklookup.first ) {
|
||||
Global.asCurrentTexturePath = buftp;
|
||||
return model;
|
||||
}
|
||||
|
||||
// not yet loaded, check if it's on disk
|
||||
std::string lookup { find_on_disk( filename ) };
|
||||
// first load attempt, check if it's on disk
|
||||
std::string disklookup { find_on_disk( filename ) };
|
||||
|
||||
if( false == lookup.empty() ) {
|
||||
model = LoadModel( lookup, Dynamic ); // model nie znaleziony, to wczytać
|
||||
if( false == disklookup.empty() ) {
|
||||
model = LoadModel( disklookup, Dynamic ); // model nie znaleziony, to wczytać
|
||||
}
|
||||
else {
|
||||
// there's nothing matching in the databank nor on the disk, report failure
|
||||
// there's nothing matching in the databank nor on the disk, report failure...
|
||||
ErrorLog( "Bad file: failed do locate 3d model file \"" + filename + "\"", logtype::file );
|
||||
// ...and link it with the error model slot
|
||||
m_modelsmap.emplace( filename, null_handle );
|
||||
}
|
||||
Global.asCurrentTexturePath = buftp; // odtworzenie ścieżki do tekstur
|
||||
return model; // NULL jeśli błąd
|
||||
};
|
||||
|
||||
TModel3d *
|
||||
std::pair<bool, TModel3d *>
|
||||
TModelsManager::find_in_databank( std::string const &Name ) {
|
||||
|
||||
std::vector<std::string> filenames {
|
||||
@@ -125,11 +124,11 @@ TModelsManager::find_in_databank( std::string const &Name ) {
|
||||
for( auto const &filename : filenames ) {
|
||||
auto const lookup { m_modelsmap.find( filename ) };
|
||||
if( lookup != m_modelsmap.end() ) {
|
||||
return ( m_models[ lookup->second ].Model.get() );
|
||||
return { true, m_models[ lookup->second ].Model.get() };
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
return { false, nullptr };
|
||||
}
|
||||
|
||||
// checks whether specified file exists. returns name of the located file, or empty string.
|
||||
|
||||
@@ -33,7 +33,7 @@ private:
|
||||
static stringmodelcontainerindex_map m_modelsmap;
|
||||
// methods:
|
||||
static TModel3d *LoadModel( std::string const &Name, bool const Dynamic );
|
||||
static TModel3d *find_in_databank( std::string const &Name );
|
||||
static std::pair<bool, TModel3d *> find_in_databank( std::string const &Name );
|
||||
// checks whether specified file exists. returns name of the located file, or empty string.
|
||||
static std::string find_on_disk( std::string const &Name );
|
||||
|
||||
|
||||
@@ -760,12 +760,7 @@ texture_manager::create( std::string Filename, bool const Loadnow ) {
|
||||
Filename.erase( traitpos );
|
||||
}
|
||||
|
||||
if( ( Filename.rfind( '.' ) != std::string::npos )
|
||||
&& ( Filename.rfind( '.' ) != Filename.rfind( ".." ) + 1 ) ) {
|
||||
// trim extension if there's one, but don't mistake folder traverse for extension
|
||||
Filename.erase( Filename.rfind( '.' ) );
|
||||
}
|
||||
|
||||
erase_extension( Filename );
|
||||
// change slashes to cross-platform
|
||||
std::replace(
|
||||
std::begin( Filename ), std::end( Filename ),
|
||||
|
||||
@@ -547,6 +547,7 @@ TTrain::get_state() const {
|
||||
return {
|
||||
btLampkaSHP.GetValue(),
|
||||
btLampkaCzuwaka.GetValue(),
|
||||
btLampkaRadioStop.GetValue(),
|
||||
btLampkaOpory.GetValue(),
|
||||
btLampkaWylSzybki.GetValue(),
|
||||
btLampkaNadmSil.GetValue(),
|
||||
|
||||
1
Train.h
1
Train.h
@@ -70,6 +70,7 @@ class TTrain
|
||||
struct state_t {
|
||||
std::uint8_t shp;
|
||||
std::uint8_t alerter;
|
||||
std::uint8_t radio_stop;
|
||||
std::uint8_t motor_resistors;
|
||||
std::uint8_t line_breaker;
|
||||
std::uint8_t motor_overload;
|
||||
|
||||
@@ -132,12 +132,7 @@ buffer_manager::create( std::string const &Filename ) {
|
||||
|
||||
auto filename { ToLower( Filename ) };
|
||||
|
||||
auto const dotpos { filename.rfind( '.' ) };
|
||||
if( ( dotpos != std::string::npos )
|
||||
&& ( dotpos != filename.rfind( ".." ) + 1 ) ) {
|
||||
// trim extension if there's one, but don't mistake folder traverse for extension
|
||||
filename.erase( dotpos );
|
||||
}
|
||||
erase_extension( filename );
|
||||
// convert slashes
|
||||
std::replace(
|
||||
std::begin( filename ), std::end( filename ),
|
||||
|
||||
@@ -110,11 +110,7 @@ material_manager::create( std::string const &Filename, bool const Loadnow ) {
|
||||
if( filename.find( '|' ) != std::string::npos )
|
||||
filename.erase( filename.find( '|' ) ); // po | może być nazwa kolejnej tekstury
|
||||
|
||||
if( ( filename.rfind( '.' ) != std::string::npos )
|
||||
&& ( filename.rfind( '.' ) != filename.rfind( ".." ) + 1 ) ) {
|
||||
// we can get extension for .mat or, in legacy files, some image format. just trim it and set it to material file extension
|
||||
filename.erase( filename.rfind( '.' ) );
|
||||
}
|
||||
erase_extension( filename );
|
||||
filename += ".mat";
|
||||
|
||||
// change slashes to llinux-compatible
|
||||
|
||||
@@ -38,9 +38,9 @@ public:
|
||||
m_stack.emplace( m_stack.top() ); }
|
||||
void
|
||||
pop_matrix() {
|
||||
m_stack.pop();
|
||||
if( m_stack.empty() ) { m_stack.emplace( 1.f ); }
|
||||
upload(); }
|
||||
if( m_stack.size() > 1 ) {
|
||||
m_stack.pop();
|
||||
upload(); } }
|
||||
void
|
||||
load_identity() {
|
||||
m_stack.top() = glm::mat4( 1.f );
|
||||
@@ -80,7 +80,7 @@ private:
|
||||
|
||||
// methods:
|
||||
void
|
||||
upload() { ::glLoadMatrixf( &m_stack.top()[0][0] ); }
|
||||
upload() { ::glLoadMatrixf( glm::value_ptr( m_stack.top() ) ); }
|
||||
|
||||
// members:
|
||||
mat4_stack m_stack;
|
||||
|
||||
12
scene.cpp
12
scene.cpp
@@ -874,12 +874,8 @@ basic_region::serialize( std::string const &Scenariofile ) const {
|
||||
// trim leading $ char rainsted utility may add to the base name for modified .scn files
|
||||
filename.erase( 0, 1 );
|
||||
}
|
||||
erase_extension( filename );
|
||||
filename = Global.asCurrentSceneryPath + filename;
|
||||
if( ( filename.rfind( '.' ) != std::string::npos )
|
||||
&& ( filename.rfind( '.' ) != filename.rfind( ".." ) + 1 ) ) {
|
||||
// trim extension, it's typically going to be for different file type
|
||||
filename.erase( filename.rfind( '.' ) );
|
||||
}
|
||||
filename += EU07_FILEEXTENSION_REGION;
|
||||
|
||||
std::ofstream output { filename, std::ios::binary };
|
||||
@@ -917,12 +913,8 @@ basic_region::deserialize( std::string const &Scenariofile ) {
|
||||
// trim leading $ char rainsted utility may add to the base name for modified .scn files
|
||||
filename.erase( 0, 1 );
|
||||
}
|
||||
erase_extension( filename );
|
||||
filename = Global.asCurrentSceneryPath + filename;
|
||||
if( ( filename.rfind( '.' ) != std::string::npos )
|
||||
&& ( filename.rfind( '.' ) != filename.rfind( ".." ) + 1 ) ) {
|
||||
// trim extension, it's typically going to be for different file type
|
||||
filename.erase( filename.rfind( '.' ) );
|
||||
}
|
||||
filename += EU07_FILEEXTENSION_REGION;
|
||||
|
||||
if( false == FileExists( filename ) ) {
|
||||
|
||||
1
uart.cpp
1
uart.cpp
@@ -272,6 +272,7 @@ void uart_input::poll()
|
||||
(uint8_t)(
|
||||
trainstate.recorder_braking << 3
|
||||
| trainstate.recorder_power << 4
|
||||
| trainstate.radio_stop <<5
|
||||
| trainstate.alerter_sound << 7),
|
||||
//byte 7-8
|
||||
SPLIT_INT16(brake_press),
|
||||
|
||||
@@ -318,3 +318,19 @@ last_modified( std::string const &Filename ) {
|
||||
if( ::stat( Filename.c_str(), &filestat ) == 0 ) { return filestat.st_mtime; }
|
||||
else { return 0; }
|
||||
}
|
||||
|
||||
// potentially erases file extension from provided file name. returns: true if extension was removed, false otherwise
|
||||
bool
|
||||
erase_extension( std::string &Filename ) {
|
||||
|
||||
auto const extensionpos { Filename.rfind( '.' ) };
|
||||
|
||||
if( extensionpos == std::string::npos ) { return false; }
|
||||
|
||||
if( extensionpos != Filename.rfind( ".." ) + 1 ) {
|
||||
// we can get extension for .mat or, in legacy files, some image format. just trim it and set it to material file extension
|
||||
Filename.erase( extensionpos );
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -179,6 +179,10 @@ bool FileExists( std::string const &Filename );
|
||||
// returns time of last modification for specified file
|
||||
std::time_t last_modified( std::string const &Filename );
|
||||
|
||||
// potentially erases file extension from provided file name. returns: true if extension was removed, false otherwise
|
||||
bool
|
||||
erase_extension( std::string &Filename );
|
||||
|
||||
template <typename Type_>
|
||||
void SafeDelete( Type_ &Pointer ) {
|
||||
delete Pointer;
|
||||
|
||||
Reference in New Issue
Block a user