public void BlockRemoved(BlockType blockType, int x, int y, int z) { if (!BlockInformation.IsLightTransparentBlock(blockType) && !BlockInformation.IsLightEmittingBlock(blockType)) { toLight.Enqueue(new Light(x, y, z, _lighting[x, y, z])); } if (BlockInformation.IsLightEmittingBlock(blockType)) { LightRemoved(x, y, z); } }
private void LightRegion(int sx, int ex, int sz, int ez) { if (sx < 0) { sx = 0; } if (sz < 0) { sz = 0; } if (ex > WorldSettings.MAPWIDTH) { ex = WorldSettings.MAPWIDTH; } if (ez > WorldSettings.MAPLENGTH) { ex = WorldSettings.MAPLENGTH; } for (int x = sx; x < ex; x++) { for (int z = sz; z < ez; z++) { bool inShadow = false; for (int y = WorldSettings.MAPHEIGHT - 1; y > 0; y--) { Block block = _world.BlockAt(x, y, z); if (!BlockInformation.IsLightTransparentBlock(block.BlockType) && !inShadow) { inShadow = true; _lightHeight[x, z] = y + 1; } if (!inShadow) { _lighting[x, y, z] = WorldSettings.MAXLIGHT; toLight.Enqueue(new Light(x, y, z, WorldSettings.MAXLIGHT)); } else { _lighting[x, y, z] = WorldSettings.MINLIGHT; if (BlockInformation.IsLightEmittingBlock(block.BlockType)) { toLight.Enqueue(new Light(x, y, z, WorldSettings.MAXLIGHT)); } } _world.MakeDirty(x, y, z); } } } }
public void BlockAdded(BlockType blockType, int x, int y, int z) { // Don't want to call this during initial map loading if (_lighting != null) { if (BlockInformation.IsLightEmittingBlock(blockType)) { toLight.Enqueue(new Light(x, y, z, WorldSettings.MAXLIGHT)); } if (!BlockInformation.IsLightTransparentBlock(blockType)) { toDark.Enqueue(new Light(x, y, z, WorldSettings.MAXLIGHT * 2)); } } }
private void CheckLight(int x, int y, int z, byte intensity) { intensity = (byte)(intensity - 1); if (_world.InWorldBounds(x, y, z)) { if (_lighting[x, y, z] < intensity) { _lighting[x, y, z] = intensity; _world.MakeDirty(x, y, z); if (BlockInformation.IsLightTransparentBlock(_world.BlockAt(x, y, z).BlockType)) { toLight.Enqueue(new Light(x, y, z, intensity)); } } } }
private void CheckDark(int x, int y, int z, byte intensity) { intensity = (byte)(intensity - 1); if (_world.InWorldBounds(x, y, z)) { if (intensity > WorldSettings.MINLIGHT && _lighting[x, y, z] != WorldSettings.MINLIGHT) { _lighting[x, y, z] = WorldSettings.MINLIGHT; // If we're in sunlight on a light emitter we need to requeue if (y >= _lightHeight[x, z] || BlockInformation.IsLightEmittingBlock(_world.BlockAt(x, y, z).BlockType)) { // We darked a light so schedule it to be relit toLight.Enqueue(new Light(x, y, z, WorldSettings.MAXLIGHT + 1)); } _world.MakeDirty(x, y, z); toDark.Enqueue(new Light(x, y, z, intensity)); } } }
public bool SolidAt(int x, int y, int z) { BlockType blockType = BlockAt(x, y, z).BlockType; return(BlockInformation.IsSolidBlock(blockType)); }
private void SetBlockFaces(BlockType blockType, int bx, int by, int bz, BlockType neighbourType, int nx, int ny, int nz, BlockFaceDirection bFace, BlockFaceDirection nFace) { if (neighbourType == BlockType.None) { // Bordering sky make face visible if (blockType != BlockType.None) { if (blockType == BlockType.Water) { _world.AddWaterFace(bx, by, bz, bFace); } else { _world.AddSolidFace(bx, by, bz, bFace); } } } else { if (neighbourType == BlockType.Water) { if (blockType == BlockType.None) { if (blockType == BlockType.Water) { _world.AddWaterFace(bx, by, bz, bFace); } else { _world.AddSolidFace(bx, by, bz, bFace); } } else if (blockType == BlockType.Water) { // Removed ajoining faces if both blocks are water _world.RemoveWaterFace(bx, by, bz, bFace); _world.RemoveWaterFace(nx, ny, nz, nFace); } else if (BlockInformation.IsModelBlock(blockType)) { _world.AddModelFace(bx, by, bz, bFace); _world.AddWaterFace(nx, ny, nz, nFace); } else { // Can always see face through water if (blockType == BlockType.Water) { _world.AddWaterFace(bx, by, bz, bFace); } else { _world.AddSolidFace(bx, by, bz, bFace); } _world.RemoveWaterFace(nx, ny, nz, nFace); } } else if (BlockInformation.IsModelBlock(neighbourType)) { if (blockType == BlockType.None) { _world.AddModelFace(nx, ny, nz, nFace); } else if (blockType == BlockType.Water) { // Can see through water _world.AddWaterFace(bx, by, bz, bFace); _world.AddModelFace(nx, ny, nz, nFace); } else if (BlockInformation.IsModelBlock(blockType)) { // Can see through transparent _world.AddModelFace(bx, by, bz, bFace); _world.AddModelFace(nx, ny, nz, nFace); } else { // Can see through transparent and note that neightbour face is occluded _world.AddSolidFace(bx, by, bz, bFace); _world.RemoveModelFace(nx, ny, nz, nFace); } } else { if (blockType == BlockType.None) { _world.AddSolidFace(nx, ny, nz, nFace); } else if (blockType == BlockType.Water) { // We can see it through water if (bFace == BlockFaceDirection.YIncreasing) { _world.AddWaterFace(bx, by, bz, bFace); } else { _world.RemoveWaterFace(bx, by, bz, bFace); } _world.AddSolidFace(nx, ny, nz, nFace); } else if (BlockInformation.IsModelBlock(blockType)) { // We can see neighbour face and note that block face is occluded _world.RemoveModelFace(bx, by, bz, bFace); _world.AddSolidFace(nx, ny, nz, nFace); } else if (bFace == BlockFaceDirection.YIncreasing && by == _world.CURRENTMAPLEVEL - 1) { _world.AddSolidFace(bx, by, bz, bFace); } else { // Both faces hidden _world.RemoveSolidFace(bx, by, bz, bFace); _world.RemoveSolidFace(nx, ny, nz, nFace); } } } }
private void BuildBlockVertices(VertexPositionTextureShade[] vertexArray, Buffer buffer, BlockType blockType, byte faceInfo, Vector3i position) { if ((faceInfo & (byte)BlockFaceDirection.XDecreasing) > 0) { BuildFaceVertices(position.x, position.y, position.z, buffer, ref vertexArray, BlockFaceDirection.XDecreasing, BlockInformation.GetTexture(blockType, BlockFaceDirection.XDecreasing)); } if ((faceInfo & (byte)BlockFaceDirection.XIncreasing) > 0) { BuildFaceVertices(position.x, position.y, position.z, buffer, ref vertexArray, BlockFaceDirection.XIncreasing, BlockInformation.GetTexture(blockType, BlockFaceDirection.XIncreasing)); } if ((faceInfo & (byte)BlockFaceDirection.YDecreasing) > 0) { BuildFaceVertices(position.x, position.y, position.z, buffer, ref vertexArray, BlockFaceDirection.YDecreasing, BlockInformation.GetTexture(blockType, BlockFaceDirection.YDecreasing)); } if ((faceInfo & (byte)BlockFaceDirection.YIncreasing) > 0) { BuildFaceVertices(position.x, position.y, position.z, buffer, ref vertexArray, BlockFaceDirection.YIncreasing, BlockInformation.GetTexture(blockType, BlockFaceDirection.YIncreasing)); } if ((faceInfo & (byte)BlockFaceDirection.ZDecreasing) > 0) { BuildFaceVertices(position.x, position.y, position.z, buffer, ref vertexArray, BlockFaceDirection.ZDecreasing, BlockInformation.GetTexture(blockType, BlockFaceDirection.ZDecreasing)); } if ((faceInfo & (byte)BlockFaceDirection.ZIncreasing) > 0) { BuildFaceVertices(position.x, position.y, position.z, buffer, ref vertexArray, BlockFaceDirection.ZIncreasing, BlockInformation.GetTexture(blockType, BlockFaceDirection.ZIncreasing)); } }
public void BuildVertexBuffers() { //_solidVertexList.Clear(); //_modelVertexList.Clear(); //_waterVertexList.Clear(); _solidVertexArray = new VertexPositionTextureShade[_solidFaceCount * 6]; _modelVertexArray = new VertexPositionTextureShade[_modelFaceCount * 6]; _waterVertexArray = new VertexPositionTextureShade[_waterFaceCount * 6]; _solidIndex = 0; _waterIndex = 0; _modelIndex = 0; for (int x = 0; x < WorldSettings.REGIONWIDTH; x++) { for (int y = 0; y < _world.CURRENTMAPLEVEL; y++) { for (int z = 0; z < WorldSettings.REGIONLENGTH; z++) { BlockType blockType = Blocks[x, y, z].BlockType; Blocks[x, y, z].IsActive = true; if (blockType != BlockType.None) { byte faceInfo = _faceInfo[x, y, z]; Vector3i position = new Vector3i(_position.x + x, _position.y + y, _position.z + z); if (blockType == BlockType.Water) { BuildBlockVertices(_waterVertexArray, Buffer.Water, blockType, faceInfo, position); } else if (BlockInformation.IsModelBlock(blockType)) { BuildBlockVertices(_modelVertexArray, Buffer.Model, blockType, faceInfo, position); } else { BuildBlockVertices(_solidVertexArray, Buffer.Solid, blockType, faceInfo, position); } } } } } if (_waterVertexArray.Length > 0) { _waterVertexBuffer = new VertexBuffer(_world.Game.GraphicsDevice, typeof(VertexPositionTextureShade), _waterVertexArray.Length, BufferUsage.WriteOnly); _waterVertexBuffer.SetData(_waterVertexArray); } else { _waterVertexBuffer = null; } if (_modelVertexArray.Length > 0) { _modelVertexBuffer = new VertexBuffer(_world.Game.GraphicsDevice, typeof(VertexPositionTextureShade), _modelVertexArray.Length, BufferUsage.WriteOnly); _modelVertexBuffer.SetData(_modelVertexArray); } else { _modelVertexBuffer = null; } if (_solidVertexArray.Length > 0) { _solidVertexBuffer = new VertexBuffer( _world.Game.GraphicsDevice, typeof(VertexPositionTextureShade), _solidVertexArray.Length, BufferUsage.WriteOnly); _solidVertexBuffer.SetData(_solidVertexArray); } else { _solidVertexBuffer = null; } }