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

Method Start

internal/mapper/mapper.go:247–392  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

245}
246
247func (r *mapper) Start() {
248
249 // Don't redo.
250 if len(r.crawledRooms) > 0 {
251 return
252 }
253
254 minX, maxX, minY, maxY, minZ, maxZ := 0, 0, 0, 0, 0, 0
255
256 r.crawlQueue = make([]crawlRoom, 0, 100) // pre-allocate 100 capacity
257
258 // Determine the root room's stored position (if any) so that rooms without
259 // absolute coordinates can be aligned to the same origin.
260 var rootStoredPos positionDelta
261 var rootHasStoredCoords bool
262 if rootRoom := rooms.LoadRoom(r.rootRoomId); rootRoom != nil && rootRoom.HasCoordinates && rootRoom.Zone == r.rootZone {
263 rootStoredPos = positionDelta{x: rootRoom.MapX, y: rootRoom.MapY, z: rootRoom.MapZ}
264 rootHasStoredCoords = true
265 }
266
267 r.crawlQueue = append(r.crawlQueue, crawlRoom{RoomId: r.rootRoomId, Pos: positionDelta{}})
268 for len(r.crawlQueue) > 0 {
269
270 roomNow := r.crawlQueue[0]
271 r.crawlQueue = r.crawlQueue[1:]
272
273 if _, ok := r.crawledRooms[roomNow.RoomId]; ok {
274 continue
275 }
276
277 node := r.getMapNode(roomNow.RoomId)
278 if node == nil {
279 continue
280 }
281
282 // Absolute coordinates are authoritative. Only fall back to the
283 // crawl-derived position when a room has no stored coordinates.
284 if !node.HasStoredCoords {
285 node.Pos = roomNow.Pos
286 }
287
288 if node.Pos.x < minX {
289 minX = node.Pos.x
290 } else if node.Pos.x > maxX {
291 maxX = node.Pos.x
292 }
293 if node.Pos.y < minY {
294 minY = node.Pos.y
295 } else if node.Pos.y > maxY {
296 maxY = node.Pos.y
297 }
298 if node.Pos.z < minZ {
299 minZ = node.Pos.z
300 } else if node.Pos.z > maxZ {
301 maxZ = node.Pos.z
302 }
303
304 // Add to crawled list so we don't revisit it

Callers 3

GetMapperFunction · 0.80
MigrateCoordinatesFunction · 0.80
ExecuteFunction · 0.80

Calls 5

getMapNodeMethod · 0.95
LoadRoomFunction · 0.92
CombineMethod · 0.80
initializeMethod · 0.80
addNodeMethod · 0.80

Tested by

no test coverage detected