public void Awake() { this.RunningTasks = new EQueue <ActorTask>(); this.WaitingTasks = new EQueue <ActorTask>(); this.WindowSize = 1; this.CancellationTokenSource = new CancellationTokenSource(); }
public BTEditorTree(BehaviorTreeConfig config) { Type rootType = typeof(Game).Assembly.GetType($"Model.{config.RootNodeProto.Name}"); Node root = (Node)Activator.CreateInstance(rootType, config.RootNodeProto); root.Id = BTEditor.NodeIdStartIndex; EQueue <NodeProto> protoStack = new EQueue <NodeProto>(); EQueue <Node> nodeStack = new EQueue <Node>(); protoStack.Enqueue(config.RootNodeProto); nodeStack.Enqueue(root); while (protoStack.Count > 0) { NodeProto p = protoStack.Dequeue(); Node node = nodeStack.Dequeue(); foreach (KeyValuePair <string, object> argsItem in p.Args.Dict()) { FieldInfo fieldInfo = node.GetType().GetField(argsItem.Key, BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public); fieldInfo.SetValue(node, argsItem.Value); } foreach (NodeProto child in p.Children) { Type t = typeof(Game).Assembly.GetType($"Model.{child.Name}"); Node childNode = (Node)Activator.CreateInstance(t, child); AddChild(childNode, node); protoStack.Enqueue(child); nodeStack.Enqueue(childNode); } } this.BTConfig = config; _root = root; }
public static void Serialize(this Node root, BehaviorTreeConfig config) { config.Clear(); BehaviorNodeConfig rootNp = config.AddRootNode(root.GetType().Name); EQueue <Node> queue = new EQueue <Node>(); EQueue <BehaviorNodeConfig> npQue = new EQueue <BehaviorNodeConfig>(); rootNp.describe = root.Description; queue.Enqueue(root); npQue.Enqueue(rootNp); while (queue.Count > 0) { Node cur = queue.Dequeue(); BehaviorNodeConfig np = npQue.Dequeue(); foreach (Node child in cur.GetChildren) { BehaviorNodeConfig childNp = GetNodeConfigFromNode(child); queue.Enqueue(child); npQue.Enqueue(childNp); config.AddChild(np, childNp); } } // PrintNode(root); // PrintConfigNode(config.RootNodeConfig); }
public void Awake() { this.LastSendTime = TimeHelper.Now(); this.RunningTasks = new EQueue <ActorTask>(); this.WaitingTasks = new EQueue <ActorTask>(); this.WindowSize = 1; this.CancellationTokenSource = new CancellationTokenSource(); }
public void AddTask(long key, LocationTask task) { if (!this.taskQueues.TryGetValue(key, out EQueue <LocationTask> tasks)) { tasks = new EQueue <LocationTask>(); this.taskQueues[key] = tasks; } task.Scene = this.GetEntity <Scene>(); tasks.Enqueue(task); }
public string DebugQueue(EQueue <ActorTask> tasks) { string s = ""; foreach (ActorTask task in tasks) { s += $" {task.message.GetType().Name}"; } return(s); }
public void Recycle(Disposer obj) { Type type = obj.GetType(); EQueue <Disposer> queue; if (!this.dictionary.TryGetValue(type, out queue)) { queue = new EQueue <Disposer>(); } queue.Enqueue(obj); }
private void OnEvents() { lock (lockObject) { localQueue = concurrentQueue; concurrentQueue = new EQueue <Action>(); } while (this.localQueue.Count > 0) { Action a = this.localQueue.Dequeue(); a(); } }
public void Update() { lock (lockObject) { localQueue = queue; queue = new EQueue <Action>(); } while (this.localQueue.Count > 0) { Action a = this.localQueue.Dequeue(); a(); } }
public static T GetChildInType <T>(this Node root) where T : Node { EQueue <Node> nodeStack = new EQueue <Node>(); nodeStack.Enqueue(root); while (nodeStack.Count > 0) { Node c = nodeStack.Dequeue(); foreach (Node child in c.GetChildren) { if (child.GetType() == typeof(T)) { return(child as T); } nodeStack.Enqueue(child); } } return(null); }
public Disposer Fetch(Type type) { EQueue <Disposer> queue; if (!this.dictionary.TryGetValue(type, out queue)) { queue = new EQueue <Disposer>(); this.dictionary.Add(type, queue); } Disposer obj; if (queue.Count > 0) { obj = queue.Dequeue(); obj.Id = IdGenerater.GenerateId(); return(obj); } obj = (Disposer)Activator.CreateInstance(type); return(obj); }
public static T[] GetChildrenInType <T>(this Node root) where T : Node { EQueue <Node> nodeStack = new EQueue <Node>(); List <T> list = new List <T>(); nodeStack.Enqueue(root); while (nodeStack.Count > 0) { Node c = nodeStack.Dequeue(); foreach (Node child in c.GetChildren) { if (child.GetType() == typeof(T)) { list.Add(child as T); } nodeStack.Enqueue(child); } } return(list.ToArray()); }