Skip to content

Preserve vehicle component visibility #4287

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions Client/mods/deathmatch/logic/CClientVehicle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1090,7 +1090,10 @@ void CClientVehicle::SetModelBlocking(unsigned short usModel, unsigned char ucVa

SetSirenOrAlarmActive(false);

// clear our component data to regenerate it
// Cache current component visibility and clear data so it can be regenerated.
m_ComponentVisibilityBackup.clear();
for (const auto& pair : m_ComponentData)
m_ComponentVisibilityBackup[pair.first] = pair.second.m_bVisible;
m_ComponentData.clear();

// Reset stored dummy positions
Expand Down Expand Up @@ -1118,7 +1121,11 @@ void CClientVehicle::SetVariant(unsigned char ucVariant, unsigned char ucVariant
m_ucVariation = ucVariant;
m_ucVariation2 = ucVariant2;

// clear our component data to regenerate it
// Cache visibility so component state survives variant changes
m_ComponentVisibilityBackup.clear();
for (const auto& pair : m_ComponentData)
m_ComponentVisibilityBackup[pair.first] = pair.second.m_bVisible;
// Clear component data to regenerate it on next create
m_ComponentData.clear();

ReCreate();
Expand Down Expand Up @@ -2858,6 +2865,22 @@ void CClientVehicle::Create()
}
}
}

// Merge saved visibility data from previous variant/handling updates
if (!m_ComponentVisibilityBackup.empty())
{
for (const auto& pair : m_ComponentVisibilityBackup)
{
auto it = m_ComponentData.find(pair.first);
if (it != m_ComponentData.end())
{
it->second.m_bVisible = pair.second;
SetComponentVisible(pair.first, pair.second);
}
}
m_ComponentVisibilityBackup.clear();
}

// Grab our component data
std::map<SString, SVehicleComponentData>::iterator iter = m_ComponentData.begin();
// Loop through our component data
Expand Down
2 changes: 2 additions & 0 deletions Client/mods/deathmatch/logic/CClientVehicle.h
Original file line number Diff line number Diff line change
Expand Up @@ -754,6 +754,8 @@ class CClientVehicle : public CClientStreamElement
SLastSyncedVehData* m_LastSyncedData;
SSirenInfo m_tSirenBeaconInfo;
std::map<SString, SVehicleComponentData> m_ComponentData;
// Store visibility state when the component map is regenerated
std::map<SString, bool> m_ComponentVisibilityBackup;
bool m_bAsyncLoadingDisabled;

std::array<CVector, static_cast<std::size_t>(VehicleDummies::VEHICLE_DUMMY_COUNT)> m_dummyPositions;
Expand Down
Loading