From bb12d60c0c295ade72c8c004661260e86ef0a5d8 Mon Sep 17 00:00:00 2001 From: Justin Aquadro Date: Thu, 21 Apr 2011 00:30:13 +0000 Subject: [PATCH] Added heightmap rebuilding (for maps with invalid heightmaps), and added it to the relight example. Made a couple level.dat fields auto-create if missing. --- Substrate/SubstrateCS/Examples/Relight/Program.cs | 1 + Substrate/SubstrateCS/Source/Chunk.cs | 15 +++++++++++++++ Substrate/SubstrateCS/Source/ChunkRef.cs | 6 ++++++ Substrate/SubstrateCS/Source/Level.cs | 4 ++-- 4 files changed, 24 insertions(+), 2 deletions(-) diff --git a/Substrate/SubstrateCS/Examples/Relight/Program.cs b/Substrate/SubstrateCS/Examples/Relight/Program.cs index 7c8e540..813ff06 100644 --- a/Substrate/SubstrateCS/Examples/Relight/Program.cs +++ b/Substrate/SubstrateCS/Examples/Relight/Program.cs @@ -27,6 +27,7 @@ namespace Relight // First blank out all of the lighting in all of the chunks foreach (ChunkRef chunk in cm) { + chunk.RebuildHeightMap(); chunk.ResetBlockLight(); chunk.ResetSkyLight(); cm.Save(); diff --git a/Substrate/SubstrateCS/Source/Chunk.cs b/Substrate/SubstrateCS/Source/Chunk.cs index 2597516..4398a7b 100644 --- a/Substrate/SubstrateCS/Source/Chunk.cs +++ b/Substrate/SubstrateCS/Source/Chunk.cs @@ -749,6 +749,21 @@ namespace Substrate #endregion + public void RebuildHeightMap () + { + for (int x = 0; x < XDim; x++) { + for (int z = 0; z < ZDim; z++) { + for (int y = YDim - 1; y >= 0; y--) { + BlockInfo info = GetBlockInfo(x, y, z); + if (BlockInfo.BlockTable[GetBlockID(x, y, z)].Opacity > BlockInfo.MIN_OPACITY) { + _heightMap[z << 4 | x] = (byte)y; + break; + } + } + } + } + } + public void ResetBlockLight () { _blockLight.Clear(); diff --git a/Substrate/SubstrateCS/Source/ChunkRef.cs b/Substrate/SubstrateCS/Source/ChunkRef.cs index 8fdd97d..e1ed906 100644 --- a/Substrate/SubstrateCS/Source/ChunkRef.cs +++ b/Substrate/SubstrateCS/Source/ChunkRef.cs @@ -448,6 +448,12 @@ namespace Substrate #endregion + public void RebuildHeightMap () + { + GetChunk().RebuildHeightMap(); + MarkDirty(); + } + private BitArray _lightbit; private Queue _update; diff --git a/Substrate/SubstrateCS/Source/Level.cs b/Substrate/SubstrateCS/Source/Level.cs index 2f62531..edac3ab 100644 --- a/Substrate/SubstrateCS/Source/Level.cs +++ b/Substrate/SubstrateCS/Source/Level.cs @@ -15,12 +15,12 @@ namespace Substrate new NBTCompoundNode("Data") { new NBTScalerNode("Time", TagType.TAG_LONG), - new NBTScalerNode("LastPlayed", TagType.TAG_LONG), + new NBTScalerNode("LastPlayed", TagType.TAG_LONG, NBTOptions.CREATE_ON_MISSING), new NBTCompoundNode("Player", Player.PlayerSchema, NBTOptions.OPTIONAL), new NBTScalerNode("SpawnX", TagType.TAG_INT), new NBTScalerNode("SpawnY", TagType.TAG_INT), new NBTScalerNode("SpawnZ", TagType.TAG_INT), - new NBTScalerNode("SizeOnDisk", TagType.TAG_LONG), + new NBTScalerNode("SizeOnDisk", TagType.TAG_LONG, NBTOptions.CREATE_ON_MISSING), new NBTScalerNode("RandomSeed", TagType.TAG_LONG), new NBTScalerNode("version", TagType.TAG_INT, NBTOptions.OPTIONAL), new NBTScalerNode("LevelName", TagType.TAG_STRING, NBTOptions.OPTIONAL),