public void GetRawDataNoCheck(out ChunkPos pos, out IWorld world, out BlockData[,,] blocks, out Quaternion[,,] rotations, out NibbleArray skyLights, out byte[,] heightMap) { pos = m_Position; world = m_World; blocks = m_Blocks; rotations = m_Rotations; skyLights = m_SkyLights; heightMap = m_HeightMap; }
public void Dispose() { m_Accessible = false; m_Position = default; m_World = default; m_SkyLights.Clear(); m_AmbientLights.Clear(); Array.Clear(m_Blocks, 0, m_Blocks.Length); Array.Clear(m_Rotations, 0, m_Rotations.Length); Array.Clear(m_HeightMap, 0, m_HeightMap.Length); }
public Chunk() { m_Accessible = false; m_Position = default; m_World = default; m_Blocks = new BlockData[ChunkWidth, ChunkHeight, ChunkWidth]; m_Rotations = new Quaternion[ChunkWidth, ChunkHeight, ChunkWidth]; m_SkyLights = new NibbleArray(ChunkWidth * ChunkHeight * ChunkWidth); m_AmbientLights = new NibbleArray(ChunkWidth * ChunkHeight * ChunkWidth); m_HeightMap = new byte[ChunkWidth, ChunkWidth]; }
public void Initialize(ChunkPos pos, ChunkManager chunkManager) { for (int x = XOffsetBegin; x <= XOffsetEnd; x++) { for (int z = ZOffsetBegin; z <= ZOffsetEnd; z++) { ChunkPos neighbor = pos.AddOffset(x, z); bool result = chunkManager.GetChunk(neighbor, false, out Chunk chunk); Assert.IsTrue(result); m_Members[x + 1, z + 1] = chunk; } } Accessible = true; }
private void LightBlocks(Stack <Vector3Int> queue, ref int limit, ModificationSource source) { while (limit-- > 0 && queue.Count > 0) { Vector3Int blockPos = queue.Pop(); if (blockPos.y < 0 || blockPos.y >= ChunkHeight) { continue; } if (!ChunkManager.GetChunk(ChunkPos.GetFromAny(blockPos.x, blockPos.z), false, out _)) { // 我不想管这个了,如果有人有好的算法请告诉我! // m_BlocksToLightQueue.Push(blockPos); // break; continue; } int x = blockPos.x; int y = blockPos.y; int z = blockPos.z; BlockData block = RWAccessor.GetBlock(x, y, z); int opacity = Mathf.Max(block.LightOpacity, 1); int finalLight = 0; if (opacity < MaxLight || block.LightValue > 0) // 不然就是0 { int max = RWAccessor.GetAmbientLight(x + 1, y, z); int temp; if ((temp = RWAccessor.GetAmbientLight(x - 1, y, z)) > max) { max = temp; } if ((temp = RWAccessor.GetAmbientLight(x, y + 1, z)) > max) { max = temp; } if ((temp = RWAccessor.GetAmbientLight(x, y - 1, z)) > max) { max = temp; } if ((temp = RWAccessor.GetAmbientLight(x, y, z + 1)) > max) { max = temp; } if ((temp = RWAccessor.GetAmbientLight(x, y, z - 1)) > max) { max = temp; } finalLight = max - opacity; if (block.LightValue > finalLight) { finalLight = block.LightValue; // 假设这个值一定是合法的(不过确实应该是合法的) } else if (finalLight < 0) { finalLight = 0; } //else if (finalLight > MaxLight) //{ // finalLight = MaxLight; //} } if (RWAccessor.SetAmbientLightLevel(x, y, z, finalLight, source)) { queue.Push(new Vector3Int(x - 1, y, z)); queue.Push(new Vector3Int(x, y - 1, z)); queue.Push(new Vector3Int(x, y, z - 1)); queue.Push(new Vector3Int(x + 1, y, z)); queue.Push(new Vector3Int(x, y + 1, z)); queue.Push(new Vector3Int(x, y, z + 1)); } } }
public void OnChunkUnloaded(ChunkPos pos) { print("Unload " + pos); }
public void Initialize(int x, int z, IWorld world) { m_Position = ChunkPos.Get(x, z); m_World = world; }