Update (un-update?) world implementation to b1.7.3
This commit is contained in:
parent
96ecbc708c
commit
09163f36ee
@ -10,11 +10,11 @@ namespace TrueCraft.API.World
|
|||||||
ISection[] Sections { get; }
|
ISection[] Sections { get; }
|
||||||
byte[] Biomes { get; }
|
byte[] Biomes { get; }
|
||||||
DateTime LastAccessed { get; set; }
|
DateTime LastAccessed { get; set; }
|
||||||
short GetBlockID(Coordinates3D coordinates);
|
byte GetBlockID(Coordinates3D coordinates);
|
||||||
byte GetMetadata(Coordinates3D coordinates);
|
byte GetMetadata(Coordinates3D coordinates);
|
||||||
byte GetSkyLight(Coordinates3D coordinates);
|
byte GetSkyLight(Coordinates3D coordinates);
|
||||||
byte GetBlockLight(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 SetMetadata(Coordinates3D coordinates, byte value);
|
||||||
void SetSkyLight(Coordinates3D coordinates, byte value);
|
void SetSkyLight(Coordinates3D coordinates, byte value);
|
||||||
void SetBlockLight(Coordinates3D coordinates, byte value);
|
void SetBlockLight(Coordinates3D coordinates, byte value);
|
||||||
|
@ -9,11 +9,11 @@ namespace TrueCraft.API.World
|
|||||||
NibbleArray BlockLight { get; }
|
NibbleArray BlockLight { get; }
|
||||||
NibbleArray SkyLight { get; }
|
NibbleArray SkyLight { get; }
|
||||||
byte Y { get; }
|
byte Y { get; }
|
||||||
short GetBlockID(Coordinates3D coordinates);
|
byte GetBlockID(Coordinates3D coordinates);
|
||||||
byte GetMetadata(Coordinates3D coordinates);
|
byte GetMetadata(Coordinates3D coordinates);
|
||||||
byte GetSkyLight(Coordinates3D coordinates);
|
byte GetSkyLight(Coordinates3D coordinates);
|
||||||
byte GetBlockLight(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 SetMetadata(Coordinates3D coordinates, byte value);
|
||||||
void SetSkyLight(Coordinates3D coordinates, byte value);
|
void SetSkyLight(Coordinates3D coordinates, byte value);
|
||||||
void SetBlockLight(Coordinates3D coordinates, byte value);
|
void SetBlockLight(Coordinates3D coordinates, byte value);
|
||||||
|
@ -11,10 +11,10 @@ namespace TrueCraft.API.World
|
|||||||
string Name { get; set; }
|
string Name { get; set; }
|
||||||
|
|
||||||
IChunk GetChunk(Coordinates2D coordinates);
|
IChunk GetChunk(Coordinates2D coordinates);
|
||||||
short GetBlockID(Coordinates3D coordinates);
|
byte GetBlockID(Coordinates3D coordinates);
|
||||||
byte GetMetadata(Coordinates3D coordinates);
|
byte GetMetadata(Coordinates3D coordinates);
|
||||||
byte GetSkyLight(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 SetMetadata(Coordinates3D coordinates, byte value);
|
||||||
void SetSkyLight(Coordinates3D coordinates, byte value);
|
void SetSkyLight(Coordinates3D coordinates, byte value);
|
||||||
void SetBlockLight(Coordinates3D coordinates, byte value);
|
void SetBlockLight(Coordinates3D coordinates, byte value);
|
||||||
|
@ -71,7 +71,7 @@ namespace TrueCraft.Core.World
|
|||||||
Z = coordinates.Z;
|
Z = coordinates.Z;
|
||||||
}
|
}
|
||||||
|
|
||||||
public short GetBlockID(Coordinates3D coordinates)
|
public byte GetBlockID(Coordinates3D coordinates)
|
||||||
{
|
{
|
||||||
LastAccessed = DateTime.Now;
|
LastAccessed = DateTime.Now;
|
||||||
int section = GetSectionNumber(coordinates.Y);
|
int section = GetSectionNumber(coordinates.Y);
|
||||||
@ -103,7 +103,7 @@ namespace TrueCraft.Core.World
|
|||||||
return Sections[section].GetBlockLight(coordinates);
|
return Sections[section].GetBlockLight(coordinates);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetBlockID(Coordinates3D coordinates, short value)
|
public void SetBlockID(Coordinates3D coordinates, byte value)
|
||||||
{
|
{
|
||||||
LastAccessed = DateTime.Now;
|
LastAccessed = DateTime.Now;
|
||||||
IsModified = true;
|
IsModified = true;
|
||||||
|
@ -13,8 +13,6 @@ namespace TrueCraft.Core.World
|
|||||||
public NibbleArray Metadata { get; set; }
|
public NibbleArray Metadata { get; set; }
|
||||||
public NibbleArray BlockLight { get; set; }
|
public NibbleArray BlockLight { get; set; }
|
||||||
public NibbleArray SkyLight { get; set; }
|
public NibbleArray SkyLight { get; set; }
|
||||||
[IgnoreOnNull]
|
|
||||||
public NibbleArray Add { get; set; }
|
|
||||||
public byte Y { get; set; }
|
public byte Y { get; set; }
|
||||||
|
|
||||||
private int nonAirCount;
|
private int nonAirCount;
|
||||||
@ -33,7 +31,6 @@ namespace TrueCraft.Core.World
|
|||||||
SkyLight = new NibbleArray(size);
|
SkyLight = new NibbleArray(size);
|
||||||
for (int i = 0; i < size; i++)
|
for (int i = 0; i < size; i++)
|
||||||
SkyLight[i] = 0xFF;
|
SkyLight[i] = 0xFF;
|
||||||
Add = null; // Only used when needed
|
|
||||||
nonAirCount = 0;
|
nonAirCount = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -43,13 +40,10 @@ namespace TrueCraft.Core.World
|
|||||||
get { return nonAirCount == 0; }
|
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);
|
int index = coordinates.X + (coordinates.Z * Width) + (coordinates.Y * Height * Width);
|
||||||
short value = Blocks[index];
|
return Blocks[index];
|
||||||
if (Add != null)
|
|
||||||
value |= (short)(Add[index] << 8);
|
|
||||||
return value;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public byte GetMetadata(Coordinates3D coordinates)
|
public byte GetMetadata(Coordinates3D coordinates)
|
||||||
@ -70,7 +64,7 @@ namespace TrueCraft.Core.World
|
|||||||
return BlockLight[index];
|
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);
|
int index = coordinates.X + (coordinates.Z * Width) + (coordinates.Y * Height * Width);
|
||||||
if (value == 0)
|
if (value == 0)
|
||||||
@ -83,12 +77,7 @@ namespace TrueCraft.Core.World
|
|||||||
if (Blocks[index] == 0)
|
if (Blocks[index] == 0)
|
||||||
nonAirCount++;
|
nonAirCount++;
|
||||||
}
|
}
|
||||||
Blocks[index] = (byte)value;
|
Blocks[index] = value;
|
||||||
if ((value & ~0xFF) != 0)
|
|
||||||
{
|
|
||||||
if (Add == null) Add = new NibbleArray(Width * Height * Depth);
|
|
||||||
Add[index] = (byte)((ushort)value >> 8);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetMetadata(Coordinates3D coordinates, byte value)
|
public void SetMetadata(Coordinates3D coordinates, byte value)
|
||||||
|
@ -109,7 +109,7 @@ namespace TrueCraft.Core.World
|
|||||||
Regions[regionPosition].UnloadChunk(new Coordinates2D(coordinates.X - regionX * 32, coordinates.Z - regionZ * 32));
|
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;
|
IChunk chunk;
|
||||||
coordinates = FindBlockPosition(coordinates, out chunk);
|
coordinates = FindBlockPosition(coordinates, out chunk);
|
||||||
@ -137,7 +137,7 @@ namespace TrueCraft.Core.World
|
|||||||
return chunk.GetBlockLight(coordinates);
|
return chunk.GetBlockLight(coordinates);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetBlockID(Coordinates3D coordinates, short value)
|
public void SetBlockID(Coordinates3D coordinates, byte value)
|
||||||
{
|
{
|
||||||
IChunk chunk;
|
IChunk chunk;
|
||||||
var adjustedCoordinates = FindBlockPosition(coordinates, out chunk);
|
var adjustedCoordinates = FindBlockPosition(coordinates, out chunk);
|
||||||
|
@ -14,9 +14,9 @@ namespace TrueCraft
|
|||||||
public IPacketReader PacketReader { get; private set; }
|
public IPacketReader PacketReader { get; private set; }
|
||||||
public IList<IRemoteClient> Clients { get; private set; }
|
public IList<IRemoteClient> Clients { get; private set; }
|
||||||
|
|
||||||
private Timer NetworkWorker;
|
private Timer NetworkWorker, EnvironmentWorker;
|
||||||
private TcpListener Listener;
|
private TcpListener Listener;
|
||||||
private PacketHandler[] PacketHandlers;
|
private readonly PacketHandler[] PacketHandlers;
|
||||||
|
|
||||||
public MultiplayerServer()
|
public MultiplayerServer()
|
||||||
{
|
{
|
||||||
@ -24,6 +24,7 @@ namespace TrueCraft
|
|||||||
PacketReader = reader;
|
PacketReader = reader;
|
||||||
Clients = new List<IRemoteClient>();
|
Clients = new List<IRemoteClient>();
|
||||||
NetworkWorker = new Timer(DoNetwork);
|
NetworkWorker = new Timer(DoNetwork);
|
||||||
|
EnvironmentWorker = new Timer(DoEnvironment);
|
||||||
PacketHandlers = new PacketHandler[0x100];
|
PacketHandlers = new PacketHandler[0x100];
|
||||||
|
|
||||||
reader.RegisterCorePackets();
|
reader.RegisterCorePackets();
|
||||||
@ -41,6 +42,7 @@ namespace TrueCraft
|
|||||||
Listener.Start();
|
Listener.Start();
|
||||||
Listener.BeginAcceptTcpClient(AcceptClient, null);
|
Listener.BeginAcceptTcpClient(AcceptClient, null);
|
||||||
NetworkWorker.Change(100, 1000 / 20);
|
NetworkWorker.Change(100, 1000 / 20);
|
||||||
|
EnvironmentWorker.Change(100, 1000 / 20);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void AcceptClient(IAsyncResult result)
|
private void AcceptClient(IAsyncResult result)
|
||||||
@ -50,6 +52,13 @@ namespace TrueCraft
|
|||||||
Clients.Add(client);
|
Clients.Add(client);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void DoEnvironment(object discarded)
|
||||||
|
{
|
||||||
|
for (int i = 0, ClientsCount = Clients.Count; i < ClientsCount; i++)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void DoNetwork(object discarded)
|
private void DoNetwork(object discarded)
|
||||||
{
|
{
|
||||||
for (int i = 0, ClientsCount = Clients.Count; i < ClientsCount; i++)
|
for (int i = 0, ClientsCount = Clients.Count; i < ClientsCount; i++)
|
||||||
|
Reference in New Issue
Block a user