上传任务对象池

This commit is contained in:
liwei1dao 2023-03-10 15:50:10 +08:00
parent 5acf0521c4
commit 05e35cac0a
2 changed files with 36 additions and 7 deletions

24
comm/pool.go Normal file
View File

@ -0,0 +1,24 @@
package comm
import (
"go_dreamfactory/pb"
"sync"
)
var taskParamPool = &sync.Pool{
New: func() interface{} {
return &pb.AgentMessage{}
},
}
func GettaskParam(t TaskType, p ...int32) *TaskParam {
task := taskParamPool.Get().(*TaskParam)
task.TT = t
task.Params = append(task.Params, p...)
return task
}
func PuttaskParam(r *TaskParam) {
r.Params = r.Params[:0]
taskParamPool.Put(r)
}

View File

@ -97,6 +97,7 @@ func (this *modelEquipmentComp) AddEquipments(session comm.IUserSession, cIds ma
configure *cfg.GameEquip
add map[string]*pb.DB_Equipment
uId string = session.GetUserId()
tasks []*comm.TaskParam
)
if configure, err = this.module.configure.GetEquipmentConfigure(); err != nil {
return
@ -110,8 +111,8 @@ func (this *modelEquipmentComp) AddEquipments(session comm.IUserSession, cIds ma
return nil, err
} else {
//随机任务
this.module.ModuleRtask.SendToRtask(session, comm.Rtype50, 1, c.Star)
this.module.ModuleRtask.SendToRtask(session, comm.Rtype97, 1, c.Suittype, c.Star)
tasks = append(tasks, comm.GettaskParam(comm.Rtype50, 1, c.Star))
tasks = append(tasks, comm.GettaskParam(comm.Rtype97, 1, c.Suittype, c.Star))
unm := int32(1)
if equipment.AdverbEntry != nil {
unm += int32(len(equipment.AdverbEntry))
@ -119,19 +120,24 @@ func (this *modelEquipmentComp) AddEquipments(session comm.IUserSession, cIds ma
if equipment.Adverbskill != nil {
unm += int32(len(equipment.Adverbskill))
}
this.module.ModuleRtask.SendToRtask(session, comm.Rtype99, 1, unm, c.Star)
tasks = append(tasks, comm.GettaskParam(comm.Rtype99, 1, unm, c.Star))
if c.Pos == 7 {
this.module.ModuleRtask.SendToRtask(session, comm.Rtype103, 1, c.Star)
tasks = append(tasks, comm.GettaskParam(comm.Rtype103, 1, c.Star))
} else if c.Pos == 6 {
this.module.ModuleRtask.SendToRtask(session, comm.Rtype101, 1, c.Star)
tasks = append(tasks, comm.GettaskParam(comm.Rtype101, 1, c.Star))
}
add[equipment.Id] = equipment
change = append(change, equipment)
}
}
}
}
//异步出发任务启动
if len(tasks) > 0 {
go this.module.ModuleRtask.TriggerTask(session.GetUserId(), tasks...)
}
if len(add) > 0 {
var (
model *db.DBModel
@ -151,7 +157,6 @@ func (this *modelEquipmentComp) AddEquipments(session comm.IUserSession, cIds ma
return
}
}
}
return
}