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; _blocks.data[index] = (byte)id;
_dirty = true; MarkDirty();
return true; return true;
} }
@ -142,7 +142,7 @@ namespace NBToolkit
} }
_data[index] = data; _data[index] = data;
_dirty = true; MarkDirty();
return true; return true;
} }
@ -151,5 +151,16 @@ namespace NBToolkit
{ {
return GetTree().getRoot().findTagByName("Level").findTagByName("TerrainPopulated").value.toByte().data == 1; 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 RegionManager _regionMan;
protected Dictionary<ChunkKey, WeakReference> _cache; protected Dictionary<ChunkKey, WeakReference> _cache;
protected Dictionary<ChunkKey, Chunk> _dirty;
public ChunkManager (RegionManager rm) public ChunkManager (RegionManager rm)
{ {
_regionMan = rm; _regionMan = rm;
_cache = new Dictionary<ChunkKey, WeakReference>(); _cache = new Dictionary<ChunkKey, WeakReference>();
_dirty = new Dictionary<ChunkKey, Chunk>();
} }
public Chunk GetChunk (int cx, int cz) public Chunk GetChunk (int cx, int cz)
@ -61,6 +63,39 @@ namespace NBToolkit
return _regionMan.GetRegion(cx, cz); 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 () public RegionManager GetRegionManager ()
{ {
return _regionMan; return _regionMan;

View file

@ -146,7 +146,6 @@ using NDesk.Options;
namespace NDesk.Options { namespace NDesk.Options {
public class OptionValueCollection : IList, IList<string> { public class OptionValueCollection : IList, IList<string> {
List<string> values = new List<string> (); List<string> values = new List<string> ();
OptionContext c; OptionContext c;
@ -319,10 +318,13 @@ namespace NDesk.Options {
(names.Length > 1 && this.MaxValueCount > 1))) (names.Length > 1 && this.MaxValueCount > 1)))
throw new ArgumentException ( throw new ArgumentException (
"The default option handler '<>' cannot require values.", "The default option handler '<>' cannot require values.",
"prototype"); "prototype");
}
for (int i = 0; i < names.Length; i++)
public string Prototype {get {return prototype;}} names[i] = names[i].ToLower();
}
public string Prototype { get { return prototype; } }
public string Description {get {return description;}} public string Description {get {return description;}}
public OptionValueType OptionValueType {get {return type;}} public OptionValueType OptionValueType {get {return type;}}
public int MaxValueCount {get {return count;}} public int MaxValueCount {get {return count;}}
@ -735,7 +737,7 @@ namespace NDesk.Options {
Unprocessed (unprocessed, def, c, argument); Unprocessed (unprocessed, def, c, argument);
continue; continue;
} }
if (!Parse (argument, c)) if (!Parse (argument.ToLower(), c))
Unprocessed (unprocessed, def, c, argument); Unprocessed (unprocessed, def, c, argument);
} }
if (c.Option != null) if (c.Option != null)

View file

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