forked from mirrors/NBTExplorer
Another global lighting performance increase
This commit is contained in:
parent
e3021a66a4
commit
b03fe0fa09
2 changed files with 47 additions and 27 deletions
|
@ -29,5 +29,5 @@ using System.Runtime.InteropServices;
|
||||||
// Build Number
|
// Build Number
|
||||||
// Revision
|
// Revision
|
||||||
//
|
//
|
||||||
[assembly: AssemblyVersion("0.5.0.0")]
|
[assembly: AssemblyVersion("0.5.1.0")]
|
||||||
[assembly: AssemblyFileVersion("0.5.0.0")]
|
[assembly: AssemblyFileVersion("0.5.1.0")]
|
||||||
|
|
|
@ -82,9 +82,13 @@ namespace Substrate
|
||||||
{
|
{
|
||||||
IBoundedLitBlockCollection[,] chunkMap = LocalBlockLightMap();
|
IBoundedLitBlockCollection[,] chunkMap = LocalBlockLightMap();
|
||||||
|
|
||||||
for (int x = 0; x < _blockset.XDim; x++) {
|
int xdim = _blockset.XDim;
|
||||||
for (int z = 0; z < _blockset.ZDim; z++) {
|
int ydim = _blockset.YDim;
|
||||||
for (int y = 0; y < _blockset.YDim; y++) {
|
int zdim = _blockset.ZDim;
|
||||||
|
|
||||||
|
for (int x = 0; x < xdim; x++) {
|
||||||
|
for (int z = 0; z < zdim; z++) {
|
||||||
|
for (int y = 0; y < ydim; y++) {
|
||||||
BlockInfo info = _blockset.GetInfo(x, y, z);
|
BlockInfo info = _blockset.GetInfo(x, y, z);
|
||||||
if (info.Luminance > 0) {
|
if (info.Luminance > 0) {
|
||||||
SpreadBlockLight(chunkMap, x, y, z);
|
SpreadBlockLight(chunkMap, x, y, z);
|
||||||
|
@ -99,9 +103,13 @@ namespace Substrate
|
||||||
IBoundedLitBlockCollection[,] chunkMap = LocalBlockLightMap();
|
IBoundedLitBlockCollection[,] chunkMap = LocalBlockLightMap();
|
||||||
int[,] heightMap = LocalHeightMap(chunkMap);
|
int[,] heightMap = LocalHeightMap(chunkMap);
|
||||||
|
|
||||||
|
int xdim = _blockset.XDim;
|
||||||
|
int ydim = _blockset.YDim;
|
||||||
|
int zdim = _blockset.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 < _blockset.XDim; x++) {
|
for (int x = 0; x < xdim; x++) {
|
||||||
for (int z = 0; z < _blockset.ZDim; z++) {
|
for (int z = 0; z < zdim; z++) {
|
||||||
int xi = x + _blockset.XDim;
|
int xi = x + _blockset.XDim;
|
||||||
int zi = z + _blockset.ZDim;
|
int zi = z + _blockset.ZDim;
|
||||||
|
|
||||||
|
@ -111,7 +119,7 @@ namespace Substrate
|
||||||
h = Math.Max(h, heightMap[xi + 1, zi]);
|
h = Math.Max(h, heightMap[xi + 1, zi]);
|
||||||
h = Math.Max(h, heightMap[xi, zi + 1]);
|
h = Math.Max(h, heightMap[xi, zi + 1]);
|
||||||
|
|
||||||
for (int y = h + 1; y < _blockset.YDim; y++) {
|
for (int y = h + 1; y < ydim; y++) {
|
||||||
_blockset.SetSkyLight(x, y, z, BlockInfo.MAX_LUMINANCE);
|
_blockset.SetSkyLight(x, y, z, BlockInfo.MAX_LUMINANCE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -123,9 +131,13 @@ namespace Substrate
|
||||||
|
|
||||||
public void RebuildHeightMap ()
|
public void RebuildHeightMap ()
|
||||||
{
|
{
|
||||||
for (int x = 0; x < _blockset.XDim; x++) {
|
int xdim = _blockset.XDim;
|
||||||
for (int z = 0; z < _blockset.ZDim; z++) {
|
int ydim = _blockset.YDim;
|
||||||
for (int y = _blockset.YDim - 1; y >= 0; y--) {
|
int zdim = _blockset.ZDim;
|
||||||
|
|
||||||
|
for (int x = 0; x < xdim; x++) {
|
||||||
|
for (int z = 0; z < zdim; z++) {
|
||||||
|
for (int y = ydim - 1; y >= 0; y--) {
|
||||||
BlockInfo info = _blockset.GetInfo(x, y, z);
|
BlockInfo info = _blockset.GetInfo(x, y, z);
|
||||||
if (info.Opacity > BlockInfo.MIN_OPACITY || !info.TransmitsLight) {
|
if (info.Opacity > BlockInfo.MIN_OPACITY || !info.TransmitsLight) {
|
||||||
_blockset.SetHeight(x, z, y);
|
_blockset.SetHeight(x, z, y);
|
||||||
|
@ -401,11 +413,15 @@ namespace Substrate
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int xdim = _blockset.XDim;
|
||||||
|
int ydim = _blockset.YDim;
|
||||||
|
int zdim = _blockset.ZDim;
|
||||||
|
|
||||||
Queue<LightRecord> spread = new Queue<LightRecord>();
|
Queue<LightRecord> spread = new Queue<LightRecord>();
|
||||||
if (ly > 0) {
|
if (ly > 0) {
|
||||||
spread.Enqueue(new LightRecord(lx, ly - 1, lz, primary.Luminance - 1));
|
spread.Enqueue(new LightRecord(lx, ly - 1, lz, primary.Luminance - 1));
|
||||||
}
|
}
|
||||||
if (ly < _blockset.YDim - 1) {
|
if (ly < ydim - 1) {
|
||||||
spread.Enqueue(new LightRecord(lx, ly + 1, lz, primary.Luminance - 1));
|
spread.Enqueue(new LightRecord(lx, ly + 1, lz, primary.Luminance - 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -417,17 +433,17 @@ namespace Substrate
|
||||||
while (spread.Count > 0) {
|
while (spread.Count > 0) {
|
||||||
LightRecord rec = spread.Dequeue();
|
LightRecord rec = spread.Dequeue();
|
||||||
|
|
||||||
int xi = rec.x + _blockset.XDim;
|
int xi = rec.x + xdim;
|
||||||
int zi = rec.z + _blockset.ZDim;
|
int zi = rec.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 = rec.y;
|
int y = rec.y;
|
||||||
int z = zi % _blockset.ZDim;
|
int z = zi % zdim;
|
||||||
|
|
||||||
BlockInfo info = cc.GetInfo(x, y, z);
|
BlockInfo info = cc.GetInfo(x, y, z);
|
||||||
int light = cc.GetBlockLight(x, y, z);
|
int light = cc.GetBlockLight(x, y, z);
|
||||||
|
@ -443,7 +459,7 @@ namespace Substrate
|
||||||
if (rec.y > 0) {
|
if (rec.y > 0) {
|
||||||
spread.Enqueue(new LightRecord(rec.x, rec.y - 1, rec.z, strength));
|
spread.Enqueue(new LightRecord(rec.x, rec.y - 1, rec.z, strength));
|
||||||
}
|
}
|
||||||
if (rec.y < _blockset.YDim - 1) {
|
if (rec.y < ydim - 1) {
|
||||||
spread.Enqueue(new LightRecord(rec.x, rec.y + 1, rec.z, strength));
|
spread.Enqueue(new LightRecord(rec.x, rec.y + 1, rec.z, strength));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -472,8 +488,12 @@ namespace Substrate
|
||||||
|
|
||||||
Queue<LightRecord> spread = new Queue<LightRecord>();
|
Queue<LightRecord> spread = new Queue<LightRecord>();
|
||||||
|
|
||||||
int lxi = lx + _blockset.XDim;
|
int xdim = _blockset.XDim;
|
||||||
int lzi = lz + _blockset.ZDim;
|
int ydim = _blockset.YDim;
|
||||||
|
int zdim = _blockset.ZDim;
|
||||||
|
|
||||||
|
int lxi = lx + xdim;
|
||||||
|
int lzi = lz + zdim;
|
||||||
|
|
||||||
int strength = (primary.Opacity > 0) ? priLum : priLum - 1;
|
int strength = (primary.Opacity > 0) ? priLum : priLum - 1;
|
||||||
|
|
||||||
|
@ -486,7 +506,7 @@ namespace Substrate
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ly < _blockset.YDim - 1) {
|
if (ly < ydim - 1) {
|
||||||
if (heightMap[lxi, lzi] > ly + 1) {
|
if (heightMap[lxi, lzi] > ly + 1) {
|
||||||
spread.Enqueue(new LightRecord(lx, ly + 1, lz, strength));
|
spread.Enqueue(new LightRecord(lx, ly + 1, lz, strength));
|
||||||
}
|
}
|
||||||
|
@ -508,17 +528,17 @@ namespace Substrate
|
||||||
while (spread.Count > 0) {
|
while (spread.Count > 0) {
|
||||||
LightRecord rec = spread.Dequeue();
|
LightRecord rec = spread.Dequeue();
|
||||||
|
|
||||||
int xi = rec.x + _blockset.XDim;
|
int xi = rec.x + xdim;
|
||||||
int zi = rec.z + _blockset.ZDim;
|
int zi = rec.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 = rec.y;
|
int y = rec.y;
|
||||||
int z = zi % _blockset.ZDim;
|
int z = zi % zdim;
|
||||||
|
|
||||||
BlockInfo info = cc.GetInfo(x, y, z);
|
BlockInfo info = cc.GetInfo(x, y, z);
|
||||||
int light = cc.GetSkyLight(x, y, z);
|
int light = cc.GetSkyLight(x, y, z);
|
||||||
|
@ -540,7 +560,7 @@ namespace Substrate
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rec.y < _blockset.YDim - 1) {
|
if (rec.y < ydim - 1) {
|
||||||
if (heightMap[xi, zi] > rec.y + 1) {
|
if (heightMap[xi, zi] > rec.y + 1) {
|
||||||
spread.Enqueue(new LightRecord(rec.x, rec.y + 1, rec.z, strength));
|
spread.Enqueue(new LightRecord(rec.x, rec.y + 1, rec.z, strength));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue