Spatial packets
This commit is contained in:
@@ -75,6 +75,7 @@ var dungeon: Dictionary = {
|
||||
var self_player: Dictionary = {}
|
||||
var players: Dictionary = {}
|
||||
var mobs: Dictionary = {}
|
||||
var mob_catalog: Dictionary = {} # Cached static mob render metadata (id -> {definitionId, name, spriteConfig, tintColor, scale})
|
||||
var chests: Dictionary = {}
|
||||
var dropped_items: Dictionary = {}
|
||||
var portals: Dictionary = {}
|
||||
@@ -288,10 +289,11 @@ func _handle_dungeon_enter(data: Dictionary):
|
||||
|
||||
players.clear()
|
||||
mobs.clear()
|
||||
mob_catalog.clear()
|
||||
chests.clear()
|
||||
dropped_items.clear()
|
||||
portals.clear()
|
||||
|
||||
|
||||
# Parse initial portals
|
||||
var portal_list = data.get("portals", data.get("Portals", []))
|
||||
for p in portal_list:
|
||||
@@ -429,11 +431,54 @@ func _handle_dungeon_state(data: Dictionary):
|
||||
else:
|
||||
players[pid] = p
|
||||
|
||||
# Parse mob catalog (sent once per dungeon join, contains static render metadata)
|
||||
var catalog = data.get("mobCatalog", data.get("MobCatalog", []))
|
||||
if catalog is Array and catalog.size() > 0:
|
||||
for entry in catalog:
|
||||
var cid = entry.get("id", entry.get("Id"))
|
||||
if cid != null:
|
||||
mob_catalog[cid] = entry
|
||||
print("[GameState] Mob catalog received: %d entries" % catalog.size())
|
||||
# Prefetch textures from catalog entries
|
||||
_prefetch_mob_textures_from_list(catalog)
|
||||
|
||||
# With spatial filtering, mobs array only contains nearby/relevant mobs.
|
||||
# Don't clear the full dict — update present mobs and track visibility.
|
||||
var ms = data.get("mobs", data.get("Mobs", []))
|
||||
mobs.clear()
|
||||
var mobs_in_packet: Array = []
|
||||
for m in ms:
|
||||
var mid = m.get("id", m.get("Id"))
|
||||
mobs_in_packet.append(mid)
|
||||
# Merge catalog metadata into mob data when per-tick data lacks render fields
|
||||
if mob_catalog.has(mid):
|
||||
var cat = mob_catalog[mid]
|
||||
if not m.has("spriteConfig") and not m.has("SpriteConfig"):
|
||||
var sc = cat.get("spriteConfig", cat.get("SpriteConfig", null))
|
||||
if sc != null:
|
||||
m["spriteConfig"] = sc
|
||||
if not m.has("tintColor") and not m.has("TintColor"):
|
||||
var tc = cat.get("tintColor", cat.get("TintColor", null))
|
||||
if tc != null:
|
||||
m["tintColor"] = tc
|
||||
if not m.has("scale") and not m.has("Scale"):
|
||||
var s = cat.get("scale", cat.get("Scale", null))
|
||||
if s != null:
|
||||
m["scale"] = s
|
||||
if not m.has("name") and not m.has("Name"):
|
||||
var n = cat.get("name", cat.get("Name", null))
|
||||
if n != null:
|
||||
m["name"] = n
|
||||
if not m.has("definitionId") and not m.has("DefinitionId"):
|
||||
var did = cat.get("definitionId", cat.get("DefinitionId", null))
|
||||
if did != null:
|
||||
m["definitionId"] = did
|
||||
m["_visible"] = true
|
||||
m["_last_seen"] = Time.get_ticks_msec()
|
||||
mobs[mid] = m
|
||||
# Mark mobs not in this packet as out-of-range (but keep them)
|
||||
for mid in mobs:
|
||||
if mid not in mobs_in_packet:
|
||||
mobs[mid]["_visible"] = false
|
||||
|
||||
var cs = data.get("chests", data.get("Chests", []))
|
||||
for c_item in cs:
|
||||
@@ -446,11 +491,13 @@ func _handle_dungeon_state(data: Dictionary):
|
||||
var iid = i.get("id", i.get("Id"))
|
||||
dropped_items[iid] = i
|
||||
|
||||
# Parse portals
|
||||
# Parse portals — server sends the authoritative active set each packet
|
||||
var ports = data.get("portals", data.get("Portals", []))
|
||||
for p in ports:
|
||||
var pid = p.get("id", p.get("Id"))
|
||||
portals[pid] = p
|
||||
if ports is Array and ports.size() > 0:
|
||||
portals.clear()
|
||||
for p in ports:
|
||||
var pid = p.get("id", p.get("Id"))
|
||||
portals[pid] = p
|
||||
|
||||
# Parse loot chests (personal to this player)
|
||||
var lchests = data.get("lootChests", data.get("LootChests", []))
|
||||
@@ -547,6 +594,7 @@ func _handle_escape_success(_data: Dictionary):
|
||||
# Clear dungeon data
|
||||
players.clear()
|
||||
mobs.clear()
|
||||
mob_catalog.clear()
|
||||
chests.clear()
|
||||
dropped_items.clear()
|
||||
portals.clear()
|
||||
@@ -558,7 +606,7 @@ func _handle_escape_success(_data: Dictionary):
|
||||
"tiles": [],
|
||||
"phase": "active"
|
||||
}
|
||||
|
||||
|
||||
escaped.emit()
|
||||
# Server will send HUB_STATE next which will call set_state(STATE_HUB)
|
||||
|
||||
@@ -633,6 +681,7 @@ func _handle_portal_used(_data: Dictionary):
|
||||
# Clear dungeon data
|
||||
players.clear()
|
||||
mobs.clear()
|
||||
mob_catalog.clear()
|
||||
chests.clear()
|
||||
dropped_items.clear()
|
||||
portals.clear()
|
||||
|
||||
Reference in New Issue
Block a user