forked from mirrors/NBTExplorer
A little more optimization
This commit is contained in:
parent
b03fe0fa09
commit
41cfa1b425
1 changed files with 125 additions and 89 deletions
|
@ -25,6 +25,10 @@ namespace Substrate
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private readonly int _xdim;
|
||||||
|
private readonly int _ydim;
|
||||||
|
private readonly int _zdim;
|
||||||
|
|
||||||
private IBoundedLitBlockCollection _blockset;
|
private IBoundedLitBlockCollection _blockset;
|
||||||
|
|
||||||
// Maintains internal state of multi-block relighting algorithms
|
// Maintains internal state of multi-block relighting algorithms
|
||||||
|
@ -39,6 +43,10 @@ namespace Substrate
|
||||||
{
|
{
|
||||||
_blockset = blockset;
|
_blockset = blockset;
|
||||||
|
|
||||||
|
_xdim = _blockset.XDim;
|
||||||
|
_ydim = _blockset.YDim;
|
||||||
|
_zdim = _blockset.ZDim;
|
||||||
|
|
||||||
_lightbit = new BitArray(_blockset.XDim * 3 * _blockset.ZDim * 3 * _blockset.YDim);
|
_lightbit = new BitArray(_blockset.XDim * 3 * _blockset.ZDim * 3 * _blockset.YDim);
|
||||||
_update = new Queue<BlockKey>();
|
_update = new Queue<BlockKey>();
|
||||||
}
|
}
|
||||||
|
@ -47,6 +55,10 @@ namespace Substrate
|
||||||
{
|
{
|
||||||
_blockset = bl._blockset;
|
_blockset = bl._blockset;
|
||||||
|
|
||||||
|
_xdim = bl._xdim;
|
||||||
|
_ydim = bl._ydim;
|
||||||
|
_zdim = bl._zdim;
|
||||||
|
|
||||||
_lightbit = new BitArray(_blockset.XDim * 3 * _blockset.ZDim * 3 * _blockset.YDim);
|
_lightbit = new BitArray(_blockset.XDim * 3 * _blockset.ZDim * 3 * _blockset.YDim);
|
||||||
_update = new Queue<BlockKey>();
|
_update = new Queue<BlockKey>();
|
||||||
}
|
}
|
||||||
|
@ -82,9 +94,10 @@ namespace Substrate
|
||||||
{
|
{
|
||||||
IBoundedLitBlockCollection[,] chunkMap = LocalBlockLightMap();
|
IBoundedLitBlockCollection[,] chunkMap = LocalBlockLightMap();
|
||||||
|
|
||||||
int xdim = _blockset.XDim;
|
// Because the JIT is less intelligent than I hoped
|
||||||
int ydim = _blockset.YDim;
|
int xdim = _xdim;
|
||||||
int zdim = _blockset.ZDim;
|
int ydim = _ydim;
|
||||||
|
int zdim = _zdim;
|
||||||
|
|
||||||
for (int x = 0; x < xdim; x++) {
|
for (int x = 0; x < xdim; x++) {
|
||||||
for (int z = 0; z < zdim; z++) {
|
for (int z = 0; z < zdim; z++) {
|
||||||
|
@ -103,15 +116,15 @@ namespace Substrate
|
||||||
IBoundedLitBlockCollection[,] chunkMap = LocalBlockLightMap();
|
IBoundedLitBlockCollection[,] chunkMap = LocalBlockLightMap();
|
||||||
int[,] heightMap = LocalHeightMap(chunkMap);
|
int[,] heightMap = LocalHeightMap(chunkMap);
|
||||||
|
|
||||||
int xdim = _blockset.XDim;
|
int xdim = _xdim;
|
||||||
int ydim = _blockset.YDim;
|
int ydim = _ydim;
|
||||||
int zdim = _blockset.ZDim;
|
int zdim = _zdim;
|
||||||
|
|
||||||
// Optimization - only need to queue at level of highest neighbor's height
|
// Optimization - only need to queue at level of highest neighbor's height
|
||||||
for (int x = 0; x < xdim; x++) {
|
for (int x = 0; x < xdim; x++) {
|
||||||
for (int z = 0; z < zdim; z++) {
|
for (int z = 0; z < zdim; z++) {
|
||||||
int xi = x + _blockset.XDim;
|
int xi = x + xdim;
|
||||||
int zi = z + _blockset.ZDim;
|
int zi = z + zdim;
|
||||||
|
|
||||||
int h = heightMap[xi, zi];
|
int h = heightMap[xi, zi];
|
||||||
h = Math.Max(h, heightMap[xi, zi - 1]);
|
h = Math.Max(h, heightMap[xi, zi - 1]);
|
||||||
|
@ -131,9 +144,9 @@ namespace Substrate
|
||||||
|
|
||||||
public void RebuildHeightMap ()
|
public void RebuildHeightMap ()
|
||||||
{
|
{
|
||||||
int xdim = _blockset.XDim;
|
int xdim = _xdim;
|
||||||
int ydim = _blockset.YDim;
|
int ydim = _ydim;
|
||||||
int zdim = _blockset.ZDim;
|
int zdim = _zdim;
|
||||||
|
|
||||||
for (int x = 0; x < xdim; x++) {
|
for (int x = 0; x < xdim; x++) {
|
||||||
for (int z = 0; z < zdim; z++) {
|
for (int z = 0; z < zdim; z++) {
|
||||||
|
@ -170,41 +183,45 @@ namespace Substrate
|
||||||
// TODO: Revise to cache the specified chunk into local map
|
// TODO: Revise to cache the specified chunk into local map
|
||||||
public void StitchBlockLight (IBoundedLitBlockCollection chunk, BlockCollectionEdge edge)
|
public void StitchBlockLight (IBoundedLitBlockCollection chunk, BlockCollectionEdge edge)
|
||||||
{
|
{
|
||||||
if (chunk.XDim != _blockset.XDim ||
|
int xdim = _xdim;
|
||||||
chunk.YDim != _blockset.YDim ||
|
int ydim = _ydim;
|
||||||
chunk.ZDim != _blockset.ZDim) {
|
int zdim = _zdim;
|
||||||
|
|
||||||
|
if (chunk.XDim != xdim ||
|
||||||
|
chunk.YDim != ydim ||
|
||||||
|
chunk.ZDim != zdim) {
|
||||||
throw new InvalidOperationException("BlockLight must have same dimensions to be stitched");
|
throw new InvalidOperationException("BlockLight must have same dimensions to be stitched");
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (edge) {
|
switch (edge) {
|
||||||
case BlockCollectionEdge.EAST:
|
case BlockCollectionEdge.EAST:
|
||||||
for (int x = 0; x < _blockset.XDim; x++) {
|
for (int x = 0; x < xdim; x++) {
|
||||||
for (int y = 0; y < _blockset.YDim; y++) {
|
for (int y = 0; y < ydim; y++) {
|
||||||
TestBlockLight(chunk, x, y, 0, x, y, _blockset.ZDim - 1);
|
TestBlockLight(chunk, x, y, 0, x, y, zdim - 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case BlockCollectionEdge.NORTH:
|
case BlockCollectionEdge.NORTH:
|
||||||
for (int z = 0; z < _blockset.ZDim; z++) {
|
for (int z = 0; z < zdim; z++) {
|
||||||
for (int y = 0; y < _blockset.YDim; y++) {
|
for (int y = 0; y < ydim; y++) {
|
||||||
TestBlockLight(chunk, 0, y, z, _blockset.XDim - 1, y, z);
|
TestBlockLight(chunk, 0, y, z, xdim - 1, y, z);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case BlockCollectionEdge.WEST:
|
case BlockCollectionEdge.WEST:
|
||||||
for (int x = 0; x < _blockset.XDim; x++) {
|
for (int x = 0; x < xdim; x++) {
|
||||||
for (int y = 0; y < _blockset.YDim; y++) {
|
for (int y = 0; y < ydim; y++) {
|
||||||
TestBlockLight(chunk, x, y, _blockset.ZDim - 1, x, y, 0);
|
TestBlockLight(chunk, x, y, zdim - 1, x, y, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case BlockCollectionEdge.SOUTH:
|
case BlockCollectionEdge.SOUTH:
|
||||||
for (int z = 0; z < _blockset.ZDim; z++) {
|
for (int z = 0; z < zdim; z++) {
|
||||||
for (int y = 0; y < _blockset.YDim; y++) {
|
for (int y = 0; y < ydim; y++) {
|
||||||
TestBlockLight(chunk, _blockset.XDim - 1, y, z, 0, y, z);
|
TestBlockLight(chunk, xdim - 1, y, z, 0, y, z);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -233,41 +250,45 @@ namespace Substrate
|
||||||
|
|
||||||
public void StitchBlockSkyLight (IBoundedLitBlockCollection chunk, BlockCollectionEdge edge)
|
public void StitchBlockSkyLight (IBoundedLitBlockCollection chunk, BlockCollectionEdge edge)
|
||||||
{
|
{
|
||||||
if (chunk.XDim != _blockset.XDim ||
|
int xdim = _xdim;
|
||||||
chunk.YDim != _blockset.YDim ||
|
int ydim = _ydim;
|
||||||
chunk.ZDim != _blockset.ZDim) {
|
int zdim = _zdim;
|
||||||
|
|
||||||
|
if (chunk.XDim != xdim ||
|
||||||
|
chunk.YDim != ydim ||
|
||||||
|
chunk.ZDim != zdim) {
|
||||||
throw new InvalidOperationException("BlockLight must have same dimensions to be stitched");
|
throw new InvalidOperationException("BlockLight must have same dimensions to be stitched");
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (edge) {
|
switch (edge) {
|
||||||
case BlockCollectionEdge.EAST:
|
case BlockCollectionEdge.EAST:
|
||||||
for (int x = 0; x < _blockset.XDim; x++) {
|
for (int x = 0; x < xdim; x++) {
|
||||||
for (int y = 0; y < _blockset.YDim; y++) {
|
for (int y = 0; y < ydim; y++) {
|
||||||
TestSkyLight(chunk, x, y, 0, x, y, _blockset.ZDim - 1);
|
TestSkyLight(chunk, x, y, 0, x, y, zdim - 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case BlockCollectionEdge.NORTH:
|
case BlockCollectionEdge.NORTH:
|
||||||
for (int z = 0; z < _blockset.ZDim; z++) {
|
for (int z = 0; z < zdim; z++) {
|
||||||
for (int y = 0; y < _blockset.YDim; y++) {
|
for (int y = 0; y < ydim; y++) {
|
||||||
TestSkyLight(chunk, 0, y, z, _blockset.XDim - 1, y, z);
|
TestSkyLight(chunk, 0, y, z, xdim, y, z);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case BlockCollectionEdge.WEST:
|
case BlockCollectionEdge.WEST:
|
||||||
for (int x = 0; x < _blockset.XDim; x++) {
|
for (int x = 0; x < xdim; x++) {
|
||||||
for (int y = 0; y < _blockset.YDim; y++) {
|
for (int y = 0; y < ydim; y++) {
|
||||||
TestSkyLight(chunk, x, y, _blockset.ZDim - 1, x, y, 0);
|
TestSkyLight(chunk, x, y, zdim - 1, x, y, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case BlockCollectionEdge.SOUTH:
|
case BlockCollectionEdge.SOUTH:
|
||||||
for (int z = 0; z < _blockset.ZDim; z++) {
|
for (int z = 0; z < zdim; z++) {
|
||||||
for (int y = 0; y < _blockset.YDim; y++) {
|
for (int y = 0; y < ydim; y++) {
|
||||||
TestSkyLight(chunk, _blockset.XDim - 1, y, z, 0, y, z);
|
TestSkyLight(chunk, xdim - 1, y, z, 0, y, z);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -281,15 +302,18 @@ namespace Substrate
|
||||||
{
|
{
|
||||||
IBoundedLitBlockCollection[,] chunkMap = LocalBlockLightMap();
|
IBoundedLitBlockCollection[,] chunkMap = LocalBlockLightMap();
|
||||||
|
|
||||||
|
int xdim = _xdim;
|
||||||
|
int zdim = _zdim;
|
||||||
|
|
||||||
while (_update.Count > 0) {
|
while (_update.Count > 0) {
|
||||||
BlockKey k = _update.Dequeue();
|
BlockKey k = _update.Dequeue();
|
||||||
int index = LightBitmapIndex(k);
|
int index = LightBitmapIndex(k);
|
||||||
_lightbit[index] = false;
|
_lightbit[index] = false;
|
||||||
|
|
||||||
int xi = k.x + _blockset.XDim;
|
int xi = k.x + xdim;
|
||||||
int zi = k.z + _blockset.ZDim;
|
int zi = k.z + zdim;
|
||||||
|
|
||||||
IBoundedLitBlockCollection cc = chunkMap[xi / _blockset.XDim, zi / _blockset.ZDim];
|
IBoundedLitBlockCollection cc = chunkMap[xi / xdim, zi / zdim];
|
||||||
if (cc == null) {
|
if (cc == null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -301,9 +325,9 @@ namespace Substrate
|
||||||
int lld = NeighborLight(chunkMap, k.x, k.y - 1, k.z);
|
int lld = NeighborLight(chunkMap, k.x, k.y - 1, k.z);
|
||||||
int llu = NeighborLight(chunkMap, k.x, k.y + 1, k.z);
|
int llu = NeighborLight(chunkMap, k.x, k.y + 1, k.z);
|
||||||
|
|
||||||
int x = xi % _blockset.XDim;
|
int x = xi % xdim;
|
||||||
int y = k.y;
|
int y = k.y;
|
||||||
int z = zi % _blockset.ZDim;
|
int z = zi % zdim;
|
||||||
|
|
||||||
int lightval = cc.GetBlockLight(x, y, z);
|
int lightval = cc.GetBlockLight(x, y, z);
|
||||||
BlockInfo info = cc.GetInfo(x, y, z);
|
BlockInfo info = cc.GetInfo(x, y, z);
|
||||||
|
@ -339,22 +363,25 @@ namespace Substrate
|
||||||
{
|
{
|
||||||
IBoundedLitBlockCollection[,] chunkMap = LocalBlockLightMap();
|
IBoundedLitBlockCollection[,] chunkMap = LocalBlockLightMap();
|
||||||
|
|
||||||
|
int xdim = _xdim;
|
||||||
|
int zdim = _zdim;
|
||||||
|
|
||||||
while (_update.Count > 0) {
|
while (_update.Count > 0) {
|
||||||
BlockKey k = _update.Dequeue();
|
BlockKey k = _update.Dequeue();
|
||||||
int index = LightBitmapIndex(k);
|
int index = LightBitmapIndex(k);
|
||||||
_lightbit[index] = false;
|
_lightbit[index] = false;
|
||||||
|
|
||||||
int xi = k.x + _blockset.XDim;
|
int xi = k.x + xdim;
|
||||||
int zi = k.z + _blockset.ZDim;
|
int zi = k.z + zdim;
|
||||||
|
|
||||||
IBoundedLitBlockCollection cc = chunkMap[xi / _blockset.XDim, zi / _blockset.ZDim];
|
IBoundedLitBlockCollection cc = chunkMap[xi / xdim, zi / zdim];
|
||||||
if (cc == null) {
|
if (cc == null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
int x = xi % _blockset.XDim;
|
int x = xi % xdim;
|
||||||
int y = k.y;
|
int y = k.y;
|
||||||
int z = zi % _blockset.ZDim;
|
int z = zi % zdim;
|
||||||
|
|
||||||
int lightval = cc.GetSkyLight(x, y, z);
|
int lightval = cc.GetSkyLight(x, y, z);
|
||||||
BlockInfo info = cc.GetInfo(x, y, z);
|
BlockInfo info = cc.GetInfo(x, y, z);
|
||||||
|
@ -413,9 +440,9 @@ namespace Substrate
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int xdim = _blockset.XDim;
|
int xdim = _xdim;
|
||||||
int ydim = _blockset.YDim;
|
int ydim = _ydim;
|
||||||
int zdim = _blockset.ZDim;
|
int zdim = _zdim;
|
||||||
|
|
||||||
Queue<LightRecord> spread = new Queue<LightRecord>();
|
Queue<LightRecord> spread = new Queue<LightRecord>();
|
||||||
if (ly > 0) {
|
if (ly > 0) {
|
||||||
|
@ -488,9 +515,9 @@ namespace Substrate
|
||||||
|
|
||||||
Queue<LightRecord> spread = new Queue<LightRecord>();
|
Queue<LightRecord> spread = new Queue<LightRecord>();
|
||||||
|
|
||||||
int xdim = _blockset.XDim;
|
int xdim = _xdim;
|
||||||
int ydim = _blockset.YDim;
|
int ydim = _ydim;
|
||||||
int zdim = _blockset.ZDim;
|
int zdim = _zdim;
|
||||||
|
|
||||||
int lxi = lx + xdim;
|
int lxi = lx + xdim;
|
||||||
int lzi = lz + zdim;
|
int lzi = lz + zdim;
|
||||||
|
@ -586,12 +613,12 @@ namespace Substrate
|
||||||
|
|
||||||
private int LightBitmapIndex (BlockKey key)
|
private int LightBitmapIndex (BlockKey key)
|
||||||
{
|
{
|
||||||
int x = key.x + _blockset.XDim;
|
int x = key.x + _xdim;
|
||||||
int y = key.y;
|
int y = key.y;
|
||||||
int z = key.z + _blockset.ZDim;
|
int z = key.z + _zdim;
|
||||||
|
|
||||||
int zstride = _blockset.YDim;
|
int zstride = _ydim;
|
||||||
int xstride = _blockset.ZDim * 3 * zstride;
|
int xstride = _zdim * 3 * zstride;
|
||||||
|
|
||||||
return (x * xstride) + (z * zstride) + y;
|
return (x * xstride) + (z * zstride) + y;
|
||||||
}
|
}
|
||||||
|
@ -613,7 +640,7 @@ namespace Substrate
|
||||||
|
|
||||||
private IBoundedLitBlockCollection LocalChunk (int lx, int ly, int lz)
|
private IBoundedLitBlockCollection LocalChunk (int lx, int ly, int lz)
|
||||||
{
|
{
|
||||||
if (ly < 0 || ly >= _blockset.YDim) {
|
if (ly < 0 || ly >= _ydim) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -621,16 +648,16 @@ namespace Substrate
|
||||||
if (lz < 0) {
|
if (lz < 0) {
|
||||||
return OnResolveNeighbor(-1, 0, -1);
|
return OnResolveNeighbor(-1, 0, -1);
|
||||||
}
|
}
|
||||||
else if (lz >= _blockset.ZDim) {
|
else if (lz >= _zdim) {
|
||||||
return OnResolveNeighbor(-1, 0, 1);
|
return OnResolveNeighbor(-1, 0, 1);
|
||||||
}
|
}
|
||||||
return OnResolveNeighbor(-1, 0, 0);
|
return OnResolveNeighbor(-1, 0, 0);
|
||||||
}
|
}
|
||||||
else if (lx >= _blockset.XDim) {
|
else if (lx >= _xdim) {
|
||||||
if (lz < 0) {
|
if (lz < 0) {
|
||||||
return OnResolveNeighbor(1, 0, -1);
|
return OnResolveNeighbor(1, 0, -1);
|
||||||
}
|
}
|
||||||
else if (lz >= _blockset.ZDim) {
|
else if (lz >= _zdim) {
|
||||||
return OnResolveNeighbor(1, 0, 1);
|
return OnResolveNeighbor(1, 0, 1);
|
||||||
}
|
}
|
||||||
return OnResolveNeighbor(1, 0, 0);
|
return OnResolveNeighbor(1, 0, 0);
|
||||||
|
@ -639,7 +666,7 @@ namespace Substrate
|
||||||
if (lz < 0) {
|
if (lz < 0) {
|
||||||
return OnResolveNeighbor(0, 0, -1);
|
return OnResolveNeighbor(0, 0, -1);
|
||||||
}
|
}
|
||||||
else if (lz >= _blockset.ZDim) {
|
else if (lz >= _zdim) {
|
||||||
return OnResolveNeighbor(0, 0, 1);
|
return OnResolveNeighbor(0, 0, 1);
|
||||||
}
|
}
|
||||||
return _blockset;
|
return _blockset;
|
||||||
|
@ -648,20 +675,23 @@ namespace Substrate
|
||||||
|
|
||||||
private int NeighborLight (IBoundedLitBlockCollection[,] chunkMap, int x, int y, int z)
|
private int NeighborLight (IBoundedLitBlockCollection[,] chunkMap, int x, int y, int z)
|
||||||
{
|
{
|
||||||
if (y < 0 || y >= _blockset.YDim) {
|
if (y < 0 || y >= _ydim) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int xi = x + _blockset.XDim;
|
int xdim = _xdim;
|
||||||
int zi = z + _blockset.ZDim;
|
int zdim = _zdim;
|
||||||
|
|
||||||
IBoundedLitBlockCollection src = chunkMap[xi / _blockset.XDim, zi / _blockset.ZDim];
|
int xi = x + xdim;
|
||||||
|
int zi = z + zdim;
|
||||||
|
|
||||||
|
IBoundedLitBlockCollection src = chunkMap[xi / xdim, zi / zdim];
|
||||||
if (src == null) {
|
if (src == null) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
x = xi % _blockset.XDim;
|
x = xi % xdim;
|
||||||
z = zi % _blockset.ZDim;
|
z = zi % zdim;
|
||||||
|
|
||||||
BlockInfo info = src.GetInfo(x, y, z);
|
BlockInfo info = src.GetInfo(x, y, z);
|
||||||
if (!info.TransmitsLight) {
|
if (!info.TransmitsLight) {
|
||||||
|
@ -675,20 +705,23 @@ namespace Substrate
|
||||||
|
|
||||||
private int NeighborSkyLight (IBoundedLitBlockCollection[,] chunkMap, int x, int y, int z)
|
private int NeighborSkyLight (IBoundedLitBlockCollection[,] chunkMap, int x, int y, int z)
|
||||||
{
|
{
|
||||||
if (y < 0 || y >= _blockset.YDim) {
|
if (y < 0 || y >= _ydim) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int xi = x + _blockset.XDim;
|
int xdim = _xdim;
|
||||||
int zi = z + _blockset.ZDim;
|
int zdim = _zdim;
|
||||||
|
|
||||||
IBoundedLitBlockCollection src = chunkMap[xi / _blockset.XDim, zi / _blockset.ZDim];
|
int xi = x + xdim;
|
||||||
|
int zi = z + zdim;
|
||||||
|
|
||||||
|
IBoundedLitBlockCollection src = chunkMap[xi / xdim, zi / zdim];
|
||||||
if (src == null) {
|
if (src == null) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
x = xi % _blockset.XDim;
|
x = xi % xdim;
|
||||||
z = zi % _blockset.ZDim;
|
z = zi % zdim;
|
||||||
|
|
||||||
BlockInfo info = src.GetInfo(x, y, z);
|
BlockInfo info = src.GetInfo(x, y, z);
|
||||||
if (!info.TransmitsLight) {
|
if (!info.TransmitsLight) {
|
||||||
|
@ -704,11 +737,11 @@ namespace Substrate
|
||||||
{
|
{
|
||||||
IBoundedLitBlockCollection src = LocalChunk(x, 0, z);
|
IBoundedLitBlockCollection src = LocalChunk(x, 0, z);
|
||||||
if (src == null) {
|
if (src == null) {
|
||||||
return _blockset.YDim - 1;
|
return _ydim - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
x = (x + _blockset.XDim * 2) % _blockset.XDim;
|
x = (x + _xdim * 2) % _xdim;
|
||||||
z = (z + _blockset.ZDim * 2) % _blockset.ZDim;
|
z = (z + _zdim * 2) % _zdim;
|
||||||
|
|
||||||
return src.GetHeight(x, z);
|
return src.GetHeight(x, z);
|
||||||
}
|
}
|
||||||
|
@ -758,19 +791,22 @@ namespace Substrate
|
||||||
|
|
||||||
private int[,] LocalHeightMap (IBoundedLitBlockCollection[,] chunkMap)
|
private int[,] LocalHeightMap (IBoundedLitBlockCollection[,] chunkMap)
|
||||||
{
|
{
|
||||||
int[,] map = new int[3 * _blockset.XDim, 3 * _blockset.ZDim];
|
int xdim = _xdim;
|
||||||
|
int zdim = _zdim;
|
||||||
|
|
||||||
|
int[,] map = new int[3 * xdim, 3 * zdim];
|
||||||
|
|
||||||
for (int xi = 0; xi < 3; xi++) {
|
for (int xi = 0; xi < 3; xi++) {
|
||||||
int xoff = xi * _blockset.XDim;
|
int xoff = xi * xdim;
|
||||||
for (int zi = 0; zi < 3; zi++) {
|
for (int zi = 0; zi < 3; zi++) {
|
||||||
int zoff = zi * _blockset.ZDim;
|
int zoff = zi * zdim;
|
||||||
if (chunkMap[xi, zi] == null) {
|
if (chunkMap[xi, zi] == null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int x = 0; x < _blockset.XDim; x++) {
|
for (int x = 0; x < xdim; x++) {
|
||||||
int xx = xoff + x;
|
int xx = xoff + x;
|
||||||
for (int z = 0; z < _blockset.ZDim; z++) {
|
for (int z = 0; z < zdim; z++) {
|
||||||
int zz = zoff + z;
|
int zz = zoff + z;
|
||||||
map[xx, zz] = chunkMap[xi, zi].GetHeight(x, z);
|
map[xx, zz] = chunkMap[xi, zi].GetHeight(x, z);
|
||||||
}
|
}
|
||||||
|
@ -791,9 +827,9 @@ namespace Substrate
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (n.XDim != _blockset.XDim ||
|
if (n.XDim != _xdim ||
|
||||||
n.YDim != _blockset.YDim ||
|
n.YDim != _ydim ||
|
||||||
n.ZDim != _blockset.ZDim) {
|
n.ZDim != _zdim) {
|
||||||
throw new InvalidOperationException("Subscriber returned incompatible ILitBlockCollection");
|
throw new InvalidOperationException("Subscriber returned incompatible ILitBlockCollection");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue