Bugfix, case-insensitive options and ore generator saves all modified chunks

This commit is contained in:
Justin Aquadro 2011-03-12 21:38:14 +00:00
parent b6c4c0655f
commit d58ed4f372
4 changed files with 58 additions and 9 deletions

View file

@ -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;
}
}
}

View file

@ -18,11 +18,13 @@ namespace NBToolkit
protected RegionManager _regionMan;
protected Dictionary<ChunkKey, WeakReference> _cache;
protected Dictionary<ChunkKey, Chunk> _dirty;
public ChunkManager (RegionManager rm)
{
_regionMan = rm;
_cache = new Dictionary<ChunkKey, WeakReference>();
_dirty = new Dictionary<ChunkKey, Chunk>();
}
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;

View file

@ -146,7 +146,6 @@ using NDesk.Options;
namespace NDesk.Options {
public class OptionValueCollection : IList, IList<string> {
List<string> values = new List<string> ();
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)

View file

@ -192,7 +192,8 @@ namespace NBToolkit
affectedChunks++;
ApplyChunk(world, chunk);
chunk.Save();
//chunk.Save();
world.GetChunkManager().SaveDirtyChunks();
}
Console.WriteLine("Affected Chunks: " + affectedChunks);