aboutsummaryrefslogtreecommitdiff
path: root/internal/game/render_map.go
diff options
context:
space:
mode:
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
}