Minor stuff

This commit is contained in:
Justin Aquadro 2011-04-13 09:17:50 +00:00
parent 6f78009c0e
commit 9c7a96d3b9
3 changed files with 20 additions and 67 deletions

View file

@ -28,6 +28,14 @@ namespace Substrate
protected ChunkRef _cache; protected ChunkRef _cache;
private bool _autoLight;
public bool AutoRecalcLight
{
get { return _autoLight; }
set { _autoLight = value; }
}
public BlockManager (IChunkManager cm) public BlockManager (IChunkManager cm)
{ {
_chunkMan = cm; _chunkMan = cm;
@ -158,7 +166,14 @@ namespace Substrate
return false; return false;
} }
return _cache.SetBlockID(x & _chunkXMask, y & _chunkYMask, z & _chunkZMask, id); bool autolight = _cache.AutoRecalcLight;
_cache.AutoRecalcLight = _autoLight;
bool ret = _cache.SetBlockID(x & _chunkXMask, y & _chunkYMask, z & _chunkZMask, id);
_cache.AutoRecalcLight = autolight;
return ret;
} }
public bool SetBlockData (int x, int y, int z, int data) public bool SetBlockData (int x, int y, int z, int data)

View file

@ -734,72 +734,6 @@ namespace Substrate
#endregion #endregion
public void ResetBlockLight ()
{
for (int i = 0; i < _blocks.Length; i++) {
BlockInfo info = BlockInfo.BlockTable[_blocks[i]];
if (info == null) {
_blockLight[i] = 0;
}
else {
_blockLight[i] = Math.Max(info.Luminance - info.Opacity, 0);
}
}
}
public void StepBlockLight (IChunk east, IChunk north, IChunk south, IChunk west)
{
for (int x = 0; x < XDim; x++) {
for (int z = 0; z < ZDim; z++) {
for (int y = 0; y < YDim; y++) {
int lle = NeighborLight(x, y, z - 1, east);
int lln = NeighborLight(x - 1, y, z, north);
int lls = NeighborLight(x, y, z + 1, south);
int llw = NeighborLight(x + 1, y, z, west);
int lld = NeighborLight(x, y - 1, z, null);
int llu = NeighborLight(x, y + 1, z, null);
BlockInfo info = GetBlockInfo(x, y, z);
int light = Math.Max(info.Luminance, 0);
light = Math.Max(light, lle - 1);
light = Math.Max(light, lln - 1);
light = Math.Max(light, lls - 1);
light = Math.Max(light, llw - 1);
light = Math.Max(light, lld - 1);
light = Math.Max(light, llu - 1);
light = Math.Max(light - info.Opacity, 0);
SetBlockLight(x, y, z, light);
}
}
}
}
private int NeighborLight (int x, int y, int z, IChunk n)
{
if (y < 0 || y >= YDim) {
return 0;
}
IChunk src = this;
if (x < 0 || x >= XDim || z < 0 || z >= ZDim) {
src = n;
x = (x + XDim) % XDim;
z = (z + ZDim) % ZDim;
}
if (src == null) {
return 0;
}
BlockInfo info = src.GetBlockInfo(x, y, z);
int light = src.GetBlockLight(x, y, z);
return Math.Max(light, info.Luminance);
}
private int Timestamp () private int Timestamp ()
{ {
DateTime epoch = new DateTime(1970, 1, 1, 0, 0, 0, 0); DateTime epoch = new DateTime(1970, 1, 1, 0, 0, 0, 0);

View file

@ -149,6 +149,10 @@ namespace Substrate
{ {
_player = new Player(); _player = new Player();
_player.World = _name; _player.World = _name;
_player.Position.X = _spawnX;
_player.Position.Y = _spawnY + 1.7;
_player.Position.Z = _spawnZ;
} }
public bool Save () public bool Save ()