Ai
7 Star 27 Fork 2

Gitee 极速下载/goworld

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
此仓库是为了提升国内下载速度的镜像仓库,每日同步一次。 原始仓库: https://github.com/xiaonanln/goworld
克隆/下载
dispatchercluster.go 4.32 KB
一键复制 编辑 原始数据 按行查看 历史
seis 提交于 2018-07-08 16:10 +08:00 . CreateSpaceOnGame, CreateEntityOnGame
package dispatchercluster
import (
"github.com/xiaonanln/goworld/engine/common"
"github.com/xiaonanln/goworld/engine/config"
"github.com/xiaonanln/goworld/engine/dispatchercluster/dispatcherclient"
"github.com/xiaonanln/goworld/engine/gwlog"
"github.com/xiaonanln/goworld/engine/netutil"
"github.com/xiaonanln/goworld/engine/proto"
)
var (
dispatcherConns []*dispatcherclient.DispatcherConnMgr
dispatcherNum int
gid uint16
)
func Initialize(_gid uint16, dctype dispatcherclient.DispatcherClientType, isRestoreGame, isBanBootEntity bool, delegate dispatcherclient.IDispatcherClientDelegate) {
gid = _gid
if gid == 0 {
gwlog.Fatalf("gid is 0")
}
dispIds := config.GetDispatcherIDs()
dispatcherNum = len(dispIds)
if dispatcherNum == 0 {
gwlog.Fatalf("dispatcher number is 0")
}
dispatcherConns = make([]*dispatcherclient.DispatcherConnMgr, dispatcherNum)
for _, dispid := range dispIds {
dispatcherConns[dispid-1] = dispatcherclient.NewDispatcherConnMgr(gid, dctype, dispid, isRestoreGame, isBanBootEntity, delegate)
}
for _, dispConn := range dispatcherConns {
dispConn.Connect()
}
}
func SendNotifyDestroyEntity(id common.EntityID) error {
return SelectByEntityID(id).SendNotifyDestroyEntity(id)
}
func SendMigrateRequest(entityID common.EntityID, spaceID common.EntityID, spaceGameID uint16) error {
return SelectByEntityID(entityID).SendMigrateRequest(entityID, spaceID, spaceGameID)
}
func SendRealMigrate(eid common.EntityID, targetGame uint16, data []byte) error {
return SelectByEntityID(eid).SendRealMigrate(eid, targetGame, data)
}
func SendCallFilterClientProxies(op proto.FilterClientsOpType, key, val string, method string, args []interface{}) {
pkt := proto.AllocCallFilterClientProxiesPacket(op, key, val, method, args)
broadcast(pkt)
pkt.Release()
return
}
func broadcast(packet *netutil.Packet) {
for _, dcm := range dispatcherConns {
dcm.GetDispatcherClientForSend().SendPacket(packet)
}
}
func SendNotifyCreateEntity(id common.EntityID) error {
if gid != 0 {
return SelectByEntityID(id).SendNotifyCreateEntity(id)
} else {
// goes here when creating nil space or restoring freezed entities
return nil
}
}
func SendLoadEntityAnywhere(typeName string, entityID common.EntityID) error {
return SelectByEntityID(entityID).SendLoadEntitySomewhere(typeName, entityID, 0)
}
func SendLoadEntityOnGame(typeName string, entityID common.EntityID, gameid uint16) error {
return SelectByEntityID(entityID).SendLoadEntitySomewhere(typeName, entityID, gameid)
}
func SendCreateEntitySomewhere(gameid uint16, entityid common.EntityID, typeName string, data map[string]interface{}) error {
return SelectByEntityID(entityid).SendCreateEntitySomewhere(gameid, entityid, typeName, data)
}
func SendGameLBCInfo(lbcinfo proto.GameLBCInfo) {
packet := proto.AllocGameLBCInfoPacket(lbcinfo)
broadcast(packet)
packet.Release()
}
func SendStartFreezeGame() {
pkt := proto.AllocStartFreezeGamePacket()
broadcast(pkt)
pkt.Release()
return
}
func SendSrvdisRegister(srvid string, info string, force bool) {
SelectBySrvID(srvid).SendSrvdisRegister(srvid, info, force)
}
func SendCallNilSpaces(exceptGameID uint16, method string, args []interface{}) {
// construct one packet for multiple sending
packet := proto.AllocCallNilSpacesPacket(exceptGameID, method, args)
broadcast(packet)
packet.Release()
}
func EntityIDToDispatcherID(entityid common.EntityID) uint16 {
return uint16((hashEntityID(entityid) % dispatcherNum) + 1)
}
func SrvIDToDispatcherID(srvid string) uint16 {
return uint16((hashSrvID(srvid) % dispatcherNum) + 1)
}
func SelectByEntityID(entityid common.EntityID) *dispatcherclient.DispatcherClient {
idx := hashEntityID(entityid) % dispatcherNum
return dispatcherConns[idx].GetDispatcherClientForSend()
}
func SelectByGateID(gateid uint16) *dispatcherclient.DispatcherClient {
idx := hashGateID(gateid) % dispatcherNum
return dispatcherConns[idx].GetDispatcherClientForSend()
}
func SelectByDispatcherID(dispid uint16) *dispatcherclient.DispatcherClient {
return dispatcherConns[dispid-1].GetDispatcherClientForSend()
}
func SelectBySrvID(srvid string) *dispatcherclient.DispatcherClient {
idx := hashSrvID(srvid) % dispatcherNum
return dispatcherConns[idx].GetDispatcherClientForSend()
}
func Select(dispidx int) *dispatcherclient.DispatcherClient {
return dispatcherConns[dispidx].GetDispatcherClientForSend()
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/mirrors/goworld.git
git@gitee.com:mirrors/goworld.git
mirrors
goworld
goworld
v0.1.6

搜索帮助