MCPcopy Create free account
hub / github.com/GoMudEngine/GoMud / GetMapper

Function GetMapper

internal/mapper/mapper.go:1097–1153  ·  view source on GitHub ↗

Get the mapper if it exists, otherwises generates a new map from the roomId

(roomId int, forceRefresh ...bool)

Source from the content-addressed store, hash-verified

1095
1096// Get the mapper if it exists, otherwises generates a new map from the roomId
1097func GetMapper(roomId int, forceRefresh ...bool) *mapper {
1098
1099 var cachedMap *mapper = nil
1100 // Check the room-to-cache lookup
1101
1102 if zoneName, ok := roomIdToMapperCache[roomId]; ok {
1103 cachedMap = mapperZoneCache[zoneName]
1104 if len(forceRefresh) == 0 || !forceRefresh[0] {
1105 return cachedMap
1106 }
1107 }
1108
1109 // We are force rebuilding (or building if not exists) at this point
1110
1111 // Since we will be regenerating the whole map,
1112 // lets clear out any roomId's tracked for this room.
1113 // That way if something has changed, such as a room moving to a different map,
1114 // It won't point to here.
1115 if cachedMap != nil {
1116 for crawledRoomId, _ := range cachedMap.crawledRooms {
1117 delete(roomIdToMapperCache, crawledRoomId)
1118 }
1119 }
1120
1121 room := rooms.LoadRoom(roomId)
1122 if room == nil {
1123 return nil
1124 }
1125
1126 // Track the time it takes
1127 tStart := time.Now()
1128
1129 // multiple maps MIGHT exist within a zone, so use the zone+maps root to track it uniquely.
1130 // We could just use the roomId, but this makes debugging easier.
1131 zoneName := room.Zone + `-` + strconv.Itoa(roomId)
1132
1133 m := NewMapper(roomId)
1134 if m == nil {
1135 mudlog.Error("GetMapper", "error", "Could not generate a mapper for RoomId", "RoomId", roomId)
1136 return nil
1137 }
1138 m.Start()
1139
1140 mudlog.Info("New Mapper", "zone", zoneName, "size", len(m.crawledRooms), "time taken", time.Since(tStart))
1141
1142 roomIdToMapperCache[roomId] = zoneName
1143
1144 for _, crawledRoomId := range m.CrawledRoomIds() {
1145 if _, ok := roomIdToMapperCache[crawledRoomId]; !ok {
1146 roomIdToMapperCache[crawledRoomId] = zoneName
1147 }
1148 }
1149
1150 mapperZoneCache[zoneName] = m
1151
1152 return m
1153}
1154

Callers 14

zombieCommandMethod · 0.92
pickRoamExitMethod · 0.92
exitTowardHomeMethod · 0.92
buildWorldMapMethod · 0.92
GetRoomNodeMethod · 0.92
GetMapFunction · 0.92
CallForHelpFunction · 0.92
HandleMapRebuildFunction · 0.92
BuildFunction · 0.92
MapFunction · 0.92
TeleportFunction · 0.92
lookRoomFunction · 0.92

Calls 7

LoadRoomFunction · 0.92
ErrorFunction · 0.92
InfoFunction · 0.92
deleteFunction · 0.85
NewMapperFunction · 0.85
StartMethod · 0.80
CrawledRoomIdsMethod · 0.80

Tested by

no test coverage detected