From c6ee97a53b681286dcd458a6c2b919a9037156a1 Mon Sep 17 00:00:00 2001 From: Justin Aquadro Date: Wed, 13 Apr 2011 07:09:41 +0000 Subject: [PATCH] Bugfixes for creating new worlds/regions/chunks --- Substrate/SubstrateCS/Source/ChunkManager.cs | 3 --- Substrate/SubstrateCS/Source/ChunkRef.cs | 4 ++++ Substrate/SubstrateCS/Source/RegionFile.cs | 4 ++++ Substrate/SubstrateCS/Source/RegionManager.cs | 7 ++++++- Substrate/SubstrateCS/Source/World.cs | 5 +++++ 5 files changed, 19 insertions(+), 4 deletions(-) diff --git a/Substrate/SubstrateCS/Source/ChunkManager.cs b/Substrate/SubstrateCS/Source/ChunkManager.cs index a0b2c0d..eedf08c 100644 --- a/Substrate/SubstrateCS/Source/ChunkManager.cs +++ b/Substrate/SubstrateCS/Source/ChunkManager.cs @@ -246,9 +246,6 @@ namespace Substrate } if (MoveNextInRegion()) { _chunk = _region.GetChunkRef(_x, _z, _cm); - if (_chunk == null) { - throw new Exception(); - } return true; } } diff --git a/Substrate/SubstrateCS/Source/ChunkRef.cs b/Substrate/SubstrateCS/Source/ChunkRef.cs index 61dbf55..0da9817 100644 --- a/Substrate/SubstrateCS/Source/ChunkRef.cs +++ b/Substrate/SubstrateCS/Source/ChunkRef.cs @@ -576,6 +576,10 @@ namespace Substrate private ChunkRef LocalChunk (int lx, int ly, int lz) { + if (ly < 0 || ly >= YDim) { + return null; + } + if (lx < 0) { if (lz < 0) { return _container.GetChunkRef(_cx - 1, _cz - 1); diff --git a/Substrate/SubstrateCS/Source/RegionFile.cs b/Substrate/SubstrateCS/Source/RegionFile.cs index 63112b8..5a1c8cd 100644 --- a/Substrate/SubstrateCS/Source/RegionFile.cs +++ b/Substrate/SubstrateCS/Source/RegionFile.cs @@ -102,6 +102,8 @@ namespace Substrate file.Write(int0, 0, 4); } + file.Flush(); + sizeDelta += SECTOR_BYTES * 2; } @@ -110,6 +112,8 @@ namespace Substrate for (int i = 0; i < (file.Length & 0xfff); ++i) { file.WriteByte(0); } + + file.Flush(); } /* set up the available sector map */ diff --git a/Substrate/SubstrateCS/Source/RegionManager.cs b/Substrate/SubstrateCS/Source/RegionManager.cs index e84f14c..0f3dc7c 100644 --- a/Substrate/SubstrateCS/Source/RegionManager.cs +++ b/Substrate/SubstrateCS/Source/RegionManager.cs @@ -60,9 +60,14 @@ namespace Substrate Region r = GetRegion(rx, rz); if (r == null) { string fp = "r." + rx + "." + rz + ".mcr"; - new RegionFile(Path.Combine(_regionPath, fp)); + using (RegionFile rf = new RegionFile(Path.Combine(_regionPath, fp))) { + + } r = new Region(this, rx, rz); + + RegionKey k = new RegionKey(rx, rz); + _cache[k] = r; } return r; diff --git a/Substrate/SubstrateCS/Source/World.cs b/Substrate/SubstrateCS/Source/World.cs index 1683c25..d02e14f 100644 --- a/Substrate/SubstrateCS/Source/World.cs +++ b/Substrate/SubstrateCS/Source/World.cs @@ -335,6 +335,11 @@ namespace Substrate throw new DirectoryNotFoundException("Directory '" + path + "' not found"); } + string regpath = Path.Combine(path, _REGION_DIR); + if (!Directory.Exists(regpath)) { + Directory.CreateDirectory(regpath); + } + _path = path; _level = new Level(this);