diff options
Diffstat (limited to 'internal/world')
| -rw-r--r-- | internal/world/world.go | 38 |
1 files changed, 26 insertions, 12 deletions
diff --git a/internal/world/world.go b/internal/world/world.go index 7a91894..10ceb08 100644 --- a/internal/world/world.go +++ b/internal/world/world.go @@ -18,10 +18,14 @@ type World struct { dataDir string mu sync.Mutex roomPathIndex map[int]string - groundItems map[int][]*groundEntry - seeded map[int]bool - objStates map[string]*ObjState - objMoves []ObjMove + // roomIDMismatchLogged dedupes the "declared id ignored" warning, which + // would otherwise fire on every prompt/tick for a room file copied from a + // template with a stale id:. Guarded by mu. + roomIDMismatchLogged map[int]bool + groundItems map[int][]*groundEntry + seeded map[int]bool + objStates map[string]*ObjState + objMoves []ObjMove hazardMu sync.Mutex hazardPathIndex map[string]string @@ -30,12 +34,13 @@ type World struct { func New(dataDir string) *World { return &World{ - dataDir: dataDir, - roomPathIndex: behavior.BuildRoomIndex(filepath.Join(dataDir, "rooms")), - groundItems: make(map[int][]*groundEntry), - seeded: make(map[int]bool), - objStates: make(map[string]*ObjState), - hazardDefs: make(map[string]*HazardDef), + dataDir: dataDir, + roomPathIndex: behavior.BuildRoomIndex(filepath.Join(dataDir, "rooms")), + roomIDMismatchLogged: make(map[int]bool), + groundItems: make(map[int][]*groundEntry), + seeded: make(map[int]bool), + objStates: make(map[string]*ObjState), + hazardDefs: make(map[string]*HazardDef), } } @@ -58,8 +63,17 @@ func (w *World) LoadRoom(id int) (*Room, error) { // declared id: is silently ignored, so surface it rather than leave the // author believing their written id is in use. if room.ID != 0 && room.ID != id { - log.Printf("room %d: file %s declares id %d but is loaded as room %d; the filename is authoritative and the declared id is ignored", - id, path, room.ID, id) + w.mu.Lock() + if w.roomIDMismatchLogged == nil { + w.roomIDMismatchLogged = make(map[int]bool) + } + already := w.roomIDMismatchLogged[id] + w.roomIDMismatchLogged[id] = true + w.mu.Unlock() + if !already { + log.Printf("room %d: file %s declares id %d but is loaded as room %d; the filename is authoritative and the declared id is ignored", + id, path, room.ID, id) + } } room.ID = id if room.Exits == nil { |
