Update (un-update?) world implementation to b1.7.3

This commit is contained in:
Drew DeVault 2014-12-27 12:51:45 -07:00
parent 96ecbc708c
commit 09163f36ee
7 changed files with 25 additions and 27 deletions

View File

@ -10,11 +10,11 @@ namespace TrueCraft.API.World
ISection[] Sections { get; }
byte[] Biomes { get; }
DateTime LastAccessed { get; set; }
short GetBlockID(Coordinates3D coordinates);
byte GetBlockID(Coordinates3D coordinates);
byte GetMetadata(Coordinates3D coordinates);
byte GetSkyLight(Coordinates3D coordinates);
byte GetBlockLight(Coordinates3D coordinates);
void SetBlockID(Coordinates3D coordinates, short value);
void SetBlockID(Coordinates3D coordinates, byte value);
void SetMetadata(Coordinates3D coordinates, byte value);
void SetSkyLight(Coordinates3D coordinates, byte value);
void SetBlockLight(Coordinates3D coordinates, byte value);

View File

@ -9,11 +9,11 @@ namespace TrueCraft.API.World
NibbleArray BlockLight { get; }
NibbleArray SkyLight { get; }
byte Y { get; }
short GetBlockID(Coordinates3D coordinates);
byte GetBlockID(Coordinates3D coordinates);
byte GetMetadata(Coordinates3D coordinates);
byte GetSkyLight(Coordinates3D coordinates);
byte GetBlockLight(Coordinates3D coordinates);
void SetBlockID(Coordinates3D coordinates, short value);
void SetBlockID(Coordinates3D coordinates, byte value);
void SetMetadata(Coordinates3D coordinates, byte value);
void SetSkyLight(Coordinates3D coordinates, byte value);
void SetBlockLight(Coordinates3D coordinates, byte value);

View File

@ -11,10 +11,10 @@ namespace TrueCraft.API.World
string Name { get; set; }
IChunk GetChunk(Coordinates2D coordinates);
short GetBlockID(Coordinates3D coordinates);
byte GetBlockID(Coordinates3D coordinates);
byte GetMetadata(Coordinates3D coordinates);
byte GetSkyLight(Coordinates3D coordinates);
void SetBlockID(Coordinates3D coordinates, short value);
void SetBlockID(Coordinates3D coordinates, byte value);
void SetMetadata(Coordinates3D coordinates, byte value);
void SetSkyLight(Coordinates3D coordinates, byte value);
void SetBlockLight(Coordinates3D coordinates, byte value);

View File

@ -71,7 +71,7 @@ namespace TrueCraft.Core.World
Z = coordinates.Z;
}
public short GetBlockID(Coordinates3D coordinates)
public byte GetBlockID(Coordinates3D coordinates)
{
LastAccessed = DateTime.Now;
int section = GetSectionNumber(coordinates.Y);
@ -103,7 +103,7 @@ namespace TrueCraft.Core.World
return Sections[section].GetBlockLight(coordinates);
}
public void SetBlockID(Coordinates3D coordinates, short value)
public void SetBlockID(Coordinates3D coordinates, byte value)
{
LastAccessed = DateTime.Now;
IsModified = true;

View File

@ -13,8 +13,6 @@ namespace TrueCraft.Core.World
public NibbleArray Metadata { get; set; }
public NibbleArray BlockLight { get; set; }
public NibbleArray SkyLight { get; set; }
[IgnoreOnNull]
public NibbleArray Add { get; set; }
public byte Y { get; set; }
private int nonAirCount;
@ -33,7 +31,6 @@ namespace TrueCraft.Core.World
SkyLight = new NibbleArray(size);
for (int i = 0; i < size; i++)
SkyLight[i] = 0xFF;
Add = null; // Only used when needed
nonAirCount = 0;
}
@ -43,13 +40,10 @@ namespace TrueCraft.Core.World
get { return nonAirCount == 0; }
}
public short GetBlockID(Coordinates3D coordinates)
public byte GetBlockID(Coordinates3D coordinates)
{
int index = coordinates.X + (coordinates.Z * Width) + (coordinates.Y * Height * Width);
short value = Blocks[index];
if (Add != null)
value |= (short)(Add[index] << 8);
return value;
return Blocks[index];
}
public byte GetMetadata(Coordinates3D coordinates)
@ -70,7 +64,7 @@ namespace TrueCraft.Core.World
return BlockLight[index];
}
public void SetBlockID(Coordinates3D coordinates, short value)
public void SetBlockID(Coordinates3D coordinates, byte value)
{
int index = coordinates.X + (coordinates.Z * Width) + (coordinates.Y * Height * Width);
if (value == 0)
@ -83,12 +77,7 @@ namespace TrueCraft.Core.World
if (Blocks[index] == 0)
nonAirCount++;
}
Blocks[index] = (byte)value;
if ((value & ~0xFF) != 0)
{
if (Add == null) Add = new NibbleArray(Width * Height * Depth);
Add[index] = (byte)((ushort)value >> 8);
}
Blocks[index] = value;
}
public void SetMetadata(Coordinates3D coordinates, byte value)

View File

@ -109,7 +109,7 @@ namespace TrueCraft.Core.World
Regions[regionPosition].UnloadChunk(new Coordinates2D(coordinates.X - regionX * 32, coordinates.Z - regionZ * 32));
}
public short GetBlockID(Coordinates3D coordinates)
public byte GetBlockID(Coordinates3D coordinates)
{
IChunk chunk;
coordinates = FindBlockPosition(coordinates, out chunk);
@ -137,7 +137,7 @@ namespace TrueCraft.Core.World
return chunk.GetBlockLight(coordinates);
}
public void SetBlockID(Coordinates3D coordinates, short value)
public void SetBlockID(Coordinates3D coordinates, byte value)
{
IChunk chunk;
var adjustedCoordinates = FindBlockPosition(coordinates, out chunk);

View File

@ -14,9 +14,9 @@ namespace TrueCraft
public IPacketReader PacketReader { get; private set; }
public IList<IRemoteClient> Clients { get; private set; }
private Timer NetworkWorker;
private Timer NetworkWorker, EnvironmentWorker;
private TcpListener Listener;
private PacketHandler[] PacketHandlers;
private readonly PacketHandler[] PacketHandlers;
public MultiplayerServer()
{
@ -24,6 +24,7 @@ namespace TrueCraft
PacketReader = reader;
Clients = new List<IRemoteClient>();
NetworkWorker = new Timer(DoNetwork);
EnvironmentWorker = new Timer(DoEnvironment);
PacketHandlers = new PacketHandler[0x100];
reader.RegisterCorePackets();
@ -41,6 +42,7 @@ namespace TrueCraft
Listener.Start();
Listener.BeginAcceptTcpClient(AcceptClient, null);
NetworkWorker.Change(100, 1000 / 20);
EnvironmentWorker.Change(100, 1000 / 20);
}
private void AcceptClient(IAsyncResult result)
@ -50,6 +52,13 @@ namespace TrueCraft
Clients.Add(client);
}
private void DoEnvironment(object discarded)
{
for (int i = 0, ClientsCount = Clients.Count; i < ClientsCount; i++)
{
}
}
private void DoNetwork(object discarded)
{
for (int i = 0, ClientsCount = Clients.Count; i < ClientsCount; i++)