aboutsummaryrefslogtreecommitdiff
path: root/internal/game/render_map.go
diff options
context:
space:
mode:
authorhistoria <[not public]>2026-10-06 12:57:23 -0400
committerhistoria <[not public]>2026-10-06 12:57:23 -0400
commit9666676766bf21364f4fc4d0d1d336e72f2a91b4 (patch)
tree0cade34091d7602790dc38cd44053f0b74bbadf2 /internal/game/render_map.go
parent4bc1daaf259e0c19c5fe4a12ec8bc7f6e5a735c1 (diff)
downloadthehouseoficarus-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.go21
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
}