Skip to content
Merged
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
117 changes: 83 additions & 34 deletions Client/game_sa/CIplStoreSA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,52 @@ CIplStoreSA::CIplStoreSA() : m_isStreamingEnabled(true), m_ppIplPoolInterface((C

void CIplStoreSA::UnloadAndDisableStreaming(int iplId)
{
// Is pool valid?
if (!m_ppIplPoolInterface)
return;

// Is pool object valid?
auto pool = *m_ppIplPoolInterface;
if (!pool)
return;

// Is IPL in pool?
if (!pool->IsContains(iplId))
return;

// Is IPL object valid?
auto ipl = pool->GetObject(iplId);
if (!ipl)
return;

typedef void*(__cdecl * Function_EnableStreaming)(int);
((Function_EnableStreaming)(0x405890))(iplId);
}

void CIplStoreSA::EnableStreaming(int iplId)
{
auto ipl = (*m_ppIplPoolInterface)->GetObject(iplId);
// Is pool valid?
if (!m_ppIplPoolInterface)
return;

// Is pool object valid?
auto pool = *m_ppIplPoolInterface;
if (!pool)
return;

// Is IPL in pool?
if (!pool->IsContains(iplId))
return;

// Is IPL object valid?
auto ipl = pool->GetObject(iplId);
if (!ipl)
return;

ipl->bDisabledStreaming = false;

(*gIplQuadTree)->AddItem(ipl, &ipl->rect);
if (*gIplQuadTree)
(*gIplQuadTree)->AddItem(ipl, &ipl->rect);
}

void CIplStoreSA::SetDynamicIplStreamingEnabled(bool state)
Expand All @@ -42,27 +78,33 @@ void CIplStoreSA::SetDynamicIplStreamingEnabled(bool state)
// Ipl with 0 index is generic
// We don't unload this IPL

auto pPool = *m_ppIplPoolInterface;
auto pool = *m_ppIplPoolInterface;
if (!pool)
return;

// Collect all IPL ids
std::vector<int> iplIds;
iplIds.reserve(pool->m_nSize);

for (int i = 1; i < pool->m_nSize; i++)
{
if (pool->IsContains(i))
iplIds.push_back(i);
}

// Now enable/disable streaming for all IPLs
if (!state)
{
for (int i = 1; i < pPool->m_nSize; i++)
{
if (pPool->IsContains(i))
{
UnloadAndDisableStreaming(i);
}
}
(*gIplQuadTree)->RemoveAllItems();
for (int iplId : iplIds)
UnloadAndDisableStreaming(iplId);

if (*gIplQuadTree)
(*gIplQuadTree)->RemoveAllItems();
}
else
{
for (int i = 1; i < pPool->m_nSize; i++)
{
if (pPool->IsContains(i))
{
EnableStreaming(i);
}
}
for (int iplId : iplIds)
EnableStreaming(iplId);
}

m_isStreamingEnabled = state;
Expand All @@ -76,27 +118,34 @@ void CIplStoreSA::SetDynamicIplStreamingEnabled(bool state, std::function<bool(C
// Ipl with 0 index is generic
// We don't unload this IPL

auto pPool = *m_ppIplPoolInterface;
auto pool = *m_ppIplPoolInterface;
if (!pool)
return;

// Collect IPL ids that match the filter
std::vector<int> iplIds;
iplIds.reserve(pool->m_nSize);

for (int i = 1; i < pool->m_nSize; i++)
{
auto ipl = pool->GetObject(i);
if (ipl && pool->IsContains(i) && filter(ipl))
iplIds.push_back(i);
}

// Apply the streaming state change
if (!state)
{
for (int i = 1; i < pPool->m_nSize; i++)
{
if (pPool->IsContains(i) && filter(pPool->GetObject(i)))
{
UnloadAndDisableStreaming(i);
}
}
(*gIplQuadTree)->RemoveAllItems();
for (int iplId : iplIds)
UnloadAndDisableStreaming(iplId);

if (*gIplQuadTree)
(*gIplQuadTree)->RemoveAllItems();
}
else
{
for (int i = 1; i < pPool->m_nSize; i++)
{
if (pPool->IsContains(i) && filter(pPool->GetObject(i)))
{
EnableStreaming(i);
}
}
for (int iplId : iplIds)
EnableStreaming(iplId);
}

m_isStreamingEnabled = state;
Expand Down