Split BlockManager into AlphaBlockManager and AnvilBlockManager

This commit is contained in:
Justin Aquadro 2012-05-25 21:48:19 -04:00
parent e9fe001656
commit 0ca56beb76
4 changed files with 43 additions and 17 deletions

View file

@ -175,7 +175,7 @@ namespace Substrate
}
AlphaChunkManager cm = new AlphaChunkManager(path);
BlockManager bm = new BlockManager(cm);
BlockManager bm = new AlphaBlockManager(cm);
_chunkMgrs[dim] = cm;
_blockMgrs[dim] = bm;

View file

@ -295,7 +295,7 @@ namespace Substrate
AnvilRegionManager rm = new AnvilRegionManager(path, cc);
RegionChunkManager cm = new RegionChunkManager(rm, cc);
BlockManager bm = new BlockManager(cm);
BlockManager bm = new AnvilBlockManager(cm);
_regionMgrs[dim] = rm;
_chunkMgrs[dim] = cm;

View file

@ -295,7 +295,7 @@ namespace Substrate
BetaRegionManager rm = new BetaRegionManager(path, cc);
RegionChunkManager cm = new RegionChunkManager(rm, cc);
BlockManager bm = new BlockManager(cm);
BlockManager bm = new AlphaBlockManager(cm);
_regionMgrs[dim] = rm;
_chunkMgrs[dim] = cm;

View file

@ -3,10 +3,48 @@ using Substrate.Core;
namespace Substrate
{
public class AlphaBlockManager : BlockManager
{
public AlphaBlockManager (IChunkManager cm)
: base(cm)
{
IChunk c = AlphaChunk.Create(0, 0);
chunkXDim = c.Blocks.XDim;
chunkYDim = c.Blocks.YDim;
chunkZDim = c.Blocks.ZDim;
chunkXMask = chunkXDim - 1;
chunkYMask = chunkYDim - 1;
chunkZMask = chunkZDim - 1;
chunkXLog = Log2(chunkXDim);
chunkYLog = Log2(chunkYDim);
chunkZLog = Log2(chunkZDim);
}
}
public class AnvilBlockManager : BlockManager
{
public AnvilBlockManager (IChunkManager cm)
: base(cm)
{
IChunk c = AnvilChunk.Create(0, 0);
chunkXDim = c.Blocks.XDim;
chunkYDim = c.Blocks.YDim;
chunkZDim = c.Blocks.ZDim;
chunkXMask = chunkXDim - 1;
chunkYMask = chunkYDim - 1;
chunkZMask = chunkZDim - 1;
chunkXLog = Log2(chunkXDim);
chunkYLog = Log2(chunkYDim);
chunkZLog = Log2(chunkZDim);
}
}
/// <summary>
/// Represents an Alpha-compatible interface for globally managing blocks.
/// </summary>
public class BlockManager : IVersion10BlockManager, IBlockManager
public abstract class BlockManager : IVersion10BlockManager, IBlockManager
{
public const int MIN_X = -32000000;
public const int MAX_X = 32000000;
@ -67,18 +105,6 @@ namespace Substrate
public BlockManager (IChunkManager cm)
{
chunkMan = cm;
IChunk c = AlphaChunk.Create(0, 0);
chunkXDim = c.Blocks.XDim;
chunkYDim = c.Blocks.YDim;
chunkZDim = c.Blocks.ZDim;
chunkXMask = chunkXDim - 1;
chunkYMask = chunkYDim - 1;
chunkZMask = chunkZDim - 1;
chunkXLog = Log2(chunkXDim);
chunkYLog = Log2(chunkYDim);
chunkZLog = Log2(chunkZDim);
}
/// <summary>
@ -151,7 +177,7 @@ namespace Substrate
return chunkMan.GetChunkRef(x, z);
}
private int Log2 (int x)
protected int Log2 (int x)
{
int c = 0;
while (x > 1) {