data_type

package
v0.0.0-...-bd0de05 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 13, 2023 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const VIEW_GRID_WITH float64 = 150.0 // 150M

视野网格 直径

Variables

View Source
var NearPosOffsets = map[GridPos]proto.Vector3{
	GRID_POS_LEFT_UP:    proto.Vector3{X: -1, Y: 0, Z: 1},
	GRID_POS_UP:         proto.Vector3{X: 0, Y: 0, Z: 1},
	GRID_POS_RIGHT_UP:   proto.Vector3{X: 1, Y: 0, Z: 1},
	GRID_POS_RIGHT:      proto.Vector3{X: 1, Y: 0, Z: 0},
	GRID_POS_RIGHT_DOWN: proto.Vector3{X: 1, Y: 0, Z: -1},
	GRID_POS_DOWN:       proto.Vector3{X: 0, Y: 0, Z: -1},
	GRID_POS_LEFT_DOWN:  proto.Vector3{X: -1, Y: 0, Z: -1},
	GRID_POS_LEFT:       proto.Vector3{X: -1, Y: 0, Z: 0},
}

Functions

func CalGridId

func CalGridId(gridPosX int64, gridPosZ int64) int64

/ 根据grid pos 计算grid id, 注意gridPos 不是场景坐标

Types

type ChatMap

type ChatMap struct {
	AppId string
	MapId int32
	Grids map[int64]*ViewGrid
	Users map[int64]*UserChatData
}

func NewChatMap

func NewChatMap(appId string, mapId int32) *ChatMap

func (*ChatMap) AddPlayer

func (mg *ChatMap) AddPlayer(player *UserChatData)

func (*ChatMap) GridById

func (mg *ChatMap) GridById(gridId int64) *ViewGrid

/ 使用gridId 查询 grid, 查询失败 返回null

func (*ChatMap) GridByXYZ

func (mg *ChatMap) GridByXYZ(x, y, z float32) *ViewGrid

/ 查询 场景坐标(XYZ) 所在的grid, 会动态创建grid

func (*ChatMap) RemovePlayer

func (mg *ChatMap) RemovePlayer(userId int64)

func (*ChatMap) UpdateAndAddPlayerRecord

func (mg *ChatMap) UpdateAndAddPlayerRecord(player *UserChatData)

type GridPos

type GridPos int64
const (
	GRID_POS_LEFT_UP GridPos = iota
	GRID_POS_UP
	GRID_POS_RIGHT_UP
	GRID_POS_LEFT
	GRID_POS_CENTRE
	GRID_POS_RIGHT
	GRID_POS_LEFT_DOWN
	GRID_POS_DOWN
	GRID_POS_RIGHT_DOWN
)

type UserChatData

type UserChatData struct {
	UserId            int64                           `json:"userId"`
	Name              string                          `json:"name"`
	RoleIcon          string                          `json:"roleIcon"`
	MapId             int32                           `json:"mapId"`
	X                 float32                         `json:"x"`
	Y                 float32                         `json:"y"`
	Z                 float32                         `json:"z"`
	SceneServiceAppId string                          `json:"sceneServiceAppId"`
	AgentAppId        string                          `json:"agentAppId"`
	UserSocketId      string                          `json:"userSocketId"`
	InGrid            *ViewGrid                       `json:"-"`
	ChatCDs           map[proto.ChatChannelType]int64 `json:"-"` // map[ChatChannelType]nextSendAt<ms>
}

func NewUserChatData

func NewUserChatData(
	userId int64,
	name string,
	roleIcon string,
	mapId int32,
	x float32,
	y float32,
	z float32,
	sceneServiceAppId string,
	agentAppId string,
	userSocketId string,
) *UserChatData

func (*UserChatData) UpChatCD

func (p *UserChatData) UpChatCD(chatType proto.ChatChannelType)

type ViewGrid

type ViewGrid struct {
	Id    int64
	PosX  int64
	PosZ  int64
	InMap int32
	// contains filtered or unexported fields
}

func NewViewGrid

func NewViewGrid(inMapId int32, gridPosX, gridPosZ, gridId int64) *ViewGrid

func (*ViewGrid) AddPlayer

func (g *ViewGrid) AddPlayer(playerData *UserChatData)

func (*ViewGrid) Broadcast

func (g *ViewGrid) Broadcast(
	msgType proto.EnvelopeType, chatMsg googleProto.Message, exceptEntity int64,
)

/ <summary> / 对在grid中的玩家广播消息 / </summary>

func (*ViewGrid) BroadcastNearMessage

func (g *ViewGrid) BroadcastNearMessage(
	msgType proto.EnvelopeType, chatMsg googleProto.Message, exceptUser int64,
)

/ 对以该grid作为中心点的九宫格中的所以grid广播消息

func (*ViewGrid) NineGridsAndPos

func (g *ViewGrid) NineGridsAndPos() map[GridPos]*ViewGrid

/ 查询以该grid为中心的 9宫格 grid

func (*ViewGrid) PlayerById

func (g *ViewGrid) PlayerById(userId int64) (*UserChatData, bool)

func (*ViewGrid) RangeNear

func (g *ViewGrid) RangeNear(f func(grid *ViewGrid) bool)

func (*ViewGrid) RangeNearPlayers

func (g *ViewGrid) RangeNearPlayers(f func(*UserChatData) bool)

func (*ViewGrid) RangePlayers

func (g *ViewGrid) RangePlayers(f func(*UserChatData) bool)

func (*ViewGrid) RemovePlayer

func (g *ViewGrid) RemovePlayer(userId int64)

func (*ViewGrid) SetNearGrid

func (g *ViewGrid) SetNearGrid(pos GridPos, nearG *ViewGrid) bool

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL