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