diff --git a/application/editoruipanels.cpp b/application/editoruipanels.cpp index 11c1e4f0..966f14fb 100644 --- a/application/editoruipanels.cpp +++ b/application/editoruipanels.cpp @@ -97,17 +97,17 @@ void itemproperties_panel::update(scene::basic_node const *Node) // 3d shape auto modelfile{((subnode->pModel != nullptr) ? subnode->pModel->NameGet() : "(none)")}; - if (modelfile.find(szModelPath) == 0) + if (modelfile.find(paths::models) == 0) { // don't include 'models/' in the path - modelfile.erase(0, std::string{szModelPath}.size()); + modelfile.erase(0, std::string{paths::models}.size()); } // texture auto texturefile{((subnode->Material()->replacable_skins[1] != null_handle) ? GfxRenderer->Material(subnode->Material()->replacable_skins[1])->GetName() : "(none)")}; - if (texturefile.find(szTexturePath) == 0) + if (texturefile.find(paths::textures) == 0) { // don't include 'textures/' in the path - texturefile.erase(0, std::string{szTexturePath}.size()); + texturefile.erase(0, std::string{paths::textures}.size()); } text_lines.emplace_back("mesh: " + modelfile, Global.UITextColor); text_lines.emplace_back("skin: " + texturefile, Global.UITextColor); @@ -131,14 +131,14 @@ void itemproperties_panel::update(scene::basic_node const *Node) text_lines.emplace_back(textline, Global.UITextColor); // textures auto texturefile{((subnode->m_material1 != null_handle) ? GfxRenderer->Material(subnode->m_material1)->GetName() : "(none)")}; - if (texturefile.find(szTexturePath) == 0) + if (texturefile.find(paths::textures) == 0) { - texturefile.erase(0, std::string{szTexturePath}.size()); + texturefile.erase(0, std::string{paths::textures}.size()); } auto texturefile2{((subnode->m_material2 != null_handle) ? GfxRenderer->Material(subnode->m_material2)->GetName() : "(none)")}; - if (texturefile2.find(szTexturePath) == 0) + if (texturefile2.find(paths::textures) == 0) { - texturefile2.erase(0, std::string{szTexturePath}.size()); + texturefile2.erase(0, std::string{paths::textures}.size()); } textline = "skins:\n " + texturefile + "\n " + texturefile2; text_lines.emplace_back(textline, Global.UITextColor); diff --git a/audio/audio.cpp b/audio/audio.cpp index 65bd5ec9..8bdf1dd1 100644 --- a/audio/audio.cpp +++ b/audio/audio.cpp @@ -135,11 +135,11 @@ buffer_manager::create( std::string const &Filename ) { } } // if dynamic-specific and/or direct lookups find nothing, try the default sound folder - lookup = find_buffer( szSoundPath + filename ); + lookup = find_buffer( paths::sounds + filename ); if( lookup != null_handle ) { return lookup; } - filelookup = find_file( szSoundPath + filename ); + filelookup = find_file( paths::sounds + filename ); if( false == filelookup.empty() ) { return emplace( filelookup ); } diff --git a/audio/sound.cpp b/audio/sound.cpp index 8fcdd033..77e6c9c2 100644 --- a/audio/sound.cpp +++ b/audio/sound.cpp @@ -319,9 +319,9 @@ sound_source::export_as_text( std::ostream &Output ) const { << m_offset.z << ' '; // sound data auto soundfile { audio::renderer.buffer( sound( sound_id::main ).buffer ).name }; - if( soundfile.find( szSoundPath ) == 0 ) { + if( soundfile.find( paths::sounds ) == 0 ) { // don't include 'sounds/' in the path - soundfile.erase( 0, std::string{ szSoundPath }.size() ); + soundfile.erase( 0, std::string{ paths::sounds }.size() ); } Output << soundfile << ' '; diff --git a/betterRenderer/renderer/source/nvtexture.cpp b/betterRenderer/renderer/source/nvtexture.cpp index 47178111..adc3ff1d 100644 --- a/betterRenderer/renderer/source/nvtexture.cpp +++ b/betterRenderer/renderer/source/nvtexture.cpp @@ -314,7 +314,7 @@ size_t NvTextureManager::FetchTexture(std::string path, int format_hint, { const std::array filenames{ - Global.asCurrentTexturePath + path, path, szTexturePath + path}; + Global.asCurrentTexturePath + path, path, paths::textures + path}; for (const auto &filename : filenames) { if (auto found = m_texture_map.find(filename); found != m_texture_map.end()) diff --git a/model/AnimModel.cpp b/model/AnimModel.cpp index 20fdd628..247efda6 100644 --- a/model/AnimModel.cpp +++ b/model/AnimModel.cpp @@ -675,9 +675,9 @@ TAnimModel::export_as_text_( std::ostream &Output ) const { pModel ? pModel->NameGet() + ".t3d" : // rainsted requires model file names to include an extension "none" ) }; - if( modelfile.find( szModelPath ) == 0 ) { + if( modelfile.find( paths::models ) == 0 ) { // don't include 'models/' in the path - modelfile.erase( 0, std::string{ szModelPath }.size() ); + modelfile.erase( 0, std::string{ paths::models }.size() ); } Output << modelfile << ' '; // texture @@ -685,9 +685,9 @@ TAnimModel::export_as_text_( std::ostream &Output ) const { m_materialdata.replacable_skins[ 1 ] != null_handle ? GfxRenderer->Material( m_materialdata.replacable_skins[ 1 ] )->GetName() : "none" ) }; - if( texturefile.find( szTexturePath ) == 0 ) { + if( texturefile.find( paths::textures ) == 0 ) { // don't include 'textures/' in the path - texturefile.erase( 0, std::string{ szTexturePath }.size() ); + texturefile.erase( 0, std::string{ paths::textures }.size() ); } if( contains( texturefile, ' ' ) ) { Output << "\"" << texturefile << "\"" << ' '; diff --git a/model/MdlMngr.cpp b/model/MdlMngr.cpp index b0a7ba76..f70ba118 100644 --- a/model/MdlMngr.cpp +++ b/model/MdlMngr.cpp @@ -125,7 +125,7 @@ TModelsManager::find_in_databank( std::string const &Name ) { std::vector filenames { Name, - szModelPath + Name }; + paths::models + Name }; for( auto const &filename : filenames ) { auto const lookup { m_modelsmap.find( filename ) }; @@ -146,7 +146,7 @@ TModelsManager::find_on_disk( std::string const &Name ) { auto lookup = ( FileExists( Name + extension ) ? Name : - FileExists( szModelPath + Name + extension ) ? szModelPath + Name : + FileExists( paths::models + Name + extension ) ? paths::models + Name : "" ); if( false == lookup.empty() ) { return lookup; diff --git a/model/Texture.cpp b/model/Texture.cpp index f4085edf..c4dabd34 100644 --- a/model/Texture.cpp +++ b/model/Texture.cpp @@ -1467,7 +1467,7 @@ texture_manager::find_in_databank( std::string const &Texturename ) const { std::vector const filenames { Global.asCurrentTexturePath + Texturename, Texturename, - szTexturePath + Texturename }; + paths::textures + Texturename }; for( auto const &filename : filenames ) { auto const lookup { m_texturemappings.find( filename ) }; @@ -1486,7 +1486,7 @@ texture_manager::find_on_disk( std::string const &Texturename ) { std::vector const filenames { Global.asCurrentTexturePath + Texturename, Texturename, - szTexturePath + Texturename }; + paths::textures + Texturename }; auto lookup = FileExists( diff --git a/model/material.cpp b/model/material.cpp index 99261338..e0b04475 100644 --- a/model/material.cpp +++ b/model/material.cpp @@ -582,7 +582,7 @@ material_manager::find_in_databank( std::string const &Materialname ) const { std::vector const filenames { Global.asCurrentTexturePath + Materialname, Materialname, - szTexturePath + Materialname }; + paths::textures + Materialname }; for( auto const &filename : filenames ) { auto const lookup { m_materialmappings.find( filename ) }; @@ -602,7 +602,7 @@ material_manager::find_on_disk( std::string const &Materialname ) { auto const materialname { ToLower( Materialname ) }; return ( FileExists( - { Global.asCurrentTexturePath + materialname, materialname, szTexturePath + materialname }, + { Global.asCurrentTexturePath + materialname, materialname, paths::textures + materialname }, { ".mat" } ) ); } diff --git a/scene/scenenode.h b/scene/scenenode.h index fb0959a7..eac74651 100644 --- a/scene/scenenode.h +++ b/scene/scenenode.h @@ -15,7 +15,7 @@ http://mozilla.org/MPL/2.0/. #include "model/material.h" #include "model/vertex.h" #include "rendering/geometrybank.h" -#include "utils/uuid.hpp" +#include "../utilities/uuid.hpp" struct lighting_data { diff --git a/utilities/Globals.cpp b/utilities/Globals.cpp index 241d8c2f..4e72cb9e 100644 --- a/utilities/Globals.cpp +++ b/utilities/Globals.cpp @@ -23,18 +23,25 @@ http://mozilla.org/MPL/2.0/. #include "utilities/Timer.h" #include "vao.h" -void -global_settings::LoadIniFile(std::string asFileName) { +void global_settings::LoadIniFile(std::string asFileName) +{ + // initialize season data in case the main config file doesn't + std::time_t timenow = std::time(nullptr); - // initialize season data in case the main config file doesn't - std::time_t timenow = std::time( 0 ); - std::tm *localtime = std::localtime( &timenow ); - fMoveLight = localtime->tm_yday + 1; // numer bieżącego dnia w roku - simulation::Environment.compute_season( fMoveLight ); + std::tm tm{}; - cParser parser(asFileName, cParser::buffer_FILE); - ConfigParse(parser); -}; +#ifdef _WIN32 + localtime_s(&tm, &timenow); +#else + localtime_r(&timenow, &tm); +#endif + + fMoveLight = tm.tm_yday + 1; // numer bieżącego dnia w roku + simulation::Environment.compute_season(fMoveLight); + + cParser parser(asFileName, cParser::buffer_FILE); + ConfigParse(parser); +} void global_settings::ConfigParse(cParser &Parser) { diff --git a/utilities/Globals.h b/utilities/Globals.h index fc5a4f8f..c7743655 100644 --- a/utilities/Globals.h +++ b/utilities/Globals.h @@ -65,7 +65,7 @@ struct global_settings { int iPause{ 0 }; // globalna pauza ruchu: b0=start,b1=klawisz,b2=tło,b3=lagi,b4=wczytywanie float AirTemperature{ 15.f }; std::string asCurrentSceneryPath{ "scenery/" }; - std::string asCurrentTexturePath{ szTexturePath }; + std::string asCurrentTexturePath{ paths::textures }; std::string asCurrentDynamicPath; int CurrentMaxTextureSize{ 4096 }; bool UpdateMaterials{ true }; diff --git a/utilities/Logs.cpp b/utilities/Logs.cpp index b6a09a8d..48d74317 100644 --- a/utilities/Logs.cpp +++ b/utilities/Logs.cpp @@ -158,55 +158,57 @@ void LogService() } -void WriteLog(const char *str, logtype const Type, bool isError) +bool ShouldSkipLog(std::string_view str, logtype type) { - if (!str || *str == '\0') - return; - if (TestFlag(Global.DisabledLogTypes, static_cast(Type))) - return; - - // time calculation - auto now = std::chrono::steady_clock::now(); - auto elapsed = now - Global.startTimestamp; - double seconds = std::chrono::duration_cast>(elapsed).count(); - - // time format - std::ostringstream oss; - oss << "[ " << std::fixed << std::setprecision(3) << seconds << " ] "; - - // wyrownanie do np. 10 znaków długości + dwie tabulacje - std::ostringstream final; - final << std::setw(10) << oss.str() << "\t\t" << str; - - - logMutex.lock(); - InfoStack.emplace_back(final.str(), isError); - logMutex.unlock(); + return str.empty() || + TestFlag(Global.DisabledLogTypes, static_cast(type)); } -void ErrorLog(const char *str, logtype const Type) +std::string FormatLogMessage(std::string_view str) { - if (!str || *str == '\0') - return; - if (TestFlag(Global.DisabledLogTypes, static_cast(Type))) + const auto now = std::chrono::steady_clock::now(); + const auto elapsed = now - Global.startTimestamp; + const double seconds = std::chrono::duration(elapsed).count(); + + return std::format("[ {:8.3f} ]\t\t{}", seconds, str); +} + +void WriteLog(std::string_view str, logtype type, bool isError) +{ + if (ShouldSkipLog(str, type)) return; - // time calculation - auto now = std::chrono::steady_clock::now(); - auto elapsed = now - Global.startTimestamp; - double seconds = std::chrono::duration_cast>(elapsed).count(); + const auto message = FormatLogMessage(str); - // time format - std::ostringstream oss; - oss << "[ " << std::fixed << std::setprecision(3) << seconds << " ] "; + std::lock_guard lock(logMutex); + InfoStack.push_back({message, isError}); +} - // wyrownanie do np. 10 znaków długości + dwie tabulacje - std::ostringstream final; - final << std::setw(10) << oss.str() << "\t\t" << str; +void ErrorLog(std::string_view str, logtype type) +{ + if (ShouldSkipLog(str, type)) + return; - logMutex.lock(); - ErrorStack.emplace_back(final.str()); - logMutex.unlock(); + const auto message = FormatLogMessage(str); + + std::lock_guard lock(logMutex); + ErrorStack.push_back(message); +} + +void WriteLog(const char* str, logtype type, bool isError) +{ + if (str == nullptr || *str == '\0') + return; + + WriteLog(std::string_view{str}, type, isError); +} + +void ErrorLog(const char* str, logtype type) +{ + if (str == nullptr || *str == '\0') + return; + + ErrorLog(std::string_view{str}, type); } diff --git a/utilities/utilities.h b/utilities/utilities.h index 0844b085..058220ca 100644 --- a/utilities/utilities.h +++ b/utilities/utilities.h @@ -29,12 +29,15 @@ template T sign(T x) #define DegToRad(a) ((M_PI / 180.0) * (a)) //(a) w nawiasie, bo może być dodawaniem #define RadToDeg(r) ((180.0 / M_PI) * (r)) -#define szSceneryPath "scenery/" -#define szTexturePath "textures/" -#define szModelPath "models/" -#define szDynamicPath "dynamic/" -#define szSoundPath "sounds/" -#define szDataPath "data/" +namespace paths +{ +inline constexpr const char *scenery = "scenery/"; +inline constexpr const char *textures = "textures/"; +inline constexpr const char *models = "models/"; +inline constexpr const char *dynamic = "dynamic/"; +inline constexpr const char *sounds = "sounds/"; +inline constexpr const char *data = "data/"; +} #define MAKE_ID4(a, b, c, d) (((std::uint32_t)(d) << 24) | ((std::uint32_t)(c) << 16) | ((std::uint32_t)(b) << 8) | (std::uint32_t)(a)) diff --git a/utils/uuid.hpp b/utilities/uuid.hpp similarity index 100% rename from utils/uuid.hpp rename to utilities/uuid.hpp diff --git a/vehicle/Driver.cpp b/vehicle/Driver.cpp index ae6b256d..33a7a43d 100644 --- a/vehicle/Driver.cpp +++ b/vehicle/Driver.cpp @@ -4541,7 +4541,7 @@ bool TController::PutCommand( std::string NewCommand, double NewValue1, double N // NewCommand = Global.asCurrentSceneryPath + NewCommand; auto lookup = FileExists( - { Global.asCurrentSceneryPath + NewCommand, szSoundPath + NewCommand }, + { Global.asCurrentSceneryPath + NewCommand, paths::sounds + NewCommand }, { ".ogg", ".flac", ".wav" } ); if( false == lookup.first.empty() ) { // wczytanie dźwięku odjazdu podawanego bezpośrenido @@ -4552,7 +4552,7 @@ bool TController::PutCommand( std::string NewCommand, double NewValue1, double N NewCommand += "radio"; lookup = FileExists( - { Global.asCurrentSceneryPath + NewCommand, szSoundPath + NewCommand }, + { Global.asCurrentSceneryPath + NewCommand, paths::sounds + NewCommand }, { ".ogg", ".flac", ".wav" } ); if( false == lookup.first.empty() ) { // wczytanie dźwięku odjazdu w wersji radiowej (słychać tylko w kabinie) diff --git a/vehicle/DynObj.cpp b/vehicle/DynObj.cpp index 63e6940d..0af7d324 100644 --- a/vehicle/DynObj.cpp +++ b/vehicle/DynObj.cpp @@ -63,7 +63,7 @@ TextureTest( std::string const &Name ) { auto const lookup { FileExists( - { Global.asCurrentTexturePath + Name, Name, szTexturePath + Name }, + { Global.asCurrentTexturePath + Name, Name, paths::textures + Name }, { ".mat", ".dds", ".tga", ".ktx", ".png", ".bmp", ".jpg", ".tex" } ) }; return ( lookup.first + lookup.second ); @@ -1982,7 +1982,7 @@ TDynamicObject::Init(std::string Name, // nazwa pojazdu, np. "EU07-424" ) { // Ustawienie początkowe pojazdu iDirection = (Reversed ? 0 : 1); // Ra: 0, jeśli ma być wstawiony jako obrócony tyłem - asBaseDir = szDynamicPath + BaseDir + "/"; // McZapkie-310302 + asBaseDir = paths::dynamic + BaseDir + "/"; // McZapkie-310302 asName = Name; std::string asAnimName; // zmienna robocza do wyszukiwania osi i wózków // Ra: zmieniamy znaczenie obsady na jednoliterowe, żeby dosadzić kierownika @@ -3011,7 +3011,7 @@ void TDynamicObject::LoadUpdate() { // update bindings between lowpoly sections and potential load chunks placed inside them update_load_sections(); // z powrotem defaultowa sciezka do tekstur - Global.asCurrentTexturePath = std::string( szTexturePath ); + Global.asCurrentTexturePath = std::string( paths::textures ); } } @@ -5337,7 +5337,7 @@ void TDynamicObject::LoadMMediaFile( std::string const &TypeName, std::string co if (ReplacableSkin != "none") { m_materialdata.assign( ReplacableSkin ); } - Global.asCurrentTexturePath = szTexturePath; // z powrotem defaultowa sciezka do tekstur + Global.asCurrentTexturePath = paths::textures; // z powrotem defaultowa sciezka do tekstur do { token = ""; parser.getTokens(); parser >> token; @@ -6011,7 +6011,7 @@ void TDynamicObject::LoadMMediaFile( std::string const &TypeName, std::string co mdLoad = LoadMMediaFile_mdload( MoverParameters->LoadType.name ); // z powrotem defaultowa sciezka do tekstur - Global.asCurrentTexturePath = std::string( szTexturePath ); + Global.asCurrentTexturePath = std::string( paths::textures ); } } // models @@ -7148,7 +7148,7 @@ void TDynamicObject::LoadMMediaFile( std::string const &TypeName, std::string co attachment->Init(); } - Global.asCurrentTexturePath = szTexturePath; // kiedyś uproszczone wnętrze mieszało tekstury nieba + Global.asCurrentTexturePath = paths::textures; // kiedyś uproszczone wnętrze mieszało tekstury nieba Global.asCurrentDynamicPath = ""; // position sound emitters which weren't defined in the config file diff --git a/vehicle/Train.cpp b/vehicle/Train.cpp index 50fdb489..e512f6b2 100644 --- a/vehicle/Train.cpp +++ b/vehicle/Train.cpp @@ -9311,7 +9311,7 @@ bool TTrain::InitializeCab(int NewCabNo, std::string const &asFileName) TModel3d *kabina = TModelsManager::GetModel(DynamicObject->asBaseDir + token, true, true, (Global.network_servers.empty() && !Global.network_client) ? 0 : id()); // z powrotem defaultowa sciezka do tekstur - Global.asCurrentTexturePath = szTexturePath; + Global.asCurrentTexturePath = paths::textures; // if (DynamicObject->mdKabina!=k) if (kabina != nullptr) { diff --git a/world/Event.cpp b/world/Event.cpp index 015ad7b2..f7513825 100644 --- a/world/Event.cpp +++ b/world/Event.cpp @@ -1654,7 +1654,7 @@ animation_event::deserialize_( cParser &Input, scene::scratch_data &Scratchpad ) { // animacja z pliku VMD { m_animationfilename = token; - std::ifstream file( szModelPath + m_animationfilename, std::ios::binary | std::ios::ate ); file.unsetf( std::ios::skipws ); + std::ifstream file( paths::models + m_animationfilename, std::ios::binary | std::ios::ate ); file.unsetf( std::ios::skipws ); auto size = file.tellg(); // ios::ate already positioned us at the end of the file file.seekg( 0, std::ios::beg ); // rewind the caret afterwards // animation size, previously held in param 7 diff --git a/world/Track.cpp b/world/Track.cpp index f1fb356b..22387323 100644 --- a/world/Track.cpp +++ b/world/Track.cpp @@ -2266,9 +2266,9 @@ TTrack::export_as_text_( std::ostream &Output ) const { m_material1 != null_handle ? GfxRenderer->Material( m_material1 )->GetName() : "none" ) }; - if( texturefile.find( szTexturePath ) == 0 ) { + if( texturefile.find( paths::textures ) == 0 ) { // don't include 'textures/' in the path - texturefile.erase( 0, std::string{ szTexturePath }.size() ); + texturefile.erase( 0, std::string{ paths::textures }.size() ); } Output << texturefile << ' ' @@ -2278,9 +2278,9 @@ TTrack::export_as_text_( std::ostream &Output ) const { m_material2 != null_handle ? GfxRenderer->Material( m_material2 )->GetName() : "none" ); - if( texturefile.find( szTexturePath ) == 0 ) { + if( texturefile.find( paths::textures ) == 0 ) { // don't include 'textures/' in the path - texturefile.erase( 0, std::string{ szTexturePath }.size() ); + texturefile.erase( 0, std::string{ paths::textures }.size() ); } Output << texturefile << ' '; @@ -2351,9 +2351,9 @@ TTrack::export_as_text_( std::ostream &Output ) const { if( ( eType == tt_Switch ) && ( SwitchExtension->m_material3 != null_handle ) ) { auto texturefile { GfxRenderer->Material( m_material2 )->GetName() }; - if( texturefile.find( szTexturePath ) == 0 ) { + if( texturefile.find( paths::textures ) == 0 ) { // don't include 'textures/' in the path - texturefile.erase( 0, std::string{ szTexturePath }.size() ); + texturefile.erase( 0, std::string{ paths::textures }.size() ); } Output << "trackbed " << texturefile << ' '; } @@ -2384,7 +2384,7 @@ std::string TTrack::tooltip() const std::pair TTrack::fetch_track_rail_profile( std::string const &Profile ) { - auto const railprofilepath { std::string( szModelPath ) + "tory/railprofile_" }; + auto const railprofilepath { std::string( paths::models ) + "tory/railprofile_" }; auto const railkeyprefix { std::string( "rail_" ) }; if( m_profiles.empty() ) { @@ -2414,7 +2414,7 @@ TTrack::fetch_default_profiles() { if( false == m_profiles.empty() ) { return; } - auto const railprofilepath { std::string( szModelPath ) + "tory/railprofile_" }; + auto const railprofilepath { std::string( paths::models ) + "tory/railprofile_" }; auto const railkeyprefix { std::string( "rail_" ) }; m_profiles.emplace_back( deserialize_profile( railprofilepath + "default" ) ); diff --git a/world/mtable.cpp b/world/mtable.cpp index c6460248..ba560ff1 100644 --- a/world/mtable.cpp +++ b/world/mtable.cpp @@ -617,7 +617,7 @@ TTrainParameters::load_sounds() { auto const lookup { FileExists( - { Global.asCurrentSceneryPath + stationname, std::string{ szSoundPath } + "sip/" + stationname }, + { Global.asCurrentSceneryPath + stationname, std::string{ paths::sounds } + "sip/" + stationname }, { ".ogg", ".flac", ".wav" } ) }; if( lookup.first.empty() ) { continue;