diff options
| author | historia <[not public]> | 2026-10-06 12:57:23 -0400 |
|---|---|---|
| committer | historia <[not public]> | 2026-10-06 12:57:23 -0400 |
| commit | 9666676766bf21364f4fc4d0d1d336e72f2a91b4 (patch) | |
| tree | 0cade34091d7602790dc38cd44053f0b74bbadf2 /internal/game/render_map.go | |
| parent | 4bc1daaf259e0c19c5fe4a12ec8bc7f6e5a735c1 (diff) | |
| download | thehouseoficarus-9666676766bf21364f4fc4d0d1d336e72f2a91b4.tar.gz | |
refactor: split casino.go, dedup helpers, remove audit docs
Diffstat (limited to 'internal/game/render_map.go')
| -rw-r--r-- | internal/game/render_map.go | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/internal/game/render_map.go b/internal/game/render_map.go index e8d7cea..ff36344 100644 --- a/internal/game/render_map.go +++ b/internal/game/render_map.go @@ -57,10 +57,23 @@ type mapGraph struct { const playerZ = 0 func buildGraph(g *Game, sess *net.Session, startRoomID int) *mapGraph { - rg := world.BuildGrid(startRoomID, func(id int) (*world.Room, bool) { - return loadRoom(g, id) - }, nil, func(fromID int, dir world.ExitDir, targetID int) bool { - room, ok := loadRoom(g, fromID) + // BuildGrid calls load for the BFS node AND edgeInclude re-loads the same + // room for its exit check, so memoize per render: without this every room + // reachable from the player is os.ReadFile+yaml.Unmarshal'd twice per map. + cache := make(map[int]*world.Room) + load := func(id int) (*world.Room, bool) { + if r, ok := cache[id]; ok { + return r, true + } + r, ok := loadRoom(g, id) + if !ok { + return nil, false + } + cache[id] = r + return r, true + } + rg := world.BuildGrid(startRoomID, load, nil, func(fromID int, dir world.ExitDir, targetID int) bool { + room, ok := load(fromID) if !ok { return true } |
