예제 #1
0
        protected override int OnUpdate(BTWorkingData wData)
        {
            var      thisContext   = (BTCActionSequence *)wData.GetContext(_uniqueKey);
            int      runningStatus = BTRunningStatus.FINISHED;
            BTAction node          = GetChild <BTAction>(thisContext->currentSelectedIndex);

            runningStatus = node.Update(wData);
            if (_continueIfErrorOccors == false && BTRunningStatus.IsError(runningStatus))
            {
                thisContext->currentSelectedIndex = -1;
                return(runningStatus);
            }
            if (BTRunningStatus.IsFinished(runningStatus))
            {
                thisContext->currentSelectedIndex++;
                if (IsIndexValid(thisContext->currentSelectedIndex))
                {
                    runningStatus = BTRunningStatus.EXECUTING;
                }
                else
                {
                    thisContext->currentSelectedIndex = -1;
                }
            }
            return(runningStatus);
        }
예제 #2
0
        //------------------------------------------------------
        protected override bool OnEvaluate(/*in*/ BTWorkingData wData)
        {
            var thisContext = (BTCActionParallel *)wData.GetContext(_uniqueKey);

            thisContext->evaluationStatus.Init(false);
            bool finalResult = false;

            for (int i = 0; i < GetChildCount(); ++i)
            {
                BTAction node = GetChild <BTAction>(i);
                bool     ret  = node.Evaluate(wData);
                //early break
                if (_evaluationRelationship == ECHILDREN_RELATIONSHIP.AND && ret == false)
                {
                    finalResult = false;
                    break;
                }

                if (ret == true)
                {
                    finalResult = true;
                }

                thisContext->evaluationStatus[i] = ret;
            }

            return(finalResult);
        }
예제 #3
0
        protected sealed override int OnUpdate(BTWorkingData wData)
        {
            int runningState = BTRunningStatus.FINISHED;
            var thisContext  = (BTCActionLeaf *)wData.GetContext(_uniqueKey);

            if (thisContext->status == ACTION_READY)
            {
                OnEnter(wData);
                thisContext->needExit = true;
                thisContext->status   = ACTION_RUNNING;
            }

            if (thisContext->status == ACTION_RUNNING)
            {
                runningState = OnExecute(wData);
                if (BTRunningStatus.IsFinished(runningState))
                {
                    thisContext->status = ACTION_FINISHED;
                }
            }

            if (thisContext->status == ACTION_FINISHED)
            {
                if (thisContext->needExit)
                {
                    OnExit(wData, runningState);
                }

                thisContext->status   = ACTION_READY;
                thisContext->needExit = false;
            }

            return(runningState);
        }
예제 #4
0
        protected override int OnUpdate(BTWorkingData wData)
        {
            var thisContext  = (BTCActionPrioritizedSelector *)wData.GetContext(_uniqueKey);
            int runningState = BTRunningStatus.FINISHED;

            if (thisContext->currentSelectedIndex != thisContext->lastSelectedIndex)
            {
                if (IsIndexValid(thisContext->lastSelectedIndex))
                {
                    BTAction node = GetChild <BTAction>(thisContext->lastSelectedIndex);
                    node.Transition(wData);
                }

                thisContext->lastSelectedIndex = thisContext->currentSelectedIndex;
            }

            if (IsIndexValid(thisContext->lastSelectedIndex))
            {
                BTAction node = GetChild <BTAction>(thisContext->lastSelectedIndex);
                runningState = node.Update(wData);
                if (BTRunningStatus.IsFinished(runningState))
                {
                    thisContext->lastSelectedIndex = -1;
                }
            }

            return(runningState);
        }
예제 #5
0
        public BTWorkingData Clone()
        {
            var ret = new BTWorkingData();

            ret.Init(this._dataOffset, this._dataLen);
            NativeHelper.MemCpy(this._pDatas, ret._pDatas, _dataLen);
            return(ret);
        }
예제 #6
0
        protected override void OnTransition(BTWorkingData wData)
        {
            var thisContext = (BTActionLoopContext *)wData.GetContext(_uniqueKey);

            if (IsIndexValid(0))
            {
                BTAction node = GetChild <BTAction>(0);
                node.Transition(wData);
            }
            thisContext->currentCount = 0;
        }
예제 #7
0
        protected override void OnTransition(BTWorkingData wData)
        {
            var      thisContext = (BTCActionSequence *)wData.GetContext(_uniqueKey);
            BTAction node        = GetChild <BTAction>(thisContext->currentSelectedIndex);

            if (node != null)
            {
                node.Transition(wData);
            }
            thisContext->currentSelectedIndex = -1;
        }
예제 #8
0
        protected sealed override void OnTransition(BTWorkingData wData)
        {
            var thisContext = (BTCActionLeaf *)wData.GetContext(_uniqueKey);

            if (thisContext->needExit)
            {
                OnExit(wData, BTRunningStatus.TRANSITION);
            }

            thisContext->status   = ACTION_READY;
            thisContext->needExit = false;
        }
예제 #9
0
        protected override void OnTransition(BTWorkingData wData)
        {
            var thisContext = (BTCActionParallel *)wData.GetContext(_uniqueKey);

            for (int i = 0; i < GetChildCount(); ++i)
            {
                BTAction node = GetChild <BTAction>(i);
                node.Transition(wData);
            }

            //clear running status
            thisContext->StatusRunning.Init((byte)(int)BTRunningStatus.EXECUTING);
        }
예제 #10
0
        protected override bool OnEvaluate(/*in*/ BTWorkingData wData)
        {
            var thisContext = (BTCActionNonPrioritizedSelector *)wData.GetContext(_uniqueKey);

            //check last node first
            if (IsIndexValid(thisContext->currentSelectedIndex))
            {
                BTAction node = GetChild <BTAction>(thisContext->currentSelectedIndex);
                if (node.Evaluate(wData))
                {
                    return(true);
                }
            }
            return(base.OnEvaluate(wData));
        }
예제 #11
0
        //-------------------------------------------------------
        protected override bool OnEvaluate(/*in*/ BTWorkingData wData)
        {
            var  thisContext    = (BTActionLoopContext *)wData.GetContext(_uniqueKey);
            bool checkLoopCount = (_loopCount == INFINITY || thisContext->currentCount < _loopCount);

            if (checkLoopCount == false)
            {
                return(false);
            }
            if (IsIndexValid(0))
            {
                BTAction node = GetChild <BTAction>(0);
                return(node.Evaluate(wData));
            }
            return(false);
        }
예제 #12
0
        protected override int OnUpdate(BTWorkingData wData)
        {
            var thisContext = (BTCActionParallel *)wData.GetContext(_uniqueKey);
            //first time initialization

            bool hasFinished  = false;
            bool hasExecuting = false;

            for (int i = 0; i < GetChildCount(); ++i)
            {
                if (thisContext->evaluationStatus[i] == false)
                {
                    continue;
                }

                if (BTRunningStatus.IsFinished(thisContext->StatusRunning[i]))
                {
                    hasFinished = true;
                    continue;
                }

                BTAction node          = GetChild <BTAction>(i);
                int      runningStatus = node.Update(wData);
                if (BTRunningStatus.IsFinished(runningStatus))
                {
                    hasFinished = true;
                }
                else
                {
                    hasExecuting = true;
                }

                thisContext->StatusRunning[i] = (byte)runningStatus;
            }

            if (_runningStatusRelationship == ECHILDREN_RELATIONSHIP.OR && hasFinished ||
                _runningStatusRelationship == ECHILDREN_RELATIONSHIP.AND && hasExecuting == false)
            {
                thisContext->StatusRunning.Init((byte)(int)BTRunningStatus.EXECUTING);
                return(BTRunningStatus.FINISHED);
            }

            return(BTRunningStatus.EXECUTING);
        }
예제 #13
0
        protected override bool OnEvaluate(/*in*/ BTWorkingData wData)
        {
            var thisContext = (BTCActionPrioritizedSelector *)wData.GetContext(_uniqueKey);

            thisContext->currentSelectedIndex = -1;
            int childCount = GetChildCount();

            for (int i = 0; i < childCount; ++i)
            {
                BTAction node = GetChild <BTAction>(i);
                if (node.Evaluate(wData))
                {
                    thisContext->currentSelectedIndex = i;
                    return(true);
                }
            }

            return(false);
        }
예제 #14
0
        protected override int OnUpdate(BTWorkingData wData)
        {
            var thisContext   = (BTActionLoopContext *)wData.GetContext(_uniqueKey);
            int runningStatus = BTRunningStatus.FINISHED;

            if (IsIndexValid(0))
            {
                BTAction node = GetChild <BTAction>(0);
                runningStatus = node.Update(wData);
                if (BTRunningStatus.IsFinished(runningStatus))
                {
                    thisContext->currentCount++;
                    if (thisContext->currentCount < _loopCount || _loopCount == INFINITY)
                    {
                        runningStatus = BTRunningStatus.EXECUTING;
                    }
                }
            }
            return(runningStatus);
        }
예제 #15
0
        //------------------------------------------------------
        protected override bool OnEvaluate(/*in*/ BTWorkingData wData)
        {
            var thisContext      = (BTCActionSequence *)wData.GetContext(_uniqueKey);
            int checkedNodeIndex = -1;

            if (IsIndexValid(thisContext->currentSelectedIndex))
            {
                checkedNodeIndex = thisContext->currentSelectedIndex;
            }
            else
            {
                checkedNodeIndex = 0;
            }
            if (IsIndexValid(checkedNodeIndex))
            {
                BTAction node = GetChild <BTAction>(checkedNodeIndex);
                if (node.Evaluate(wData))
                {
                    thisContext->currentSelectedIndex = checkedNodeIndex;
                    return(true);
                }
            }
            return(false);
        }
예제 #16
0
 protected virtual int OnUpdate(BTWorkingData wData)
 {
     return(BTRunningStatus.FINISHED);
 }
예제 #17
0
 //--------------------------------------------------------
 // inherented by children-
 protected virtual void OnEnter(/*in*/ BTWorkingData wData)
 {
 }
예제 #18
0
 protected void *GetUserContextData(BTWorkingData wData)
 {
     return((byte *)wData.GetContext(_uniqueKey) + sizeof(BTCActionLeaf));
 }
예제 #19
0
 //-------------------------------------------------------------
 public bool Evaluate(/*in*/ BTWorkingData wData)
 {
     return((_precondition == null || _precondition.IsTrue(wData)) && OnEvaluate(wData));
 }
예제 #20
0
 protected virtual void OnExit(BTWorkingData wData, int runningStatus)
 {
 }
예제 #21
0
 public void Transition(BTWorkingData wData)
 {
     OnTransition(wData);
 }
예제 #22
0
 public int Update(BTWorkingData wData)
 {
     return(OnUpdate(wData));
 }
예제 #23
0
 //--------------------------------------------------------
 // inherented by children
 protected virtual bool OnEvaluate(/*in*/ BTWorkingData wData)
 {
     return(true);
 }
예제 #24
0
 public override bool IsTrue(/*in*/ BTWorkingData wData)
 {
     return(GetChild <BTPrecondition>(0).IsTrue(wData) &&
            GetChild <BTPrecondition>(1).IsTrue(wData));
 }
예제 #25
0
 public override bool IsTrue(/*in*/ BTWorkingData wData)
 {
     return(false);
 }
예제 #26
0
 public abstract bool IsTrue(/*in*/ BTWorkingData wData);
예제 #27
0
 protected virtual void OnTransition(BTWorkingData wData)
 {
 }