public static BTProgram BuildProgram(BTLParser.Node[][] treeSets)
        {
            BTProgram program = new BTProgram();

            int n = treeSets.Length;

            program._treeSets = new BTTree[n][];
            program._codemaps = new CodeMap[n];

            for (int i = 0; i < n; ++i)
            {
                program._treeSets[i] = Build(treeSets[i], out program._codemaps[i], true);
            }

            List <BTTree> trees = new List <BTTree>();

            foreach (var set in program.treeSets)
            {
                trees.AddRange(set);
            }

            BTRuntimeBuilder.ResolveProxies(trees.ToArray());

            return(program);
        }
Example #2
0
        public void Bind(object[] objects)
        {
            _boundState = BoundState.Bound;
            hasThrownExceptionOnTick = false;
            m_boundObjects           = objects;
            if (main != null)
            {
                BTRuntimeBuilder.Bind(this, objects);

                var tasks = this.tasks;
                foreach (var t in tasks)
                {
                    if (t.boundState != BoundState.Bound)
                    {
                        _boundState = BoundState.Failed;
                        break;
                    }
                }

                Reset();
            }
            else
            {
                _boundState = BoundState.Failed;
            }
        }
Example #3
0
        public static BTProgram CreateBehaviourProgram(BTSource[] btlSources)
        {
            if (!isPandaInitialized)
            {
                InitializePanda();
                isPandaInitialized = true;
            }

            BTProgram program = null;

            BTLParser.Node[][] nodeSets = null;

            var cache = Fetch(btlSources);

            var exceptions = cache.exceptions;

            // A program is correct when it does not contain any exceptions.
            bool isCorrect = true;

            foreach (var ex in exceptions)
            {
                if (ex != null)
                {
                    isCorrect = false;
                    break;
                }
            }

            if (isCorrect)
            {
                nodeSets = GetBTLRoots(btlSources);
                program  = BTRuntimeBuilder.BuildProgram(nodeSets);
            }


            return(program);
        }