Beispiel #1
0
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public override ProcessingInfo ActivateLogic(ProcessingContext context_, NodeSlot slot_)
        {
            ProcessingInfo info = new ProcessingInfo();
            info.State = ActionNode.LogicState.Ok;

            object objCond = GetValueFromSlot((int)NodeSlotId.VarCond);

            if (objCond == null)
            {
                info.State = ActionNode.LogicState.Warning;
                info.ErrorMessage = "Please connect a variable node into the slot Condition";
                LogManager.Instance.WriteLine(LogVerbosity.Warning,
                    "{0} : Branch failed. {1}.",
                    Title, info.ErrorMessage);
            }

            if (objCond != null)
            {
                bool cond = (bool)objCond;

                if (cond == true)
                {
                    ActivateOutputLink(context_, (int)NodeSlotId.OutTrue);
                }
                else
                {
                    ActivateOutputLink(context_, (int)NodeSlotId.OutFalse);
                }
            }

            return info;
        }
Beispiel #2
0
 /// <summary>
 /// 
 /// </summary>
 /// <returns></returns>
 public override ProcessingInfo ActivateLogic(ProcessingContext context_, NodeSlot slot_)
 {
     ProcessingInfo info = new ProcessingInfo();
     info.State = ActionNode.LogicState.Ok;
     ActivateOutputLink(context_, (int)NodeSlotId.Out);
     context_.RegisterNextSequence(GetFunction(), typeof(OnEnterFunctionEvent), null);
     return info;
 }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="seq_"></param>
        /// <param name="stack_"></param>
        /// <param name="parent_"></param>
        public ProcessingContext(SequenceBase seq_, MemoryStackFrameManager stack_, ProcessingContext parent_ = null)
        {
            State = ProcessingContextState.Stop;

            m_FreeCallID++;
            CallID = m_FreeCallID;

            Parent = parent_;
            SequenceBase = seq_;
            MemoryStackFrame = stack_;
        }
Beispiel #4
0
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public override ProcessingInfo ActivateLogic(ProcessingContext context_, NodeSlot slot_)
        {
            ProcessingInfo info = new ProcessingInfo();
            info.State = ActionNode.LogicState.Ok;

            //TODO
            //Set output variable

            // the nodes executed after the node CallFunctionNode are already registered
            // we only have to delete the subsequence
            context_.RemoveLastSequence();

            return info;
        }
Beispiel #5
0
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public override ProcessingInfo ActivateLogic(ProcessingContext context_, NodeSlot slot_)
        {
            ProcessingInfo info = new ProcessingInfo();
            info.State = ActionNode.LogicState.Ok;

            //call script with input nodes
            List<ScriptSlotData> list = new List<ScriptSlotData>(m_ScriptElement.InputCount);
            foreach (NodeSlot slot in this.SlotVariableIn)
            {
                if (slot is NodeSlotVar)
                {
                    NodeSlotVar varSlot = slot as NodeSlotVar;
                    list.Add(new ScriptSlotData(varSlot.Text, varSlot.ID, GetValueFromSlot(varSlot.ID)));
                }
            }
            ScriptSlotDataCollection parameters = new ScriptSlotDataCollection(list);
            list.Clear();

            //
            foreach (NodeSlot slot in this.SlotVariableOut)
            {
                if (slot is NodeSlotVar)
                {
                    NodeSlotVar varSlot = slot as NodeSlotVar;
                    list.Add(new ScriptSlotData(varSlot.Text, varSlot.ID, GetValueFromSlot(varSlot.ID)));
                }
            }
            ScriptSlotDataCollection returnVals = new ScriptSlotDataCollection(list);
            list.Clear();

            if (m_ScriptElement.Run(parameters, returnVals) == false)
            {
                info.ErrorMessage = "Some errors in the execution of the script";
                info.State = ActionNode.LogicState.Error;
                return info;
            }

            //set output slot value
            foreach (ScriptSlotData s in returnVals.List)
            {
                SetValueInSlot(s.ID, s.Value);
            }

            ActivateOutputLink(context_, (int)NodeSlotId.Out);

            return info;
        }
Beispiel #6
0
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public override ProcessingInfo ActivateLogic(ProcessingContext context_, NodeSlot slot_)
        {
            ProcessingInfo info = new ProcessingInfo();
            info.State = ActionNode.LogicState.Ok;
            object val = GetValueFromSlot((int)NodeSlotId.Message);

            if (val == null)
            {
                info.State = ActionNode.LogicState.Warning;
                info.ErrorMessage = "Please connect a string variable node";

                LogManager.Instance.WriteLine(LogVerbosity.Warning,
                    "{0} : No message display because no variable node connected. {1}.",
                    Title, info.ErrorMessage);
            }
            else
            {
                LogManager.Instance.WriteLine(LogVerbosity.Info, val.ToString());
            }

            ActivateOutputLink(context_, (int)NodeSlotId.Out);

            return info;
        }
Beispiel #7
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="context_"></param>
 /// <param name="step_"></param>
 public void RemoveExecution(ProcessingContext context_, ProcessingContextStep step_)
 {
     context_.m_NextExecutions.Remove(step_);
 }
Beispiel #8
0
 /// <summary>
 ///
 /// </summary>
 /// <returns></returns>
 public ProcessingContext PushNewContext()
 {
     Child = new ProcessingContext(SequenceBase, MemoryStackFrame, this);
     return(Child);
 }
Beispiel #9
0
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public override ProcessingInfo ActivateLogic(ProcessingContext context_, NodeSlot slot_)
        {
            ProcessingInfo info = new ProcessingInfo();
            info.State = ActionNode.LogicState.Ok;

            MemoryStackItem memoryItem = context_.CurrentFrame.GetValueFromID(Id);

            if (memoryItem == null)
            {
                object a = GetValueFromSlot((int)NodeSlotId.VarInStartClosed);
                bool state = a != null ? (bool)a : true;
                memoryItem = context_.CurrentFrame.Allocate(Id, state);
            }

            bool val = (bool)memoryItem.Value;

            if (slot_.ID == (int)NodeSlotId.InEnter)
            {
                if (val == true)
                {
                    ActivateOutputLink(context_, (int)NodeSlotId.Out);
                }
            }
            else if (slot_.ID == (int)NodeSlotId.InOpen)
            {
                memoryItem.Value = true;
            }
            else if (slot_.ID == (int)NodeSlotId.InClose)
            {
                memoryItem.Value = false;
            }
            else if (slot_.ID == (int)NodeSlotId.InToggle)
            {
                memoryItem.Value = !val;
            }

            return info;
        }
Beispiel #10
0
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public override ProcessingInfo ActivateLogic(ProcessingContext context_, NodeSlot slot_)
        {
            ProcessingInfo info = new ProcessingInfo();
            info.State = ActionNode.LogicState.Ok;

            if (slot_.ID == (int)NodeSlotId.In)
            {
                int firstIndex = 0, lastIndex = -1;

                #region first index

                object objFirstIndex = GetValueFromSlot((int)NodeSlotId.VarInFirstIndex);

                if (objFirstIndex == null)
                {
                    info.State = ActionNode.LogicState.Warning;
                    info.ErrorMessage = "Please connect a variable node into the slot First Index";
                    LogManager.Instance.WriteLine(LogVerbosity.Warning,
                        "{0} : For Loop failed. {1}.",
                        Title, info.ErrorMessage);
                    return info;
                }

                if (objFirstIndex != null)
                {
                    firstIndex = (int)objFirstIndex;
                }

                #endregion // first index

                #region last index

                object objLastIndex = GetValueFromSlot((int)NodeSlotId.VarInLastIndex);

                if (objLastIndex == null)
                {
                    info.State = ActionNode.LogicState.Warning;
                    info.ErrorMessage = "Please connect a variable node into the slot Last Index";
                    LogManager.Instance.WriteLine(LogVerbosity.Warning,
                        "{0} : For Loop failed. {1}.",
                        Title, info.ErrorMessage);
                    return info;
                }

                if (objLastIndex != null)
                {
                    lastIndex = (int)objLastIndex;
                }

                #endregion last index

                MemoryStackItem memoryItem = context_.CurrentFrame.GetValueFromID(Id);

                if (memoryItem == null)
                {
                    memoryItem = context_.CurrentFrame.Allocate(Id, new ForLoopNodeInfo { Counter = firstIndex, IsWaitingLoopBody = false });
                }

                ForLoopNodeInfo memoryInfo = (ForLoopNodeInfo)memoryItem.Value;

                if (memoryInfo.IsWaitingLoopBody == false)
                {
                    SetValueInSlot((int)NodeSlotId.VarOutIndex, memoryInfo.Counter);

                    if (memoryInfo.Counter <= lastIndex)
                    {
                        memoryInfo.IsWaitingLoopBody = true;
                        memoryInfo.Counter++;
                        // register again this node in order to active itself
                        // after the sequence activated by the loop body slot
                        // is finished
                        memoryInfo.Step = context_.RegisterNextExecution(GetSlotById((int)NodeSlotId.In));
                        memoryItem.Value = memoryInfo;

                        ProcessingContext newContext = context_.PushNewContext();
                        newContext.Finished += new EventHandler(OnLoopBodyFinished);
                        ActivateOutputLink(newContext, (int)NodeSlotId.OutLoop);
                    }
                    else
                    {
                        context_.CurrentFrame.Deallocate(Id);
                        ActivateOutputLink(context_, (int)NodeSlotId.OutCompleted);
                    }
                }
            }
            else if (slot_.ID == (int)NodeSlotId.InBreak)
            {
                MemoryStackItem memoryItem = context_.CurrentFrame.GetValueFromID(Id);
                ForLoopNodeInfo memoryInfo = (ForLoopNodeInfo)memoryItem.Value;
                context_.RemoveExecution(context_, memoryInfo.Step);
                context_.CurrentFrame.Deallocate(Id);
                ActivateOutputLink(context_, (int)NodeSlotId.OutCompleted);
            }

            return info;
        }
Beispiel #11
0
        /// <summary>
        /// Used to activate the nodes in the next step, see Sequence.Run()
        /// </summary>
        /// <param name="context_"></param>
        public void RegisterNodes(ProcessingContext context_)
        {
            foreach (NodeSlot slot in ConnectedNodes)
            {
                if (slot.Node is ActionNode)
                {
                    context_.RegisterNextExecution(slot);
                }
            }

            if (Activated != null)
            {
                Activated.Invoke(this, EventArgs.Empty);
            }
        }
Beispiel #12
0
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public override ProcessingInfo ActivateLogic(ProcessingContext context_, NodeSlot slot_)
        {
            ProcessingInfo info = new ProcessingInfo();
            info.State = ActionNode.LogicState.Ok;

            MemoryStackItem memoryItem = context_.CurrentFrame.GetValueFromID(Id);

            if (memoryItem == null)
            {
                memoryItem = context_.CurrentFrame.Allocate(Id, true);
            }

            if (slot_.ID == (int)NodeSlotId.InEnter)
            {
                bool val = (bool)memoryItem.Value;
                memoryItem.Value = !((bool)memoryItem.Value);

                SetValueInSlot((int)NodeSlotId.VarOutIsA, val);

                if (val == true)
                {
                    ActivateOutputLink(context_, (int)NodeSlotId.OutA);
                }
                else
                {
                    ActivateOutputLink(context_, (int)NodeSlotId.OutB);
                }
            }

            return info;
        }
Beispiel #13
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="context"></param>
 /// <param name="slot"></param>
 /// <returns></returns>
 public ProcessingInfo Activate(ProcessingContext context, NodeSlot slot)
 {
     State = ActivateLogic(context, slot);
     return State;
 }
Beispiel #14
0
 /// <summary>
 /// 
 /// </summary>
 /// <returns></returns>
 public ProcessingContext PushNewContext()
 {
     Child = new ProcessingContext(SequenceBase, MemoryStackFrame, this);
     return Child;
 }
Beispiel #15
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="seq_"></param>
        /// <param name="eventType_"></param>
        /// <param name="index_"></param>
        /// <param name="param_"></param>
        public void LaunchSequence(SequenceBase seq_, Type eventType_, int index_, object param_)
        {
            MemoryStackFrameManager stackFrames = new MemoryStackFrameManager();
            //stackFrames.Clear();
            stackFrames.AddStackFrame(); // 1st frame
            seq_.AllocateAllVariables(stackFrames.CurrentFrame);
            ProcessingContext processContext = new ProcessingContext(seq_, stackFrames);
            seq_.OnEvent(processContext, eventType_, index_, param_);
            m_CallStacks.Add(processContext);

            Resume();
        }
Beispiel #16
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="context_"></param>
 /// <param name="id_"></param>
 public void ActivateOutputLink(ProcessingContext context_, int id_)
 {
     GetSlotById(id_).RegisterNodes(context_);
 }
Beispiel #17
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="context_"></param>
 /// <param name="step_"></param>
 public void RemoveExecution(ProcessingContext context_, ProcessingContextStep step_)
 {
     context_.m_NextExecutions.Remove(step_);
 }
Beispiel #18
0
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public override ProcessingInfo ActivateLogic(ProcessingContext context_, NodeSlot slot_)
        {
            ProcessingInfo info = new ProcessingInfo();
            info.State = ActionNode.LogicState.Ok;

            if (slot_.ID == (int)NodeSlotId.InReset)
            {
                m_Counter = 0;
                m_IsInitial = false;
            }
            else if (slot_.ID == (int)NodeSlotId.InEnter)
            {
                MemoryStackItem memoryItem = context_.CurrentFrame.GetValueFromID(Id);

                if (m_IsInitial == false)
                {
                    object objN = GetValueFromSlot((int)NodeSlotId.VarInN);

                    if (objN == null)
                    {
                        info.State = ActionNode.LogicState.Warning;
                        info.ErrorMessage = "Please connect a variable node into the slot N";
                        LogManager.Instance.WriteLine(LogVerbosity.Warning,
                            "{0} : DoN failed. {1}.",
                            Title, info.ErrorMessage);
                    }

                    if (objN != null)
                    {
                        int n = (int)objN;

                        if (memoryItem == null)
                        {
                            memoryItem = context_.CurrentFrame.Allocate(Id, n);
                        }

                        memoryItem.Value = n;
                    }

                    m_IsInitial = true;
                }

                if (m_Counter < (int)memoryItem.Value)
                {
                    m_Counter++;
                    ActivateOutputLink(context_, (int)NodeSlotId.Out);
                }
            }

            return info;
        }
Beispiel #19
0
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public override ProcessingInfo ActivateLogic(ProcessingContext context_, NodeSlot slot_)
        {
            ProcessingInfo info = new ProcessingInfo();
            info.State = ActionNode.LogicState.Ok;

            MemoryStackItem memoryItem = context_.CurrentFrame.GetValueFromID(Id);

            if (memoryItem == null)
            {
                memoryItem = context_.CurrentFrame.Allocate(Id, false);
            }

            if (slot_.ID == (int)NodeSlotId.InReset)
            {
                memoryItem.Value = false;
            }
            else if (slot_.ID == (int)NodeSlotId.InEnter)
            {
                if ((bool)memoryItem.Value == false)
                {
                    memoryItem.Value = true;
                    ActivateOutputLink(context_, (int)NodeSlotId.Out);
                }
            }

            return info;
        }
Beispiel #20
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="context_"></param>
 /// <param name="index_"></param>
 public void Triggered(ProcessingContext context_, int index_, object param_)
 {
     TriggeredImpl(param_);
     ActivateOutputLink(context_, index_);
 }
Beispiel #21
0
 /// <summary>
 /// Methods call when the node is activated.
 /// The other node connected to the input connector has activated his output link.
 /// </summary>
 /// <param name="context_"></param>
 /// <param name="slot_"></param>
 /// <returns></returns>
 public abstract ProcessingInfo ActivateLogic(ProcessingContext context_, NodeSlot slot_);