Merge pull request #30 from taoria/working-in-process

Working in process
main
taoria 3 years ago committed by GitHub
commit bec7b8540d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 13
      TNode/TNodeCore/Runtime/Components/RuntimeGraph.cs
  2. 5
      TNode/TNodeCore/Runtime/Models/NodeData.cs
  3. 4
      TNode/TNodeCore/Runtime/RuntimeCache/RuntimeCache.cs
  4. 10
      TNode/TNodeCore/Runtime/RuntimeNode.cs

@ -19,11 +19,12 @@ namespace TNodeCore.Components{
/// <summary> /// <summary>
/// Map of node id to runtime node /// Map of node id to runtime node
/// </summary> /// </summary>
[NonSerialized]
public readonly Dictionary<string, RuntimeNode> RuntimeNodes = new Dictionary<string, RuntimeNode>(); public readonly Dictionary<string, RuntimeNode> RuntimeNodes = new Dictionary<string, RuntimeNode>();
///<summary> ///<summary>
/// The graph tool the current runtime graph is using /// The graph tool the current runtime graph is using
/// </summary> /// </summary>
[NonSerialized]
private GraphTool _graphTool; private GraphTool _graphTool;
/// <summary> /// <summary>
/// Inner graph tool to help with graph operations /// Inner graph tool to help with graph operations
@ -35,6 +36,8 @@ namespace TNodeCore.Components{
/// </summary> /// </summary>
[NonSerialized] [NonSerialized]
public readonly List<RuntimeNode> TopologicalOrder = new List<RuntimeNode>(); public readonly List<RuntimeNode> TopologicalOrder = new List<RuntimeNode>();
public RuntimeGraph Parent;
/// <summary> /// <summary>
/// Entry nodes of the graph. These are the nodes that has no input. /// Entry nodes of the graph. These are the nodes that has no input.
@ -100,8 +103,7 @@ namespace TNodeCore.Components{
return; return;
} }
runtimeNode.NodeData.Process(); runtimeNode.NodeData.Process();
Parent.StartCoroutine(runtimeNode.NodeData.AfterProcess());
} }
/// <summary> /// <summary>
/// Max depth of dependency traversal,in case of some special situation. the dependency level bigger than this number will be considered as a loop. /// Max depth of dependency traversal,in case of some special situation. the dependency level bigger than this number will be considered as a loop.
@ -133,8 +135,9 @@ namespace TNodeCore.Components{
/// <param name="list">List of nodes you need to traversal to build graph tool</param> /// <param name="list">List of nodes you need to traversal to build graph tool</param>
/// <param name="graphNodes">Map stores the mapping of node data id to runtime node</param> /// <param name="graphNodes">Map stores the mapping of node data id to runtime node</param>
public GraphTool(List<RuntimeNode> list, Dictionary<string, RuntimeNode> graphNodes){ public GraphTool(List<RuntimeNode> list, Dictionary<string, RuntimeNode> graphNodes,RuntimeGraph graph){
RuntimeNodes = graphNodes; RuntimeNodes = graphNodes;
Parent = graph;
if (list == null) return; if (list == null) return;
Queue<RuntimeNode> queue = new Queue<RuntimeNode>(); Queue<RuntimeNode> queue = new Queue<RuntimeNode>();
Dictionary<string,int> inDegreeCounterForTopologicalSort = new Dictionary<string, int>(); Dictionary<string,int> inDegreeCounterForTopologicalSort = new Dictionary<string, int>();
@ -195,7 +198,7 @@ namespace TNodeCore.Components{
} }
Debug.Log("hi"); Debug.Log("hi");
var nodeList = RuntimeNodes.Values; var nodeList = RuntimeNodes.Values;
_graphTool = new GraphTool(nodeList.ToList(),RuntimeNodes); _graphTool = new GraphTool(nodeList.ToList(),RuntimeNodes,this);
var sceneNodes = RuntimeNodes.Values.Where(x => x.NodeData is SceneNodeData).Select(x => x.NodeData as SceneNodeData); var sceneNodes = RuntimeNodes.Values.Where(x => x.NodeData is SceneNodeData).Select(x => x.NodeData as SceneNodeData);
foreach (var sceneNode in sceneNodes){ foreach (var sceneNode in sceneNodes){
if (sceneNode != null) sceneNode.BlackboardData = runtimeBlackboardData; if (sceneNode != null) sceneNode.BlackboardData = runtimeBlackboardData;

@ -1,4 +1,5 @@
using System; using System;
using System.Collections;
using TNodeCore.Attribute; using TNodeCore.Attribute;
using UnityEngine; using UnityEngine;
@ -25,6 +26,10 @@ namespace TNodeCore.Models{
public virtual void Process(){ public virtual void Process(){
} }
public virtual IEnumerator AfterProcess(){
yield return null;
}
#if UNITY_EDITOR #if UNITY_EDITOR
[HideInInspector] public bool isTest; [HideInInspector] public bool isTest;

@ -121,11 +121,9 @@ namespace TNodeCore.RuntimeCache{
//Check if the type is implementing IPortTypeConversion<T1,T2> //Check if the type is implementing IPortTypeConversion<T1,T2>
if(type.BaseType is{IsGenericType: true} && type.BaseType.GetGenericTypeDefinition()==typeof(PortTypeConversion<,>)){ if(type.BaseType is{IsGenericType: true} && type.BaseType.GetGenericTypeDefinition()==typeof(PortTypeConversion<,>)){
//if it is, add it to the cache //if it is, add it to the cache
Debug.Log("find conversion");
CacheRuntimePortTypeConversion(type); CacheRuntimePortTypeConversion(type);
} }
else{ else{
Debug.Log(type);
} }
} }
@ -142,8 +140,6 @@ namespace TNodeCore.RuntimeCache{
var type1 = type.BaseType.GetGenericArguments()[0]; var type1 = type.BaseType.GetGenericArguments()[0];
var type2 = type.BaseType.GetGenericArguments()[1]; var type2 = type.BaseType.GetGenericArguments()[1];
Debug.Log(type1);
Debug.Log(type2);
var specificType = typeof(PortConverterHelper<,>).MakeGenericType(type1, type2); var specificType = typeof(PortConverterHelper<,>).MakeGenericType(type1, type2);
var instance = Activator.CreateInstance(specificType, type) as IPortConverterHelper; var instance = Activator.CreateInstance(specificType, type) as IPortConverterHelper;
if (instance == null){ if (instance == null){

@ -1,4 +1,5 @@
using System; using System;
using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Reflection; using System.Reflection;
using Codice.Client.Common.TreeGrouper; using Codice.Client.Common.TreeGrouper;
@ -29,11 +30,6 @@ namespace TNodeCore.Runtime{
_portAccessors[portName].SetValue(this.NodeData,value); _portAccessors[portName].SetValue(this.NodeData,value);
} }
} }
public object GetOutput(string portName){ public object GetOutput(string portName){
@ -42,7 +38,7 @@ namespace TNodeCore.Runtime{
private readonly Dictionary<string, IModelPropertyAccessor> _portAccessors; private readonly Dictionary<string, IModelPropertyAccessor> _portAccessors;
public Action Process;
public RuntimeNode(NodeData nodeData){ public RuntimeNode(NodeData nodeData){
NodeData = nodeData; NodeData = nodeData;
@ -51,6 +47,8 @@ namespace TNodeCore.Runtime{
var info = nodeData.GetType().GetProperties(); var info = nodeData.GetType().GetProperties();
_portAccessors = RuntimeCache.RuntimeCache.Instance.CachedPropertyAccessors[_type]; _portAccessors = RuntimeCache.RuntimeCache.Instance.CachedPropertyAccessors[_type];
} }
public List<string> GetInputNodesId(){ public List<string> GetInputNodesId(){
List<string> dependencies = new List<string>(); List<string> dependencies = new List<string>();

Loading…
Cancel
Save