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

network tweaks

This commit is contained in:
milek7
2019-11-16 14:58:17 +01:00
parent b823e0a5b6
commit c31af696c4
4 changed files with 26 additions and 16 deletions

View File

@@ -42,22 +42,22 @@ TModelsManager::stringmodelcontainerindex_map TModelsManager::m_modelsmap;
// wczytanie modelu do tablicy // wczytanie modelu do tablicy
TModel3d * TModel3d *
TModelsManager::LoadModel(std::string const &Name, bool dynamic) { TModelsManager::LoadModel(std::string const &Name, std::string const &virtualName, bool dynamic) {
m_models.emplace_back(); m_models.emplace_back();
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( virtualName, m_models.size() - 1 );
} }
else { else {
m_models.pop_back(); m_models.pop_back();
m_modelsmap.emplace( Name, null_handle ); m_modelsmap.emplace( virtualName, null_handle );
} }
return model; return model;
} }
TModel3d * TModel3d *
TModelsManager::GetModel(std::string const &Name, bool const Dynamic, bool const Logerrors ) TModelsManager::GetModel(std::string const &Name, bool const Dynamic, bool const Logerrors, int uid )
{ // model może być we wpisie "node...model" albo "node...dynamic", a także być dodatkowym w dynamic { // model może być we wpisie "node...model" albo "node...dynamic", a także być dodatkowym w dynamic
// (kabina, wnętrze, ładunek) // (kabina, wnętrze, ładunek)
// dla "node...dynamic" mamy podaną ścieżkę w "\dynamic\" i musi być co najmniej 1 poziom, zwkle // dla "node...dynamic" mamy podaną ścieżkę w "\dynamic\" i musi być co najmniej 1 poziom, zwkle
@@ -89,9 +89,12 @@ TModelsManager::GetModel(std::string const &Name, bool const Dynamic, bool const
} }
erase_extension( filename ); erase_extension( filename );
filename = ToLower( filename ); filename = ToLower( filename );
std::string postfix;
if (uid != 0)
postfix = "^^" + std::to_string(uid);
// see if we have it in the databank // see if we have it in the databank
auto banklookup { find_in_databank( filename ) }; auto banklookup { find_in_databank( filename + postfix ) };
TModel3d *model { banklookup.second }; TModel3d *model { banklookup.second };
if( true == banklookup.first ) { if( true == banklookup.first ) {
Global.asCurrentTexturePath = buftp; Global.asCurrentTexturePath = buftp;
@@ -102,7 +105,7 @@ TModelsManager::GetModel(std::string const &Name, bool const Dynamic, bool const
std::string disklookup { find_on_disk( filename ) }; std::string disklookup { find_on_disk( filename ) };
if( false == disklookup.empty() ) { if( false == disklookup.empty() ) {
model = LoadModel( disklookup, Dynamic ); // model nie znaleziony, to wczytać model = LoadModel( disklookup, disklookup + postfix, 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...
@@ -110,7 +113,7 @@ TModelsManager::GetModel(std::string const &Name, bool const Dynamic, bool const
ErrorLog( "Bad file: failed to locate 3d model file \"" + filename + "\"", logtype::file ); ErrorLog( "Bad file: failed to locate 3d model file \"" + filename + "\"", logtype::file );
} }
// ...and link it with the error model slot // ...and link it with the error model slot
m_modelsmap.emplace( filename, null_handle ); m_modelsmap.emplace( filename + postfix, 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

View File

@@ -22,7 +22,7 @@ private:
class TModelsManager { class TModelsManager {
public: public:
// McZapkie: dodalem sciezke, notabene Path!=Patch :) // McZapkie: dodalem sciezke, notabene Path!=Patch :)
static TModel3d *GetModel( std::string const &Name, bool const dynamic = false, bool const Logerrors = true ); static TModel3d *GetModel(std::string const &Name, bool const dynamic = false, bool const Logerrors = true , int uid = 0);
private: private:
// types: // types:
@@ -32,7 +32,7 @@ private:
static modelcontainer_sequence m_models; static modelcontainer_sequence m_models;
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, const std::string &virtualName, bool const Dynamic );
static std::pair<bool, 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

@@ -5315,10 +5315,11 @@ void TTrain::OnCommand_radiocall3send( TTrain *Train, command_data const &Comman
void TTrain::OnCommand_cabchangeforward( TTrain *Train, command_data const &Command ) { void TTrain::OnCommand_cabchangeforward( TTrain *Train, command_data const &Command ) {
if( Command.action == GLFW_PRESS ) { if( Command.action == GLFW_PRESS ) {
auto const movedirection { auto ownerDir = Train->DynamicObject->ctOwner ? Train->DynamicObject->ctOwner->Vehicle( end::front )->DirectionGet() : 1;
1 * ( Train->DynamicObject->ctOwner->Vehicle( end::front )->DirectionGet() == Train->DynamicObject->DirectionGet() ? auto const movedirection {
1 * ( ownerDir == Train->DynamicObject->DirectionGet() ?
1 : 1 :
-1 ) }; -1 ) };
if( false == Train->CabChange( movedirection ) ) { if( false == Train->CabChange( movedirection ) ) {
auto const exitdirection { ( auto const exitdirection { (
movedirection > 0 ? movedirection > 0 ?
@@ -5346,8 +5347,9 @@ void TTrain::OnCommand_cabchangeforward( TTrain *Train, command_data const &Comm
void TTrain::OnCommand_cabchangebackward( TTrain *Train, command_data const &Command ) { void TTrain::OnCommand_cabchangebackward( TTrain *Train, command_data const &Command ) {
if( Command.action == GLFW_PRESS ) { if( Command.action == GLFW_PRESS ) {
auto ownerDir = Train->DynamicObject->ctOwner ? Train->DynamicObject->ctOwner->Vehicle( end::front )->DirectionGet() : 1;
auto const movedirection { auto const movedirection {
-1 * ( Train->DynamicObject->ctOwner->Vehicle( end::front )->DirectionGet() == Train->DynamicObject->DirectionGet() ? -1 * ( ownerDir == Train->DynamicObject->DirectionGet() ?
1 : 1 :
-1 ) }; -1 ) };
if( false == Train->CabChange( movedirection ) ) { if( false == Train->CabChange( movedirection ) ) {
@@ -7349,7 +7351,8 @@ bool TTrain::InitializeCab(int NewCabNo, std::string const &asFileName)
if( token[ 0 ] == '/' ) { if( token[ 0 ] == '/' ) {
token.erase( 0, 1 ); token.erase( 0, 1 );
} }
TModel3d *kabina = TModelsManager::GetModel(DynamicObject->asBaseDir + token, true); TModel3d *kabina = TModelsManager::GetModel(DynamicObject->asBaseDir + token, true, true,
(Global.network_servers.empty() && !Global.network_client) ? 0 : id());
// z powrotem defaultowa sciezka do tekstur // z powrotem defaultowa sciezka do tekstur
Global.asCurrentTexturePath = szTexturePath; Global.asCurrentTexturePath = szTexturePath;
// if (DynamicObject->mdKabina!=k) // if (DynamicObject->mdKabina!=k)

View File

@@ -253,9 +253,13 @@ eu07_application::run() {
if (m_network && m_network->client) if (m_network && m_network->client)
{ {
// verify sync // verify sync
if (sync != slave_sync) { if (sync != slave_sync) {
WriteLog("net: desync! calculated: " + std::to_string(sync) WriteLog("net: desync! calculated: " + std::to_string(sync)
+ ", received: " + std::to_string(slave_sync), logtype::net); + ", received: " + std::to_string(slave_sync), logtype::net);
ImGui::Begin("NET");
ImGui::TextUnformatted("desync!");
ImGui::End();
} }
// set total delta for rendering code // set total delta for rendering code