mirror of
https://github.com/duanhf2012/origin.git
synced 2026-05-18 06:57:29 +08:00
蓝图优化
This commit is contained in:
@@ -167,6 +167,7 @@ func (em *innerExecNode) CloneInOutPort() ([]IPort, []IPort) {
|
|||||||
for _, port := range em.inPort {
|
for _, port := range em.inPort {
|
||||||
if port == nil {
|
if port == nil {
|
||||||
inPorts = append(inPorts, nil)
|
inPorts = append(inPorts, nil)
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if port.IsPortExec() {
|
if port.IsPortExec() {
|
||||||
@@ -182,6 +183,7 @@ func (em *innerExecNode) CloneInOutPort() ([]IPort, []IPort) {
|
|||||||
for _, port := range em.outPort {
|
for _, port := range em.outPort {
|
||||||
if port == nil {
|
if port == nil {
|
||||||
outPorts = append(outPorts, nil)
|
outPorts = append(outPorts, nil)
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if port.IsPortExec() {
|
if port.IsPortExec() {
|
||||||
@@ -396,7 +398,7 @@ func (en *BaseExecNode) GetOutPortArrayValStr(index int, idx int) (Port_Str, boo
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (en *BaseExecNode) GetOutPortBool(index int) (Port_Bool, bool) {
|
func (en *BaseExecNode) GetOutPortBool(index int) (Port_Bool, bool) {
|
||||||
port := en.GetInPort(index)
|
port := en.GetOutPort(index)
|
||||||
if port == nil {
|
if port == nil {
|
||||||
return false, false
|
return false, false
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,6 +47,24 @@ type graphContext struct {
|
|||||||
globalVariables map[string]IPort // 全局变量,g_Return,为执行返回值
|
globalVariables map[string]IPort // 全局变量,g_Return,为执行返回值
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func clonePortMap(source map[string]IPort) map[string]IPort {
|
||||||
|
if source == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
target := make(map[string]IPort, len(source))
|
||||||
|
for key, port := range source {
|
||||||
|
if port == nil {
|
||||||
|
target[key] = nil
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
target[key] = port.Clone()
|
||||||
|
}
|
||||||
|
|
||||||
|
return target
|
||||||
|
}
|
||||||
|
|
||||||
type nodeConfig struct {
|
type nodeConfig struct {
|
||||||
Id string `json:"id"`
|
Id string `json:"id"`
|
||||||
Class string `json:"class"`
|
Class string `json:"class"`
|
||||||
@@ -153,7 +171,7 @@ func (gr *Graph) GetAndCreateReturnPort() IPort {
|
|||||||
return p
|
return p
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gr *Graph) Do(entranceID int64, args ...any) (Port_Array, error) {
|
func (gr *Graph) Do(entranceID int64, args ...any) (ret Port_Array, err error) {
|
||||||
if IsDebug {
|
if IsDebug {
|
||||||
log.Debug("Graph Do", log.String("graphName", gr.graphFileName), log.Int64("graphID", gr.graphID), log.Int64("entranceID", entranceID))
|
log.Debug("Graph Do", log.String("graphName", gr.graphFileName), log.Int64("graphID", gr.graphID), log.Int64("entranceID", entranceID))
|
||||||
}
|
}
|
||||||
@@ -166,13 +184,29 @@ func (gr *Graph) Do(entranceID int64, args ...any) (Port_Array, error) {
|
|||||||
gr.variables = map[string]IPort{}
|
gr.variables = map[string]IPort{}
|
||||||
gr.context = map[string]*ExecContext{}
|
gr.context = map[string]*ExecContext{}
|
||||||
|
|
||||||
|
prevGlobalVariables := clonePortMap(gr.globalVariables)
|
||||||
|
gr.globalVariables = clonePortMap(gr.globalVariables)
|
||||||
if gr.globalVariables == nil {
|
if gr.globalVariables == nil {
|
||||||
gr.globalVariables = map[string]IPort{}
|
gr.globalVariables = map[string]IPort{}
|
||||||
} else {
|
|
||||||
gr.globalVariables[ReturnVarial] = nil
|
|
||||||
}
|
}
|
||||||
|
gr.globalVariables[ReturnVarial] = nil
|
||||||
|
|
||||||
err := entranceNode.Do(gr, args...)
|
defer func() {
|
||||||
|
if r := recover(); r != nil {
|
||||||
|
gr.globalVariables = prevGlobalVariables
|
||||||
|
ret = nil
|
||||||
|
err = fmt.Errorf("blueprint graph %s entrance %d panic: %v", gr.graphFileName, entranceID, r)
|
||||||
|
log.StackError(
|
||||||
|
"blueprint execute panic",
|
||||||
|
log.String("graphName", gr.graphFileName),
|
||||||
|
log.Int64("graphID", gr.graphID),
|
||||||
|
log.Int64("entranceID", entranceID),
|
||||||
|
log.Any("panic", r),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
err = entranceNode.Do(gr, args...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -232,5 +266,6 @@ func (gr *Graph) GetGraphFileName() string {
|
|||||||
|
|
||||||
func (gr *Graph) Clone() IGraph {
|
func (gr *Graph) Clone() IGraph {
|
||||||
cloneGr := *gr
|
cloneGr := *gr
|
||||||
|
cloneGr.globalVariables = clonePortMap(gr.globalVariables)
|
||||||
return &cloneGr
|
return &cloneGr
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user