Ejemplo n.º 1
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.º 2
0
        private void editor_ValueWasChanged(object sender, DesignerPropertyInfo property)
        {
            if (string.IsNullOrEmpty(_agentFullname))
            {
                return;
            }

            int index = getRowIndex(sender as DesignerPropertyEditor);

            if (index > -1)
            {
                RowControl row = _rowControls[index];

                VariableDef var = row.ValueEditor.GetVariable();

                if (var != null && var.Value != null)
                {
                    string value = var.Value.ToString();

                    if (!string.IsNullOrEmpty(value))
                    {
                        string valueType = row.TypeLabel.Text;
                        string valueName = row.NameLabel.Text;

                        if (AgentDataPool.CurrentFrame > -1)
                        {
                            AgentDataPool.AddValue(_agentFullname, valueName, AgentDataPool.CurrentFrame, value);
                        }

                        NetworkManager.Instance.SendProperty(_agentFullname, valueType, valueName, value);
                    }
                }
            }
        }
Ejemplo n.º 3
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.º 4
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.º 5
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;
            List <AgentDataPool.ValueMark> values = AgentDataPool.GetValidValues(agentType, agentFullname, frame);

            foreach (AgentDataPool.ValueMark value in values)
            {
                ParametersDock.SetProperty(typeName, agentName, value.Name, value.Value);
            }
        }
Ejemplo n.º 6
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.º 7
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);
        }