コード例 #1
0
        public static void Log(string format, params object[] args)
        {
#if !BEHAVIAC_RELEASE
            if (Config.IsLoggingOrSocketing)
            {
                // make result string
                string buffer = string.Format(format, args);

                Output(null, buffer);
                SocketUtils.SendText(buffer);
            }
#endif
        }
コード例 #2
0
ファイル: socketconnect.cs プロジェクト: ChillyYep/AI-Demo
        protected override void OnConnection()
        {
            Log("behaviac: sending initial settings.\n");

            this.SendInitialSettings();

            SocketUtils.SendWorkspaceSettings();

            this.SendInitialProperties();

            {
                Log("behaviac: sending packets before connecting.\n");

                this.SendExistingPackets();
            }

            SocketUtils.SendText("[connected]precached message done\n");

            //when '[connected]' is handled in the designer, it will send back all the breakpoints if any and '[breakcpp]' and '[start]'
            //here we block until all those messages have been received, otherwise, if we don't block here to wait for all those messages
            //the breakpoints checking might be wrong.
            bool bLoop = true;

            while (bLoop && m_isDisconnected.Get() == 0 &&
                   this.m_writeSocket != null && this.m_writeSocket.Connected)
            {
                //sending packets if any
                if (m_packetsCount > 0)
                {
                    SendAllPackets();
                }

                string kStartMsg = "[start]";
                bool   bFound    = this.ReceivePackets(kStartMsg);

                if (bFound)
                {
                    bLoop = false;
                }
                else
                {
                    System.Threading.Thread.Sleep(1);
                }
            }

            //this.m_bHandleMessage = false;
        }
コード例 #3
0
        //mode
        public static void Log(LogMode mode, string filterString, string format, params object[] args)
        {
#if !BEHAVIAC_RELEASE
            if (Config.IsLoggingOrSocketing)
            {
                //BEHAVIAC_PROFILE("LogManager.LogMode");

                // make result string
                string buffer = string.Format(format, args);

                string filterStr = filterString;
                if (string.IsNullOrEmpty(filterString))
                {
                    filterStr = "empty";
                }

                string target = "";

                if (mode == LogMode.ELM_tick)
                {
                    target = string.Format("[applog]{0}:{1}\n", filterStr, buffer);
                }
                else if (mode == LogMode.ELM_continue)
                {
                    target = string.Format("[continue][applog]{0}:{1}\n", filterStr, buffer);
                }
                else if (mode == LogMode.ELM_breaked)
                {
                    //[applog]door opened
                    target = string.Format("[breaked][applog]{0}:{1}\n", filterStr, buffer);
                }
                else if (mode == LogMode.ELM_log)
                {
                    target = string.Format("[log]{0}:{1}\n", filterStr, buffer);
                }
                else
                {
                    Debug.Check(false);
                }

                Output(null, target);
                SocketUtils.SendText(target);
            }
#endif
        }
コード例 #4
0
        //property
        public static void Log(Agent pAgent, string typeName, string varName, string value)
        {
#if !BEHAVIAC_RELEASE
            if (Config.IsLoggingOrSocketing)
            {
                //BEHAVIAC_PROFILE("LogManager.LogVar");

                if (!System.Object.ReferenceEquals(pAgent, null) && pAgent.IsMasked())
                {
                    string agentClassName    = pAgent.GetClassTypeName();
                    string agentInstanceName = pAgent.GetName();

                    agentClassName    = agentClassName.Replace(".", "::");
                    agentInstanceName = agentInstanceName.Replace(".", "::");

                    //[property]WorldState.World WorldState.time.276854364
                    //[property]Ship.Ship_1 GameObject.HP.100
                    //[property]Ship.Ship_1 GameObject.age.0
                    //[property]Ship.Ship_1 GameObject.speed.0.000000
                    string buffer;

                    bool bIsPar = Utils.IsParVar(varName);

                    if (bIsPar)
                    {
                        string tn = typeName;
                        //filter out "signed "
                        tn.Replace("signed ", "");

                        buffer = string.Format("[property]{0}#{1} {2} {3}->{4}\n", agentClassName, agentInstanceName, tn, varName, value);
                    }
                    else
                    {
                        buffer = string.Format("[property]{0}#{1} {2}->{3}\n", agentClassName, agentInstanceName, varName, value);
                    }

                    Output(pAgent, buffer);
                    SocketUtils.SendText(buffer);
                }
            }
#endif
        }
コード例 #5
0
        private void Output(Agent pAgent, string msg)
        {
#if !BEHAVIAC_RELEASE
            if (Config.IsLoggingOrSocketing)
            {
                string txt = string.Format("[{0:00000000}]{1}", _msg_index++, msg);

                System.IO.StreamWriter fp = GetFile(pAgent);

                string szTime = DateTime.Now.ToString();

                string buffer = string.Format("[{0}]{1}", szTime, txt);

                //socket sending before logging as logging is a 'slow' process
                if (Config.IsSocketing)
                {
                    SocketUtils.SendText(txt);
                }

                if (Config.IsLogging)
                {
                    //printf(buffer);

                    if (fp != null)
                    {
                        lock (fp)
                        {
                            fp.Write(buffer);

                            if (Config.IsLoggingFlush)
                            {
                                fp.Flush();
                            }
                        }
                    }
                }
            }
#endif
        }
コード例 #6
0
        //profiler
        public static void Log(Agent pAgent, string btMsg, long time)
        {
#if !BEHAVIAC_RELEASE
            if (Config.IsLoggingOrSocketing)
            {
                if (ms_bProfilerEnabled)
                {
                    //BEHAVIAC_PROFILE("LogManager.LogProfiler");

                    if (!System.Object.ReferenceEquals(pAgent, null) && pAgent.IsMasked())
                    {
                        //string agentClassName = pAgent.GetObjectTypeName();
                        //string agentInstanceName = pAgent.GetName();

                        BehaviorTreeTask bt = !System.Object.ReferenceEquals(pAgent, null) ? pAgent.btgetcurrent() : null;

                        string btName;
                        if (bt != null)
                        {
                            btName = bt.GetName();
                        }
                        else
                        {
                            btName = "None";
                        }

                        //[profiler]Ship.Ship_1 ships\suicide.xml.BehaviorTree[0] 0.031
                        string buffer;

                        //buffer = FormatString("[profiler]%s.%s %s.%s %d\n", agentClassName, agentInstanceName, btName, btMsg, time);
                        buffer = string.Format("[profiler]{0}.xml.{1} {2}\n", btName, btMsg, time);

                        Output(pAgent, buffer);
                        SocketUtils.SendText(buffer);
                    }
                }
            }
#endif
        }
コード例 #7
0
        //action
        public static void Log(Agent pAgent, string btMsg, EActionResult actionResult, LogMode mode)
        {
#if !BEHAVIAC_RELEASE
            if (Config.IsLoggingOrSocketing)
            {
                //BEHAVIAC_PROFILE("LogManager.LogAction");
                if (!System.Object.ReferenceEquals(pAgent, null) && pAgent.IsMasked())
                {
                    if (!string.IsNullOrEmpty(btMsg))
                    {
                        string agentClassName = pAgent.GetClassTypeName();

                        agentClassName = agentClassName.Replace(".", "::");

                        string agentName = agentClassName;
                        agentName += "#";
                        agentName += pAgent.GetName();

                        string actionResultStr = "";
                        if (actionResult == EActionResult.EAR_success)
                        {
                            actionResultStr = "success";
                        }
                        else if (actionResult == EActionResult.EAR_failure)
                        {
                            actionResultStr = "failure";
                        }
                        else
                        {
                            //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
                            //when it is EAR_none, it is for update
                            if (actionResult == behaviac.EActionResult.EAR_none && mode == behaviac.LogMode.ELM_tick)
                            {
                                actionResultStr = "running";
                            }
                            else
                            {
                                actionResultStr = "none";
                            }
                        }

                        if (mode == LogMode.ELM_continue)
                        {
                            //[continue]Ship.Ship_1 ships\suicide.xml.BehaviorTreeTask[0]:enter [all/success/failure] [1]
                            int count = Workspace.GetActionCount(btMsg);
                            Debug.Check(count > 0);
                            string buffer = string.Format("[continue]{0} {1} [{2}] [{3}]\n", agentName, btMsg, actionResultStr, count);

                            Output(pAgent, buffer);
                            SocketUtils.SendText(buffer);
                        }
                        else if (mode == LogMode.ELM_breaked)
                        {
                            //[breaked]Ship.Ship_1 ships\suicide.xml.BehaviorTreeTask[0]:enter [all/success/failure] [1]
                            int count = Workspace.GetActionCount(btMsg);
                            Debug.Check(count > 0);
                            string buffer = string.Format("[breaked]{0} {1} [{2}] [{3}]\n", agentName, btMsg, actionResultStr, count);

                            Output(pAgent, buffer);
                            SocketUtils.SendText(buffer);
                        }
                        else if (mode == LogMode.ELM_tick)
                        {
                            //[tick]Ship.Ship_1 ships\suicide.xml.BehaviorTreeTask[0]:enter [all/success/failure] [1]
                            //[tick]Ship.Ship_1 ships\suicide.xml.BehaviorTreeTask[0]:update [1]
                            //[tick]Ship.Ship_1 ships\suicide.xml.Selector[1]:enter [all/success/failure] [1]
                            //[tick]Ship.Ship_1 ships\suicide.xml.Selector[1]:update [1]
                            int count = Workspace.UpdateActionCount(btMsg);

                            string buffer = string.Format("[tick]{0} {1} [{2}] [{3}]\n", agentName, btMsg, actionResultStr, count);

                            Output(pAgent, buffer);
                            SocketUtils.SendText(buffer);
                        }
                        else if (mode == LogMode.ELM_jump)
                        {
                            string buffer = string.Format("[jump]{0} {1}\n", agentName, btMsg);

                            Output(pAgent, buffer);
                            SocketUtils.SendText(buffer);
                        }
                        else if (mode == LogMode.ELM_return)
                        {
                            string buffer = string.Format("[return]{0} {1}\n", agentName, btMsg);

                            Output(pAgent, buffer);
                            SocketUtils.SendText(buffer);
                        }
                        else
                        {
                            Debug.Check(false);
                        }
                    }
                }
            }
#endif
        }