From c1a3527a7e1ad88adcba529e65429e5c0e3fccd3 Mon Sep 17 00:00:00 2001 From: Petr Ohlidal Date: Tue, 11 Jul 2023 10:03:08 +0200 Subject: [PATCH] Cvar 'mp_cyclethru_net_actors(bool)' - for cycling with `CTRL + [` and `CTRL + ]` Also configurable in MultiplayerSelector UI, "Settings" tab. --- source/main/Application.cpp | 1 + source/main/Application.h | 1 + .../gui/panels/GUI_MultiplayerSelector.cpp | 1 + source/main/physics/ActorManager.cpp | 47 ++++++++++++------- source/main/system/CVar.cpp | 2 + 5 files changed, 36 insertions(+), 16 deletions(-) diff --git a/source/main/Application.cpp b/source/main/Application.cpp index 67eabaa417..5c6056d222 100644 --- a/source/main/Application.cpp +++ b/source/main/Application.cpp @@ -123,6 +123,7 @@ CVar* mp_server_password; CVar* mp_player_name; CVar* mp_player_token; CVar* mp_api_url; +CVar* mp_cyclethru_net_actors; // New remote API CVar* remote_query_url; diff --git a/source/main/Application.h b/source/main/Application.h index 6befcc5813..6193766180 100644 --- a/source/main/Application.h +++ b/source/main/Application.h @@ -326,6 +326,7 @@ extern CVar* mp_server_password; extern CVar* mp_player_name; extern CVar* mp_player_token; extern CVar* mp_api_url; +extern CVar* mp_cyclethru_net_actors; //!< Include remote actors when cycling through with CTRL + [ and CTRL + ] // New remote API extern CVar* remote_query_url; diff --git a/source/main/gui/panels/GUI_MultiplayerSelector.cpp b/source/main/gui/panels/GUI_MultiplayerSelector.cpp index 77fa3f4878..d41bc3afa1 100644 --- a/source/main/gui/panels/GUI_MultiplayerSelector.cpp +++ b/source/main/gui/panels/GUI_MultiplayerSelector.cpp @@ -193,6 +193,7 @@ void MultiplayerSelector::DrawSetupTab() DrawGCheckbox(App::mp_hide_net_labels, _LC("MultiplayerSelector", "Hide net labels")); DrawGCheckbox(App::mp_hide_own_net_label, _LC("MultiplayerSelector", "Hide own net label")); DrawGCheckbox(App::mp_pseudo_collisions, _LC("MultiplayerSelector", "Multiplayer collisions")); + DrawGCheckbox(App::mp_cyclethru_net_actors, _LC("MultiplayerSelector", "Include remote actors when cycling via hotkeys")); ImGui::SetCursorPosY(ImGui::GetCursorPosY() + BUTTONS_EXTRA_SPACE); ImGui::Separator(); diff --git a/source/main/physics/ActorManager.cpp b/source/main/physics/ActorManager.cpp index 39d4f8b88f..f002f90845 100644 --- a/source/main/physics/ActorManager.cpp +++ b/source/main/physics/ActorManager.cpp @@ -953,6 +953,9 @@ void ActorManager::DeleteActorInternal(ActorPtr actor) m_actors[i]->ar_vector_index = i; } +// ACTORLIST for cycling with hotkeys +// ---------------------------------- + int FindPivotActorId(ActorPtr player, ActorPtr prev_player) { if (player != nullptr) @@ -962,29 +965,42 @@ int FindPivotActorId(ActorPtr player, ActorPtr prev_player) return -1; } +bool ShouldIncludeActorInList(const ActorPtr& actor) +{ + bool retval = !actor->isPreloadedWithTerrain(); + + // Exclude remote actors, if desired + if (!App::mp_cyclethru_net_actors->getBool()) + { + if (actor->ar_state == ActorState::NETWORKED_OK || actor->ar_state == ActorState::NETWORKED_HIDDEN) + { + retval = false; + } + } + + return retval; +} + const ActorPtr& ActorManager::FetchNextVehicleOnList(ActorPtr player, ActorPtr prev_player) { int pivot_index = FindPivotActorId(player, prev_player); for (int i = pivot_index + 1; i < m_actors.size(); i++) { - if (m_actors[i]->ar_state != ActorState::NETWORKED_OK && !m_actors[i]->isPreloadedWithTerrain()) - { + if (ShouldIncludeActorInList(m_actors[i])) return m_actors[i]; - } } for (int i = 0; i < pivot_index; i++) { - if (m_actors[i]->ar_state != ActorState::NETWORKED_OK && !m_actors[i]->isPreloadedWithTerrain()) - { + if (ShouldIncludeActorInList(m_actors[i])) return m_actors[i]; - } } - if (pivot_index >= 0 && m_actors[pivot_index]->ar_state != ActorState::NETWORKED_OK && !m_actors[pivot_index]->isPreloadedWithTerrain()) + if (pivot_index >= 0) { - return m_actors[pivot_index]; + if (ShouldIncludeActorInList(m_actors[pivot_index])) + return m_actors[pivot_index]; } return ACTORPTR_NULL; @@ -996,28 +1012,27 @@ const ActorPtr& ActorManager::FetchPreviousVehicleOnList(ActorPtr player, ActorP for (int i = pivot_index - 1; i >= 0; i--) { - if (m_actors[i]->ar_state != ActorState::NETWORKED_OK && !m_actors[i]->isPreloadedWithTerrain()) - { + if (ShouldIncludeActorInList(m_actors[i])) return m_actors[i]; - } } for (int i = static_cast(m_actors.size()) - 1; i > pivot_index; i--) { - if (m_actors[i]->ar_state != ActorState::NETWORKED_OK && !m_actors[i]->isPreloadedWithTerrain()) - { + if (ShouldIncludeActorInList(m_actors[i])) return m_actors[i]; - } } - if (pivot_index >= 0 && m_actors[pivot_index]->ar_state != ActorState::NETWORKED_OK && !m_actors[pivot_index]->isPreloadedWithTerrain()) + if (pivot_index >= 0) { - return m_actors[pivot_index]; + if (ShouldIncludeActorInList(m_actors[pivot_index])) + return m_actors[pivot_index]; } return ACTORPTR_NULL; } +// END actorlist + const ActorPtr& ActorManager::FetchRescueVehicle() { for (ActorPtr& actor: m_actors) diff --git a/source/main/system/CVar.cpp b/source/main/system/CVar.cpp index a4aa4f887b..37f03184d4 100644 --- a/source/main/system/CVar.cpp +++ b/source/main/system/CVar.cpp @@ -72,6 +72,8 @@ void Console::cVarSetupBuiltins() App::mp_player_name = this->cVarCreate("mp_player_name", "Nickname", CVAR_ARCHIVE, "Player"); App::mp_player_token = this->cVarCreate("mp_player_token", "User Token", CVAR_ARCHIVE | CVAR_NO_LOG); App::mp_api_url = this->cVarCreate("mp_api_url", "Online API URL", CVAR_ARCHIVE, "http://api.rigsofrods.org"); + App::mp_cyclethru_net_actors = this->cVarCreate("mp_cyclethru_net_actors", "", CVAR_ARCHIVE | CVAR_TYPE_BOOL, "false"); + App::remote_query_url = this->cVarCreate("remote_query_url", "", CVAR_ARCHIVE, "https://v2.api.rigsofrods.org"); App::diag_auto_spawner_report= this->cVarCreate("diag_auto_spawner_report","AutoActorSpawnerReport", CVAR_ARCHIVE | CVAR_TYPE_BOOL, "false");