Chunk load most ikely causing latency
This commit is contained in:
@@ -422,16 +422,31 @@ public sealed class WorldHandler : IClientMessageHandler
|
|||||||
{
|
{
|
||||||
var required = new HashSet<string>(StringComparer.Ordinal);
|
var required = new HashSet<string>(StringComparer.Ordinal);
|
||||||
var list = new List<(string, object)>();
|
var list = new List<(string, object)>();
|
||||||
for (var zy = Math.Max(0, s.ZoneY - 1); zy <= Math.Min(region.ZonesPerRegionY - 1, s.ZoneY + 1); zy++)
|
var chunksPerRegionX = region.ZonesPerRegionX * region.ChunksPerZoneX;
|
||||||
for (var zx = Math.Max(0, s.ZoneX - 1); zx <= Math.Min(region.ZonesPerRegionX - 1, s.ZoneX + 1); zx++)
|
var chunksPerRegionY = region.ZonesPerRegionY * region.ChunksPerZoneY;
|
||||||
for (var cy = Math.Max(0, s.ChunkY - 1); cy <= Math.Min(region.ChunksPerZoneY - 1, s.ChunkY + 1); cy++)
|
if (chunksPerRegionX <= 0 || chunksPerRegionY <= 0)
|
||||||
for (var cx = Math.Max(0, s.ChunkX - 1); cx <= Math.Min(region.ChunksPerZoneX - 1, s.ChunkX + 1); cx++)
|
|
||||||
{
|
{
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
var centerAbsChunkX = (s.ZoneX * region.ChunksPerZoneX) + s.ChunkX;
|
||||||
|
var centerAbsChunkY = (s.ZoneY * region.ChunksPerZoneY) + s.ChunkY;
|
||||||
|
|
||||||
|
for (var ay = Math.Max(0, centerAbsChunkY - 1); ay <= Math.Min(chunksPerRegionY - 1, centerAbsChunkY + 1); ay++)
|
||||||
|
for (var ax = Math.Max(0, centerAbsChunkX - 1); ax <= Math.Min(chunksPerRegionX - 1, centerAbsChunkX + 1); ax++)
|
||||||
|
{
|
||||||
|
var zx = ax / region.ChunksPerZoneX;
|
||||||
|
var zy = ay / region.ChunksPerZoneY;
|
||||||
|
var cx = ax % region.ChunksPerZoneX;
|
||||||
|
var cy = ay % region.ChunksPerZoneY;
|
||||||
var key = $"{region.Id}:{zx}:{zy}:{cx}:{cy}";
|
var key = $"{region.Id}:{zx}:{zy}:{cx}:{cy}";
|
||||||
required.Add(key);
|
required.Add(key);
|
||||||
var data = await LoadChunkAsync(db, region, zx, zy, cx, cy, ct);
|
|
||||||
if (!s.ChunkVersions.TryGetValue(key, out var known) || known != data.version)
|
// Load chunk payload only when it enters the visible set.
|
||||||
|
// Runtime chunk edits should be pushed by dedicated world-edit services/events.
|
||||||
|
if (!s.ChunkVersions.ContainsKey(key))
|
||||||
{
|
{
|
||||||
|
var data = await LoadChunkAsync(db, region, zx, zy, cx, cy, ct);
|
||||||
s.ChunkVersions[key] = data.version;
|
s.ChunkVersions[key] = data.version;
|
||||||
list.Add(("chunk_full", new { type = "chunk_full", chunk = data.chunk, tiles = data.tiles, objects = data.objects, npcs = data.npcs, mobs = data.mobs }));
|
list.Add(("chunk_full", new { type = "chunk_full", chunk = data.chunk, tiles = data.tiles, objects = data.objects, npcs = data.npcs, mobs = data.mobs }));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user