Do lighting updates on client as blocks change
This is broken.
This commit is contained in:
parent
82552248da
commit
a3281e6d07
@ -1,10 +1,12 @@
|
||||
using System;
|
||||
using TrueCraft.API;
|
||||
|
||||
namespace TrueCraft.Client.Events
|
||||
{
|
||||
public class ChunkEventArgs : EventArgs
|
||||
{
|
||||
public ReadOnlyChunk Chunk { get; set; }
|
||||
public Coordinates3D Source { get; set; }
|
||||
|
||||
public ChunkEventArgs(ReadOnlyChunk chunk)
|
||||
{
|
||||
|
@ -28,7 +28,9 @@ namespace TrueCraft.Client.Handlers
|
||||
}
|
||||
chunk.SetBlockID(adjusted, (byte)packet.BlockID);
|
||||
chunk.SetMetadata(adjusted, (byte)packet.Metadata);
|
||||
client.OnChunkModified(new ChunkEventArgs(new ReadOnlyChunk(chunk)));
|
||||
var args = new ChunkEventArgs(new ReadOnlyChunk(chunk));
|
||||
args.Source = coordinates;
|
||||
client.OnChunkModified(args);
|
||||
}
|
||||
|
||||
public static void HandleChunkPreamble(IPacket _packet, MultiplayerClient client)
|
||||
|
@ -8,6 +8,9 @@ using System.ComponentModel;
|
||||
using TrueCraft.API;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using TrueCraft.Core.Lighting;
|
||||
using TrueCraft.Client.Events;
|
||||
using TrueCraft.Core.World;
|
||||
|
||||
namespace TrueCraft.Client.Modules
|
||||
{
|
||||
@ -16,6 +19,7 @@ namespace TrueCraft.Client.Modules
|
||||
public TrueCraftGame Game { get; set; }
|
||||
public ChunkRenderer ChunkRenderer { get; set; }
|
||||
public int ChunksRendered { get; set; }
|
||||
public WorldLighting WorldLighting { get; set; }
|
||||
|
||||
private HashSet<Coordinates2D> ActiveMeshes { get; set; }
|
||||
private List<ChunkMesh> ChunkMeshes { get; set; }
|
||||
@ -28,10 +32,12 @@ namespace TrueCraft.Client.Modules
|
||||
{
|
||||
Game = game;
|
||||
|
||||
WorldLighting = new WorldLighting(Game.Client.World.World, Game.BlockRepository);
|
||||
|
||||
ChunkRenderer = new ChunkRenderer(Game.Client.World, Game, Game.BlockRepository);
|
||||
Game.Client.ChunkLoaded += (sender, e) => ChunkRenderer.Enqueue(e.Chunk);
|
||||
Game.Client.ChunkUnloaded += (sender, e) => UnloadChunk(e.Chunk);
|
||||
Game.Client.ChunkModified += (sender, e) => ChunkRenderer.Enqueue(e.Chunk, true);
|
||||
Game.Client.ChunkModified += HandleChunkModified;
|
||||
ChunkRenderer.MeshCompleted += MeshCompleted;
|
||||
ChunkRenderer.Start();
|
||||
|
||||
@ -60,6 +66,23 @@ namespace TrueCraft.Client.Modules
|
||||
IncomingChunks.Add(e.Result);
|
||||
}
|
||||
|
||||
void HandleChunkModified(object sender, ChunkEventArgs e)
|
||||
{
|
||||
Game.PendingMainThreadActions.Add(() =>
|
||||
{
|
||||
/*var posA = e.Source;
|
||||
posA.Y = 0;
|
||||
var posB = e.Source;
|
||||
posB.Y = World.Height;
|
||||
posB.X++; posB.Z++;
|
||||
WorldLighting.EnqueueOperation(new TrueCraft.API.BoundingBox(posA, posB), true);
|
||||
WorldLighting.EnqueueOperation(new TrueCraft.API.BoundingBox(posA, posB), false);*/
|
||||
//while (WorldLighting.TryLightNext()) { } // flush
|
||||
WorldLighting.InitialLighting(e.Chunk.Chunk);
|
||||
ChunkRenderer.Enqueue(e.Chunk, true);
|
||||
});
|
||||
}
|
||||
|
||||
void UnloadChunk(ReadOnlyChunk chunk)
|
||||
{
|
||||
Game.Invoke(() =>
|
||||
|
@ -87,6 +87,7 @@ namespace TrueCraft.Client
|
||||
internal ReadOnlyChunk(IChunk chunk)
|
||||
{
|
||||
Chunk = chunk;
|
||||
Chunk.TerrainPopulated = true;
|
||||
}
|
||||
|
||||
public byte GetBlockId(Coordinates3D coordinates)
|
||||
|
@ -134,12 +134,14 @@ namespace TrueCraft.Core.World
|
||||
/// <summary>
|
||||
/// Sets the chunk at the specified local position to the given value.
|
||||
/// </summary>
|
||||
public void SetChunk(Coordinates2D position, IChunk chunk)
|
||||
public bool SetChunk(Coordinates2D position, IChunk chunk)
|
||||
{
|
||||
if (!Chunks.ContainsKey(position))
|
||||
bool isNew = !Chunks.ContainsKey(position);
|
||||
if (isNew)
|
||||
Chunks.Add(position, chunk);
|
||||
chunk.IsModified = true;
|
||||
Chunks[position] = chunk;
|
||||
return isNew;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -142,7 +142,9 @@ namespace TrueCraft.Core.World
|
||||
lock (region)
|
||||
{
|
||||
chunk.IsModified = true;
|
||||
region.SetChunk(new Coordinates2D(coordinates.X - regionX * 32, coordinates.Z - regionZ * 32), chunk);
|
||||
bool isNew = region.SetChunk(new Coordinates2D(coordinates.X - regionX * 32, coordinates.Z - regionZ * 32), chunk);
|
||||
if (isNew)
|
||||
OnChunkLoaded(new ChunkLoadedEventArgs(chunk));
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user