From 0657cf5bd3ef31c41021e122b9c85d167e358109 Mon Sep 17 00:00:00 2001 From: Justin Aquadro Date: Sat, 16 Apr 2011 01:46:46 +0000 Subject: [PATCH] Bugfixes and more relighting control --- Substrate/SubstrateCS/Examples/Examples.sln | 6 ++++ Substrate/SubstrateCS/Source/BlockManager.cs | 2 +- Substrate/SubstrateCS/Source/Chunk.cs | 29 ++++--------------- Substrate/SubstrateCS/Source/ChunkManager.cs | 25 ++++++++++++++++ Substrate/SubstrateCS/Source/ChunkRef.cs | 2 ++ .../SubstrateCS/Source/NBT/NBTVerifier.cs | 2 +- .../SubstrateCS/Source/Utility/NibbleArray.cs | 7 +++++ 7 files changed, 48 insertions(+), 25 deletions(-) diff --git a/Substrate/SubstrateCS/Examples/Examples.sln b/Substrate/SubstrateCS/Examples/Examples.sln index 95d0a0c..bff6188 100644 --- a/Substrate/SubstrateCS/Examples/Examples.sln +++ b/Substrate/SubstrateCS/Examples/Examples.sln @@ -15,6 +15,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Skyscraper", "Skyscraper\Sk EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Relight", "Relight\Relight.csproj", "{EBDD447B-01FA-4A29-B4AB-380EC4379B5F}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Maze", "Maze\Maze.csproj", "{62D70576-FE3A-4530-B283-889C14B52E9E}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -49,6 +51,10 @@ Global {EBDD447B-01FA-4A29-B4AB-380EC4379B5F}.Debug|Any CPU.Build.0 = Debug|Any CPU {EBDD447B-01FA-4A29-B4AB-380EC4379B5F}.Release|Any CPU.ActiveCfg = Release|Any CPU {EBDD447B-01FA-4A29-B4AB-380EC4379B5F}.Release|Any CPU.Build.0 = Release|Any CPU + {62D70576-FE3A-4530-B283-889C14B52E9E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {62D70576-FE3A-4530-B283-889C14B52E9E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {62D70576-FE3A-4530-B283-889C14B52E9E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {62D70576-FE3A-4530-B283-889C14B52E9E}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Substrate/SubstrateCS/Source/BlockManager.cs b/Substrate/SubstrateCS/Source/BlockManager.cs index 7c18369..360d128 100644 --- a/Substrate/SubstrateCS/Source/BlockManager.cs +++ b/Substrate/SubstrateCS/Source/BlockManager.cs @@ -28,7 +28,7 @@ namespace Substrate protected ChunkRef _cache; - private bool _autoLight; + private bool _autoLight = true; public bool AutoRecalcLight { diff --git a/Substrate/SubstrateCS/Source/Chunk.cs b/Substrate/SubstrateCS/Source/Chunk.cs index d5bc7b2..50345f0 100644 --- a/Substrate/SubstrateCS/Source/Chunk.cs +++ b/Substrate/SubstrateCS/Source/Chunk.cs @@ -18,8 +18,8 @@ namespace Substrate new NBTArrayNode("SkyLight", 16384), new NBTArrayNode("BlockLight", 16384), new NBTArrayNode("HeightMap", 256), - new NBTListNode("Entities", TagType.TAG_COMPOUND), - new NBTListNode("TileEntities", TagType.TAG_COMPOUND, TileEntity.BaseSchema), + new NBTListNode("Entities", TagType.TAG_COMPOUND, 0, NBTOptions.CREATE_ON_MISSING), + new NBTListNode("TileEntities", TagType.TAG_COMPOUND, TileEntity.BaseSchema, NBTOptions.CREATE_ON_MISSING), new NBTScalerNode("LastUpdate", TagType.TAG_LONG, NBTOptions.CREATE_ON_MISSING), new NBTScalerNode("xPos", TagType.TAG_INT), new NBTScalerNode("zPos", TagType.TAG_INT), @@ -633,7 +633,8 @@ namespace Substrate public bool ValidateTree (TagValue tree) { - return new NBTVerifier(tree, LevelSchema).Verify(); + NBTVerifier v = new NBTVerifier(tree, LevelSchema); + return v.Verify(); } #endregion @@ -736,30 +737,12 @@ namespace Substrate public void ResetBlockLight () { - for (int i = 0; i < _blocks.Length; i++) { - //BlockInfo info = BlockInfo.BlockTable[_blocks[i]]; - _blockLight[i] = 0; // Math.Max(info.Luminance - info.Opacity, 0); - } + _blockLight.Clear(); } public void ResetSkyLight () { - for (int x = 0; x < XDim; x++) { - for (int z = 0; z < ZDim; z++) { - int height = GetHeight(x, z); - int ystride = x << 11 | z << 7; - for (int y = 0; y < YDim; y++ ) { - int index = ystride + y; - - if (y >= height) { - _skyLight[index] = BlockInfo.MIN_LUMINANCE; - } - else { - _skyLight[index] = BlockInfo.MIN_LUMINANCE; - } - } - } - } + _skyLight.Clear(); } private int Timestamp () diff --git a/Substrate/SubstrateCS/Source/ChunkManager.cs b/Substrate/SubstrateCS/Source/ChunkManager.cs index 254730d..1d66de5 100644 --- a/Substrate/SubstrateCS/Source/ChunkManager.cs +++ b/Substrate/SubstrateCS/Source/ChunkManager.cs @@ -179,6 +179,31 @@ namespace Substrate return true; } + public void RelightDirtyChunks () + { + List dirty = new List(); + + IEnumerator en = _cache.GetDirtyEnumerator(); + while (en.MoveNext()) { + dirty.Add(en.Current); + } + + foreach (ChunkRef chunk in dirty) { + chunk.ResetBlockLight(); + chunk.ResetSkyLight(); + } + + foreach (ChunkRef chunk in dirty) { + chunk.RebuildBlockLight(); + chunk.RebuildSkyLight(); + } + + foreach (ChunkRef chunk in dirty) { + chunk.UpdateEdgeBlockLight(); + chunk.UpdateEdgeSkyLight(); + } + } + public RegionManager GetRegionManager () { return _regionMan; diff --git a/Substrate/SubstrateCS/Source/ChunkRef.cs b/Substrate/SubstrateCS/Source/ChunkRef.cs index 7f334ea..bf6371a 100644 --- a/Substrate/SubstrateCS/Source/ChunkRef.cs +++ b/Substrate/SubstrateCS/Source/ChunkRef.cs @@ -775,12 +775,14 @@ namespace Substrate public void UpdateEdgeBlockLight () { + GetChunk(); QueueChunkEdges(); UpdateBlockLight(); } public void UpdateEdgeSkyLight () { + GetChunk(); QueueChunkEdges(); UpdateSkyLight(); } diff --git a/Substrate/SubstrateCS/Source/NBT/NBTVerifier.cs b/Substrate/SubstrateCS/Source/NBT/NBTVerifier.cs index e176863..88387b7 100644 --- a/Substrate/SubstrateCS/Source/NBT/NBTVerifier.cs +++ b/Substrate/SubstrateCS/Source/NBT/NBTVerifier.cs @@ -211,7 +211,7 @@ namespace Substrate.NBT if (value == null) { if ((node.Options & NBTOptions.CREATE_ON_MISSING) == NBTOptions.CREATE_ON_MISSING) { - _scratch[node.Name] = schema.BuildDefaultTree(); + _scratch[node.Name] = node.BuildDefaultTree(); continue; } else if ((node.Options & NBTOptions.OPTIONAL) == NBTOptions.OPTIONAL) { diff --git a/Substrate/SubstrateCS/Source/Utility/NibbleArray.cs b/Substrate/SubstrateCS/Source/Utility/NibbleArray.cs index a21a558..b07e8fc 100644 --- a/Substrate/SubstrateCS/Source/Utility/NibbleArray.cs +++ b/Substrate/SubstrateCS/Source/Utility/NibbleArray.cs @@ -47,6 +47,13 @@ namespace Substrate.Utility } } + public void Clear () + { + for (int i = 0; i < _data.Length; i++) { + _data[i] = 0; + } + } + #region ICopyable Members public NibbleArray Copy ()