private void LogPlanEnd(Agent a, Task root) { #if !BEHAVIAC_RELEASE if (Config.IsLoggingOrSocketing) { string agentClassName = a.GetClassTypeName(); string agentInstanceName = a.GetName(); agentClassName = agentClassName.Replace(".", "::"); agentInstanceName = agentInstanceName.Replace(".", "::"); string ni = BehaviorTask.GetTickInfo(a, root, null); string buffer = string.Format("[plan_end]{0}#{1} {2}\n", agentClassName, agentInstanceName, ni); LogManager.Log(buffer); } #endif }
//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 }
private void LogPlanBegin(Agent a, Task root) { #if !BEHAVIAC_RELEASE if (Config.IsLoggingOrSocketing) { string agentClassName = a.GetClassTypeName(); string agentInstanceName = a.GetName(); agentClassName = agentClassName.Replace(".", "::"); agentInstanceName = agentInstanceName.Replace(".", "::"); string ni = BehaviorTask.GetTickInfo(a, root, "plan"); int count = Workspace.Instance.GetActionCount(ni) + 1; string buffer = string.Format("[plan_begin]{0}#{1} {2} {3}\n", agentClassName, agentInstanceName, ni, count); LogManager.Log(buffer); a.Variables.Log(a, true); } #endif }
//action public void Log(Agent pAgent, string btMsg, EActionResult actionResult, LogMode mode) { #if !BEHAVIAC_RELEASE if (Config.IsLoggingOrSocketing) { //BEHAVIAC_PROFILE("LogManager.Instance.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 if (actionResult == EActionResult.EAR_all) { actionResultStr = "all"; } 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.Instance.GetActionCount(btMsg); Debug.Check(count > 0); string buffer = string.Format("[continue]{0} {1} [{2}] [{3}]\n", agentName, btMsg, actionResultStr, count); Output(pAgent, buffer); } else if (mode == LogMode.ELM_breaked) { //[breaked]Ship.Ship_1 ships\suicide.xml.BehaviorTreeTask[0]:enter [all/success/failure] [1] int count = Workspace.Instance.GetActionCount(btMsg); Debug.Check(count > 0); string buffer = string.Format("[breaked]{0} {1} [{2}] [{3}]\n", agentName, btMsg, actionResultStr, count); Output(pAgent, 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.Instance.UpdateActionCount(btMsg); string buffer = string.Format("[tick]{0} {1} [{2}] [{3}]\n", agentName, btMsg, actionResultStr, count); Output(pAgent, buffer); } else if (mode == LogMode.ELM_jump) { string buffer = string.Format("[jump]{0} {1}\n", agentName, btMsg); Output(pAgent, buffer); } else if (mode == LogMode.ELM_return) { string buffer = string.Format("[return]{0} {1}\n", agentName, btMsg); Output(pAgent, buffer); } else { Debug.Check(false); } } } } #endif }
//property public void Log(Agent pAgent, string typeName, string varName, string value) { #if !BEHAVIAC_RELEASE if (Config.IsLoggingOrSocketing) { //BEHAVIAC_PROFILE("LogManager.Instance.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; buffer = string.Format("[property]{0}#{1} {2}->{3}\n", agentClassName, agentInstanceName, varName, value); bool bOutput = true; if (pAgent.PlanningTop >= 0) { string agentFullName = string.Format("{0}#{1}", agentClassName, agentInstanceName); Dictionary <string, string> p = null; if (!_planningLoggedProperties.ContainsKey(agentFullName)) { p = new Dictionary <string, string>(); _planningLoggedProperties.Add(agentFullName, p); } else { p = _planningLoggedProperties[agentFullName]; } if (p.ContainsKey(varName)) { if (p[varName] == value) { bOutput = false; } else { p[varName] = value; } } else { p.Add(varName, value); } } if (bOutput) { Output(pAgent, buffer); } } } #endif }
protected override EBTStatus update(Agent pAgent, EBTStatus childStatus) { ReferencedBehavior pNode = this.GetNode() as ReferencedBehavior; Debug.Check(pNode != null); #if !BEHAVIAC_RELEASE pAgent.m_debug_count++; if (pAgent.m_debug_count > 20) { Debug.LogWarning(string.Format("{0} might be in a recurrsive inter calling of trees\n", pAgent.GetName())); Debug.Check(false); } #endif EBTStatus result = this.m_subTree.exec(pAgent); bool bTransitioned = State.UpdateTransitions(pAgent, pNode, pNode.m_transitions, ref this.m_nextStateId, result); if (bTransitioned) { result = EBTStatus.BT_SUCCESS; } return(result); }
private EBTStatus UpdateFSM(Agent pAgent, EBTStatus childStatus) { Debug.Check(this.m_node != null); Debug.Check(this.m_currentNodeId != -1); #if !BEHAVIAC_RELEASE int kMaxCount = 10; Dictionary <int, int> state_update_count = new Dictionary <int, int>(); #endif//#if !BEHAVIAC_RELEASE EBTStatus status = childStatus; bool bLoop = true; while (bLoop) { BehaviorTask currentState = this.GetChildById(this.m_currentNodeId); currentState.exec(pAgent); if (currentState is State.StateTask) { State.StateTask pStateTask = (State.StateTask)currentState; if (pStateTask.IsEndState) { return(EBTStatus.BT_SUCCESS); } } int nextStateId = currentState.GetNextStateId(); if (nextStateId == -1) { //if not transitioned, don't go on next state, to exit bLoop = false; } else { #if !BEHAVIAC_RELEASE if (state_update_count.ContainsKey(this.m_currentNodeId)) { state_update_count[this.m_currentNodeId]++; } else { state_update_count.Add(this.m_currentNodeId, 1); } if (state_update_count[this.m_currentNodeId] > kMaxCount) { string treeName = BehaviorTask.GetParentTreeName(pAgent, this.GetNode()); Debug.LogError(string.Format("{0} might be updating an FSM('{1}') endlessly, possibly a dead loop, please redesign it!\n", pAgent.GetName(), treeName)); Debug.Check(false); } #endif //if transitioned, go on next state this.m_currentNodeId = nextStateId; } } return(status); }