Skip to content

Commit

Permalink
Merge branch 'v0.1-develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaonanln committed Jun 18, 2018
2 parents 73cf0af + bd2ea81 commit 214db1b
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 83 deletions.
20 changes: 10 additions & 10 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,6 @@
[[constraint]]
name = "gopkg.in/mgo.v2"

[[constraint]]
name = "github.com/xiaonanln/go-aoi"
version = "^0.0.2"

[[constraint]]
name = "github.com/chasex/redis-go-cluster"
branch = "master"
36 changes: 0 additions & 36 deletions components/dispatcher/DispatcherService.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,12 @@ import (
"github.com/xiaonanln/goworld/engine/proto"
)

type callQueueItem struct {
packet *netutil.Packet
}

type entityDispatchInfo struct {
gameid uint16
blockUntilTime time.Time
pendingPacketQueue []*netutil.Packet
}

func newEntityDispatchInfo() *entityDispatchInfo {
return &entityDispatchInfo{}
}

func (edi *entityDispatchInfo) blockRPC(d time.Duration) {
t := time.Now().Add(d)
if edi.blockUntilTime.Before(t) {
Expand Down Expand Up @@ -573,23 +565,6 @@ func (service *DispatcherService) cleanupEntitiesOfGame(gameid uint16) {
}
}

//// for all services whose entity is cleaned, notify all games that the service is down
//undeclaredServices := common.StringSet{}
//for serviceName, serviceEids := range service.srvdisRegisterMap {
// var serviceRemoveEids []common.EntityID
// for serviceEid := range serviceEids {
// if cleanEids.Contains(serviceEid) { // this service entity is down, tell other games
// undeclaredServices.Add(serviceName)
// serviceRemoveEids = append(serviceRemoveEids, serviceEid)
// service.handleServiceDown(gameid, serviceName, serviceEid)
// }
// }
//
// for _, eid := range serviceRemoveEids {
// serviceEids.Del(eid)
// }
//}

for eid := range cleanEids {
service.cleanupEntityInfo(eid)
}
Expand All @@ -616,17 +591,6 @@ func (service *DispatcherService) handleNotifyDestroyEntity(dcp *dispatcherClien

func (service *DispatcherService) cleanupEntityInfo(entityID common.EntityID) {
service.delEntityDispatchInfo(entityID)
//if services, ok := service.entityIDToServices[entityID]; ok {
// for serviceName := range services {
// serviceEids := service.srvdisRegisterMap[serviceName]
// serviceEids.Del(entityID)
// if len(serviceEids) == 0 {
// delete(service.srvdisRegisterMap, serviceName)
// }
// }
// delete(service.entityIDToServices, entityID)
// gwlog.Warnf("%s: entity %s is cleaned up, undeclared servies %v", service, entityID, services.ToList())
//}
}

func (service *DispatcherService) handleNotifyClientConnected(dcp *dispatcherClientProxy, pkt *netutil.Packet) {
Expand Down
1 change: 1 addition & 0 deletions components/gate/GateService.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ func (gs *GateService) handleDispatcherClientPacket(msgtype proto.MsgType, packe
}
} else {
// client already disconnected, but the game service seems not knowing it, so tell it
// fixme: uncomment bellow line, it is just for test
dispatchercluster.SelectByGateID(gateid).SendNotifyClientDisconnected(clientid)
}
} else if msgtype == proto.MT_SYNC_POSITION_YAW_ON_CLIENTS {
Expand Down
7 changes: 7 additions & 0 deletions engine/entity/Entity.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,11 +307,17 @@ func (e *Entity) OnLeaveAOI(otherAoi *aoi.AOI) {

// Interests and Uninterest among entities
func (e *Entity) interest(other *Entity) {
if e == other || e.Neighbors.Contains(other) {
gwlog.Panicf("interest multiple times: %s & %s", e, other)
}
e.Neighbors.Add(other)
e.client.sendCreateEntity(other, false)
}

func (e *Entity) uninterest(other *Entity) {
if e == other || !e.Neighbors.Contains(other) {
gwlog.Panicf("not interested yet: %s & %s", e, other)
}
e.Neighbors.Del(other)
e.client.sendDestroyEntity(other)
}
Expand Down Expand Up @@ -933,6 +939,7 @@ func (e *Entity) sendListAttrChangeToClients(la *ListAttr, index int, val interf
flag := la.flag

if flag&afAllClient != 0 {
// TODO: only pack 1 packet, do not marshal multiple times
path := la.getPathFromOwner()
e.client.sendNotifyListAttrChange(e.ID, path, uint32(index), val)
for neighbor := range e.Neighbors {
Expand Down
3 changes: 2 additions & 1 deletion engine/entity/Space.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ func (space *Space) EnableAOI() {
}

space.Attrs.SetBool(_SPACE_ENABLE_AOI_KEY, true)
space.aoiMgr = aoi.NewXZListAOICalculator()
space.aoiMgr = aoi.NewXZListAOIManager()
//space.aoiMgr = aoi.NewTowerAOIManager(-500, 500, -500, 500, 10)
}

//func (space *Space) UseTowerAOI(minX, maxX, minY, maxY Coord, towerRange Coord) {
Expand Down
15 changes: 1 addition & 14 deletions engine/gwlog/gwlog.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,6 @@ var (
PanicLevel Level = Level(zap.PanicLevel)
// FatalLevel level
FatalLevel Level = Level(zap.FatalLevel)

//// Debugf logs formatted debug message
//Debugf logFormatFunc
//// Infof logs formatted info message
//Infof logFormatFunc
//// Warnf logs formatted warn message
//Warnf logFormatFunc
//// Errorf logs formatted error message
//Errorf logFormatFunc
//Panicf logFormatFunc
//Fatalf logFormatFunc
//Error func(args ...interface{})
//Fatal func(args ...interface{})
//Panic func(args ...interface{})
)

type logFormatFunc func(format string, args ...interface{})
Expand Down Expand Up @@ -162,6 +148,7 @@ func Panicf(format string, args ...interface{}) {
}

func Fatalf(format string, args ...interface{}) {
debug.PrintStack()
sugar.With(zap.Time("ts", time.Now())).Fatalf(format, args...)
}

Expand Down
17 changes: 6 additions & 11 deletions examples/test_client/ClientBot.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,13 +222,15 @@ func (bot *ClientBot) handlePacket(msgtype proto.MsgType, packet *netutil.Packet
defer func() {
err := recover()
if err != nil {
gwlog.Fatalf("handle packet faild: %v", err)
gwlog.TraceError("handle packet faild: %v", err)
}
}()

bot.Lock()
defer bot.Unlock()

//gwlog.Infof("client handle packet: msgtype=%v, payload=%v", msgtype, packet.Payload())

if msgtype >= proto.MT_REDIRECT_TO_GATEPROXY_MSG_TYPE_START && msgtype <= proto.MT_REDIRECT_TO_GATEPROXY_MSG_TYPE_STOP {
_ = packet.ReadUint16()
_ = packet.ReadClientID() // TODO: strip these two fields ? seems a little difficult, maybe later.
Expand Down Expand Up @@ -261,27 +263,21 @@ func (bot *ClientBot) handlePacket(msgtype proto.MsgType, packet *netutil.Packet
index := packet.ReadUint32()
var val interface{}
packet.ReadData(&val)
if !quiet {
gwlog.Debugf("Entity %s Attribute %v: set [%d]=%v", entityID, path, index, val)
}
//gwlog.Infof("Entity %s Attribute %v: set [%d]=%v", entityID, path, index, val)
bot.applyListAttrChange(entityID, path, int(index), val)
} else if msgtype == proto.MT_NOTIFY_LIST_ATTR_APPEND_ON_CLIENT {
entityID := packet.ReadEntityID()
var path []interface{}
packet.ReadData(&path)
var val interface{}
packet.ReadData(&val)
if !quiet {
gwlog.Debugf("Entity %s Attribute %v: append %v", entityID, path, val)
}
//gwlog.Infof("Entity %s Attribute %v: append %v", entityID, path, val)
bot.applyListAttrAppend(entityID, path, val)
} else if msgtype == proto.MT_NOTIFY_LIST_ATTR_POP_ON_CLIENT {
entityID := packet.ReadEntityID()
var path []interface{}
packet.ReadData(&path)
if !quiet {
gwlog.Debugf("Entity %s Attribute %v: pop", entityID, path)
}
//gwlog.Infof("Entity %s Attribute %v: pop", entityID, path)
bot.applyListAttrPop(entityID, path)
} else if msgtype == proto.MT_CREATE_ENTITY_ON_CLIENT {
isPlayer := packet.ReadBool()
Expand Down Expand Up @@ -417,7 +413,6 @@ func (bot *ClientBot) applyListAttrPop(entityID common.EntityID, path []interfac
}
entity := bot.entities[entityID]
entity.applyListAttrPop(path)

}

func (bot *ClientBot) createEntity(typeName string, entityID common.EntityID, isPlayer bool, clientData map[string]interface{}, x, y, z entity.Coord, yaw entity.Yaw) {
Expand Down
24 changes: 17 additions & 7 deletions examples/test_client/ClientEntity.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,12 +165,12 @@ type _Something struct {
var (
_DO_THINGS = []*_Something{
{"DoEnterRandomSpace", 20, time.Minute},
{"DoEnterRandomNilSpace", 10, time.Minute},
//{"DoEnterRandomNilSpace", 10, time.Minute},
//{"DoSendMail", 5, time.Minute},
//{"DoGetMails", 10, time.Minute},
{"DoSayInWorldChannel", 5, time.Minute},
{"DoSayInProfChannel", 5, time.Minute},
{"DoTestListField", 10, time.Minute},
//{"DoSayInWorldChannel", 5, time.Minute},
//{"DoSayInProfChannel", 5, time.Minute},
{"DoTestListField", 20, time.Minute},
//{"DoTestPublish", 1, time.Minute},
}
)
Expand Down Expand Up @@ -384,30 +384,40 @@ func (e *clientEntity) applyMapAttrDel(path []interface{}, key string) {
}

func (e *clientEntity) applyListAttrChange(path []interface{}, index int, val interface{}) {
gwlog.Debugf("applyListAttrChange: path=%v, index=%v, val=%v", path, index, val)
_attr, _, _ := e.findAttrByPath(path)
attr := _attr.([]interface{})
//gwlog.Infof("%s applyListAttrChange: path=%v, index=%v, val=%v, attr=%#v", e, path, index, val, attr)
if index >= len(attr) {
gwlog.Panicf("%s: ListAttr change error: list size is %d, index = %d, path=%s, attr=%#v", e, len(attr), index, path, attr)
return
}
attr[index] = val
e.onAttrChange(path, "")
}

func (e *clientEntity) applyListAttrAppend(path []interface{}, val interface{}) {
gwlog.Debugf("applyListAttrAppend: path=%v, val=%v, attrs=%v", path, val, e.Attrs)
_attr, parent, pkey := e.findAttrByPath(path)
attr := _attr.([]interface{})

//gwlog.Infof("%s applyListAttrAppend: path=%v, val=%v, attr=%#v", e, path, val, attr)
if parentmap, ok := parent.(map[string]interface{}); ok {
parentmap[pkey.(string)] = append(attr, val)
} else if parentlist, ok := parent.([]interface{}); ok {
parentlist[pkey.(int64)] = append(attr, val)
} else {
gwlog.Panicf("parent type is %T", parent)
}

e.onAttrChange(path, "")
}
func (e *clientEntity) applyListAttrPop(path []interface{}) {
gwlog.Debugf("applyListAttrPop: path=%v", path)
_attr, parent, pkey := e.findAttrByPath(path)
attr := _attr.([]interface{})
//gwlog.Infof("%s applyListAttrPop: path=%v, attr=%#v", e, path, attr)
if len(attr) == 0 {
gwlog.Panicf("%s: ListAttr pop error: list is empty: path=%s, attr=%#v", e, path, attr)
return
}

if parentmap, ok := parent.(map[string]interface{}); ok {
parentmap[pkey.(string)] = attr[:len(attr)-1]
Expand Down

0 comments on commit 214db1b

Please sign in to comment.