Skip to content

Commit

Permalink
Cvar 'mp_cyclethru_net_actors(bool)' - for cycling with CTRL + [ an…
Browse files Browse the repository at this point in the history
…d `CTRL + ]`

Also configurable in MultiplayerSelector UI, "Settings" tab.
  • Loading branch information
ohlidalp committed Oct 2, 2023
1 parent 91f99be commit c1a3527
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 16 deletions.
1 change: 1 addition & 0 deletions source/main/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions source/main/Application.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions source/main/gui/panels/GUI_MultiplayerSelector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
47 changes: 31 additions & 16 deletions source/main/physics/ActorManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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;
Expand All @@ -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<int>(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)
Expand Down
2 changes: 2 additions & 0 deletions source/main/system/CVar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down

0 comments on commit c1a3527

Please sign in to comment.