Exemple #1
0
        public void Start(BehaviourTree tree, BTAgent agent)
        {
            /*m_instances.Add(new BTInstance
             * {
             *  Tree = tree,
             *  Agent = agent,
             *  ExecutionContext = new WaitCallback(tree.Tick)
             * });*/
            int slotsPerChunk = 30;

            if (m_currentChunk == null || m_currentChunk.m_freeSlots <= 0)
            {
                m_currentChunk = new ThreadChunk
                {
                    Instances   = new BTInstance[slotsPerChunk],
                    m_freeSlots = slotsPerChunk
                };

                m_chunks.Add(m_currentChunk);
            }

            int index = slotsPerChunk - m_currentChunk.m_freeSlots;

            m_currentChunk.Instances[index] = new BTInstance
            {
                Tree  = tree,
                Agent = agent
            };
            m_currentChunk.m_freeSlots--;
        }
Exemple #2
0
        private void TickTree(object chunkObject)
        {
            ThreadChunk chunk = (ThreadChunk)chunkObject;

            chunk.IsRunning = true;
            for (int i = 0; i < chunk.Instances.Length; i++)
            {
                if (chunk.Instances[i] != null)
                {
                    chunk.Instances[i].Tree.Tick();
                }
            }

            chunk.IsRunning = false;
        }
Exemple #3
0
        public void Tick()
        {
            for (int i = 0; i < m_chunks.Count; i++)
            {
                ThreadChunk chunk = m_chunks[i];
                if (!chunk.IsRunning)
                {
                    ThreadPool.QueueUserWorkItem(TickTree, chunk);
                }
            }

            /*for(int i = 0; i < m_instances.Count; i++)
             * {
             *  BTInstance instance = m_instances[i];
             *  instance.Tree.Tick();
             *  /*if (instance.Tree.IsRunning == false)
             *  {
             *      ThreadPool.QueueUserWorkItem(instance.ExecutionContext);
             *  }*/
            //}
        }