Ejemplo n.º 1
0
        private static void processReturn(string msg)
        {
            try
            {
                // [return]CleaningRobot::RobotController#Controller CleanRooms.xml
                string[] tokens = msg.Substring(8).Split(' ');

                if (tokens.Length == 2)
                {
                    string[] types = tokens[0].Split(new char[] { '#' }, StringSplitOptions.RemoveEmptyEntries);
                    Debug.Check(types.Length == 2);
                    string agentType     = types[0];
                    string agentName     = types[1];
                    string agentFullname = tokens[0];

                    //AgentInstancePool.AddInstance(agentType, agentName, true);

                    string returnFromTree = tokens[1].Trim(new char[] { '\n' });

                    FrameStatePool.SetReturnInfo(agentFullname, returnFromTree);
                }
            }
            catch
            {
            }
        }
Ejemplo n.º 2
0
        private static void processTick(string msg)
        {
            // [tick]Ship::Ship_1 ships\basic.xml->BehaviorTree[0]:enter [all/success/failure] [1]
            // [tick]Ship::Ship_1 ships\basic.xml->BehaviorTree[0]:update [1]

            string[] tokens = msg.Substring(6).Split(' ');

            if (tokens.Length == 4)
            {
                string[] types = tokens[0].Split(new char[] { '#' }, StringSplitOptions.RemoveEmptyEntries);
                Debug.Check(types.Length == 2);
                string agentType     = types[0];
                string agentName     = types[1];
                string agentFullname = tokens[0];

                AgentInstancePool.AddInstance(agentType, agentName, true);

                string[] nodes = tokens[1].Split(new string[] { "->" }, StringSplitOptions.RemoveEmptyEntries);

                if (nodes.Length == 2)
                {
                    string behaviorFilename = nodes[0];

                    checkBehaviorFiles(behaviorFilename);
                    FrameStatePool.SetJumpInfo(agentFullname, behaviorFilename, true);

                    string[] actions = nodes[1].Split(new char[] { '[', ']' }, StringSplitOptions.RemoveEmptyEntries);

                    if (actions.Length == 3)
                    {
                        string[] actionResults = tokens[2].Split(new char[] { '[', ']' }, StringSplitOptions.RemoveEmptyEntries);
                        string[] hitCounts     = tokens[3].Split(new char[] { '[', ']' }, StringSplitOptions.RemoveEmptyEntries);
                        int      hitCount      = int.Parse(hitCounts[0]);
                        string   nodeId        = actions[1];

                        if (actions[2] == ":enter")
                        {
                            FrameStatePool.EnterNode(agentFullname, AgentDataPool.TotalFrames, behaviorFilename, nodeId, actionResults[0], hitCount);
                        }
                        else if (actions[2] == ":exit")
                        {
                            FrameStatePool.ExitNode(agentFullname, AgentDataPool.TotalFrames, behaviorFilename, nodeId, actionResults[0], hitCount);
                        }
                        else if (actions[2] == ":update")
                        {
                            List <string> highlightNodeIds = FrameStatePool.GetHighlightNodeIds(agentFullname, AgentDataPool.TotalFrames, behaviorFilename);

                            if (highlightNodeIds != null && !highlightNodeIds.Contains(nodeId))
                            {
                                FrameStatePool.EnterNode(agentFullname, AgentDataPool.TotalFrames, behaviorFilename, nodeId, actionResults[0], hitCount);
                            }
                        }
                        else if (actions[2] == ":transition")
                        {
                            FrameStatePool.UpdateTransition(agentFullname, AgentDataPool.TotalFrames, behaviorFilename, nodeId, actionResults[0]);
                        }
                    }
                }
            }
        }
Ejemplo n.º 3
0
        private static void processJump(string msg)
        {
            try
            {
                // [jump]CleaningRobot::RobotController#Controller CleanRooms.xml

                string[] tokens = msg.Substring(6).Split(' ');

                if (tokens.Length == 2)
                {
                    string[] types = tokens[0].Split(new char[] { '#' }, StringSplitOptions.RemoveEmptyEntries);
                    Debug.Check(types.Length == 2);
                    string agentType     = types[0];
                    string agentName     = types[1];
                    string agentFullname = tokens[0];

                    //AgentInstancePool.AddInstance(agentType, agentName, true);
                    string jumpTree = tokens[1].Trim(new char[] { '\n' });

                    checkBehaviorFiles(jumpTree);
                    FrameStatePool.SetJumpInfo(agentFullname, jumpTree, false);
                }
            }
            catch
            {
            }
        }
Ejemplo n.º 4
0
        private void InspectObject(AgentType agentType, string agentName, string agentFullname)
        {
            Nodes.Node node = null;
            if (agentType == null && !string.IsNullOrEmpty(agentFullname))
            {
                int           frame            = AgentDataPool.CurrentFrame > -1 ? AgentDataPool.CurrentFrame : 0;
                string        behaviorFilename = FrameStatePool.GetBehaviorFilename(agentFullname, frame);
                List <string> highlightNodeIds = FrameStatePool.GetHighlightNodeIds(agentFullname, frame, behaviorFilename);
                List <string> updatedNodeIds   = FrameStatePool.GetUpdatedNodeIds(agentFullname, frame, behaviorFilename);
                Dictionary <string, FrameStatePool.NodeProfileInfos.ProfileInfo> profileInfos = FrameStatePool.GetProfileInfos(frame, behaviorFilename);

                BehaviorNode behavior = UIUtilities.ShowBehaviorTree(agentFullname, frame, highlightNodeIds, updatedNodeIds, HighlightBreakPoint.Instance, profileInfos);
                node = behavior as Nodes.Node;
            }

            _agentType = agentType;
            _agentName = agentName;

            Hide();

            setText(agentType, agentName);
            parametersPanel.InspectObject(agentType, agentFullname, node);

            if (AgentDataPool.CurrentFrame > -1 && !string.IsNullOrEmpty(agentName))
            {
                List <AgentDataPool.ValueMark> valueSet = AgentDataPool.GetValidValues(node, agentType, agentFullname, AgentDataPool.CurrentFrame);
                foreach (AgentDataPool.ValueMark value in valueSet)
                {
                    SetProperty(agentType != null ? agentType.ToString() : null, agentName, value.Name, value.Value);
                }
            }

            lostAnyFocus();
            Show();
        }
Ejemplo n.º 5
0
        private void InspectObject(AgentType agentType, string agentName, string agentFullName, FrameStatePool.PlanningState nodeState)
        {
            Nodes.Node node = null;

            if (!string.IsNullOrEmpty(agentFullName))
            {
                int           frame            = AgentDataPool.CurrentFrame > -1 ? AgentDataPool.CurrentFrame : 0;
                string        behaviorFilename = FrameStatePool.GetBehaviorFilename(agentFullName, frame);
                List <string> transitionIds    = FrameStatePool.GetHighlightTransitionIds(agentFullName, frame, behaviorFilename);
                List <string> highlightNodeIds = FrameStatePool.GetHighlightNodeIds(agentFullName, frame, behaviorFilename);
                List <string> updatedNodeIds   = FrameStatePool.GetUpdatedNodeIds(agentFullName, frame, behaviorFilename);
                Dictionary <string, FrameStatePool.NodeProfileInfos.ProfileInfo> profileInfos = FrameStatePool.GetProfileInfos(frame, behaviorFilename);

                BehaviorNode behavior = UIUtilities.ShowBehaviorTree(agentFullName, frame, transitionIds, highlightNodeIds, updatedNodeIds, HighlightBreakPoint.Instance, profileInfos);
                node = behavior as Nodes.Node;
            }

            _agentType = agentType;
            _agentName = agentName;

            Hide();

            setText(agentType, agentName);

            if (nodeState != null)
            {
                foreach (string agentFullName1 in nodeState._agents.Keys)
                {
                    string[] tokens = agentFullName1.Split('#');
                    Debug.Check(tokens.Length == 2);
                    string at = tokens[0];
                    string an = tokens[1];

                    AgentType agentType1 = Plugin.GetAgentType(at);

                    ParametersDock dock = findParametersDock(agentType1, an);
                    dock.InspectObject(agentType1, agentFullName1);

                    dock.setProperty(nodeState, agentFullName1);
                }
            }
            else if (AgentDataPool.CurrentFrame > -1 && !string.IsNullOrEmpty(agentName))
            {
                ParametersDock dock = findParametersDock(agentType, agentName);
                dock.InspectObject(agentType, agentFullName);

                List <AgentDataPool.ValueMark> valueSet = AgentDataPool.GetValidValues(agentType, agentFullName, AgentDataPool.CurrentFrame);

                foreach (AgentDataPool.ValueMark value in valueSet)
                {
                    dock.setProperty(null, value.Name, value.Value);
                }
            }

            lostAnyFocus();
            Show();
        }
Ejemplo n.º 6
0
        public static void ShowPlanning(string agentFullName, int frame, int index)
        {
            FrameStatePool.PlanningProcess planning = FrameStatePool.GetPlanning(agentFullName, frame, index);

            if (planning != null)
            {
                showPlanning(planning);
            }
        }
Ejemplo n.º 7
0
        private static void processProperty(string msg)
        {
            // Par:   [property]a->10
            // World: [property]WorldTest::World WorldTest::Property3->10
            // Agent: [property]AgentTest::AgentTest_1 AgentTest::Property5::type::name->10

            string[] tokens = msg.Substring(10).Split(' ');
            Debug.Check(tokens.Length > 0);

            string agentType     = string.Empty;
            string agentName     = string.Empty;
            string agentFullname = string.Empty;

            // Par
            if (tokens.Length == 1)
            {
                agentType     = string.Empty;
                agentFullname = tokens[0];
            }

            // Global or Agent
            else
            {
                string[] types = tokens[0].Split(new char[] { '#' }, StringSplitOptions.RemoveEmptyEntries);
                Debug.Check(types.Length == 2);
                agentType     = types[0];
                agentName     = types[1];
                agentFullname = tokens[0];

                AgentInstancePool.AddInstance(agentType, agentName);
            }

            Debug.Check(!string.IsNullOrEmpty(agentFullname));

            string[] values = tokens[tokens.Length - 1].Split(new string[] { "->", "\n" }, StringSplitOptions.RemoveEmptyEntries);

            if (values.Length == 2)
            {
                string basicValueName = values[0];
                int    index          = basicValueName.LastIndexOf(":");
                basicValueName = basicValueName.Substring(index + 1);

                if (_ms_planning)
                {
                    FrameStatePool.PlanProperty(agentFullname, basicValueName, values[1]);
                }
                else
                {
                    if (AgentDataPool.TotalFrames > -1 && !string.IsNullOrEmpty(agentFullname))
                    {
                        AgentDataPool.AddValue(agentFullname, basicValueName, AgentDataPool.TotalFrames, values[1]);
                    }
                }
            }
        }
Ejemplo n.º 8
0
        private static void processBreaked(string msg)
        {
            string msg_real = msg.Substring(9);

            if (msg_real.StartsWith("[applog]"))
            {
                FrameStatePool.RespondToCPPBreak(AgentDataPool.TotalFrames, msg_real);
            }
            else
            {
                //[breaked]Ship::Ship_1 ships\basic.xml->BehaviorTree[0]:enter [all/success/failure] [1]
                string[] tokens = msg_real.Split(' ');

                if (tokens.Length == 4)
                {
                    string agentFullname = tokens[0];
                    //if (string.IsNullOrEmpty(Plugin.DebugAgentInstance))
                    {
                        Plugin.DebugAgentInstance = agentFullname;
                    }

                    string[] nodes = tokens[1].Split(new string[] { "->" }, StringSplitOptions.RemoveEmptyEntries);

                    if (nodes.Length == 2)
                    {
                        string[] actions = nodes[1].Split(new char[] { '[', ']' }, StringSplitOptions.RemoveEmptyEntries);

                        if (actions.Length == 3)
                        {
                            Debug.Check(actions[2].StartsWith(":"));
                            string   actionName    = actions[2].Substring(1);
                            string[] actionResults = tokens[2].Split(new char[] { '[', ']' }, StringSplitOptions.RemoveEmptyEntries);

                            //although actionResult can be EAR_none or EAR_all, but, as this is the real result of an action
                            //it can only be success or failure
                            Debug.Check(actionResults.Length == 1 && (actionResults[0] == "success" || actionResults[0] == "failure") || actionResults[0] == "all");

                            string[] hitCounts = tokens[3].Split(new char[] { '[', ']' }, StringSplitOptions.RemoveEmptyEntries);
                            int      hitCount  = int.Parse(hitCounts[0]);

                            if (actionName == "plan")
                            {
                                NodeTreeList.ShowPlanning(agentFullname, AgentDataPool.TotalFrames, hitCount);
                            }

                            FrameStatePool.RespondToAPPBreak(agentFullname, AgentDataPool.TotalFrames, nodes[0], actions[1], actionName, actionResults[0], hitCount);
                        }
                    }
                }
            }

            Plugin.UpdateMode = UpdateModes.Break;
        }
Ejemplo n.º 9
0
        private static void updateUI(int frame)
        {
            if (_timelineDock != null)
            {
                if (MessageQueue.IsConnected)
                {
                    HighlightBreakPoint breakPoint = HighlightBreakPoint.Instance;
                    string agentName = Plugin.DebugAgentInstance;

                    if (breakPoint != null || agentName == Plugin.DebugAgentInstance)
                    {
                        List <string> transitionIds    = null;
                        List <string> highlightNodeIds = null;
                        List <string> updatedNodeIds   = null;
                        Dictionary <string, FrameStatePool.NodeProfileInfos.ProfileInfo> profileInfos = null;

                        if (!string.IsNullOrEmpty(agentName))
                        {
                            string behaviorFilename = FrameStatePool.GetBehaviorFilename(agentName, frame);

                            if (!string.IsNullOrEmpty(behaviorFilename))
                            {
                                transitionIds    = FrameStatePool.GetHighlightTransitionIds(agentName, frame, behaviorFilename);
                                highlightNodeIds = FrameStatePool.GetHighlightNodeIds(agentName, frame, behaviorFilename);
                                updatedNodeIds   = FrameStatePool.GetUpdatedNodeIds(agentName, frame, behaviorFilename);
                                profileInfos     = FrameStatePool.GetProfileInfos(frame, behaviorFilename);
                            }
                        }

                        _timelineDock.updateHighlights(agentName, frame, transitionIds, highlightNodeIds, updatedNodeIds, breakPoint, profileInfos);

                        if (breakPoint != null)
                        {
                            string prompt = string.Format("Break: {0}->{1}[{2}]:{3}", breakPoint.BehaviorFilename, breakPoint.NodeType, breakPoint.NodeId, breakPoint.ActionName);

                            if (breakPoint.ActionResult == "success" || breakPoint.ActionResult == "failure")
                            {
                                prompt += string.Format(" [{0}]", breakPoint.ActionResult);
                            }

                            if (_timelineDock != null)
                            {
                                _timelineDock.setUpdateMode(UpdateModes.Break, prompt);
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 10
0
        private static void updateUI(int frame)
        {
            if (_timelineDock != null)
            {
                //when breaking cpp, only check breakpoints after [connected], i.e. skip breakpoints before connecting
                if (!Settings.Default.BreakAPP || MessageQueue.IsConnected)
                {
                    HighlightBreakPoint breakPoint = HighlightBreakPoint.Instance;
                    string agentName = Plugin.DebugAgentInstance;

                    if (breakPoint != null || agentName == Plugin.DebugAgentInstance)
                    {
                        List <string> highlightNodeIds = null;
                        List <string> updatedNodeIds   = null;
                        Dictionary <string, FrameStatePool.NodeProfileInfos.ProfileInfo> profileInfos = null;

                        if (!string.IsNullOrEmpty(agentName))
                        {
                            string behaviorFilename = FrameStatePool.GetBehaviorFilename(agentName, frame);
                            if (!string.IsNullOrEmpty(behaviorFilename))
                            {
                                highlightNodeIds = FrameStatePool.GetHighlightNodeIds(agentName, frame, behaviorFilename);
                                updatedNodeIds   = FrameStatePool.GetUpdatedNodeIds(agentName, frame, behaviorFilename);
                                profileInfos     = FrameStatePool.GetProfileInfos(frame, behaviorFilename);
                            }
                        }

                        _timelineDock.updateHighlights(agentName, frame, highlightNodeIds, updatedNodeIds, breakPoint, profileInfos);

                        if (breakPoint != null)
                        {
                            string prompt = string.Format("Break: {0}->{1}[{2}]:{3}", breakPoint.BehaviorFilename, breakPoint.NodeType, breakPoint.NodeId, breakPoint.ActionName);
                            if (breakPoint.ActionResult == "success" || breakPoint.ActionResult == "failure")
                            {
                                prompt += string.Format(" [{0}]", breakPoint.ActionResult);
                            }

                            _timelineDock.setUpdateMode(UpdateModes.Break, prompt);
                        }
                    }
                }
            }
        }
Ejemplo n.º 11
0
        private void updateParameters(AgentType agentType, string agentName, int frame)
        {
            if (string.IsNullOrEmpty(agentName))
            {
                return;
            }

            string       typeName         = (agentType == null) ? agentName : agentType.ToString();
            string       agentFullname    = (agentType == null) ? agentName : agentType.ToString() + "#" + agentName;
            string       behaviorFilename = FrameStatePool.GetBehaviorFilename(agentFullname, frame);
            BehaviorNode behavior         = null;

            if (agentFullname == Plugin.DebugAgentInstance)
            {
                behavior = UIUtilities.ShowBehavior(behaviorFilename);
            }

            List <AgentDataPool.ValueMark> values = AgentDataPool.GetValidValues(agentType, agentFullname, frame);

            foreach (AgentDataPool.ValueMark value in values)
            {
                ParametersDock.SetProperty(behavior, typeName, agentName, value.Name, value.Value);
            }
        }
Ejemplo n.º 12
0
        private static UpdateModes processMessage(string _msg)
        {
            try {
                //skip index
                //string msg = _msg.Substring(10);
                int    pos = _msg.IndexOf("][");
                string msg = _msg.Substring(pos + 1);

                //Console.WriteLine(msg.Trim());
                if (msg.StartsWith("[workspace]"))
                {
                    processWorkspace(msg);

                    TimelineDock.Continue();
                }
                else if (msg.StartsWith("[connected]"))
                {
                    processConnected();
                }
                else if (msg.StartsWith("[frame]"))
                {
                    // [frame]0
                    AgentDataPool.TotalFrames = (int.Parse(msg.Substring(7)));
                }
                else if (msg.StartsWith("[property]"))
                {
                    processProperty(msg);
                }
                else if (msg.StartsWith("[tick]"))
                {
                    processTick(msg);
                }
                else if (msg.StartsWith("[jump]"))
                {
                    processJump(msg);
                }
                else if (msg.StartsWith("[return]"))
                {
                    processReturn(msg);
                }
                else if (msg.StartsWith("[plan_"))
                {
                    string m = msg.Trim();

                    //Console.WriteLine(m);

                    processPlanning(m);
                }
                else if (msg.StartsWith("[breaked]"))
                {
                    processBreaked(msg);
                }
                else if (msg.StartsWith("[continue]"))
                {
                    if (MessageQueue.ContinueHandler != null)
                    {
                        MessageQueue.ContinueHandler(msg);
                    }
                }
                else if (msg.StartsWith("[applog]"))
                {
                    int frame = AgentDataPool.TotalFrames;
                    FrameStatePool.AddAppLog(frame, msg);
                }
                else if (msg.StartsWith("[log]"))
                {
                    int frame = AgentDataPool.TotalFrames;
                    FrameStatePool.AddLog(frame, msg);
                }
                else if (msg.StartsWith("[profiler]"))
                {
                    //[profiler]ships\0_basic.xml->BehaviorTree[-1] 685
                    string[] tokens = msg.Substring(10).Split(new char[] { ' ', '\n' }, StringSplitOptions.RemoveEmptyEntries);

                    if (tokens.Length == 2)
                    {
                        string[] nodes = tokens[0].Split(new string[] { "->" }, StringSplitOptions.RemoveEmptyEntries);

                        if (nodes.Length == 2)
                        {
                            string behaviorFilename = nodes[0];

                            string[] ids = nodes[1].Split(new char[] { '[', ']' }, StringSplitOptions.RemoveEmptyEntries);

                            if (ids.Length == 2)
                            {
                                FrameStatePool.SetProfileInfo(AgentDataPool.TotalFrames, behaviorFilename, ids[1], 0.001f * int.Parse(tokens[1]));
                            }
                        }
                    }
                }
            } catch {
                string errorInfo = string.Format("The message \"{0}\" was not processed.", _msg);
                Console.WriteLine(errorInfo);
                MessageBox.Show(errorInfo, "Error", MessageBoxButtons.OK);
            }

            return(Plugin.UpdateMode);
        }
Ejemplo n.º 13
0
        private static void processPlanning(string msg)
        {
            string[] tokens = null;

            if (MessageHandler.StartsWith(msg, "[plan_begin]", ref tokens))
            {
                //[plan_begin]CleaningRobot::RobotController#Controller CleanRooms.xml->Task[0]
                if (tokens.Length == 3)
                {
                    FrameStatePool.PlanBegin(tokens[0], tokens[1], tokens[2]);
                    _ms_planning = true;
                }
            }
            else if (FrameStatePool.PlanningProcess._planning != null)
            {
                if (MessageHandler.StartsWith(msg, "[plan_end]", ref tokens))
                {
                    //[plan_end]CleaningRobot::RobotController#Controller CleanRooms.xml->Task[0]
                    if (tokens.Length == 2)
                    {
                        FrameStatePool.PlanEnd(tokens[0], tokens[1]);
                        _ms_planning = false;
                    }
                }
                else if (MessageHandler.StartsWith(msg, "[plan_method_begin]", ref tokens))
                {
                    //[plan_method_begin]CleanRooms.xml->Method[13]
                    if (tokens.Length == 1)
                    {
                        FrameStatePool.PlanningMethodBegin(tokens[0]);
                    }
                }
                else if (MessageHandler.StartsWith(msg, "[plan_method_end]", ref tokens))
                {
                    //[plan_method_end]CleanRooms.xml->Method[13] success
                    if (tokens.Length == 2)
                    {
                        FrameStatePool.PlanningMethodEnd(tokens[0], tokens[1]);
                    }
                }
                else if (MessageHandler.StartsWith(msg, "[plan_node_begin]", ref tokens))
                {
                    //[plan_node_begin]CleanRooms.xml->Method[8]
                    if (tokens.Length == 1)
                    {
                        FrameStatePool.PlanningNodeBegin(tokens[0]);
                    }
                }
                else if (MessageHandler.StartsWith(msg, "[plan_node_pre_failed]", ref tokens))
                {
                    //[plan_node_pre_failed]CleanRooms.xml->Method[1]
                    if (tokens.Length == 1)
                    {
                        FrameStatePool.PlanningNodePreFailed(tokens[0]);
                    }
                }
                else if (MessageHandler.StartsWith(msg, "[plan_node_end]", ref tokens))
                {
                    //[plan_node_end]CleanRooms.xml->Method[1] failure
                    if (tokens.Length == 2)
                    {
                        FrameStatePool.PlanningNodeEnd(tokens[0], tokens[1]);
                    }
                }
                else if (MessageHandler.StartsWith(msg, "[plan_referencetree_enter]", ref tokens))
                {
                    //[plan_referencetree_enter]CleanRooms.xml->ReferencedBehavior[10] MoveToRoom.xml
                    if (tokens.Length == 2)
                    {
                        string fullId           = tokens[0];
                        string behaviorFilename = tokens[1];

                        FrameStatePool.PlanningReferencedEnter(fullId, behaviorFilename);
                    }
                }
                else if (MessageHandler.StartsWith(msg, "[plan_referencetree_exit]", ref tokens))
                {
                    //[plan_referencetree_exit]CleanRooms.xml->ReferencedBehavior[10] MoveToRoom.xml
                    if (tokens.Length == 2)
                    {
                        string fullId           = tokens[0];
                        string behaviorFilename = tokens[1];

                        FrameStatePool.PlanningReferencedExit(fullId, behaviorFilename);
                    }
                }
                else if (MessageHandler.StartsWith(msg, "[plan_foreach_begin]", ref tokens))
                {
                    //[plan_foreach_begin]MoveToRoom.xml->DecoratorIterator[5] 0 2
                    if (tokens.Length == 3)
                    {
                        string indexStr = tokens[1];
                        string countStr = tokens[2];

                        FrameStatePool.PlanningForEachBegin(tokens[0], indexStr, countStr);
                    }
                }
                else if (MessageHandler.StartsWith(msg, "[plan_foreach_end]", ref tokens))
                {
                    //[plan_foreach_end]MoveToRoom.xml->DecoratorIterator[5] 0 2 success
                    if (tokens.Length == 4)
                    {
                        string indexStr = tokens[1];
                        string countStr = tokens[2];
                        string result   = tokens[3];

                        FrameStatePool.PlanningForEachEnd(tokens[0], indexStr, countStr, result);
                    }
                }
                else
                {
                    Debug.Check(false);
                }
            }
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Show the behavior tree view with highlights.
        /// </summary>
        /// <param name="agentFullname">The fullname of an agent instance, as the format of "agnetType::instanceName".</param>
        /// <param name="frame">The current frame when connecting or playing.</param>
        public static BehaviorNode ShowBehaviorTree(string agentFullname, int frame, List <string> highlightedTransitionIds, List <string> highlightNodeIds, List <string> updatedNodeIds, HighlightBreakPoint highlightBreakPoint, Dictionary <string, FrameStatePool.NodeProfileInfos.ProfileInfo> profileInfos)
        {
            string behaviorFilename = (highlightBreakPoint != null) ? highlightBreakPoint.BehaviorFilename : FrameStatePool.GetBehaviorFilename(agentFullname, frame);

            if (!string.IsNullOrEmpty(behaviorFilename))
            {
                BehaviorTreeView behaviorTreeView = ShowBehaviorTree(behaviorFilename);

                if (behaviorTreeView != null)
                {
                    if (!Settings.Default.ShowProfilingInfo)
                    {
                        profileInfos = null;
                    }

                    behaviorTreeView.SetHighlights(highlightedTransitionIds, highlightNodeIds, updatedNodeIds, highlightBreakPoint, profileInfos);
                    //behaviorTreeView.Focus();

                    return(behaviorTreeView.RootNode);
                }
            }

            return(null);
        }
Ejemplo n.º 15
0
        private static UpdateModes processMessage(string msg)
        {
            if (msg.StartsWith("[workspace]"))
            {
                if (!ms_workspace_handled && Plugin.WorkspaceDelegateHandler != null)
                {
                    string str_   = msg.Substring(11);
                    string format = "";

                    //skip the space
                    int pos = 1;
                    for (; pos < str_.Length; ++pos)
                    {
                        format += str_[pos];
                        if (str_[pos] == ' ')
                        {
                            break;
                        }
                    }

                    ms_fileFormat = format.Trim();

                    Debug.Check(ms_fileFormat == "xml" || ms_fileFormat == "bson");

                    //skip the space
                    string str = str_.Substring(pos + 1);
                    if (!string.IsNullOrEmpty(str))
                    {
                        string wksName = string.Empty;
                        if (str[0] == '\"')
                        {
                            for (int i = 1; i < str.Length; ++i)
                            {
                                if (str[i] == '\"')
                                {
                                    wksName = str.Substring(1, i - 1);
                                    break;
                                }
                            }
                        }
                        else
                        {
                            string[] tokens = str.Split(' ');
                            wksName = tokens[0].Trim(new char[] { ' ', '\"' });
                        }

                        if (!string.IsNullOrEmpty(wksName))
                        {
                            wksName = Path.GetFullPath(wksName);

                            //Plugin_WorkspaceDelegateHandler might be blocked
                            ms_workspace_handled = true;
                            Plugin.WorkspaceDelegateHandler(wksName, false, true);
                            ms_workspace_handled = false;
                        }

                        //
                        AgentDataPool.TotalFrames = 0;
                    }
                }
            }
            else if (msg.StartsWith("[connected]"))
            {
                MessageQueue.IsConnected = true;

                //sending breakpoints after receving those precaches messages
                NetworkManager.Instance.SendLoadedBreakpoints();
                NetworkManager.Instance.SendProfiling(Settings.Default.ShowProfilingInfo);

                //BreakAPP can only be sent to cpp after all the breakpoints info have been sent
                //sending BreakAPP to cpp to enable the debugging
                NetworkManager.Instance.SendBreakAPP(Settings.Default.BreakAPP);
                NetworkManager.Instance.SendText("[start]\n");
            }
            else if (msg.StartsWith("[frame]"))
            {
                // [frame]0
                AgentDataPool.TotalFrames = (int.Parse(msg.Substring(7)));
            }
            else if (msg.StartsWith("[property]"))
            {
                // Par:   [property]a->10
                // World: [property]WorldTest::World WorldTest::Property3->10
                // Agent: [property]AgentTest::AgentTest_1 AgentTest::Property5::type::name->10

                string[] tokens = msg.Substring(10).Split(' ');
                Debug.Check(tokens.Length > 0);

                string agentType     = string.Empty;
                string agentName     = string.Empty;
                string agentFullname = string.Empty;

                // Par
                if (tokens.Length == 1)
                {
                    agentType     = string.Empty;
                    agentName     = VariableDef.kPar;
                    agentFullname = tokens[0];
                }
                // Global or Agent
                else
                {
                    string[] types = tokens[0].Split(new char[] { '#' }, StringSplitOptions.RemoveEmptyEntries);
                    Debug.Check(types.Length == 2);
                    agentType     = types[0];
                    agentName     = types[1];
                    agentFullname = tokens[0];

                    AgentInstancePool.AddInstance(agentType, agentName);
                }

                Debug.Check(!string.IsNullOrEmpty(agentFullname));

                string[] values = tokens[tokens.Length - 1].Split(new string[] { "->", "\n" }, StringSplitOptions.RemoveEmptyEntries);
                if (values.Length == 2)
                {
                    if (AgentDataPool.TotalFrames > -1 && !string.IsNullOrEmpty(agentFullname))
                    {
                        AgentDataPool.AddValue(agentFullname, values[0], AgentDataPool.TotalFrames, values[1]);
                    }
                }
            }
            else if (msg.StartsWith("[tick]"))
            {
                // [tick]Ship::Ship_1 ships\basic.xml->BehaviorTree[0]:enter [all/success/failure] [1]
                // [tick]Ship::Ship_1 ships\basic.xml->BehaviorTree[0]:update [1]

                string[] tokens = msg.Substring(6).Split(' ');
                if (tokens.Length == 4)
                {
                    string[] types = tokens[0].Split(new char[] { '#' }, StringSplitOptions.RemoveEmptyEntries);
                    Debug.Check(types.Length == 2);
                    string agentType     = types[0];
                    string agentName     = types[1];
                    string agentFullname = tokens[0];

                    AgentInstancePool.AddInstance(agentType, agentName, true);

                    string[] nodes = tokens[1].Split(new string[] { "->" }, StringSplitOptions.RemoveEmptyEntries);
                    if (nodes.Length == 2)
                    {
                        string behaviorFilename = nodes[0];

                        checkBehaviorFiles(behaviorFilename);

                        string[] actions = nodes[1].Split(new char[] { '[', ']' }, StringSplitOptions.RemoveEmptyEntries);
                        if (actions.Length == 3)
                        {
                            string[] actionResults = tokens[2].Split(new char[] { '[', ']' }, StringSplitOptions.RemoveEmptyEntries);
                            string[] hitCounts     = tokens[3].Split(new char[] { '[', ']' }, StringSplitOptions.RemoveEmptyEntries);
                            int      hitCount      = int.Parse(hitCounts[0]);
                            string   nodeId        = actions[1];

                            if (actions[2] == ":enter")
                            {
                                FrameStatePool.EnterNode(agentFullname, AgentDataPool.TotalFrames, behaviorFilename, nodeId, actionResults[0], hitCount);
                            }
                            else if (actions[2] == ":exit")
                            {
                                FrameStatePool.ExitNode(agentFullname, AgentDataPool.TotalFrames, behaviorFilename, nodeId, actionResults[0], hitCount);
                            }
                            else if (actions[2] == ":update")
                            {
                                List <string> highlightNodeIds = FrameStatePool.GetHighlightNodeIds(agentFullname, AgentDataPool.TotalFrames, behaviorFilename);
                                if (highlightNodeIds != null && !highlightNodeIds.Contains(nodeId))
                                {
                                    FrameStatePool.EnterNode(agentFullname, AgentDataPool.TotalFrames, behaviorFilename, actions[1], actionResults[0], hitCount);
                                }
                            }
                        }
                    }
                }
            }
            else if (msg.StartsWith("[jump]"))
            {
                // [jump]Ship::Ship_1 ships/1_1_suicide[5] ships\basic

                string[] tokens = msg.Substring(6).Split(' ');
                if (tokens.Length == 3)
                {
                    string[] types = tokens[0].Split(new char[] { '#' }, StringSplitOptions.RemoveEmptyEntries);
                    Debug.Check(types.Length == 2);
                    string agentType     = types[0];
                    string agentName     = types[1];
                    string agentFullname = tokens[0];

                    //AgentInstancePool.AddInstance(agentType, agentName, true);
                    string thisTree = null;

                    int      nodeId = -1;
                    string[] nodes  = tokens[1].Split(new char[] { '[', ']' }, StringSplitOptions.RemoveEmptyEntries);
                    if (nodes.Length == 2)
                    {
                        thisTree = nodes[0];
                        nodeId   = int.Parse(nodes[1]);
                    }
                    else
                    {
                        Debug.Check(false);
                    }

                    string jumpTree = tokens[2].Trim(new char[] { '\n' });

                    FrameStatePool.SetJumpInfo(agentFullname, thisTree, nodeId, jumpTree);
                }
            }
            else if (msg.StartsWith("[return]"))
            {
                // [return]Ship::Ship_1 ships\basic

                string[] tokens = msg.Substring(8).Split(' ');
                if (tokens.Length == 2)
                {
                    string[] types = tokens[0].Split(new char[] { '#' }, StringSplitOptions.RemoveEmptyEntries);
                    Debug.Check(types.Length == 2);
                    string agentType     = types[0];
                    string agentName     = types[1];
                    string agentFullname = tokens[0];

                    //AgentInstancePool.AddInstance(agentType, agentName, true);

                    string lastTree = tokens[1].Trim(new char[] { '\n' });

                    FrameStatePool.SetReturnInfo(agentFullname, lastTree);
                }
            }
            else if (msg.StartsWith("[breaked]"))
            {
                //BreakAPP could be toggled off when the break dialog is prompted
                //Debug.Check(MessageQueue.BreakAPP);
                if (MessageQueue.BreakAPP)
                {
                    string msg_real = msg.Substring(9);
                    if (msg_real.StartsWith("[applog]"))
                    {
                        FrameStatePool.RespondToCPPBreak(AgentDataPool.TotalFrames, msg_real);
                    }
                    else
                    {
                        //[breaked]Ship::Ship_1 ships\basic.xml->BehaviorTree[0]:enter [all/success/failure] [1]
                        string[] tokens = msg_real.Split(' ');
                        if (tokens.Length == 4)
                        {
                            string agentFullname = tokens[0];
                            //if (string.IsNullOrEmpty(Plugin.DebugAgentInstance))
                            {
                                Plugin.DebugAgentInstance = agentFullname;
                            }

                            string[] nodes = tokens[1].Split(new string[] { "->" }, StringSplitOptions.RemoveEmptyEntries);
                            if (nodes.Length == 2)
                            {
                                string[] actions = nodes[1].Split(new char[] { '[', ']' }, StringSplitOptions.RemoveEmptyEntries);
                                if (actions.Length == 3)
                                {
                                    Debug.Check(actions[2].StartsWith(":"));
                                    string   actionName    = actions[2].Substring(1);
                                    string[] actionResults = tokens[2].Split(new char[] { '[', ']' }, StringSplitOptions.RemoveEmptyEntries);

                                    //although actionResult can be EAR_none or EAR_all, but, as this is the real result of an action
                                    //it can only be success or failure
                                    Debug.Check(actionResults.Length == 1 && (actionResults[0] == "success" || actionResults[0] == "failure"));

                                    string[] hitCounts = tokens[3].Split(new char[] { '[', ']' }, StringSplitOptions.RemoveEmptyEntries);
                                    int      hitCount  = int.Parse(hitCounts[0]);

                                    FrameStatePool.RespondToAPPBreak(agentFullname, AgentDataPool.TotalFrames, nodes[0], actions[1], actionName, actionResults[0], hitCount);
                                }
                            }
                        }
                    }

                    Plugin.UpdateMode = UpdateModes.Break;
                }
            }
            else if (msg.StartsWith("[continue]"))
            {
                if (MessageQueue.ContinueHandler != null)
                {
                    MessageQueue.ContinueHandler(msg);
                }
            }
            else if (msg.StartsWith("[applog]"))
            {
                int frame = AgentDataPool.TotalFrames;
                FrameStatePool.AddAppLog(frame, msg);
            }
            else if (msg.StartsWith("[log]"))
            {
                int frame = AgentDataPool.TotalFrames;
                FrameStatePool.AddLog(frame, msg);
            }
            else if (msg.StartsWith("[profiler]"))
            {
                //[profiler]ships\0_basic.xml->BehaviorTree[-1] 685
                string[] tokens = msg.Substring(10).Split(new char[] { ' ', '\n' }, StringSplitOptions.RemoveEmptyEntries);
                if (tokens.Length == 2)
                {
                    string[] nodes = tokens[0].Split(new string[] { "->" }, StringSplitOptions.RemoveEmptyEntries);
                    if (nodes.Length == 2)
                    {
                        string behaviorFilename = nodes[0];

                        string[] ids = nodes[1].Split(new char[] { '[', ']' }, StringSplitOptions.RemoveEmptyEntries);
                        if (ids.Length == 2)
                        {
                            FrameStatePool.SetProfileInfo(AgentDataPool.TotalFrames, behaviorFilename, ids[1], 0.001f * int.Parse(tokens[1]));
                        }
                    }
                }
            }
            else
            {
                //
                //Debug.Check(false);
            }

            return(Plugin.UpdateMode);
        }
Ejemplo n.º 16
0
        //return true if breaked
        private bool update(int frame)
        {
            int _agenttype_index     = 0;
            int _agentinstance_index = 0;

            ConsoleDock.SetMesssages(frame);

            if (Plugin.EditMode == EditModes.Connect)
            {
                if (Plugin.UpdateMode == UpdateModes.Continue)
                {
                    SetTotalFrame(frame);
                    AgentDataPool.CurrentFrame = AgentDataPool.TotalFrames;
                }

                updateUI(frame);
            }

            lock (_lockObject) {
                if (_agenttype_index != -1 && _agentinstance_index != -1)
                {
                    //update could be entered multiple times for a 'frame' if there are multiple breakpoints in 'frame'
                    if (_agenttype_index == 0 && _agentinstance_index == 0)
                    {
                        AgentDataPool.CurrentFrame = frame;

                        // Global
                        //foreach (Plugin.InstanceName_t agentType in Plugin.InstanceNames)
                        //{
                        //    updateParameters(agentType.agentType_, agentType.agentType_.AgentTypeName, frame);
                        //}
                    }

                    this._break_prompt = "";

                    // Agent
                    while (_agenttype_index < Plugin.AgentTypes.Count)
                    {
                        AgentType agentType = Plugin.AgentTypes[_agenttype_index];

                        if (!agentType.IsInherited)
                        {
                            List <string> instances = AgentInstancePool.GetInstances(agentType.ToString());

                            while (_agentinstance_index < instances.Count)
                            {
                                string instance = instances[_agentinstance_index];
                                _agentinstance_index++;

                                // Parameters
                                updateParameters(agentType, instance, frame);

                                if (Plugin.EditMode == EditModes.Analyze)
                                {
                                    string agentName        = string.Format("{0}#{1}", agentType, instance);
                                    string behaviorFilename = FrameStatePool.GetBehaviorFilename(agentName, frame);

                                    if (_lastBreakFrame != frame)
                                    {
                                        _lastBreakPointIndex = 0;
                                    }

                                    // Breakpoint
                                    List <FrameStatePool.FrameState.Action> actions = FrameStatePool.GetActions(agentName, frame, behaviorFilename);
                                    HighlightBreakPoint.Instance = checkBreakpoint(behaviorFilename, actions, ref _lastBreakPointIndex);

                                    if (HighlightBreakPoint.Instance != null || agentName == Plugin.DebugAgentInstance)
                                    {
                                        // Highlights
                                        List <string> transitionIds    = FrameStatePool.GetHighlightTransitionIds(agentName, frame, behaviorFilename);
                                        List <string> highlightNodeIds = FrameStatePool.GetHighlightNodeIds(agentName, frame, behaviorFilename);
                                        List <string> updatedNodeIds   = FrameStatePool.GetUpdatedNodeIds(agentName, frame, behaviorFilename);
                                        Dictionary <string, FrameStatePool.NodeProfileInfos.ProfileInfo> profileInfos = FrameStatePool.GetProfileInfos(frame, behaviorFilename);

                                        updateHighlights(agentName, frame, transitionIds, highlightNodeIds, updatedNodeIds, HighlightBreakPoint.Instance, profileInfos);
                                    }

                                    // Return if there is breakpoint breaked.
                                    if (HighlightBreakPoint.Instance != null)
                                    {
                                        _lastBreakFrame = frame;
                                        return(true);
                                    }
                                }
                            }
                        }

                        _agenttype_index++;
                        _agentinstance_index = 0;
                    }

                    _agenttype_index     = -1;
                    _agentinstance_index = -1;

                    //after checking breakpoints, to check applog
                    _log_index = 0;
                }
            }

            lock (_lockObject) {
                if (_log_index != -1)
                {
                    if (Plugin.EditMode == EditModes.Analyze)
                    {
                        bool bCheckLog = (this.comboBoxLogFilter.Text != "");

                        if (bCheckLog)
                        {
                            if (Plugin.EditMode == EditModes.Analyze)
                            {
                                Debug.Check(true);
                            }
                            else if (MessageQueue.IsConnected)
                            {
                                Debug.Check(true);
                            }
                            else
                            {
                                bCheckLog = false;
                            }
                        }

                        if (bCheckLog)
                        {
                            List <string> logs = FrameStatePool.GetAppLog(frame, this.comboBoxLogFilter.Text);

                            if (logs != null && _log_index < logs.Count)
                            {
                                this._break_prompt = logs[_log_index++];
                                return(true);
                            }
                        }
                    }

                    _log_index = -1;
                }
            }

            return(false);
        }