Skip to content
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

Maintain APV cells loaded if at least one scene still references that cell #5900

Merged
merged 5 commits into from
Oct 8, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,15 @@ public struct ExtraDataActionInput
// List of info for cells that are yet to be loaded.
private List<CellSortInfo> m_CellsToBeLoaded = new List<CellSortInfo>();


// Ref counting here as a separate dictionary as a temporary measure to facilitate future changes that will soon go in.
// cell.index, refCount
Dictionary<int, int> m_CellRefCounting = new Dictionary<int, int>();
void InvalidateAllCellRefs()
{
m_CellRefCounting.Clear();
}

bool m_NeedLoadAsset = false;
bool m_ProbeReferenceVolumeInit = false;
bool m_EnabledBySRP = false;
Expand Down Expand Up @@ -693,20 +702,34 @@ void RemoveCell(Cell cell)
{
if (cell.loaded)
{
if (cells.ContainsKey(cell.index))
cells.Remove(cell.index);
bool needsUnloading = true;
if (m_CellRefCounting.ContainsKey(cell.index))
{
m_CellRefCounting[cell.index]--;
needsUnloading = m_CellRefCounting[cell.index] <= 0;
if (needsUnloading)
{
m_CellRefCounting[cell.index] = 0;
}
}

if (m_ChunkInfo.ContainsKey(cell.index))
m_ChunkInfo.Remove(cell.index);
if (needsUnloading)
{
if (cells.ContainsKey(cell.index))
cells.Remove(cell.index);

if (cell.flatIdxInCellIndices >= 0)
m_CellIndices.MarkCellAsUnloaded(cell.flatIdxInCellIndices);
if (m_ChunkInfo.ContainsKey(cell.index))
m_ChunkInfo.Remove(cell.index);

RegId cellBricksID = new RegId();
if (m_CellToBricks.TryGetValue(cell, out cellBricksID))
{
ReleaseBricks(cellBricksID);
m_CellToBricks.Remove(cell);
if (cell.flatIdxInCellIndices >= 0)
m_CellIndices.MarkCellAsUnloaded(cell.flatIdxInCellIndices);

RegId cellBricksID = new RegId();
if (m_CellToBricks.TryGetValue(cell, out cellBricksID))
{
ReleaseBricks(cellBricksID);
m_CellToBricks.Remove(cell);
}
}
}

Expand All @@ -715,6 +738,9 @@ void RemoveCell(Cell cell)

void AddCell(Cell cell, List<Chunk> chunks)
{
if (m_CellRefCounting.ContainsKey(cell.index)) m_CellRefCounting[cell.index]++;
else m_CellRefCounting.Add(cell.index, 1);

cell.loaded = true;
cells[cell.index] = cell;

Expand Down Expand Up @@ -898,6 +924,9 @@ void PerformPendingLoading()
// Load the ones that are already active but reload if we said we need to load
if (m_HasChangedIndex)
{
// We changed index so all assets are going to be re-loaded, hence the refs will be repopulated from scratch
InvalidateAllCellRefs();

foreach (var asset in m_ActiveAssets.Values)
{
LoadAsset(asset);
Expand Down