internal void DiscardClippedCells(RequestCollector collector) { foreach (var entry in m_clippedCells) { var data = entry.Value; data.ClippedOut = true; if (UseCache) { var clipmapCellId = MyCellCoord.GetClipmapCellHash(m_clipmap.Id, entry.Key); CellsCache.Write(clipmapCellId, data); Delete(entry.Key, data, false); } else { if (data.Cell != null) { Delete(entry.Key, data); } data.ReadyInClipmap = false; } } m_clippedCells.Clear(); }
internal void KeepOrDiscardClippedCells(RequestCollector collector) { LodLevel parentLod, childLod; GetNearbyLodLevels(out parentLod, out childLod); MyCellCoord thisLodCell = new MyCellCoord(); foreach (var entry in m_clippedCells) { var data = entry.Value; bool needed = false; // too far, but less detailed data might be missing so we still check parent thisLodCell.SetUnpack(entry.Key); needed = !WasAncestorCellLoaded(parentLod, ref thisLodCell); if (needed) { if (data.State == CellState.Invalid) { if (!TryAddCellRequest(collector, parentLod, thisLodCell, entry.Key, data)) { continue; } } m_storedCellData.Add(entry.Key, data); } else { if (UseCache && data.State == CellState.Loaded) { var clipmapCellId = MyCellCoord.GetClipmapCellHash(m_clipmap.Id, entry.Key); CellsCache.Write(clipmapCellId, data); Delete(entry.Key, data, false); } else { if (data.State == CellState.Pending) { collector.CancelRequest(entry.Key); } if (data.Cell != null) { Delete(entry.Key, data); } } if (!UseCache) { CellsCache.Reset(); } } } m_clippedCells.Clear(); }
internal void SetCellMesh(MyRenderMessageUpdateClipmapCell msg) { var cellId = msg.Metadata.Cell.PackId64(); CellData data; var clipmapCellId = MyCellCoord.GetClipmapCellHash(m_clipmap.Id, cellId); // MyCellCoord cellc = new MyCellCoord(); // cellc.SetUnpack(cellId); //MyLog.Default.WriteLine("SetCellMesh Lod: " + cellc.Lod + " Coord: " + cellc.CoordInLod); if (m_storedCellData.TryGetValue(cellId, out data)) { PendingCacheCellData.Remove(clipmapCellId); if (data.State == CellState.Invalid) { // MyLog.Default.WriteLine("Invalid"); //Cell was invalidated while calculating from old data return; } if (data.Cell == null && msg.Batches.Count != 0) { //MyLog.Default.WriteLine("added to nonempty"); data.Cell = m_clipmap.m_cellHandler.CreateCell(m_clipmap.m_scaleGroup, msg.Metadata.Cell, ref m_clipmap.m_worldMatrix); System.Diagnostics.Debug.Assert(data.Cell != null, "Cell not created"); if (data.Cell != null) { if (data.Cell.IsValid()) { data.CellHandler = m_clipmap.m_cellHandler; m_nonEmptyCells[cellId] = data; } } } else if (data.Cell != null && msg.Batches.Count == 0) { //MyLog.Default.WriteLine("removed"); RemoveFromScene(cellId, data); m_nonEmptyCells.Remove(cellId); m_clipmap.m_cellHandler.DeleteCell(data.Cell); m_blendedCells.Remove(cellId); data.Cell = null; data.CellHandler = null; if (UseCache) { CellsCache.Remove(cellId); } } if (data.Cell != null) { //MyLog.Default.WriteLine("mesh updated"); if (data.Cell.IsValid()) { m_clipmap.m_cellHandler.UpdateMesh(data.Cell, msg); } } data.State = CellState.Loaded; data.WasLoaded = true; } else if (PendingCacheCellData.TryGetValue(clipmapCellId, out data)) { if (msg.Batches.Count != 0) { data.Cell = m_clipmap.m_cellHandler.CreateCell(m_clipmap.m_scaleGroup, msg.Metadata.Cell, ref m_clipmap.m_worldMatrix); m_clipmap.m_cellHandler.UpdateMesh(data.Cell, msg); data.CellHandler = m_clipmap.m_cellHandler; } CellsCache.Write(clipmapCellId, data); PendingCacheCellData.Remove(clipmapCellId); data.State = CellState.Loaded; data.WasLoaded = true; } }