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

Merge branch 'tmj-dev'

This commit is contained in:
milek7
2018-03-11 21:19:53 +01:00
15 changed files with 58 additions and 62 deletions

View File

@@ -885,6 +885,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 // also ignore any horn cue that may be potentially set below 1 km/h and before the actual full stop
iDrivigFlags &= ~( moveStartHorn | moveStartHornNow ); iDrivigFlags &= ~( moveStartHorn | moveStartHornNow );
} }
// perform loading/unloading // perform loading/unloading
auto const platformside = static_cast<int>( std::floor( sSpeedTable[ i ].evEvent->ValueGet( 2 ) ) ) % 10; 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 ); auto const exchangetime = simulation::Station.update_load( pVehicles[ 0 ], *TrainParams, platformside );
@@ -3009,7 +3010,6 @@ void TController::Doors( bool const Open, int const Side ) {
// otwieranie drzwi // otwieranie drzwi
// otwieranie drzwi w składach wagonowych - docelowo wysyłać komendę zezwolenia na otwarcie 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) // 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 auto *vehicle = pVehicles[0]; // pojazd na czole składu
while( vehicle != nullptr ) { while( vehicle != nullptr ) {
// wagony muszą mieć baterię załączoną do otwarcia drzwi... // wagony muszą mieć baterię załączoną do otwarcia drzwi...
@@ -3019,7 +3019,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 the door are controlled by the driver, we let the user operate them...
if( true == AIControllFlag ) { if( true == AIControllFlag ) {
// ...unless this user is an ai // ...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 // jeśli jedzie do tyłu, to drzwi otwiera odwrotnie
auto const lewe = ( vehicle->DirectionGet() > 0 ) ? 1 : 2; auto const lewe = ( vehicle->DirectionGet() > 0 ) ? 1 : 2;
auto const prawe = 3 - lewe; auto const prawe = 3 - lewe;
@@ -3051,7 +3051,7 @@ void TController::Doors( bool const Open, int const Side ) {
auto *vehicle = pVehicles[ 0 ]; // pojazd na czole składu auto *vehicle = pVehicles[ 0 ]; // pojazd na czole składu
while( vehicle != nullptr ) { while( vehicle != nullptr ) {
// zamykanie drzwi w pojazdach - flaga zezwolenia była by lepsza // 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->DoorLeft( false, range::local ); // w lokomotywie można by nie zamykać...
vehicle->MoverParameters->DoorRight( false, range::local ); vehicle->MoverParameters->DoorRight( false, range::local );
} }

View File

@@ -2583,17 +2583,11 @@ void TDynamicObject::LoadUpdate() {
// try first specialized version of the load model, vehiclename_loadname // try first specialized version of the load model, vehiclename_loadname
auto const specializedloadfilename { asBaseDir + MoverParameters->TypeName + "_" + MoverParameters->LoadType }; auto const specializedloadfilename { asBaseDir + MoverParameters->TypeName + "_" + MoverParameters->LoadType };
if( ( true == FileExists( specializedloadfilename + ".e3d" ) ) mdLoad = TModelsManager::GetModel( specializedloadfilename, true );
|| ( true == FileExists( specializedloadfilename + ".t3d" ) ) ) {
mdLoad = TModelsManager::GetModel( specializedloadfilename, true );
}
if( mdLoad == nullptr ) { if( mdLoad == nullptr ) {
// if this fails, try generic load model // if this fails, try generic load model
auto const genericloadfilename { asBaseDir + MoverParameters->LoadType }; auto const genericloadfilename { asBaseDir + MoverParameters->LoadType };
if( ( true == FileExists( genericloadfilename + ".e3d" ) ) mdLoad = TModelsManager::GetModel( genericloadfilename, true );
|| ( true == FileExists( genericloadfilename + ".t3d" ) ) ) {
mdLoad = TModelsManager::GetModel( genericloadfilename, true );
}
} }
if( mdLoad != nullptr ) { if( mdLoad != nullptr ) {
// TODO: discern from vehicle component which merely uses vehicle directory and has no animations, so it can be initialized outright // TODO: discern from vehicle component which merely uses vehicle directory and has no animations, so it can be initialized outright
@@ -4164,6 +4158,7 @@ void TDynamicObject::LoadMMediaFile( std::string BaseDir, std::string TypeName,
int skinindex = 0; int skinindex = 0;
std::string texturename; nameparser >> texturename; std::string texturename; nameparser >> texturename;
while( ( texturename != "" ) && ( skinindex < 4 ) ) { while( ( texturename != "" ) && ( skinindex < 4 ) ) {
erase_extension( texturename );
m_materialdata.replacable_skins[ skinindex + 1 ] = GfxRenderer.Fetch_Material( Global.asCurrentTexturePath + texturename ); m_materialdata.replacable_skins[ skinindex + 1 ] = GfxRenderer.Fetch_Material( Global.asCurrentTexturePath + texturename );
++skinindex; ++skinindex;
texturename = ""; nameparser >> texturename; texturename = ""; nameparser >> texturename;
@@ -4172,6 +4167,7 @@ void TDynamicObject::LoadMMediaFile( std::string BaseDir, std::string TypeName,
} }
else { else {
// otherwise try the basic approach // otherwise try the basic approach
erase_extension( ReplacableSkin );
int skinindex = 0; int skinindex = 0;
do { do {
material_handle material = GfxRenderer.Fetch_Material( Global.asCurrentTexturePath + ReplacableSkin + "," + std::to_string( skinindex + 1 ), true ); material_handle material = GfxRenderer.Fetch_Material( Global.asCurrentTexturePath + ReplacableSkin + "," + std::to_string( skinindex + 1 ), true );

View File

@@ -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, TMdlContainer{} };
TModelsManager::stringmodelcontainerindex_map TModelsManager::m_modelsmap; TModelsManager::stringmodelcontainerindex_map TModelsManager::m_modelsmap;
// wczytanie modelu do tablicy // wczytanie modelu do tablicy
@@ -48,12 +48,12 @@ TModelsManager::LoadModel(std::string const &Name, bool dynamic) {
auto model = m_models.back().LoadModel( Name, dynamic ); auto model = m_models.back().LoadModel( Name, dynamic );
if( model != nullptr ) { if( model != nullptr ) {
m_modelsmap.emplace( Name, m_models.size() - 1 ); m_modelsmap.emplace( Name, m_models.size() - 1 );
return model;
} }
else { else {
m_models.pop_back(); m_models.pop_back();
return nullptr; m_modelsmap.emplace( Name, null_handle );
} }
return model;
} }
TModel3d * TModel3d *
@@ -87,35 +87,34 @@ TModelsManager::GetModel(std::string const &Name, bool const Dynamic)
Global.asCurrentTexturePath.erase( Global.asCurrentTexturePath.rfind( "/" ) + 1 ); Global.asCurrentTexturePath.erase( Global.asCurrentTexturePath.rfind( "/" ) + 1 );
} }
erase_extension( filename );
filename = ToLower( 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 // see if we have it in the databank
auto *model { find_in_databank( filename ) }; auto banklookup { find_in_databank( filename ) };
if( model != nullptr ) { TModel3d *model { banklookup.second };
if( true == banklookup.first ) {
Global.asCurrentTexturePath = buftp; Global.asCurrentTexturePath = buftp;
return model; return model;
} }
// not yet loaded, check if it's on disk // first load attempt, check if it's on disk
std::string lookup { find_on_disk( filename ) }; std::string disklookup { find_on_disk( filename ) };
if( false == lookup.empty() ) { if( false == disklookup.empty() ) {
model = LoadModel( lookup, Dynamic ); // model nie znaleziony, to wczytać model = LoadModel( disklookup, Dynamic ); // model nie znaleziony, to wczytać
} }
else { 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 ); 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 Global.asCurrentTexturePath = buftp; // odtworzenie ścieżki do tekstur
return model; // NULL jeśli błąd return model; // NULL jeśli błąd
}; };
TModel3d * std::pair<bool, TModel3d *>
TModelsManager::find_in_databank( std::string const &Name ) { TModelsManager::find_in_databank( std::string const &Name ) {
std::vector<std::string> filenames { std::vector<std::string> filenames {
@@ -125,11 +124,11 @@ TModelsManager::find_in_databank( std::string const &Name ) {
for( auto const &filename : filenames ) { for( auto const &filename : filenames ) {
auto const lookup { m_modelsmap.find( filename ) }; auto const lookup { m_modelsmap.find( filename ) };
if( lookup != m_modelsmap.end() ) { 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. // checks whether specified file exists. returns name of the located file, or empty string.

View File

@@ -33,7 +33,7 @@ private:
static stringmodelcontainerindex_map m_modelsmap; static stringmodelcontainerindex_map m_modelsmap;
// methods: // methods:
static TModel3d *LoadModel( std::string const &Name, bool const Dynamic ); 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. // checks whether specified file exists. returns name of the located file, or empty string.
static std::string find_on_disk( std::string const &Name ); static std::string find_on_disk( std::string const &Name );

View File

@@ -816,12 +816,7 @@ texture_manager::create( std::string Filename, bool const Loadnow ) {
Filename.erase( traitpos ); Filename.erase( traitpos );
} }
if( ( Filename.rfind( '.' ) != std::string::npos ) erase_extension( Filename );
&& ( Filename.rfind( '.' ) != Filename.rfind( ".." ) + 1 ) ) {
// trim extension if there's one, but don't mistake folder traverse for extension
Filename.erase( Filename.rfind( '.' ) );
}
// change slashes to cross-platform // change slashes to cross-platform
std::replace( std::replace(
std::begin( Filename ), std::end( Filename ), std::begin( Filename ), std::end( Filename ),

View File

@@ -552,6 +552,7 @@ TTrain::get_state() const {
return { return {
btLampkaSHP.GetValue(), btLampkaSHP.GetValue(),
btLampkaCzuwaka.GetValue(), btLampkaCzuwaka.GetValue(),
btLampkaRadioStop.GetValue(),
btLampkaOpory.GetValue(), btLampkaOpory.GetValue(),
btLampkaWylSzybki.GetValue(), btLampkaWylSzybki.GetValue(),
btLampkaNadmSil.GetValue(), btLampkaNadmSil.GetValue(),

View File

@@ -71,6 +71,7 @@ class TTrain
struct state_t { struct state_t {
std::uint8_t shp; std::uint8_t shp;
std::uint8_t alerter; std::uint8_t alerter;
std::uint8_t radio_stop;
std::uint8_t motor_resistors; std::uint8_t motor_resistors;
std::uint8_t line_breaker; std::uint8_t line_breaker;
std::uint8_t motor_overload; std::uint8_t motor_overload;

View File

@@ -104,12 +104,7 @@ buffer_manager::create( std::string const &Filename ) {
auto filename { ToLower( Filename ) }; auto filename { ToLower( Filename ) };
auto const dotpos { filename.rfind( '.' ) }; erase_extension( filename );
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 );
}
// convert slashes // convert slashes
std::replace( std::replace(
std::begin( filename ), std::end( filename ), std::begin( filename ), std::end( filename ),

View File

@@ -113,11 +113,7 @@ material_manager::create( std::string const &Filename, bool const Loadnow ) {
if( filename.find( '|' ) != std::string::npos ) if( filename.find( '|' ) != std::string::npos )
filename.erase( filename.find( '|' ) ); // po | może być nazwa kolejnej tekstury filename.erase( filename.find( '|' ) ); // po | może być nazwa kolejnej tekstury
if( ( filename.rfind( '.' ) != std::string::npos ) erase_extension( filename );
&& ( 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( '.' ) );
}
filename += ".mat"; filename += ".mat";
// change slashes to llinux-compatible // change slashes to llinux-compatible

View File

@@ -39,9 +39,9 @@ public:
m_stack.emplace( m_stack.top() ); } m_stack.emplace( m_stack.top() ); }
void void
pop_matrix() { pop_matrix() {
m_stack.pop(); if( m_stack.size() > 1 ) {
if( m_stack.empty() ) { m_stack.emplace( 1.f ); } m_stack.pop();
upload(); } upload(); } }
void void
load_identity() { load_identity() {
m_stack.top() = glm::mat4( 1.f ); m_stack.top() = glm::mat4( 1.f );
@@ -85,7 +85,7 @@ private:
// methods: // methods:
void void
upload() { ::glLoadMatrixf( &m_stack.top()[0][0] ); } upload() { ::glLoadMatrixf( glm::value_ptr( m_stack.top() ) ); }
// members: // members:
mat4_stack m_stack; mat4_stack m_stack;

View File

@@ -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 // trim leading $ char rainsted utility may add to the base name for modified .scn files
filename.erase( 0, 1 ); filename.erase( 0, 1 );
} }
erase_extension( filename );
filename = Global.asCurrentSceneryPath + 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; filename += EU07_FILEEXTENSION_REGION;
std::ofstream output { filename, std::ios::binary }; 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 // trim leading $ char rainsted utility may add to the base name for modified .scn files
filename.erase( 0, 1 ); filename.erase( 0, 1 );
} }
erase_extension( filename );
filename = Global.asCurrentSceneryPath + 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; filename += EU07_FILEEXTENSION_REGION;
if( false == FileExists( filename ) ) { if( false == FileExists( filename ) ) {

View File

@@ -272,6 +272,7 @@ void uart_input::poll()
(uint8_t)( (uint8_t)(
trainstate.recorder_braking << 3 trainstate.recorder_braking << 3
| trainstate.recorder_power << 4 | trainstate.recorder_power << 4
| trainstate.radio_stop <<5
| trainstate.alerter_sound << 7), | trainstate.alerter_sound << 7),
//byte 7-8 //byte 7-8
SPLIT_INT16(brake_press), SPLIT_INT16(brake_press),

View File

@@ -321,3 +321,19 @@ last_modified( std::string const &Filename ) {
else else
return 0; 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;
}

View File

@@ -179,6 +179,10 @@ bool FileExists( std::string const &Filename );
// returns time of last modification for specified file // returns time of last modification for specified file
std::time_t last_modified( std::string const &Filename ); 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_> template <typename Type_>
void SafeDelete( Type_ &Pointer ) { void SafeDelete( Type_ &Pointer ) {
delete Pointer; delete Pointer;

View File

@@ -1,5 +1,5 @@
#pragma once #pragma once
#define VERSION_MAJOR 18 #define VERSION_MAJOR 18
#define VERSION_MINOR 309 #define VERSION_MINOR 311
#define VERSION_REVISION 0 #define VERSION_REVISION 0