mirror of
https://github.com/duanhf2012/origin.git
synced 2026-02-04 06:54:45 +08:00
将port index改为id,提高兼容性
This commit is contained in:
@@ -5,18 +5,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestExecMgr(t *testing.T) {
|
func TestExecMgr(t *testing.T) {
|
||||||
var bp Blueprint
|
|
||||||
err := bp.Init("D:\\Develop\\OriginNodeEditor\\json", "D:\\Develop\\OriginNodeEditor\\vgf", nil)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("init failed,err:%v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
graphTest1 := bp.Create("testArrayOperator", 0)
|
|
||||||
err = graphTest1.Do(EntranceID_IntParam, 20, 1, 3)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("Do EntranceID_IntParam failed,err:%v", err)
|
|
||||||
}
|
|
||||||
graphTest1.Release()
|
|
||||||
//graphTest2 := bp.Create("testForeach")
|
//graphTest2 := bp.Create("testForeach")
|
||||||
//err = graphTest2.Do(EntranceID_IntParam, 1, 2, 3)
|
//err = graphTest2.Do(EntranceID_IntParam, 1, 2, 3)
|
||||||
//if err != nil {
|
//if err != nil {
|
||||||
|
|||||||
@@ -22,9 +22,6 @@ type IInnerExecNode interface {
|
|||||||
|
|
||||||
GetInPort(index int) IPort
|
GetInPort(index int) IPort
|
||||||
GetOutPort(index int) IPort
|
GetOutPort(index int) IPort
|
||||||
|
|
||||||
GetInPortParamStartIndex() int
|
|
||||||
GetOutPortParamStartIndex() int
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type IExecNode interface {
|
type IExecNode interface {
|
||||||
@@ -46,9 +43,6 @@ type innerExecNode struct {
|
|||||||
inPort []IPort
|
inPort []IPort
|
||||||
outPort []IPort
|
outPort []IPort
|
||||||
|
|
||||||
inPortParamStartIndex int // 输入参数的起始索引,用于排除执行入口
|
|
||||||
outPortParamStartIndex int // 输出参数的起始索引,用于排除执行出口
|
|
||||||
|
|
||||||
IExecNode
|
IExecNode
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -67,51 +61,100 @@ type InputConfig struct {
|
|||||||
DataType string `json:"data_type"`
|
DataType string `json:"data_type"`
|
||||||
HasInput bool `json:"has_input"`
|
HasInput bool `json:"has_input"`
|
||||||
PinWidget string `json:"pin_widget"`
|
PinWidget string `json:"pin_widget"`
|
||||||
|
PortId int `json:"port_id"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type OutInputConfig struct {
|
type OutputConfig struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
PortType string `json:"type"`
|
PortType string `json:"type"`
|
||||||
DataType string `json:"data_type"`
|
DataType string `json:"data_type"`
|
||||||
HasInput bool `json:"has_input"`
|
HasInput bool `json:"has_input"`
|
||||||
|
PortId int `json:"port_id"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type BaseExecConfig struct {
|
type BaseExecConfig struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Title string `json:"title"`
|
Title string `json:"title"`
|
||||||
Package string `json:"package"`
|
Package string `json:"package"`
|
||||||
Description string `json:"description"`
|
Description string `json:"description"`
|
||||||
IsPure bool `json:"is_pure"`
|
IsPure bool `json:"is_pure"`
|
||||||
Inputs []InputConfig `json:"inputs"`
|
Inputs []InputConfig `json:"inputs"`
|
||||||
Outputs []OutInputConfig `json:"outputs"`
|
Outputs []OutputConfig `json:"outputs"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (em *innerExecNode) AppendInPort(port ...IPort) {
|
func (bc *BaseExecConfig) GetMaxInPortId() int {
|
||||||
if len(em.inPort) == 0 {
|
maxPortId := -1
|
||||||
em.inPortParamStartIndex = -1
|
for i := range bc.Inputs {
|
||||||
}
|
if bc.Inputs[i].PortId > maxPortId {
|
||||||
|
maxPortId = bc.Inputs[i].PortId
|
||||||
for i := 0; i < len(port); i++ {
|
|
||||||
if !port[i].IsPortExec() && em.inPortParamStartIndex < 0 {
|
|
||||||
em.inPortParamStartIndex = len(em.inPort)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
em.inPort = append(em.inPort, port[i])
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return maxPortId
|
||||||
}
|
}
|
||||||
|
|
||||||
func (em *innerExecNode) AppendOutPort(port ...IPort) {
|
func (bc *BaseExecConfig) GetMaxOutPortId() int {
|
||||||
if len(em.outPort) == 0 {
|
maxPortId := -1
|
||||||
em.outPortParamStartIndex = -1
|
for i := range bc.Outputs {
|
||||||
}
|
if bc.Outputs[i].PortId > maxPortId {
|
||||||
for i := 0; i < len(port); i++ {
|
maxPortId = bc.Outputs[i].PortId
|
||||||
if !port[i].IsPortExec() && em.outPortParamStartIndex < 0 {
|
|
||||||
em.outPortParamStartIndex = len(em.outPort)
|
|
||||||
}
|
}
|
||||||
em.outPort = append(em.outPort, port[i])
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return maxPortId
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//func (em *innerExecNode) AppendInPort(port ...IPort) {
|
||||||
|
// if len(em.inPort) == 0 {
|
||||||
|
// em.inPortParamStartIndex = -1
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// for i := 0; i < len(port); i++ {
|
||||||
|
// if !port[i].IsPortExec() && em.inPortParamStartIndex < 0 {
|
||||||
|
// em.inPortParamStartIndex = len(em.inPort)
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// em.inPort = append(em.inPort, port[i])
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
|
||||||
|
func (em *innerExecNode) PrepareMaxInPortId(maxInPortId int) {
|
||||||
|
em.inPort = make([]IPort, 0, maxInPortId+1)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (em *innerExecNode) PrepareMaxOutPortId(maxOutPortId int) {
|
||||||
|
em.outPort = make([]IPort, 0, maxOutPortId+1)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (em *innerExecNode) SetInPortById(id int, port IPort) bool {
|
||||||
|
if id < 0 || id >= len(em.inPort) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
em.inPort[id] = port
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
func (em *innerExecNode) SetOutPortById(id int, port IPort) bool {
|
||||||
|
if id < 0 || id >= len(em.outPort) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
em.outPort[id] = port
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
//func (em *innerExecNode) AppendOutPort(port ...IPort) {
|
||||||
|
// if len(em.outPort) == 0 {
|
||||||
|
// em.outPortParamStartIndex = -1
|
||||||
|
// }
|
||||||
|
// for i := 0; i < len(port); i++ {
|
||||||
|
// if !port[i].IsPortExec() && em.outPortParamStartIndex < 0 {
|
||||||
|
// em.outPortParamStartIndex = len(em.outPort)
|
||||||
|
// }
|
||||||
|
// em.outPort = append(em.outPort, port[i])
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
|
||||||
func (em *innerExecNode) GetName() string {
|
func (em *innerExecNode) GetName() string {
|
||||||
return em.Name
|
return em.Name
|
||||||
}
|
}
|
||||||
@@ -182,14 +225,6 @@ func (em *innerExecNode) GetOutPort(index int) IPort {
|
|||||||
return em.outPort[index]
|
return em.outPort[index]
|
||||||
}
|
}
|
||||||
|
|
||||||
func (em *innerExecNode) GetInPortParamStartIndex() int {
|
|
||||||
return em.inPortParamStartIndex
|
|
||||||
}
|
|
||||||
|
|
||||||
func (em *innerExecNode) GetOutPortParamStartIndex() int {
|
|
||||||
return em.outPortParamStartIndex
|
|
||||||
}
|
|
||||||
|
|
||||||
func (en *BaseExecNode) GetBluePrintModule() IBlueprintModule {
|
func (en *BaseExecNode) GetBluePrintModule() IBlueprintModule {
|
||||||
return en.gr.IBlueprintModule
|
return en.gr.IBlueprintModule
|
||||||
}
|
}
|
||||||
@@ -530,8 +565,7 @@ func (en *BaseExecNode) setVariableName(name string) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (en *BaseExecNode) GetBlueprintModule() IBlueprintModule {
|
||||||
func (en *BaseExecNode) GetBlueprintModule() IBlueprintModule{
|
|
||||||
if en.gr == nil {
|
if en.gr == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -125,6 +125,8 @@ func (em *ExecPool) createExecFromJSON(baseExecConfig BaseExecConfig) (IInnerExe
|
|||||||
baseExec.Title = baseExecConfig.Title
|
baseExec.Title = baseExecConfig.Title
|
||||||
baseExec.Package = baseExecConfig.Package
|
baseExec.Package = baseExecConfig.Package
|
||||||
baseExec.Description = baseExecConfig.Description
|
baseExec.Description = baseExecConfig.Description
|
||||||
|
baseExec.PrepareMaxInPortId(baseExecConfig.GetMaxInPortId())
|
||||||
|
baseExec.PrepareMaxOutPortId(baseExecConfig.GetMaxOutPortId())
|
||||||
|
|
||||||
// exec数量
|
// exec数量
|
||||||
inExecNum := 0
|
inExecNum := 0
|
||||||
@@ -143,7 +145,8 @@ func (em *ExecPool) createExecFromJSON(baseExecConfig BaseExecConfig) (IInnerExe
|
|||||||
}
|
}
|
||||||
|
|
||||||
inExecNum++
|
inExecNum++
|
||||||
baseExec.AppendInPort(NewPortExec())
|
baseExec.SetInPortById(input.PortId, NewPortExec())
|
||||||
|
// baseExec.AppendInPort(NewPortExec())
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -152,7 +155,7 @@ func (em *ExecPool) createExecFromJSON(baseExecConfig BaseExecConfig) (IInnerExe
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
baseExec.AppendInPort(port)
|
baseExec.SetInPortById(input.PortId, port)
|
||||||
}
|
}
|
||||||
|
|
||||||
hasData := false
|
hasData := false
|
||||||
@@ -168,16 +171,17 @@ func (em *ExecPool) createExecFromJSON(baseExecConfig BaseExecConfig) (IInnerExe
|
|||||||
}
|
}
|
||||||
|
|
||||||
if portType == Config_PortType_Exec {
|
if portType == Config_PortType_Exec {
|
||||||
baseExec.AppendOutPort(NewPortExec())
|
baseExec.SetOutPortById(output.PortId, NewPortExec())
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
hasData = true
|
hasData = true
|
||||||
port, err := em.createPortByDataType(baseExec.Name, output.Name, output.DataType)
|
port, err := em.createPortByDataType(baseExec.Name, output.Name, output.DataType)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
baseExec.AppendOutPort(port)
|
baseExec.SetOutPortById(output.PortId, port)
|
||||||
}
|
}
|
||||||
return &baseExec, nil
|
return &baseExec, nil
|
||||||
}
|
}
|
||||||
@@ -201,7 +205,7 @@ func (em *ExecPool) Register(exec IExecNode) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, ok := em.execNodeMap[innerNode.GetName()]; ok {
|
if _, ok = em.execNodeMap[innerNode.GetName()]; ok {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -275,12 +279,13 @@ func (em *ExecPool) loadSysExec() error {
|
|||||||
func (em *ExecPool) regGetVariables(typ string) error {
|
func (em *ExecPool) regGetVariables(typ string) error {
|
||||||
var baseExec innerExecNode
|
var baseExec innerExecNode
|
||||||
baseExec.Name = genGetVariablesNodeName(typ)
|
baseExec.Name = genGetVariablesNodeName(typ)
|
||||||
|
baseExec.PrepareMaxOutPortId(0)
|
||||||
|
|
||||||
outPort := NewPortByType(typ)
|
outPort := NewPortByType(typ)
|
||||||
if outPort == nil {
|
if outPort == nil {
|
||||||
return fmt.Errorf("invalid type %s", typ)
|
return fmt.Errorf("invalid type %s", typ)
|
||||||
}
|
}
|
||||||
baseExec.AppendOutPort(outPort)
|
baseExec.SetOutPortById(0, outPort)
|
||||||
|
|
||||||
var getVariablesNode GetVariablesNode
|
var getVariablesNode GetVariablesNode
|
||||||
getVariablesNode.nodeName = baseExec.GetName()
|
getVariablesNode.nodeName = baseExec.GetName()
|
||||||
@@ -311,9 +316,14 @@ func (em *ExecPool) regSetVariables(typ string) error {
|
|||||||
inPort := NewPortByType(typ)
|
inPort := NewPortByType(typ)
|
||||||
outExecPort := NewPortByType(Config_PortType_Exec)
|
outExecPort := NewPortByType(Config_PortType_Exec)
|
||||||
outPort := NewPortByType(typ)
|
outPort := NewPortByType(typ)
|
||||||
|
baseExec.PrepareMaxInPortId(1)
|
||||||
|
baseExec.PrepareMaxOutPortId(1)
|
||||||
|
|
||||||
baseExec.AppendInPort(inExecPort, inPort)
|
baseExec.SetInPortById(0, inExecPort)
|
||||||
baseExec.AppendOutPort(outExecPort, outPort)
|
baseExec.SetInPortById(1, inPort)
|
||||||
|
|
||||||
|
baseExec.SetOutPortById(0, outExecPort)
|
||||||
|
baseExec.SetOutPortById(1, outPort)
|
||||||
|
|
||||||
baseExec.IExecNode = &SetVariablesNode{nodeName: baseExec.GetName()}
|
baseExec.IExecNode = &SetVariablesNode{nodeName: baseExec.GetName()}
|
||||||
if !em.loadBaseExec(&baseExec) {
|
if !em.loadBaseExec(&baseExec) {
|
||||||
|
|||||||
@@ -2,21 +2,23 @@ package blueprint
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/goccy/go-json"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/duanhf2012/origin/v2/service"
|
"github.com/duanhf2012/origin/v2/service"
|
||||||
|
"github.com/goccy/go-json"
|
||||||
)
|
)
|
||||||
|
|
||||||
const ReturnVarial = "g_Return"
|
const ReturnVarial = "g_Return"
|
||||||
|
|
||||||
type IGraph interface {
|
type IGraph interface {
|
||||||
Do(entranceID int64, args ...any) (Port_Array,error)
|
Do(entranceID int64, args ...any) (Port_Array, error)
|
||||||
Release()
|
Release()
|
||||||
}
|
}
|
||||||
|
|
||||||
type IBlueprintModule interface {
|
type IBlueprintModule interface {
|
||||||
SafeAfterFunc(timerId *uint64, d time.Duration, AdditionData interface{}, cb func(uint64, interface{}))
|
SafeAfterFunc(timerId *uint64, d time.Duration, AdditionData interface{}, cb func(uint64, interface{}))
|
||||||
TriggerEvent(graphID int64, eventID int64, args ...any) error
|
TriggerEvent(graphID int64, eventID int64, args ...any) error
|
||||||
CancelTimerId(graphID int64,timerId *uint64) bool
|
CancelTimerId(graphID int64, timerId *uint64) bool
|
||||||
GetGameService() service.IService
|
GetGameService() service.IService
|
||||||
GetBattleService() service.IService
|
GetBattleService() service.IService
|
||||||
}
|
}
|
||||||
@@ -52,8 +54,8 @@ type edgeConfig struct {
|
|||||||
SourceNodeID string `json:"source_node_id"`
|
SourceNodeID string `json:"source_node_id"`
|
||||||
DesNodeId string `json:"des_node_id"`
|
DesNodeId string `json:"des_node_id"`
|
||||||
|
|
||||||
SourcePortIndex int `json:"source_port_index"`
|
SourcePortId int `json:"source_port_id"`
|
||||||
DesPortIndex int `json:"des_port_index"`
|
DesPortId int `json:"des_port_id"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type MultiTypeValue struct {
|
type MultiTypeValue struct {
|
||||||
@@ -134,10 +136,10 @@ func (gc *graphConfig) GetNodeByID(nodeID string) *nodeConfig {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gr *Graph) Do(entranceID int64, args ...any) (Port_Array,error) {
|
func (gr *Graph) Do(entranceID int64, args ...any) (Port_Array, error) {
|
||||||
entranceNode := gr.entrance[entranceID]
|
entranceNode := gr.entrance[entranceID]
|
||||||
if entranceNode == nil {
|
if entranceNode == nil {
|
||||||
return nil,fmt.Errorf("entranceID:%d not found", entranceID)
|
return nil, fmt.Errorf("entranceID:%d not found", entranceID)
|
||||||
}
|
}
|
||||||
|
|
||||||
gr.variables = map[string]IPort{}
|
gr.variables = map[string]IPort{}
|
||||||
@@ -150,17 +152,17 @@ func (gr *Graph) Do(entranceID int64, args ...any) (Port_Array,error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if gr.globalVariables!= nil {
|
if gr.globalVariables != nil {
|
||||||
port := gr.globalVariables[ReturnVarial]
|
port := gr.globalVariables[ReturnVarial]
|
||||||
if port != nil {
|
if port != nil {
|
||||||
array,ok := port.GetArray()
|
array, ok := port.GetArray()
|
||||||
if ok{
|
if ok {
|
||||||
return array,nil
|
return array, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil,nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gr *Graph) GetNodeInPortValue(nodeID string, inPortIndex int) IPort {
|
func (gr *Graph) GetNodeInPortValue(nodeID string, inPortIndex int) IPort {
|
||||||
|
|||||||
@@ -2,10 +2,11 @@ package blueprint
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/goccy/go-json"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/goccy/go-json"
|
||||||
)
|
)
|
||||||
|
|
||||||
type GraphPool struct {
|
type GraphPool struct {
|
||||||
@@ -206,7 +207,7 @@ func (gp *GraphPool) prepareOneNode(mapNodeExec map[string]*execNode, nodeExec *
|
|||||||
func (gp *GraphPool) findOutNextNode(graphConfig *graphConfig, mapNodeExec map[string]*execNode, sourceNodeID string, sourcePortIdx int) *execNode {
|
func (gp *GraphPool) findOutNextNode(graphConfig *graphConfig, mapNodeExec map[string]*execNode, sourceNodeID string, sourcePortIdx int) *execNode {
|
||||||
// 找到出口的NodeID
|
// 找到出口的NodeID
|
||||||
for _, edge := range graphConfig.Edges {
|
for _, edge := range graphConfig.Edges {
|
||||||
if edge.SourceNodeID == sourceNodeID && edge.SourcePortIndex == sourcePortIdx {
|
if edge.SourceNodeID == sourceNodeID && edge.SourcePortId == sourcePortIdx {
|
||||||
return mapNodeExec[edge.DesNodeId]
|
return mapNodeExec[edge.DesNodeId]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -254,7 +255,7 @@ func (gp *GraphPool) prepareOneEntrance(graphName string, entranceID int64, node
|
|||||||
|
|
||||||
func (gp *GraphPool) findPreInPortNode(mapNodes map[string]*execNode, nodeExec *execNode, graphConfig *graphConfig, portIdx int) *prePortNode {
|
func (gp *GraphPool) findPreInPortNode(mapNodes map[string]*execNode, nodeExec *execNode, graphConfig *graphConfig, portIdx int) *prePortNode {
|
||||||
for _, edge := range graphConfig.Edges {
|
for _, edge := range graphConfig.Edges {
|
||||||
if edge.DesNodeId == nodeExec.Id && edge.DesPortIndex == portIdx {
|
if edge.DesNodeId == nodeExec.Id && edge.DesPortId == portIdx {
|
||||||
srcNode := mapNodes[edge.SourceNodeID]
|
srcNode := mapNodes[edge.SourceNodeID]
|
||||||
if srcNode == nil {
|
if srcNode == nil {
|
||||||
return nil
|
return nil
|
||||||
@@ -262,7 +263,7 @@ func (gp *GraphPool) findPreInPortNode(mapNodes map[string]*execNode, nodeExec *
|
|||||||
|
|
||||||
var preNode prePortNode
|
var preNode prePortNode
|
||||||
preNode.node = srcNode
|
preNode.node = srcNode
|
||||||
preNode.outPortIndex = edge.SourcePortIndex
|
preNode.outPortIndex = edge.SourcePortId
|
||||||
|
|
||||||
return &preNode
|
return &preNode
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user