新增蓝图结点

This commit is contained in:
boyce
2025-11-07 14:16:47 +08:00
parent f8953d1764
commit b78d9721f2
2 changed files with 53 additions and 16 deletions

View File

@@ -12,16 +12,16 @@ type Blueprint struct {
graphPool GraphPool graphPool GraphPool
blueprintModule IBlueprintModule blueprintModule IBlueprintModule
mapGraph map[int64]IGraph mapGraph map[int64]IGraph
seedID int64 seedID int64
cancelTimer func(*uint64)bool cancelTimer func(*uint64) bool
} }
func (bm *Blueprint) RegExecNode(execNode IExecNode) { func (bm *Blueprint) RegExecNode(execNode IExecNode) {
bm.execNodes = append(bm.execNodes, execNode) bm.execNodes = append(bm.execNodes, execNode)
} }
func (bm *Blueprint) regSysNode(){ func (bm *Blueprint) regSysNode() {
bm.RegExecNode(&AddInt{}) bm.RegExecNode(&AddInt{})
bm.RegExecNode(&SubInt{}) bm.RegExecNode(&SubInt{})
bm.RegExecNode(&MulInt{}) bm.RegExecNode(&MulInt{})
@@ -50,11 +50,12 @@ func (bm *Blueprint) regSysNode(){
bm.RegExecNode(&LessThanInteger{}) bm.RegExecNode(&LessThanInteger{})
bm.RegExecNode(&EqualInteger{}) bm.RegExecNode(&EqualInteger{})
bm.RegExecNode(&RangeCompare{}) bm.RegExecNode(&RangeCompare{})
bm.RegExecNode(&EqualSwitch{})
bm.RegExecNode(&Probability{}) bm.RegExecNode(&Probability{})
bm.RegExecNode(&CreateTimer{}) bm.RegExecNode(&CreateTimer{})
} }
func (bm *Blueprint) Init(execDefFilePath string, graphFilePath string, blueprintModule IBlueprintModule,cancelTimer func(*uint64)bool) error { func (bm *Blueprint) Init(execDefFilePath string, graphFilePath string, blueprintModule IBlueprintModule, cancelTimer func(*uint64) bool) error {
bm.regSysNode() bm.regSysNode()
err := bm.execPool.Load(execDefFilePath) err := bm.execPool.Load(execDefFilePath)
if err != nil { if err != nil {
@@ -74,7 +75,7 @@ func (bm *Blueprint) Init(execDefFilePath string, graphFilePath string, blueprin
bm.cancelTimer = cancelTimer bm.cancelTimer = cancelTimer
bm.blueprintModule = blueprintModule bm.blueprintModule = blueprintModule
bm.mapGraph = make(map[int64]IGraph,128) bm.mapGraph = make(map[int64]IGraph, 128)
return nil return nil
} }
@@ -93,26 +94,30 @@ func (bm *Blueprint) Create(graphName string) int64 {
return graphID return graphID
} }
func (bm *Blueprint) TriggerEvent(graphID int64, eventID int64, args ...any) error{ func (bm *Blueprint) TriggerEvent(graphID int64, eventID int64, args ...any) error {
graph := bm.mapGraph[graphID] graph := bm.mapGraph[graphID]
if graph == nil { if graph == nil {
return fmt.Errorf("can not find graph:%d", graphID) return fmt.Errorf("can not find graph:%d", graphID)
} }
_,err:= graph.Do(eventID, args...) _, err := graph.Do(eventID, args...)
return err return err
} }
func (bm *Blueprint) Do(graphID int64, entranceID int64, args ...any) (Port_Array,error){ func (bm *Blueprint) Do(graphID int64, entranceID int64, args ...any) (Port_Array, error) {
graph := bm.mapGraph[graphID] graph := bm.mapGraph[graphID]
if graph == nil { if graph == nil {
return nil,fmt.Errorf("can not find graph:%d", graphID) return nil, fmt.Errorf("can not find graph:%d", graphID)
} }
return graph.Do(entranceID, args...) return graph.Do(entranceID, args...)
} }
func (bm *Blueprint) ReleaseGraph(graphID int64) { func (bm *Blueprint) ReleaseGraph(graphID int64) {
if graphID == 0 {
return
}
defer delete(bm.mapGraph, graphID) defer delete(bm.mapGraph, graphID)
graph := bm.mapGraph[graphID] graph := bm.mapGraph[graphID]
if graph == nil { if graph == nil {
@@ -122,7 +127,7 @@ func (bm *Blueprint) ReleaseGraph(graphID int64) {
graph.Release() graph.Release()
} }
func (bm *Blueprint) CancelTimerId(graphID int64, timerId *uint64) bool{ func (bm *Blueprint) CancelTimerId(graphID int64, timerId *uint64) bool {
tId := *timerId tId := *timerId
bm.cancelTimer(timerId) bm.cancelTimer(timerId)
@@ -131,7 +136,7 @@ func (bm *Blueprint) CancelTimerId(graphID int64, timerId *uint64) bool{
return false return false
} }
gr,ok := graph.(*Graph) gr, ok := graph.(*Graph)
if !ok { if !ok {
return false return false
} }

View File

@@ -15,8 +15,6 @@ const (
EntranceID_Timer = 3 EntranceID_Timer = 3
) )
type Entrance_ArrayParam struct { type Entrance_ArrayParam struct {
BaseExecNode BaseExecNode
} }
@@ -77,7 +75,7 @@ func (em *DebugOutput) Exec() (int, error) {
return 0, fmt.Errorf("output Exec inParam not found") return 0, fmt.Errorf("output Exec inParam not found")
} }
log.Debug("DebugOutput Exec",log.Any("param1",val),log.Any("param2",valStr),log.Any("param3",valArray)) log.Debug("DebugOutput Exec", log.Any("param1", val), log.Any("param2", valStr), log.Any("param3", valArray))
return 0, nil return 0, nil
} }
@@ -471,6 +469,40 @@ func (em *RangeCompare) Exec() (int, error) {
return 0, nil return 0, nil
} }
// EqualSwitch 等于分支==
type EqualSwitch struct {
BaseExecNode
}
func (em *EqualSwitch) GetName() string {
return "EqualSwitch"
}
func (em *EqualSwitch) Exec() (int, error) {
inPortA := em.GetInPort(1)
if inPortA == nil {
return -1, fmt.Errorf("GreaterThanInteger inParam 1 not found")
}
ret, ok := inPortA.GetInt()
if !ok {
return -1, fmt.Errorf("GreaterThanInteger inParam 1 error")
}
intArray := em.execNode.GetInPortDefaultIntArrayValue(2)
if intArray == nil {
return 0, nil
}
for i := 0; i < len(intArray) && i < em.GetOutPortCount()-2; i++ {
if ret == intArray[i] {
return i + 2, nil
}
}
return 0, nil
}
// Probability 概率判断(万分比) // Probability 概率判断(万分比)
type Probability struct { type Probability struct {
BaseExecNode BaseExecNode