Initial pass on lighting optimizations
This commit is contained in:
parent
8966367ebf
commit
f7ffe718a7
TrueCraft.Core.Test/Lighting
TrueCraft.Core
TrueCraft
@ -7,6 +7,7 @@ using TrueCraft.Core.Logic;
|
||||
using TrueCraft.API;
|
||||
using TrueCraft.Core.World;
|
||||
using TrueCraft.Core.Logic.Blocks;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace TrueCraft.Core.Test.Lighting
|
||||
{
|
||||
@ -191,6 +192,9 @@ namespace TrueCraft.Core.Test.Lighting
|
||||
world.SetBlockID(new Coordinates3D(x, 1, 5), 0); // Dig a tunnel
|
||||
}
|
||||
|
||||
var watch = new Stopwatch();
|
||||
watch.Start();
|
||||
|
||||
lighter.EnqueueOperation(new BoundingBox(new Vector3(5, 2, 5),
|
||||
new Vector3(6, 4, 6)), true);
|
||||
|
||||
@ -198,6 +202,8 @@ namespace TrueCraft.Core.Test.Lighting
|
||||
{
|
||||
}
|
||||
|
||||
watch.Stop();
|
||||
|
||||
// Output lighting
|
||||
for (int y = 3; y >= 0; y--)
|
||||
{
|
||||
@ -238,6 +244,8 @@ namespace TrueCraft.Core.Test.Lighting
|
||||
Assert.AreEqual(expected, world.GetSkyLight(new Coordinates3D(x, 1, 5)));
|
||||
expected--;
|
||||
}
|
||||
|
||||
Console.WriteLine("{0}ms", watch.ElapsedMilliseconds);
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
@ -54,14 +54,20 @@ namespace TrueCraft.Core.Lighting
|
||||
|
||||
private void GenerateHeightMap(IChunk chunk)
|
||||
{
|
||||
Coordinates3D coords;
|
||||
var map = new byte[Chunk.Width, Chunk.Depth];
|
||||
for (int x = 0; x < Chunk.Width; x++)
|
||||
{
|
||||
for (int z = 0; z < Chunk.Depth; z++)
|
||||
{
|
||||
for (byte y = Chunk.Height - 1; y > 0; y--)
|
||||
for (byte y = (byte)(chunk.GetHeight((byte)x, (byte)z) + 2); y > 0; y--)
|
||||
{
|
||||
var id = chunk.GetBlockID(new Coordinates3D(x, y - 1, z));
|
||||
if (y >= Chunk.Height)
|
||||
continue;
|
||||
coords.X = x; coords.Y = y - 1; coords.Z = z;
|
||||
var id = chunk.GetBlockID(coords);
|
||||
if (id == 0)
|
||||
continue;
|
||||
var provider = BlockRepository.GetBlockProvider(id);
|
||||
if (provider.LightOpacity != 0)
|
||||
{
|
||||
@ -82,9 +88,15 @@ namespace TrueCraft.Core.Lighting
|
||||
return;
|
||||
var map = HeightMaps[chunk.Coordinates];
|
||||
int x = adjusted.X; int z = adjusted.Z;
|
||||
for (byte y = Chunk.Height - 1; y > 0; y--)
|
||||
Coordinates3D _;
|
||||
for (byte y = (byte)(chunk.GetHeight((byte)x, (byte)z) + 2); y > 0; y--)
|
||||
{
|
||||
var id = chunk.GetBlockID(new Coordinates3D(x, y - 1, z));
|
||||
if (y >= Chunk.Height)
|
||||
continue;
|
||||
_.X = x; _.Y = y - 1; _.Z = z;
|
||||
var id = chunk.GetBlockID(_);
|
||||
if (id == 0)
|
||||
continue;
|
||||
var provider = BlockRepository.GetBlockProvider(id);
|
||||
if (provider.LightOpacity != 0)
|
||||
{
|
||||
|
@ -82,6 +82,7 @@ namespace TrueCraft.Core.TerrainGen
|
||||
for (int i = 0; i < chunk.Biomes.Length; i++)
|
||||
chunk.Biomes[i] = (byte)Biome;
|
||||
chunk.TerrainPopulated = true;
|
||||
chunk.UpdateHeightMap();
|
||||
return chunk;
|
||||
}
|
||||
|
||||
|
@ -189,6 +189,7 @@ namespace TrueCraft.Core.TerrainGen
|
||||
foreach (var decorator in ChunkDecorators)
|
||||
decorator.Decorate(world, chunk, Biomes);
|
||||
chunk.TerrainPopulated = true;
|
||||
chunk.UpdateHeightMap();
|
||||
return chunk;
|
||||
}
|
||||
|
||||
|
@ -192,11 +192,15 @@ namespace TrueCraft
|
||||
{
|
||||
var lighter = new WorldLighting(sender as IWorld, BlockRepository);
|
||||
var coords = e.Coordinates * new Coordinates2D(Chunk.Width, Chunk.Depth);
|
||||
var watch = new Stopwatch();
|
||||
watch.Start();
|
||||
lighter.EnqueueOperation(new BoundingBox(new Vector3(coords.X, 0, coords.Z),
|
||||
new Vector3(coords.X + Chunk.Width, Chunk.Height, coords.Z + Chunk.Depth)), true, true);
|
||||
while (lighter.TryLightNext()) // Initial lighting
|
||||
{
|
||||
}
|
||||
watch.Stop();
|
||||
Console.WriteLine("Initial chunk lighting took {0}ms", watch.ElapsedMilliseconds);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user