From b78d9721f297d2b7d3d2a717b1840dbc0e0f9313 Mon Sep 17 00:00:00 2001 From: boyce <6549168@qq.com> Date: Fri, 7 Nov 2025 14:16:47 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E8=93=9D=E5=9B=BE=E7=BB=93?= =?UTF-8?q?=E7=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- util/blueprint/blueprint.go | 31 +++++++++++++++++------------- util/blueprint/sysnodes.go | 38 ++++++++++++++++++++++++++++++++++--- 2 files changed, 53 insertions(+), 16 deletions(-) diff --git a/util/blueprint/blueprint.go b/util/blueprint/blueprint.go index 1a0fca1..d16de12 100644 --- a/util/blueprint/blueprint.go +++ b/util/blueprint/blueprint.go @@ -12,16 +12,16 @@ type Blueprint struct { graphPool GraphPool blueprintModule IBlueprintModule - mapGraph map[int64]IGraph - seedID int64 - cancelTimer func(*uint64)bool + mapGraph map[int64]IGraph + seedID int64 + cancelTimer func(*uint64) bool } func (bm *Blueprint) RegExecNode(execNode IExecNode) { bm.execNodes = append(bm.execNodes, execNode) } -func (bm *Blueprint) regSysNode(){ +func (bm *Blueprint) regSysNode() { bm.RegExecNode(&AddInt{}) bm.RegExecNode(&SubInt{}) bm.RegExecNode(&MulInt{}) @@ -50,11 +50,12 @@ func (bm *Blueprint) regSysNode(){ bm.RegExecNode(&LessThanInteger{}) bm.RegExecNode(&EqualInteger{}) bm.RegExecNode(&RangeCompare{}) + bm.RegExecNode(&EqualSwitch{}) bm.RegExecNode(&Probability{}) 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() err := bm.execPool.Load(execDefFilePath) if err != nil { @@ -74,7 +75,7 @@ func (bm *Blueprint) Init(execDefFilePath string, graphFilePath string, blueprin bm.cancelTimer = cancelTimer bm.blueprintModule = blueprintModule - bm.mapGraph = make(map[int64]IGraph,128) + bm.mapGraph = make(map[int64]IGraph, 128) return nil } @@ -93,26 +94,30 @@ func (bm *Blueprint) Create(graphName string) int64 { 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] if graph == nil { return fmt.Errorf("can not find graph:%d", graphID) } - _,err:= graph.Do(eventID, args...) + _, err := graph.Do(eventID, args...) 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] 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...) } func (bm *Blueprint) ReleaseGraph(graphID int64) { + if graphID == 0 { + return + } + defer delete(bm.mapGraph, graphID) graph := bm.mapGraph[graphID] if graph == nil { @@ -122,7 +127,7 @@ func (bm *Blueprint) ReleaseGraph(graphID int64) { graph.Release() } -func (bm *Blueprint) CancelTimerId(graphID int64, timerId *uint64) bool{ +func (bm *Blueprint) CancelTimerId(graphID int64, timerId *uint64) bool { tId := *timerId bm.cancelTimer(timerId) @@ -131,11 +136,11 @@ func (bm *Blueprint) CancelTimerId(graphID int64, timerId *uint64) bool{ return false } - gr,ok := graph.(*Graph) + gr, ok := graph.(*Graph) if !ok { return false } delete(gr.mapTimerID, tId) return true -} \ No newline at end of file +} diff --git a/util/blueprint/sysnodes.go b/util/blueprint/sysnodes.go index 8ba0728..7172998 100644 --- a/util/blueprint/sysnodes.go +++ b/util/blueprint/sysnodes.go @@ -15,8 +15,6 @@ const ( EntranceID_Timer = 3 ) - - type Entrance_ArrayParam struct { BaseExecNode } @@ -77,7 +75,7 @@ func (em *DebugOutput) Exec() (int, error) { 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 } @@ -471,6 +469,40 @@ func (em *RangeCompare) Exec() (int, error) { 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 概率判断(万分比) type Probability struct { BaseExecNode