From 21e9b2cd4bc9fca170bab2d7d92b5bcb1f350bc4 Mon Sep 17 00:00:00 2001 From: boyce <6549168@qq.com> Date: Wed, 29 Oct 2025 11:03:06 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9ws=E7=89=88=E6=9C=AC=E4=BB=A5?= =?UTF-8?q?=E5=8F=8A=E7=BB=93=E7=82=B9=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- go.mod | 2 +- go.sum | 4 ++-- util/blueprint/blueprint.go | 42 ++++++++++++++++++++++++++++++++++++- util/blueprint/mathnode.go | 8 ------- util/blueprint/register.go | 5 +---- util/blueprint/sysnodes.go | 24 --------------------- 6 files changed, 45 insertions(+), 40 deletions(-) diff --git a/go.mod b/go.mod index 66bcdbd..3611d52 100644 --- a/go.mod +++ b/go.mod @@ -12,7 +12,7 @@ require ( github.com/goccy/go-json v0.10.2 github.com/gomodule/redigo v1.8.8 github.com/google/uuid v1.6.0 - github.com/gorilla/websocket v1.5.0 + github.com/gorilla/websocket v1.5.3 github.com/json-iterator/go v1.1.12 github.com/nats-io/nats.go v1.34.1 github.com/pierrec/lz4/v4 v4.1.21 diff --git a/go.sum b/go.sum index fc9db71..85fa327 100644 --- a/go.sum +++ b/go.sum @@ -88,8 +88,8 @@ github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/gorilla/securecookie v1.1.1/go.mod h1:ra0sb63/xPlUeL+yeDciTfxMRAA+MP+HVt/4epWDjd4= github.com/gorilla/sessions v1.2.1/go.mod h1:dk2InVEVJ0sfLlnXv9EAgkf6ecYs/i80K/zI+bUmuGM= -github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc= -github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= +github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg= +github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/hashicorp/errwrap v1.0.0 h1:hLrqtEDnRye3+sgx6z4qVLNuviH3MR5aQ0ykNJa/UYA= github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo= diff --git a/util/blueprint/blueprint.go b/util/blueprint/blueprint.go index 5f2bb3f..312f01b 100644 --- a/util/blueprint/blueprint.go +++ b/util/blueprint/blueprint.go @@ -6,6 +6,8 @@ import ( ) type Blueprint struct { + execNodes []IExecNode // 注册的定义执行结点 + execPool ExecPool graphPool GraphPool @@ -15,13 +17,51 @@ type Blueprint struct { cancelTimer func(*uint64)bool } +func (bm *Blueprint) RegExecNode(execNode IExecNode) { + bm.execNodes = append(bm.execNodes, execNode) +} + +func (bm *Blueprint) regSysNode(){ + bm.RegExecNode(&AddInt{}) + bm.RegExecNode(&SubInt{}) + bm.RegExecNode(&MulInt{}) + bm.RegExecNode(&DivInt{}) + bm.RegExecNode(&ModInt{}) + bm.RegExecNode(&RandNumber{}) + + bm.RegExecNode(&Entrance_ArrayParam{}) + bm.RegExecNode(&Entrance_IntParam{}) + bm.RegExecNode(&Entrance_Timer{}) + bm.RegExecNode(&Output{}) + bm.RegExecNode(&Sequence{}) + bm.RegExecNode(&Foreach{}) + bm.RegExecNode(&ForeachIntArray{}) + + bm.RegExecNode(&GetArrayInt{}) + bm.RegExecNode(&GetArrayString{}) + bm.RegExecNode(&GetArrayLen{}) + bm.RegExecNode(&CreateIntArray{}) + bm.RegExecNode(&CreateStringArray{}) + bm.RegExecNode(&AppendIntegerToArray{}) + bm.RegExecNode(&AppendStringToArray{}) + + bm.RegExecNode(&BoolIf{}) + bm.RegExecNode(&GreaterThanInteger{}) + bm.RegExecNode(&LessThanInteger{}) + bm.RegExecNode(&EqualInteger{}) + bm.RegExecNode(&RangeCompare{}) + bm.RegExecNode(&Probability{}) + bm.RegExecNode(&CreateTimer{}) +} + 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 { return err } - for _, e := range execNodes { + for _, e := range bm.execNodes { if !bm.execPool.Register(e) { return fmt.Errorf("register exec failed,exec:%s", e.GetName()) } diff --git a/util/blueprint/mathnode.go b/util/blueprint/mathnode.go index e5dce14..8b4b0d3 100644 --- a/util/blueprint/mathnode.go +++ b/util/blueprint/mathnode.go @@ -5,14 +5,6 @@ import ( "math/rand" ) -func init() { - RegExecNode(&AddInt{}) - RegExecNode(&SubInt{}) - RegExecNode(&MulInt{}) - RegExecNode(&DivInt{}) - RegExecNode(&ModInt{}) - RegExecNode(&RandNumber{}) -} // AddInt 加(int) type AddInt struct { diff --git a/util/blueprint/register.go b/util/blueprint/register.go index dc8a2a4..52737d1 100644 --- a/util/blueprint/register.go +++ b/util/blueprint/register.go @@ -1,7 +1,4 @@ package blueprint -var execNodes []IExecNode -func RegExecNode(exec IExecNode) { - execNodes = append(execNodes, exec) -} + diff --git a/util/blueprint/sysnodes.go b/util/blueprint/sysnodes.go index c5cd426..285f097 100644 --- a/util/blueprint/sysnodes.go +++ b/util/blueprint/sysnodes.go @@ -15,31 +15,7 @@ const ( EntranceID_Timer = 3 ) -func init() { - RegExecNode(&Entrance_ArrayParam{}) - RegExecNode(&Entrance_IntParam{}) - RegExecNode(&Entrance_Timer{}) - RegExecNode(&Output{}) - RegExecNode(&Sequence{}) - RegExecNode(&Foreach{}) - RegExecNode(&ForeachIntArray{}) - RegExecNode(&GetArrayInt{}) - RegExecNode(&GetArrayString{}) - RegExecNode(&GetArrayLen{}) - RegExecNode(&CreateIntArray{}) - RegExecNode(&CreateStringArray{}) - RegExecNode(&AppendIntegerToArray{}) - RegExecNode(&AppendStringToArray{}) - - RegExecNode(&BoolIf{}) - RegExecNode(&GreaterThanInteger{}) - RegExecNode(&LessThanInteger{}) - RegExecNode(&EqualInteger{}) - RegExecNode(&RangeCompare{}) - RegExecNode(&Probability{}) - RegExecNode(&CreateTimer{}) -} type Entrance_ArrayParam struct { BaseExecNode