Block when sending initial chunks

This commit is contained in:
Drew DeVault 2017-05-23 19:41:52 -04:00
parent 444a3f47ed
commit c5c0e5ddf4
3 changed files with 10 additions and 14 deletions

View File

@ -30,16 +30,9 @@ namespace TrueCraft.Core.TerrainGen
bool EnableCaves;
private const int GroundLevel = 50;
public StandardGenerator(TrueCraft.Core.World.World world) : this()
public StandardGenerator(IWorld world)
{
// TODO: Do we want to do anything with that world?
}
public StandardGenerator(bool singleBiome = false, bool enableCaves = true, byte generateBiome = (byte)Biome.Plains)
{
SingleBiome = singleBiome;
GenerationBiome = generateBiome;
EnableCaves = enableCaves;
EnableCaves = true;
CaveNoise.Octaves = 3;
CaveNoise.Amplitude = 0.05;

View File

@ -59,8 +59,7 @@ namespace TrueCraft.Handlers
// Send setup packets
remoteClient.QueuePacket(new LoginResponsePacket(client.Entity.EntityID, 0, Dimension.Overworld));
server.Scheduler.ScheduleEvent("client.update-chunks", remoteClient,
TimeSpan.Zero, s => remoteClient.UpdateChunks());
remoteClient.UpdateChunks(block: true);
remoteClient.QueuePacket(new WindowItemsPacket(0, remoteClient.Inventory.GetSlots()));
remoteClient.QueuePacket(new UpdateHealthPacket((remoteClient.Entity as PlayerEntity).Health));
remoteClient.QueuePacket(new SpawnPositionPacket((int)remoteClient.Entity.Position.X,

View File

@ -413,7 +413,7 @@ namespace TrueCraft
server.Scheduler.ScheduleEvent("remote.keepalive", this, TimeSpan.FromSeconds(10), SendKeepAlive);
}
internal void UpdateChunks()
internal void UpdateChunks(bool block = false)
{
var newChunks = new HashSet<Coordinates2D>();
var toLoad = new List<Tuple<Coordinates2D, IChunk>>();
@ -428,11 +428,11 @@ namespace TrueCraft
newChunks.Add(coords);
if (!LoadedChunks.Contains(coords))
toLoad.Add(new Tuple<Coordinates2D, IChunk>(
coords, World.GetChunk(coords, generate: false)));
coords, World.GetChunk(coords, generate: block)));
}
}
Profiler.Done();
Task.Factory.StartNew(() =>
var encode = new Action(() =>
{
Profiler.Start("client.encode-chunks");
foreach (var tup in toLoad)
@ -446,6 +446,10 @@ namespace TrueCraft
}
Profiler.Done();
});
if (block)
encode();
else
Task.Factory.StartNew(encode);
Profiler.Start("client.old-chunks");
LoadedChunks.IntersectWith(newChunks);
Profiler.Done();