Chunk load most ikely causing latency

This commit is contained in:
dingo
2026-02-16 08:25:47 -05:00
parent 023fd1ce30
commit c7ac5ea0a0
+21 -6
View File
@@ -422,16 +422,31 @@ public sealed class WorldHandler : IClientMessageHandler
{
var required = new HashSet<string>(StringComparer.Ordinal);
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++)
for (var zx = Math.Max(0, s.ZoneX - 1); zx <= Math.Min(region.ZonesPerRegionX - 1, s.ZoneX + 1); zx++)
for (var cy = Math.Max(0, s.ChunkY - 1); cy <= Math.Min(region.ChunksPerZoneY - 1, s.ChunkY + 1); cy++)
for (var cx = Math.Max(0, s.ChunkX - 1); cx <= Math.Min(region.ChunksPerZoneX - 1, s.ChunkX + 1); cx++)
var chunksPerRegionX = region.ZonesPerRegionX * region.ChunksPerZoneX;
var chunksPerRegionY = region.ZonesPerRegionY * region.ChunksPerZoneY;
if (chunksPerRegionX <= 0 || chunksPerRegionY <= 0)
{
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}";
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;
list.Add(("chunk_full", new { type = "chunk_full", chunk = data.chunk, tiles = data.tiles, objects = data.objects, npcs = data.npcs, mobs = data.mobs }));
}