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
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();
auto model = m_models.back().LoadModel( Name, dynamic );
if( model != nullptr ) {
m_modelsmap.emplace( Name, m_models.size() - 1 );
m_modelsmap.emplace( virtualName, m_models.size() - 1 );
}
else {
m_models.pop_back();
m_modelsmap.emplace( Name, null_handle );
m_modelsmap.emplace( virtualName, null_handle );
}
return model;
}
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
// (kabina, wnętrze, ładunek)
// 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 );
filename = ToLower( filename );
std::string postfix;
if (uid != 0)
postfix = "^^" + std::to_string(uid);
// see if we have it in the databank
auto banklookup { find_in_databank( filename ) };
// see if we have it in the databank
auto banklookup { find_in_databank( filename + postfix ) };
TModel3d *model { banklookup.second };
if( true == banklookup.first ) {
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 ) };
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 {
// 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 );
}
// ...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
return model; // NULL jeśli błąd

View File

@@ -22,7 +22,7 @@ private:
class TModelsManager {
public:
// 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:
// types:
@@ -32,7 +32,7 @@ private:
static modelcontainer_sequence m_models;
static stringmodelcontainerindex_map m_modelsmap;
// 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 );
// checks whether specified file exists. returns name of the located file, or empty string.
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 ) {
if( Command.action == GLFW_PRESS ) {
auto const movedirection {
1 * ( Train->DynamicObject->ctOwner->Vehicle( end::front )->DirectionGet() == Train->DynamicObject->DirectionGet() ?
auto ownerDir = Train->DynamicObject->ctOwner ? Train->DynamicObject->ctOwner->Vehicle( end::front )->DirectionGet() : 1;
auto const movedirection {
1 * ( ownerDir == Train->DynamicObject->DirectionGet() ?
1 :
-1 ) };
-1 ) };
if( false == Train->CabChange( movedirection ) ) {
auto const exitdirection { (
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 ) {
if( Command.action == GLFW_PRESS ) {
auto ownerDir = Train->DynamicObject->ctOwner ? Train->DynamicObject->ctOwner->Vehicle( end::front )->DirectionGet() : 1;
auto const movedirection {
-1 * ( Train->DynamicObject->ctOwner->Vehicle( end::front )->DirectionGet() == Train->DynamicObject->DirectionGet() ?
-1 * ( ownerDir == Train->DynamicObject->DirectionGet() ?
1 :
-1 ) };
if( false == Train->CabChange( movedirection ) ) {
@@ -7349,7 +7351,8 @@ bool TTrain::InitializeCab(int NewCabNo, std::string const &asFileName)
if( token[ 0 ] == '/' ) {
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
Global.asCurrentTexturePath = szTexturePath;
// if (DynamicObject->mdKabina!=k)

View File

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