From 09163f36ee897222f1d0b3d07328697c35f8889d Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Sat, 27 Dec 2014 12:51:45 -0700 Subject: [PATCH] Update (un-update?) world implementation to b1.7.3 --- TrueCraft.API/World/IChunk.cs | 4 ++-- TrueCraft.API/World/ISection.cs | 4 ++-- TrueCraft.API/World/IWorld.cs | 4 ++-- TrueCraft.Core/World/Chunk.cs | 4 ++-- TrueCraft.Core/World/Section.cs | 19 ++++--------------- TrueCraft.Core/World/World.cs | 4 ++-- TrueCraft/MultiplayerServer.cs | 13 +++++++++++-- 7 files changed, 25 insertions(+), 27 deletions(-) diff --git a/TrueCraft.API/World/IChunk.cs b/TrueCraft.API/World/IChunk.cs index d47dbb5..89f9b1e 100644 --- a/TrueCraft.API/World/IChunk.cs +++ b/TrueCraft.API/World/IChunk.cs @@ -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); diff --git a/TrueCraft.API/World/ISection.cs b/TrueCraft.API/World/ISection.cs index 54b4cc6..883fb7c 100644 --- a/TrueCraft.API/World/ISection.cs +++ b/TrueCraft.API/World/ISection.cs @@ -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); diff --git a/TrueCraft.API/World/IWorld.cs b/TrueCraft.API/World/IWorld.cs index 3f52d92..afa0dab 100644 --- a/TrueCraft.API/World/IWorld.cs +++ b/TrueCraft.API/World/IWorld.cs @@ -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); diff --git a/TrueCraft.Core/World/Chunk.cs b/TrueCraft.Core/World/Chunk.cs index 1621f24..6f9f293 100644 --- a/TrueCraft.Core/World/Chunk.cs +++ b/TrueCraft.Core/World/Chunk.cs @@ -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; diff --git a/TrueCraft.Core/World/Section.cs b/TrueCraft.Core/World/Section.cs index d3e436d..ac2e078 100644 --- a/TrueCraft.Core/World/Section.cs +++ b/TrueCraft.Core/World/Section.cs @@ -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) diff --git a/TrueCraft.Core/World/World.cs b/TrueCraft.Core/World/World.cs index a699ce6..5d2f70a 100644 --- a/TrueCraft.Core/World/World.cs +++ b/TrueCraft.Core/World/World.cs @@ -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); diff --git a/TrueCraft/MultiplayerServer.cs b/TrueCraft/MultiplayerServer.cs index f80787a..cfd29b5 100644 --- a/TrueCraft/MultiplayerServer.cs +++ b/TrueCraft/MultiplayerServer.cs @@ -14,9 +14,9 @@ namespace TrueCraft public IPacketReader PacketReader { get; private set; } public IList 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(); 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++)