private void Delete(UInt64 key, MyClipmap_CellData data = null, bool del = true) { data = data ?? m_storedCellData[key]; if (data.Cell != null) { if (UseDithering && data.InScene) { RemoveFromScene(key, data); if (del) { data.DeleteAfterRemove = true; } return; } m_nonEmptyCells.Remove(key); RemoveFromScene(key, data); if (del) { m_clipmap.m_cellHandler.DeleteCell(data.Cell); } } m_storedCellData.Remove(key); data.ReadyInClipmap = false; }
static void OnCellDiscarded(UInt64 cellId, MyClipmap_CellData data) { if (data.Cell != null) { if (!data.ReadyInClipmap) { data.CellHandler.DeleteCell(data.Cell); } } }
public void AddRequest(UInt64 cellId, MyClipmap_CellData data, bool highPriority) { var cellRequest = new CellRequest() { CellId = cellId, Data = data }; m_unsentRequests.Enqueue(cellRequest); data.State = CellState.Invalid; data.HighPriority = highPriority; }
private void RemoveFromScene(UInt64 key, MyClipmap_CellData data = null) { // data = data ?? m_storedCellData[key]; if (data.InScene) { Debug.Assert(data.Cell != null); if (MyClipmap.UseDithering) { CellBlendData blendData; if (!m_blendedCells.TryGetValue(key, out blendData)) { blendData = new CellBlendData(); blendData.CellData = data; System.Diagnostics.Debug.Assert(blendData.CellData.Cell.IsValid(), "Invalid cell!"); blendData.TimeAdded = m_clipmap.m_cellHandler.GetTime(); blendData.State = BlendState.Removing; m_blendedCells.Add(key, blendData); data.Cell.SetDithering(0); } else { if (blendData.State == BlendState.Adding) { blendData.UndoAfterFinish = true; } else { blendData.UndoAfterFinish = false; //blendData.CellData.DeleteAfterRemove = false; } System.Diagnostics.Debug.Assert(blendData.CellData.Cell.IsValid(), "Invalid cell!"); m_blendedCells[key] = blendData; } } else { m_clipmap.m_cellHandler.RemoveFromScene(data.Cell); data.InScene = false; } } }
private void AddToScene(UInt64 key, MyClipmap_CellData data = null) { // data = data ?? m_storedCellData[key]; CellBlendData blendData; bool inScene = data.InScene; if (!data.InScene && !data.ClippedOut) { Debug.Assert(data.Cell != null, "Adding null cell"); if (data.Cell != null) { //System.Diagnostics.Debug.Assert(data.Cell.IsValid(), "Invalid cell!"); if (data.Cell.IsValid()) { m_clipmap.m_cellHandler.AddToScene(data.Cell); data.Cell.SetDithering(0); data.InScene = true; } } } if (MyClipmap.UseDithering) { if (!m_blendedCells.TryGetValue(key, out blendData)) { if (!inScene && data.InScene) { blendData = new CellBlendData(); blendData.CellData = data; blendData.TimeAdded = m_clipmap.m_cellHandler.GetTime(); blendData.State = BlendState.Adding; m_blendedCells.Add(key, blendData); data.Cell.SetDithering(2); } } else { // System.Diagnostics.Debug.Assert(inScene, "We are blending something what was not in scene"); if (inScene) { if (!data.ClippedOut) { if (blendData.State == BlendState.Removing) { blendData.State = BlendState.Adding; blendData.UndoAfterFinish = false; blendData.CellData.DeleteAfterRemove = false; float newEndTime = m_clipmap.m_cellHandler.GetTime() - blendData.TimeAdded; blendData.TimeAdded = m_clipmap.m_cellHandler.GetTime() - CellsDitherTime; } else { blendData.UndoAfterFinish = false; } } m_blendedCells[key] = blendData; } } } }
private void UnclipCell(RequestCollector collector, MyCellCoord cell, bool isVisible) { var cellId = cell.PackId64(); var clipmapCellId = MyCellCoord.GetClipmapCellHash(m_clipmap.Id, cellId); MyClipmap_CellData data; if (isVisible) { bool highPriority = true; if (m_clippedCells.TryGetValue(cellId, out data)) { m_clippedCells.Remove(cellId); } else { highPriority = false; CellBlendData blendData; if (!m_blendedCells.TryGetValue(cellId, out blendData)) { data = CellsCache.Read(clipmapCellId); if (data == null) //cache miss { data = new MyClipmap_CellData(); ClippingCacheMisses++; } else { //cache hit ClippingCacheHits++; //System.Diagnostics.Debug.Assert((!data.InScene && data.Cell != null) || data.Cell == null, "Not allowed cell state"); data.InScene = false; if (data.Cell != null) { m_nonEmptyCells[cellId] = data; } } } else { data = blendData.CellData; if (blendData.State == BlendState.Removing) { blendData.UndoAfterFinish = true; } if (data.Cell != null) { m_nonEmptyCells[cellId] = data; } } } if (data.State == CellState.Invalid) { if (MyClipmap.UseQueries) { BoundingBoxD bbd; MyVoxelCoordSystems.RenderCellCoordToLocalAABB(ref cell, out bbd); BoundingBox bb = new BoundingBox(bbd); if (m_clipmap.m_prunningFunc == null || m_clipmap.m_prunningFunc(ref bb, false) == ContainmentType.Intersects) { collector.AddRequest(cellId, data, highPriority); } else { data.State = CellState.Loaded; data.WasLoaded = true; } } else { collector.AddRequest(cellId, data, highPriority); } } m_storedCellData.Add(cellId, data); data.ReadyInClipmap = true; data.ClippedOut = false; } else { if (!m_storedCellData.ContainsKey(cellId) && (!PendingCacheCellData.ContainsKey(clipmapCellId) || PendingCacheCellData[clipmapCellId].State == CellState.Invalid) && CellsCache.Read(clipmapCellId) == null) { if (!PendingCacheCellData.TryGetValue(clipmapCellId, out data)) { data = new MyClipmap_CellData(); PendingCacheCellData.Add(clipmapCellId, data); } if (MyClipmap.UseQueries) { BoundingBoxD bbd; MyVoxelCoordSystems.RenderCellCoordToLocalAABB(ref cell, out bbd); BoundingBox bb = new BoundingBox(bbd); if (m_clipmap.m_prunningFunc == null || m_clipmap.m_prunningFunc(ref bb, false) == ContainmentType.Intersects) { data.State = CellState.Invalid; collector.AddRequest(cellId, data, false); } else { data.State = CellState.Loaded; data.WasLoaded = true; } } else { data.State = CellState.Invalid; collector.AddRequest(cellId, data, false); } } } }