修改配置表单
This commit is contained in:
parent
7047776238
commit
3b4aa1b65d
57
lib/ai.go
57
lib/ai.go
@ -4,6 +4,7 @@ import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
"legu.airobot/storage"
|
||||
@ -14,10 +15,10 @@ type myAI struct {
|
||||
scenes []*scene
|
||||
iscenes []IScene
|
||||
tickets Tickets //票池
|
||||
robotCount uint32 //机器人数量
|
||||
countTotal uint32 //机器人总数
|
||||
useCount uint32 //使用数量
|
||||
lock sync.Mutex //
|
||||
config *storage.Config //配置
|
||||
|
||||
}
|
||||
|
||||
func NewAI(aip AIParam) (*myAI, error) {
|
||||
@ -28,7 +29,7 @@ func NewAI(aip AIParam) (*myAI, error) {
|
||||
|
||||
ai := &myAI{
|
||||
scenes: make([]*scene, 0),
|
||||
robotCount: aip.RobotCount,
|
||||
countTotal: aip.RobotCount,
|
||||
config: aip.Config,
|
||||
iscenes: aip.Scenes,
|
||||
}
|
||||
@ -44,63 +45,18 @@ func (m *myAI) init() error {
|
||||
var buf bytes.Buffer
|
||||
buf.WriteString("初始化AI")
|
||||
|
||||
tickets, err := NewTickets(m.robotCount)
|
||||
tickets, err := NewTickets(m.countTotal)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
m.tickets = tickets
|
||||
|
||||
buf.WriteString(fmt.Sprintf("完成 机器人数量:%d", m.robotCount))
|
||||
buf.WriteString(fmt.Sprintf("完成 机器人数量:%d", m.countTotal))
|
||||
logrus.Debug(buf.String())
|
||||
return nil
|
||||
}
|
||||
|
||||
//启动时载入所有Caller
|
||||
// Deprecated
|
||||
func (m *myAI) LoadCallers() []IScene {
|
||||
return m.iscenes
|
||||
}
|
||||
|
||||
// 根据场景名称获取场景接口
|
||||
// Deprecated
|
||||
func (m *myAI) GetSceneInstance(sceneName string) IScene {
|
||||
for _, v := range m.iscenes {
|
||||
if v.Info().Name == sceneName {
|
||||
return v
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// 加入机器人
|
||||
// func (m *myAI) AddRobot(scene *scene) {
|
||||
// robot := NewRobot()
|
||||
// robot.SelScene(scene)
|
||||
// m.robots = append(m.robots, robot)
|
||||
// }
|
||||
|
||||
// 获取场景下的机器人
|
||||
func (m *myAI) GetRobots(sceneName string) (robots []*Robot) {
|
||||
for _, robot := range m.robots {
|
||||
scene := robot.GetCurrentScene()
|
||||
if scene != nil && scene.Name == sceneName {
|
||||
robots = append(robots, robot)
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Deprecated
|
||||
func (m *myAI) CurrentScene() *scene {
|
||||
for _, v := range m.scenes {
|
||||
if v.status == STATUS_ENABLE {
|
||||
return v
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *myAI) appendRobot(robot *Robot) {
|
||||
defer m.lock.Unlock()
|
||||
m.lock.Lock()
|
||||
@ -116,6 +72,7 @@ func (m *myAI) Start() bool {
|
||||
go func() {
|
||||
for {
|
||||
m.tickets.Take()
|
||||
atomic.AddUint32(&m.useCount, 1)
|
||||
go func() {
|
||||
robot := NewRobot(m.config)
|
||||
robot.SetScenes(m.iscenes)
|
||||
|
21
lib/robot.go
21
lib/robot.go
@ -27,18 +27,15 @@ type IRobot interface {
|
||||
|
||||
type Robot struct {
|
||||
IStore
|
||||
account string
|
||||
sid string
|
||||
// Deprecated
|
||||
scene *scene
|
||||
account string
|
||||
sid string
|
||||
conn *websocket.Conn
|
||||
data map[string]interface{} //机器人缓存数据
|
||||
status uint32 //状态
|
||||
lock sync.Mutex //
|
||||
sceneQueue *Queue[IScene] //场景队列
|
||||
config *storage.Config //配置
|
||||
//
|
||||
resultCh chan *CallResult
|
||||
resultCh chan *CallResult
|
||||
}
|
||||
|
||||
func NewRobot(config *storage.Config) *Robot {
|
||||
@ -71,7 +68,7 @@ func (r *Robot) SendMsg(mainType, subType string, req proto.Message, rsp proto.M
|
||||
start := time.Now()
|
||||
defer func() {
|
||||
t := time.Since(start)
|
||||
logrus.WithFields(logrus.Fields{"MainType": mainType, "SubType": subType, "rsp": rsp, "since": t}).Debug("接收消息")
|
||||
logrus.WithFields(logrus.Fields{"MainType": mainType, "SubType": subType, "rsp": rsp, "since": t.String()}).Debug("接收消息")
|
||||
}()
|
||||
|
||||
head := &pb.UserMessage{MainType: mainType, SubType: subType}
|
||||
@ -133,16 +130,6 @@ func (a *Robot) SetScenes(scenes []IScene) {
|
||||
}
|
||||
}
|
||||
|
||||
// Deprecated
|
||||
func (m *Robot) SelScene(scene *scene) {
|
||||
m.scene = scene
|
||||
}
|
||||
|
||||
// Deprecated
|
||||
func (m *Robot) GetCurrentScene() *scene {
|
||||
return m.scene
|
||||
}
|
||||
|
||||
func (m *Robot) Start() bool {
|
||||
if len(m.sceneQueue.List()) == 0 {
|
||||
logrus.Warn("没有设置场景队列")
|
||||
|
@ -98,23 +98,7 @@ func (mw *MainWindow) startContainer() {
|
||||
}, mw.w)
|
||||
return
|
||||
}
|
||||
// 检查场景是否启用
|
||||
// isEnable := false
|
||||
// for _, v := range config.Scenes {
|
||||
// if v.Status == lib.STATUS_ENABLE {
|
||||
// isEnable = true
|
||||
// break
|
||||
// }
|
||||
// }
|
||||
// if !isEnable {
|
||||
// dialog.ShowCustomConfirm("提示", "启用", "取消", widget.NewLabel("还没有启用任意场景"), func(b bool) {
|
||||
// if !b {
|
||||
// return
|
||||
// }
|
||||
// mw.sceneContainer()
|
||||
// }, mw.w)
|
||||
// return
|
||||
// }
|
||||
|
||||
startBtn.Enable()
|
||||
startBtn.OnTapped = func() {
|
||||
param := lib.AIParam{
|
||||
@ -140,12 +124,17 @@ func (mw *MainWindow) configContainer() {
|
||||
wsAddrEntry := widget.NewEntry()
|
||||
sidEntry := widget.NewEntry()
|
||||
userCountEntry := widget.NewEntry()
|
||||
userTotalEntry := widget.NewEntry()
|
||||
userTotalEntry.PlaceHolder = "用户数上限"
|
||||
timeoutEntry := widget.NewEntry()
|
||||
timeoutEntry.PlaceHolder = "请求超时"
|
||||
intervalEntry := widget.NewEntry()
|
||||
intervalEntry.PlaceHolder = "每次压入用户间隔时间"
|
||||
|
||||
form := widget.NewForm(
|
||||
widget.NewFormItem("服务地址", wsAddrEntry),
|
||||
widget.NewFormItem("区服编号", sidEntry),
|
||||
widget.NewFormItem("用户总数", userTotalEntry),
|
||||
widget.NewFormItem("用户数", userCountEntry),
|
||||
widget.NewFormItem("间隔时间(s)", intervalEntry),
|
||||
widget.NewFormItem("超时时间(ms)", timeoutEntry),
|
||||
|
Loading…
Reference in New Issue
Block a user