public static void SwapChunk(this ClipmapCell clipmapCell, ClipmapChunk nullableClipmapChunk) { if (clipmapCell.IsVisible()) { if (nullableClipmapChunk) { Logger.Debug($"{clipmapCell}: Showing new chunk"); nullableClipmapChunk.Show(); } } var oldClipmapChunk = clipmapCell.chunk; if (oldClipmapChunk) { #if BelowZero if (!clipmapCell.streamer.host.terrainPoolManager.meshPoolingEnabled) { MeshBuilder.DestroyMeshes(oldClipmapChunk); } clipmapCell.ReturnChunkToPool(oldClipmapChunk); #else MeshBuilder.DestroyMeshes(oldClipmapChunk); if (oldClipmapChunk.gameObject) { UnityEngine.Object.Destroy(oldClipmapChunk.gameObject); } #endif } clipmapCell.chunk = nullableClipmapChunk; }
public static void OnEndBuildLayers(this ClipmapLevel clipmapLevel, ClipmapCell clipmapCell, ClipmapChunk nullableClipmapChunk) { nullableClipmapChunks[clipmapLevel.id][clipmapCell.id] = nullableClipmapChunk; remainingCellCount[clipmapLevel.id]--; Logger.Debug($"Decrementing remainingCellCount to {remainingCellCount[clipmapLevel.id]}"); if (remainingCellCount[clipmapLevel.id] <= 0) { clipmapLevel.SwapChunks(nullableClipmapChunks[clipmapLevel.id]); nullableClipmapChunks[clipmapLevel.id].Clear(); if (remainingCellCount.All((levelCountPair) => levelCountPair.Value <= 0)) { isMeshesRebuilding = false; Logger.Debug($"{clipmapLevel}: Mesh building finished with 'remainingCellCount' of {remainingCellCount[clipmapLevel.id]}"); if (rebuildingMessage != null) { ErrorMessageExtensions.SetMessageTimeEnd(rebuildingMessage, Time.time); ErrorMessageExtensions.pendingMessageToRemove = rebuildingMessage; rebuildingMessage = null; } } } else if (rebuildingMessage != null) { var oldTimeEnd = ErrorMessageExtensions.GetMessageTimeEnd(rebuildingMessage); var timeFadeOut = ErrorMessageExtensions.GetTimeFadeOut(); if (oldTimeEnd - timeFadeOut < Time.time) { rebuildingMessage = ErrorMessageExtensions.AddReturnMessage(rebuildingTerrainMsg); } } }
public static bool IsVisible(this ClipmapCell clipmapCell) { var clipmapCellState = clipmapCell.state; var visibleState = ClipmapCell.State.Visible; Logger.Debug($"clipmapCellState {clipmapCellState}, visibleState {visibleState} => {clipmapCellState.Equals(visibleState)}"); return(clipmapCellState.Equals(visibleState)); }
public static void RebuildLayers(this ClipmapCell clipmapCell, MeshBuilder meshBuilder, out ClipmapChunk clipmapChunk) { Logger.Debug($"{clipmapCell}: Begin"); var host = clipmapCell.level.streamer.host; clipmapChunk = meshBuilder.DoFinalizePart(host.chunkRoot, host.chunkPrefab, host.chunkLayerPrefab); clipmapCell.level.streamer.meshBuilderPool.Return(meshBuilder); Logger.Debug($"{clipmapCell}: End"); }
public static void RebuildMesh(this ClipmapCell clipmapCell, out MeshBuilder meshBuilder) { Logger.Debug($"{clipmapCell}: Begin"); var clipmapStreamer = clipmapCell.streamer; var octreesStreamer = clipmapStreamer.host.GetOctreesStreamer(clipmapCell.level.id); meshBuilder = clipmapStreamer.meshBuilderPool.Get(); meshBuilder.Reset(clipmapCell.level.id, clipmapCell.id, clipmapCell.level.cellSize, clipmapCell.level.settings, clipmapStreamer.host.blockTypes); meshBuilder.DoThreadablePart(octreesStreamer, clipmapStreamer.settings.collision); Logger.Debug($"{clipmapCell}: End"); }
public static IEnumerator RebuildLayersAsync(this ClipmapCell clipmapCell, MeshBuilder meshBuilder) { Logger.Debug($"{clipmapCell}: Begin"); ClipmapChunk nullableClipmapChunk = null; if (clipmapCell.streamer != null && clipmapCell.streamer.host != null) { var host = clipmapCell.level.streamer.host; nullableClipmapChunk = meshBuilder.DoFinalizePart(host.chunkRoot, host.terrainPoolManager); clipmapCell.streamer.meshBuilderPool.Return(meshBuilder); yield return(clipmapCell.ActivateChunkAndCollider(nullableClipmapChunk)); } clipmapCell.level.OnEndBuildLayers(clipmapCell, nullableClipmapChunk); Logger.Debug($"{clipmapCell}: End"); yield break; }
private static List <ClipmapCell> GetProcessingCells(this ClipmapLevel clipmapLevel, List <Int3.Bounds> blockRanges) { var processingCells = new List <ClipmapCell>(); foreach (var blockRange in blockRanges) { var cellBounds = clipmapLevel.GetCellRange(blockRange); foreach (Int3 cellId in cellBounds) { ClipmapCell cell = clipmapLevel.GetCell(cellId); if (cell != null) { if (!processingCells.Contains(cell)) { processingCells.Add(cell); } } } } return(processingCells); }
public static void OnBatchOctreesEdited(this ClipmapCell clipmapCell) { Logger.Debug($"Enqueing RebuildMeshTask of {clipmapCell}"); clipmapCell.level.streamer.meshingThreads.Enqueue(new Task.Function(RebuildMeshTask), clipmapCell, null); Logger.Debug($"End enqueing RebuildMeshTask of {clipmapCell}"); }