refactor(fight): 优化战斗逻辑代码结构,清理冗余代码
This commit is contained in:
@@ -48,8 +48,10 @@ func (s *Server) OnClose(c gnet.Conn, _ error) (action gnet.Action) {
|
||||
}()
|
||||
|
||||
atomic.AddInt64(&s.connected, -1)
|
||||
|
||||
//logging.Infof("conn[%v] disconnected", c.RemoteAddr().String())
|
||||
v, _ := c.Context().(*player.ClientData)
|
||||
v.LF.Close()
|
||||
if v.Player != nil {
|
||||
v.SaveL.Do(func() { //使用保存锁,确保在踢人和掉线的时候只保存一次
|
||||
//cool.Loger.Info(context.TODO(), "准备保存", v.Player.Info.UserID)
|
||||
@@ -140,7 +142,8 @@ func (s *Server) OnTraffic(c gnet.Conn) (action gnet.Action) {
|
||||
//client := conn.RemoteAddr().String()
|
||||
s.workerPool.Submit(func() { //TODO 这里可能存在顺序执行问题,待修复
|
||||
for _, msg := range messages {
|
||||
t.OnEvent(msg.Payload)
|
||||
t.LF.Producer().Write(msg.Payload)
|
||||
//t.OnEvent(msg.Payload)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -164,8 +167,8 @@ func (s *Server) handleTcp(conn gnet.Conn) (action gnet.Action) {
|
||||
}
|
||||
|
||||
s.workerPool.Submit(func() { //TODO 这里可能存在顺序执行问题,待修复
|
||||
conn.Context().(*player.ClientData).OnEvent(data)
|
||||
|
||||
//conn.Context().(*player.ClientData).OnEvent(data)
|
||||
conn.Context().(*player.ClientData).LF.Producer().Write(data)
|
||||
})
|
||||
|
||||
if conn.InboundBuffered() > 0 {
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"blazing/common/utils/bytearray"
|
||||
"blazing/cool"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"context"
|
||||
|
||||
@@ -214,18 +215,20 @@ func NewClientData(c gnet.Conn) *ClientData {
|
||||
// 创建事件处理器
|
||||
// 创建消费端串行处理的Lockfree
|
||||
|
||||
cd := ClientData{
|
||||
cd := &ClientData{
|
||||
|
||||
Player: nil,
|
||||
Conn: c,
|
||||
Wsmsg: &WsCodec{},
|
||||
Conn: c,
|
||||
}
|
||||
// cd.LF = lockfree.NewLockfree[[]byte](
|
||||
// 1024*1024,
|
||||
// cd,
|
||||
// lockfree.NewSleepBlockStrategy(time.Millisecond),
|
||||
// )
|
||||
return &cd
|
||||
cd.LF = lockfree.NewLockfree[[]byte](
|
||||
1024*1024,
|
||||
cd,
|
||||
lockfree.NewSleepBlockStrategy(time.Millisecond),
|
||||
)
|
||||
// 启动Lockfree
|
||||
if err := cd.LF.Start(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return cd
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user