BVB Source Codes

CRYENGINE Show AIDbgRecorder.cpp Source code

Return Download CRYENGINE: download AIDbgRecorder.cpp Source code - Download CRYENGINE Source code - Type:.cpp
  1. // Copyright 2001-2016 Crytek GmbH / Crytek Group. All rights reserved.
  2.  
  3. /********************************************************************
  4.    -------------------------------------------------------------------------
  5.    File name:   AIDbgRecorder.cpp
  6.    Description: Simple text AI debugging event recorder
  7.  
  8.    -------------------------------------------------------------------------
  9.    History:
  10.    -01:07:2005 : Created by Kirill Bulatsev
  11.    -19:11:2008 : Separated out by Matthew
  12.  
  13.    Notes:        Don't include the header in CAISystem - below it is redundant
  14.  
  15.  *********************************************************************/
  16.  
  17. #include "StdAfx.h"
  18. #include "AIDbgRecorder.h"
  19.  
  20. #ifdef CRYAISYSTEM_DEBUG
  21.  
  22.         #define AIRECORDER_FILENAME          "AILog.log"
  23.         #define AIRECORDER_SECONDARYFILENAME "AISignals.csv"
  24.  
  25.         #define BUFFER_SIZE                  256
  26.  
  27. //
  28. //----------------------------------------------------------------------------------------------
  29. bool CAIDbgRecorder::IsRecording(const IAIObject* pTarget, IAIRecordable::e_AIDbgEvent event) const
  30. {
  31.         if (!m_sFile.empty())
  32.                 return false;
  33.  
  34.         if (event == IAIRecordable::E_RESET)
  35.                 return true;
  36.  
  37.         if (!pTarget)
  38.                 return false;
  39.  
  40.         return !strcmp(gAIEnv.CVars.StatsTarget, "all")
  41.                || !strcmp(gAIEnv.CVars.StatsTarget, pTarget->GetName());
  42. }
  43.  
  44. //
  45. //----------------------------------------------------------------------------------------------
  46. void CAIDbgRecorder::Record(const IAIObject* pTarget, IAIRecordable::e_AIDbgEvent event, const char* pString) const
  47. {
  48.         if (event == IAIRecordable::E_RESET)
  49.         {
  50.                 LogString("\n\n--------------------------------------------------------------------------------------------\n");
  51.                 LogString("<RESETTING AI SYSTEM>\n");
  52.                 LogString("aiTick:startTime:<entity> ai_event    details\n");
  53.                 LogString("--------------------------------------------------------------------------------------------\n");
  54.                 // (MATT) Since some gAIEnv settings change only on a reset, this would be the time to list them {2008/11/20}
  55.                 return;
  56.         }
  57.         #ifdef AI_LOG_SIGNALS
  58.         else if (event == IAIRecordable::E_SIGNALEXECUTEDWARNING)
  59.         {
  60.                 char bufferString[BUFFER_SIZE];
  61.                 cry_sprintf(bufferString, "%s\n", pString);
  62.                 LogStringSecondary(bufferString);
  63.                 return;
  64.         }
  65.         #endif
  66.  
  67.         if (!pTarget)
  68.                 return;
  69.  
  70.         // Filter to only log the targets we are interested in
  71.         // I.e. if not "all" and if not our current target, return
  72.         const char* sStatsTarget = gAIEnv.CVars.StatsTarget;
  73.         if ((strcmp(sStatsTarget, "all") != 0) && (strcmp(sStatsTarget, pTarget->GetName()) != 0))
  74.                 return;
  75.  
  76.         const char* pEventString("");
  77.         switch (event)
  78.         {
  79.         case IAIRecordable::E_SIGNALRECIEVED:
  80.                 pEventString = "signal_recieved      ";
  81.                 break;
  82.         case IAIRecordable::E_SIGNALRECIEVEDAUX:
  83.                 pEventString = "auxsignal_recieved   ";
  84.                 break;
  85.         case IAIRecordable::E_SIGNALEXECUTING:
  86.                 pEventString = "signal_executing     ";
  87.                 break;
  88.         case IAIRecordable::E_GOALPIPEINSERTED:
  89.                 pEventString = "goalpipe_inserted    ";
  90.                 break;
  91.         case IAIRecordable::E_GOALPIPESELECTED:
  92.                 pEventString = "goalpipe_selected    ";
  93.                 break;
  94.         case IAIRecordable::E_GOALPIPERESETED:
  95.                 pEventString = "goalpipe_reseted     ";
  96.                 break;
  97.         case IAIRecordable::E_BEHAVIORSELECTED:
  98.                 pEventString = "behaviour_selected   ";
  99.                 break;
  100.         case IAIRecordable::E_BEHAVIORDESTRUCTOR:
  101.                 pEventString = "behaviour_destructor ";
  102.                 break;
  103.         case IAIRecordable::E_BEHAVIORCONSTRUCTOR:
  104.                 pEventString = "behaviour_constructor";
  105.                 break;
  106.         case IAIRecordable::E_ATTENTIONTARGET:
  107.                 pEventString = "atttarget_change     ";
  108.                 break;
  109.         case IAIRecordable::E_REGISTERSTIMULUS:
  110.                 pEventString = "register_stimulus    ";
  111.                 break;
  112.         case IAIRecordable::E_HANDLERNEVENT:
  113.                 pEventString = "handler_event        ";
  114.                 break;
  115.         case IAIRecordable::E_ACTIONSTART:
  116.                 pEventString = "action_start         ";
  117.                 break;
  118.         case IAIRecordable::E_ACTIONSUSPEND:
  119.                 pEventString = "action_suspend       ";
  120.                 break;
  121.         case IAIRecordable::E_ACTIONRESUME:
  122.                 pEventString = "action_resume        ";
  123.                 break;
  124.         case IAIRecordable::E_ACTIONEND:
  125.                 pEventString = "action_end           ";
  126.                 break;
  127.         case IAIRecordable::E_REFPOINTPOS:
  128.                 pEventString = "refpoint_pos         ";
  129.                 break;
  130.         case IAIRecordable::E_EVENT:
  131.                 pEventString = "triggering event     ";
  132.                 break;
  133.         case IAIRecordable::E_LUACOMMENT:
  134.                 pEventString = "lua comment          ";
  135.                 break;
  136.         default:
  137.                 pEventString = "undefined            ";
  138.                 break;
  139.         }
  140.  
  141.         // Fetch the current AI tick and the time that tick started
  142.         int frame = GetAISystem()->GetAITickCount();
  143.         float time = GetAISystem()->GetFrameStartTimeSeconds();
  144.  
  145.         char bufferString[BUFFER_SIZE];
  146.  
  147.         if (!pString)
  148.                 pString = "<null>";
  149.         cry_sprintf(bufferString, "%6d:%9.3f: <%s> %s\t\t\t%s\n", frame, time, pTarget->GetName(), pEventString, pString);
  150.         LogString(bufferString);
  151. }
  152.  
  153. //
  154. //----------------------------------------------------------------------------------------------
  155. void CAIDbgRecorder::InitFile() const
  156. {
  157.         // Set the string
  158.         m_sFile = gEnv->pSystem->GetRootFolder();
  159.         m_sFile += AIRECORDER_FILENAME;
  160.  
  161.         // Open to wipe and write any preamble
  162.         FILE* pFile = fxopen(m_sFile.c_str(), "wt");
  163.         fputs("CryAISystem text debugging log\n", pFile);
  164.  
  165.         #if CRY_PLATFORM_WINDOWS
  166.         // Get time.
  167.         time_t ltime;
  168.         time(&ltime);
  169.         tm* today = localtime(&ltime);
  170.  
  171.         char s[1024];
  172.         strftime(s, 128, "Date(%d %b %Y) Time(%H %M %S)\n\n", today);
  173.         fputs(s, pFile);
  174.         #endif
  175.  
  176.         fclose(pFile);
  177. }
  178.  
  179. //
  180. //----------------------------------------------------------------------------------------------
  181. void CAIDbgRecorder::InitFileSecondary() const
  182. {
  183.         m_sFileSecondary = gEnv->pSystem->GetRootFolder();
  184.         m_sFileSecondary += AIRECORDER_SECONDARYFILENAME;
  185.  
  186.         FILE* pFileSecondary = fxopen(m_sFileSecondary.c_str(), "wt");
  187.         fputs("Function,Time,Page faults,Entity\n", pFileSecondary);
  188.         fclose(pFileSecondary);
  189. }
  190.  
  191. //----------------------------------------------------------------------------------------------
  192. void CAIDbgRecorder::LogString(const char* pString) const
  193. {
  194.         bool mergeWithLog(gAIEnv.CVars.RecordLog != 0);
  195.         if (!mergeWithLog)
  196.         {
  197.                 if (m_sFile.empty())
  198.                         InitFile();
  199.  
  200.                 FILE* pFile = fxopen(m_sFile.c_str(), "at");
  201.                 if (!pFile)
  202.                         return;
  203.  
  204.                 fputs(pString, pFile);
  205.                 fclose(pFile);
  206.         }
  207.         else
  208.         {
  209.                 GetAISystem()->LogEvent("<AIrec>", "%s", pString);
  210.         }
  211. }
  212.  
  213. //
  214. //----------------------------------------------------------------------------------------------
  215. void CAIDbgRecorder::LogStringSecondary(const char* pString) const
  216. {
  217.         if (m_sFile.empty())
  218.                 InitFileSecondary();
  219.  
  220.         FILE* pFileSecondary = fxopen(m_sFileSecondary.c_str(), "at");
  221.         if (!pFileSecondary)
  222.                 return;
  223.  
  224.         fputs(pString, pFileSecondary);
  225.         fclose(pFileSecondary);
  226. }
  227.  
  228. #endif //CRYAISYSTEM_DEBUG
  229.  
downloadAIDbgRecorder.cpp Source code - Download CRYENGINE Source code
Related Source Codes/Software:
postal - 2017-06-11
reactide - Reactide is the first dedicated IDE for React web ... 2017-06-11
rkt - rkt is a pod-native container engine for Linux. It... 2017-06-11
uWebSockets - Tiny WebSockets https://for... 2017-06-11
realworld - TodoMVC for the RealWorld - Exemplary fullstack Me... 2017-06-11
CRYENGINE - CRYENGINE is a powerful real-time game development... 2017-06-11
goreplay - GoReplay is an open-source tool for capturing and ... 2017-06-10
pyenv - Simple Python version management 2017-06-10
redux-saga - An alternative side effect model for Redux apps ... 2017-06-10
angular-starter - 2017-06-10

 Back to top