public void ProcessChunks() { Profiler.BeginSample("ProcessChunks"); HandleVisibility(); // Process removal requests for (int i = 0; i < m_updateRequests.Count;) { Chunk chunk = m_updateRequests[i]; ProcessChunk(chunk); // Update the chunk if possible if (chunk.CanUpdate) { chunk.UpdateState(); chunk.UpdateRenderGeometry(); chunk.UpdateCollisionGeometry(); } // Automatically collect chunks which are ready to be removed from the world ChunkStateManagerClient stateManager = chunk.stateManager; if (stateManager.IsStateCompleted(ChunkState.Remove)) { // Remove the chunk from our provider and unregister it from chunk storage world.chunks.RemoveChunk(chunk); // Unregister from updates m_updateRequests.RemoveAt(i); continue; } ++i; } world.PerformBlockActions(); FullLoadOnStartUp = false; Profiler.EndSample(); // Memory savings diagnostic /*{ * long compressedMem = 0; * foreach (var chunk in world.chunks.chunkCollection) * { * compressedMem += chunk.blocks.BlocksCompressed.Count* * StructSerialization.TSSize<BlockDataAABB>.ValueSize; * } * * long uncompressedMem = (long)world.chunks.Count*Env.ChunkSizeWithPaddingPow3* * StructSerialization.TSSize<BlockData>.ValueSize; * Debug.LogFormat("mem: {0}/{1} ({2}%)", compressedMem, uncompressedMem, (int)((double)compressedMem/(double)uncompressedMem*100.0)); * }*/ }
public void ProcessChunks() { Profiler.BeginSample("ProcessChunks"); HandleVisibility(); // Process removal requests for (int i = 0; i < m_updateRequests.Count;) { Chunk chunk = m_updateRequests[i]; ProcessChunk(chunk); // Update the chunk if possible if (chunk.CanUpdate) { chunk.UpdateState(); // Build colliders if there is enough time if (Globals.GeometryBudget.HasTimeBudget) { Globals.GeometryBudget.StartMeasurement(); bool wasBuilt = chunk.UpdateRenderGeometry(); wasBuilt |= chunk.UpdateCollisionGeometry(); if (wasBuilt) { Globals.GeometryBudget.StopMeasurement(); } } } // Automatically collect chunks which are ready to be removed from the world ChunkStateManagerClient stateManager = chunk.stateManager; if (stateManager.IsStateCompleted(ChunkState.Remove)) { // Remove the chunk from our provider and unregister it from chunk storage world.chunks.RemoveChunk(chunk); // Unregister from updates m_updateRequests.RemoveAt(i); continue; } ++i; } world.PerformBlockActions(); FullLoadOnStartUp = false; Profiler.EndSample(); }
private void OnDrawGizmosSelected() { int size = Mathf.FloorToInt(Env.ChunkSize * Env.BlockSize); int halfSize = size >> 1; int smallSize = size >> 4; if (world != null && world.chunks != null && (Diag_DrawWorldBounds || Diag_DrawLoadRange)) { foreach (Chunk chunk in world.chunks.chunkCollection) { if (Diag_DrawWorldBounds) { Gizmos.color = Color.blue; Gizmos.DrawWireCube(chunk.WorldBounds.center, chunk.WorldBounds.size); } if (Diag_DrawLoadRange) { Vector3Int pos = chunk.pos; int xd = Helpers.Abs((m_viewerPos.x - pos.x) >> Env.ChunkPower); int zd = Helpers.Abs((m_viewerPos.z - pos.z) >> Env.ChunkPower); if (xd * xd + zd * zd >= HorizontalChunkDeleteRadius * HorizontalChunkDeleteRadius) { Gizmos.color = Color.red; Gizmos.DrawWireCube( new Vector3(chunk.pos.x + halfSize, 0, chunk.pos.z + halfSize), new Vector3(size - 0.05f, 0, size - 0.05f) ); } else { Gizmos.color = Color.green; Gizmos.DrawWireCube( new Vector3(chunk.pos.x + halfSize, 0, chunk.pos.z + halfSize), new Vector3(size - 0.05f, 0, size - 0.05f) ); } // Show generated chunks ChunkStateManagerClient stateManager = (ChunkStateManagerClient)chunk.stateManager; if (stateManager.IsStateCompleted(ChunkState.Generate)) { Gizmos.color = Color.magenta; Gizmos.DrawWireCube( new Vector3(chunk.pos.x + halfSize, 0, chunk.pos.z + halfSize), new Vector3(smallSize - 0.05f, 0, smallSize - 0.05f) ); } } } } }
private void OnDrawGizmosSelected() { int size = Mathf.FloorToInt(Env.ChunkSize * Env.BlockSize); int halfSize = size >> 1; int smallSize = size >> 4; if (world != null && world.chunks != null && (Diag_DrawWorldBounds || Diag_DrawLoadRange)) { foreach (Chunk chunk in world.chunks.chunkCollection) { if (Diag_DrawWorldBounds) { Gizmos.color = Color.blue; Gizmos.DrawWireCube(chunk.WorldBounds.center, chunk.WorldBounds.size); } if (Diag_DrawLoadRange) { Vector3Int pos = chunk.pos; if (chunk.pos.y == 0) { int tx = m_clipmap.TransformX(pos.x >> Env.ChunkPower); int ty = m_clipmap.TransformY(pos.y >> Env.ChunkPower); int tz = m_clipmap.TransformZ(pos.z >> Env.ChunkPower); if (!m_clipmap.IsInsideBounds_Transformed(tx, ty, tz)) { Gizmos.color = Color.red; Gizmos.DrawWireCube( new Vector3(pos.x + halfSize, 0, pos.z + halfSize), new Vector3(size - 0.05f, 0, size - 0.05f) ); } else { ClipmapItem item = m_clipmap.Get_Transformed(tx, ty, tz); if (item.IsWithinVisibleRange) { Gizmos.color = Color.green; Gizmos.DrawWireCube( new Vector3(pos.x + halfSize, 0, pos.z + halfSize), new Vector3(size - 0.05f, 0, size - 0.05f) ); } else // if (item.IsWithinCachedRange) { Gizmos.color = Color.yellow; Gizmos.DrawWireCube( new Vector3(pos.x + halfSize, 0, pos.z + halfSize), new Vector3(size - 0.05f, 0, size - 0.05f) ); } } } // Show generated chunks ChunkStateManagerClient stateManager = (ChunkStateManagerClient)chunk.stateManager; if (stateManager.IsStateCompleted(ChunkState.Generate)) { Gizmos.color = Color.magenta; Gizmos.DrawWireCube( new Vector3(pos.x + halfSize, pos.y + halfSize, pos.z + halfSize), new Vector3(smallSize - 0.05f, smallSize - 0.05f, smallSize - 0.05f) ); } } } } }
private void OnDrawGizmosSelected() { if (!enabled) { return; } float size = Env.ChunkSize * Env.BlockSize; float halfSize = size * 0.5f; float smallSize = size * 0.25f; if (world != null && world.chunks != null && (Diag_DrawWorldBounds || Diag_DrawLoadRange)) { foreach (Chunk chunk in world.chunks.chunkCollection) { if (Diag_DrawWorldBounds) { // Make central chunks more apparent by using yellow color bool isCentral = chunk.pos.x == m_viewerPos.x || chunk.pos.y == m_viewerPos.y || chunk.pos.z == m_viewerPos.z; Gizmos.color = isCentral ? Color.yellow : Color.blue; Vector3 chunkCenter = new Vector3( chunk.pos.x + (Env.ChunkSize >> 1), chunk.pos.y + (Env.ChunkSize >> 1), chunk.pos.z + (Env.ChunkSize >> 1) ); Vector3 chunkSize = new Vector3(Env.ChunkSize, Env.ChunkSize, Env.ChunkSize); Gizmos.DrawWireCube(chunkCenter, chunkSize); } if (Diag_DrawLoadRange) { Vector3Int pos = chunk.pos; int xd = Helpers.Abs((m_viewerPos.x - pos.x) / Env.ChunkSize); int zd = Helpers.Abs((m_viewerPos.z - pos.z) / Env.ChunkSize); int dist = xd * xd + zd * zd; if (dist <= HorizontalChunkLoadRadius * HorizontalChunkLoadRadius) { Gizmos.color = Color.green; Gizmos.DrawWireCube( new Vector3(chunk.pos.x + halfSize, 0, chunk.pos.z + halfSize), new Vector3(size - 1f, 0, size - 1f) ); } else { Gizmos.color = Color.red; Gizmos.DrawWireCube( new Vector3(chunk.pos.x + halfSize, 0, chunk.pos.z + halfSize), new Vector3(size - 1f, 0, size - 1f) ); } // Show generated chunks ChunkStateManagerClient stateManager = chunk.stateManager; if (stateManager.IsStateCompleted(ChunkState.Generate)) { Gizmos.color = Color.magenta; Gizmos.DrawWireCube( new Vector3(chunk.pos.x + halfSize, 0, chunk.pos.z + halfSize), new Vector3(smallSize - 0.05f, 0, smallSize - 0.05f) ); } } } } }
private void OnDrawGizmosSelected() { if (!enabled) { return; } float size = Env.ChunkSize * Env.BlockSize; float halfSize = size * 0.5f; float smallSize = size * 0.25f; if (world != null && world.chunks != null && (Diag_DrawWorldBounds || Diag_DrawLoadRange)) { foreach (Chunk chunk in world.chunks.chunkCollection) { if (Diag_DrawWorldBounds) { // Make central chunks more apparent by using yellow color bool isCentral = chunk.pos.x == m_viewerPos.x || chunk.pos.y == m_viewerPos.y || chunk.pos.z == m_viewerPos.z; Gizmos.color = isCentral ? Color.yellow : Color.blue; Vector3 chunkCenter = new Vector3( chunk.pos.x + (Env.ChunkSize >> 1), chunk.pos.y + (Env.ChunkSize >> 1), chunk.pos.z + (Env.ChunkSize >> 1) ); Vector3 chunkSize = new Vector3(Env.ChunkSize, Env.ChunkSize, Env.ChunkSize); Gizmos.DrawWireCube(chunkCenter, chunkSize); } if (Diag_DrawLoadRange) { Vector3Int pos = chunk.pos; if (chunk.pos.y == 0) { int tx = m_clipmap.TransformX(pos.x / Env.ChunkSize); int ty = m_clipmap.TransformY(pos.y / Env.ChunkSize); int tz = m_clipmap.TransformZ(pos.z / Env.ChunkSize); if (!m_clipmap.IsInsideBounds_Transformed(tx, ty, tz)) { Gizmos.color = Color.red; Gizmos.DrawWireCube( new Vector3(pos.x + halfSize, 0, pos.z + halfSize), new Vector3(size - 1f, 0, size - 1f) ); } else { ClipmapItem item = m_clipmap.Get_Transformed(tx, ty, tz); if (item.IsInVisibleRange) { Gizmos.color = Color.green; Gizmos.DrawWireCube( new Vector3(pos.x + halfSize, 0, pos.z + halfSize), new Vector3(size - 1f, 0, size - 1f) ); } } } // Show generated chunks ChunkStateManagerClient stateManager = chunk.stateManager; if (stateManager.IsStateCompleted(ChunkState.Generate)) { Gizmos.color = Color.magenta; Gizmos.DrawWireCube( new Vector3(pos.x + halfSize, pos.y + halfSize, pos.z + halfSize), new Vector3(smallSize - 0.05f, smallSize - 0.05f, smallSize - 0.05f) ); } } } } }