How To Use Room Mapping

Room mapping creates an enclosed "field" within a room where members of the room may find each other based on X and Y coordinates.

Using Diarkis Room, members may send and receive messages. By using the Mapping feature of the Diarkis Room, members may send and receive other members of the room that are within the field of vision.

Setting Up Mapping

After a room is created on the server, you may enable the mapping feature by adding the following code on the server.

// This is the entire map size that will be created within the room
mapSize := int64(34000000)
room.UseMapping(roomID, mapSize)

How To Find The Room Members Within The Field of Vision

Instead of using Diarkis Room Broadcast or Message to send messages, you may find other members that are in the field of your vision first and send messages to those members only.

// We assume this happens in a custom command handler function
mapping := room.GetMapping(roomID)

// In reality, X and Y should be sent from the client instead of hard-coding them
x := int64(100)
y := int64(45)

// userData is passed to command handler
userID := userData.ID

// We set the maximum number of members to exhange messages to 40
syncLimit := 40

membersInSight := mapping.AddAndFind(userData.ID, x, y, userID, syncLimit)

// create an array of user IDs for room.Message
members := make([]string, len(membersInSight))

for i, member := range membersInSight {
  // member.Value is userID
  members[i] = member.Value.(string)

// util is imported from
ver := util.CmdBuiltInUtilVer
cmd := util.CmdMessageRoom

// If you are using UDP server, this flag will turn the message into RUDP message
reliable := true

// Send a message to users in sight only
room.Message(roomID, members, userData, ver, cmd, message, reliable)

Last updated