From d58ed4f37224fd844bf4c47b37ffc3d985819911 Mon Sep 17 00:00:00 2001 From: Justin Aquadro Date: Sat, 12 Mar 2011 21:38:14 +0000 Subject: [PATCH] Bugfix, case-insensitive options and ore generator saves all modified chunks --- NBToolkit/NBToolkit/Chunk.cs | 15 ++++++++++-- NBToolkit/NBToolkit/ChunkManager.cs | 35 ++++++++++++++++++++++++++++ NBToolkit/NBToolkit/NDesk/Options.cs | 14 ++++++----- NBToolkit/NBToolkit/Oregen.cs | 3 ++- 4 files changed, 58 insertions(+), 9 deletions(-) diff --git a/NBToolkit/NBToolkit/Chunk.cs b/NBToolkit/NBToolkit/Chunk.cs index 146d696..86e1340 100644 --- a/NBToolkit/NBToolkit/Chunk.cs +++ b/NBToolkit/NBToolkit/Chunk.cs @@ -100,7 +100,7 @@ namespace NBToolkit } _blocks.data[index] = (byte)id; - _dirty = true; + MarkDirty(); return true; } @@ -142,7 +142,7 @@ namespace NBToolkit } _data[index] = data; - _dirty = true; + MarkDirty(); return true; } @@ -151,5 +151,16 @@ namespace NBToolkit { return GetTree().getRoot().findTagByName("Level").findTagByName("TerrainPopulated").value.toByte().data == 1; } + + protected bool MarkDirty () + { + if (_dirty) { + return false; + } + + _dirty = true; + _chunkMan.MarkChunkDirty(this); + return true; + } } } diff --git a/NBToolkit/NBToolkit/ChunkManager.cs b/NBToolkit/NBToolkit/ChunkManager.cs index 88943c9..bd4b436 100644 --- a/NBToolkit/NBToolkit/ChunkManager.cs +++ b/NBToolkit/NBToolkit/ChunkManager.cs @@ -18,11 +18,13 @@ namespace NBToolkit protected RegionManager _regionMan; protected Dictionary _cache; + protected Dictionary _dirty; public ChunkManager (RegionManager rm) { _regionMan = rm; _cache = new Dictionary(); + _dirty = new Dictionary(); } public Chunk GetChunk (int cx, int cz) @@ -61,6 +63,39 @@ namespace NBToolkit return _regionMan.GetRegion(cx, cz); } + public bool MarkChunkDirty (int cx, int cz) + { + ChunkKey k = new ChunkKey(cx, cz); + if (!_dirty.ContainsKey(k)) { + _dirty.Add(k, GetChunk(cx, cz)); + return true; + } + return false; + } + + public bool MarkChunkDirty (Chunk chunk) + { + ChunkKey k = new ChunkKey(chunk.X, chunk.Z); + if (!_dirty.ContainsKey(k)) { + _dirty.Add(k, chunk); + return true; + } + return false; + } + + public int SaveDirtyChunks () + { + int saved = 0; + foreach (Chunk c in _dirty.Values) { + if (c.Save()) { + saved++; + } + } + + _dirty.Clear(); + return saved; + } + public RegionManager GetRegionManager () { return _regionMan; diff --git a/NBToolkit/NBToolkit/NDesk/Options.cs b/NBToolkit/NBToolkit/NDesk/Options.cs index 9a43b19..a99ea23 100644 --- a/NBToolkit/NBToolkit/NDesk/Options.cs +++ b/NBToolkit/NBToolkit/NDesk/Options.cs @@ -146,7 +146,6 @@ using NDesk.Options; namespace NDesk.Options { public class OptionValueCollection : IList, IList { - List values = new List (); OptionContext c; @@ -319,10 +318,13 @@ namespace NDesk.Options { (names.Length > 1 && this.MaxValueCount > 1))) throw new ArgumentException ( "The default option handler '<>' cannot require values.", - "prototype"); - } - - public string Prototype {get {return prototype;}} + "prototype"); + + for (int i = 0; i < names.Length; i++) + names[i] = names[i].ToLower(); + } + + public string Prototype { get { return prototype; } } public string Description {get {return description;}} public OptionValueType OptionValueType {get {return type;}} public int MaxValueCount {get {return count;}} @@ -735,7 +737,7 @@ namespace NDesk.Options { Unprocessed (unprocessed, def, c, argument); continue; } - if (!Parse (argument, c)) + if (!Parse (argument.ToLower(), c)) Unprocessed (unprocessed, def, c, argument); } if (c.Option != null) diff --git a/NBToolkit/NBToolkit/Oregen.cs b/NBToolkit/NBToolkit/Oregen.cs index f6f0646..21499e5 100644 --- a/NBToolkit/NBToolkit/Oregen.cs +++ b/NBToolkit/NBToolkit/Oregen.cs @@ -192,7 +192,8 @@ namespace NBToolkit affectedChunks++; ApplyChunk(world, chunk); - chunk.Save(); + //chunk.Save(); + world.GetChunkManager().SaveDirtyChunks(); } Console.WriteLine("Affected Chunks: " + affectedChunks);