Example #1
0
 public void Awake()
 {
     this.RunningTasks            = new EQueue <ActorTask>();
     this.WaitingTasks            = new EQueue <ActorTask>();
     this.WindowSize              = 1;
     this.CancellationTokenSource = new CancellationTokenSource();
 }
Example #2
0
        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;
        }
Example #3
0
        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);
        }
Example #4
0
 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);
 }
Example #6
0
        public string DebugQueue(EQueue <ActorTask> tasks)
        {
            string s = "";

            foreach (ActorTask task in tasks)
            {
                s += $" {task.message.GetType().Name}";
            }
            return(s);
        }
Example #7
0
        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);
        }
Example #8
0
        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();
            }
        }
Example #10
0
        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);
        }
Example #11
0
        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);
        }
Example #12
0
        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());
        }