Documentation
¶
Overview ¶
Package matchmaker 提供基于属性匹配的组队原语。
玩家/会话携带 string + numeric 属性注册一张 ticket,匹配器按"桶(bucket, 如 region+mode)+ 最低共同属性"策略聚合候选,凑齐队伍即成匹配。
与基于 Bluge 全文索引的做法不同,本包用纯标准库实现一个 倒排索引 + 桶分组的轻量匹配器,适合中小规模(单机万级 ticket)。 超过此规模建议接入专用检索引擎。
零值不可用,用 New 构造。
Index ¶
- type Handler
- type Match
- type Matchmaker
- func (m *Matchmaker) Add(t Ticket, pool, bucketKey string) (string, error)
- func (m *Matchmaker) Count() int
- func (m *Matchmaker) QueryNearBySkill(pool string, val float64, n int) []*Ticket
- func (m *Matchmaker) Remove(ticketID string) bool
- func (m *Matchmaker) Start(ctx context.Context)
- func (m *Matchmaker) Stop()
- func (m *Matchmaker) Wait()
- type Option
- type Presence
- type Properties
- type Ticket
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Matchmaker ¶
type Matchmaker struct {
// contains filtered or unexported fields
}
Matchmaker 管理候选池并周期性尝试匹配。
func (*Matchmaker) Add ¶
func (m *Matchmaker) Add(t Ticket, pool, bucketKey string) (string, error)
Add 注册一张 ticket 进候选池。pool 用于隔离不同匹配类型(如 "5v5"/"3v3")。 bucketKey 由 string 属性拼成(如 "eu|ranked"),决定同桶匹配优先级。
func (*Matchmaker) QueryNearBySkill ¶
func (m *Matchmaker) QueryNearBySkill(pool string, val float64, n int) []*Ticket
QueryNearBySkill 返回 pool 中 skill 最接近 val 的 n 个 ticket(用于调试/扩展)。
func (*Matchmaker) Remove ¶
func (m *Matchmaker) Remove(ticketID string) bool
Remove 移除一张 ticket(如玩家取消)。
func (*Matchmaker) Start ¶
func (m *Matchmaker) Start(ctx context.Context)
Start 启动匹配循环。幂等。ctx 取消时停止。
type Option ¶
type Option func(*config)
Option 配置 Matchmaker。
func WithMaxWaitSec ¶
WithMaxWaitSec 设置 ticket 最长等待秒数:超时后放宽桶约束(忽略 string 属性差异)强匹配。 默认 30。<=0 不放宽。
func WithTickInterval ¶
WithTickInterval 设置匹配扫描周期,默认 500ms。
Click to show internal directories.
Click to hide internal directories.