Ejemplo n.º 1
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.º 2
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.º 3
0
 private void setAgentTreeNode(TreeNodeCollection treeNodes)
 {
     foreach (AgentType agent in Plugin.AgentTypes)
     {
         if (!agent.IsInherited)
         {
             string        agentType = agent.ToString();
             List <string> instances = AgentInstancePool.GetInstances(agentType);
             if (instances != null && instances.Count > 0)
             {
                 TreeNode agentTreeNode = treeNodes.Add(agentType, agentType, (int)NodeIcon.FolderClosed, (int)NodeIcon.FolderClosed);
                 foreach (string instance in instances)
                 {
                     agentTreeNode.Nodes.Add(agentType + "#" + instance, instance, (int)NodeIcon.FlagRed, (int)NodeIcon.FlagRed);
                 }
             }
         }
     }
 }
Ejemplo n.º 4
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.º 5
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);
        }