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.

This commit is contained in:
Justin Aquadro 2011-04-21 00:30:13 +00:00
parent 0b2db7934d
commit bb12d60c0c
4 changed files with 24 additions and 2 deletions

View file

@ -27,6 +27,7 @@ namespace Relight
// First blank out all of the lighting in all of the chunks // First blank out all of the lighting in all of the chunks
foreach (ChunkRef chunk in cm) { foreach (ChunkRef chunk in cm) {
chunk.RebuildHeightMap();
chunk.ResetBlockLight(); chunk.ResetBlockLight();
chunk.ResetSkyLight(); chunk.ResetSkyLight();
cm.Save(); cm.Save();

View file

@ -749,6 +749,21 @@ namespace Substrate
#endregion #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 () public void ResetBlockLight ()
{ {
_blockLight.Clear(); _blockLight.Clear();

View file

@ -448,6 +448,12 @@ namespace Substrate
#endregion #endregion
public void RebuildHeightMap ()
{
GetChunk().RebuildHeightMap();
MarkDirty();
}
private BitArray _lightbit; private BitArray _lightbit;
private Queue<BlockKey> _update; private Queue<BlockKey> _update;

View file

@ -15,12 +15,12 @@ namespace Substrate
new NBTCompoundNode("Data") new NBTCompoundNode("Data")
{ {
new NBTScalerNode("Time", TagType.TAG_LONG), 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 NBTCompoundNode("Player", Player.PlayerSchema, NBTOptions.OPTIONAL),
new NBTScalerNode("SpawnX", TagType.TAG_INT), new NBTScalerNode("SpawnX", TagType.TAG_INT),
new NBTScalerNode("SpawnY", TagType.TAG_INT), new NBTScalerNode("SpawnY", TagType.TAG_INT),
new NBTScalerNode("SpawnZ", 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("RandomSeed", TagType.TAG_LONG),
new NBTScalerNode("version", TagType.TAG_INT, NBTOptions.OPTIONAL), new NBTScalerNode("version", TagType.TAG_INT, NBTOptions.OPTIONAL),
new NBTScalerNode("LevelName", TagType.TAG_STRING, NBTOptions.OPTIONAL), new NBTScalerNode("LevelName", TagType.TAG_STRING, NBTOptions.OPTIONAL),