This repository has been archived on 2024-06-13. You can view files and clone it, but cannot push or open issues or pull requests.
Drew DeVault 6fb8ee7ba5 Many more optimizations and bugfixes
Again, sorry for the huge commit. Just taking on performance issues as I
see them. Changes in this:

- Deadlocks in region code finally fixed
- Chunk packet preparation optimized (saves ~10-20ms per packet, since
  we're sending these like 30 at a time that's pretty important) by
  storing chunks pre-encoded in memory (basically just using a single
  big array for IDs, metadata, and light)
- Move chunk generation and compression to the thread pool
- Move client chunk updates to the scheduler
- Improve profiler coverage
- Add knob to disable scheduling chunk events on chunk load
- Make it possible to disable specific scheduled events in config.yml
2017-05-23 18:17:44 -04:00

91 lines
2.9 KiB
C#

using System;
using NUnit.Framework;
using TrueCraft.Core.World;
using TrueCraft.API;
using fNbt;
using TrueCraft.Core.Logic.Blocks;
using System.IO;
using System.Reflection;
namespace TrueCraft.Core.Test.World
{
[TestFixture]
public class ChunkTest
{
[Test]
public void TestGetBlockID()
{
var chunk = new Chunk();
chunk.SetBlockID(Coordinates3D.Zero, 12);
Assert.AreEqual(12, chunk.GetBlockID(Coordinates3D.Zero));
}
[Test]
public void TestGetBlockLight()
{
var chunk = new Chunk();
chunk.SetBlockLight(Coordinates3D.Zero, 5);
Assert.AreEqual(5, chunk.GetBlockLight(Coordinates3D.Zero));
}
[Test]
public void TestGetSkyLight()
{
var chunk = new Chunk();
chunk.SetSkyLight(Coordinates3D.Zero, 5);
Assert.AreEqual(5, chunk.GetSkyLight(Coordinates3D.Zero));
}
[Test]
public void TestGetMetadata()
{
var chunk = new Chunk();
chunk.SetMetadata(Coordinates3D.Zero, 5);
Assert.AreEqual(5, chunk.GetMetadata(Coordinates3D.Zero));
}
[Test]
public void TestHeightMap()
{
var chunk = new Chunk();
for (int x = 0; x < Chunk.Width; ++x)
for (int z = 0; z < Chunk.Width; ++z)
chunk.SetBlockID(new Coordinates3D(x, 20, z), StoneBlock.BlockID);
chunk.UpdateHeightMap();
Assert.AreEqual(20, chunk.GetHeight(0, 0));
Assert.AreEqual(20, chunk.GetHeight(1, 0));
chunk.SetBlockID(new Coordinates3D(1, 80, 0), 1);
Assert.AreEqual(80, chunk.GetHeight(1, 0));
}
[Test]
public void TestConsistency()
{
var chunk = new Chunk();
byte val = 0;
for (int y = 0; y < Chunk.Height; y++)
for (int x = 0; x < Chunk.Width; x++)
for (int z = 0; z < Chunk.Depth; z++)
{
var coords = new Coordinates3D(x, y, z);
chunk.SetBlockID(coords, val);
chunk.SetMetadata(coords, (byte)(val % 16));
chunk.SetBlockLight(coords, (byte)(val % 16));
chunk.SetSkyLight(coords, (byte)(val % 16));
val++;
}
val = 0;
for (int y = 0; y < Chunk.Height; y++)
for (int x = 0; x < Chunk.Width; x++)
for (int z = 0; z < Chunk.Depth; z++)
{
var coords = new Coordinates3D(x, y, z);
Assert.AreEqual(val, chunk.GetBlockID(coords));
Assert.AreEqual((byte)(val % 16), chunk.GetMetadata(coords));
Assert.AreEqual((byte)(val % 16), chunk.GetBlockLight(coords));
Assert.AreEqual((byte)(val % 16), chunk.GetSkyLight(coords));
val++;
}
}
}
}