BVB Source Codes

CRYENGINE Show DialogQueuesManager.cpp Source code

Return Download CRYENGINE: download DialogQueuesManager.cpp Source code - Download CRYENGINE Source code - Type:.cpp
  1. // Copyright 2001-2016 Crytek GmbH / Crytek Group. All rights reserved.
  2.  
  3. #include "StdAfx.h"
  4. #include "DialogQueuesManager.h"
  5. #include "CryActionCVars.h"
  6.  
  7. ////////////////////////////////////////////////////////////////////////////
  8. CDialogQueuesManager::CDialogQueuesManager()
  9.         : m_numBuffers(0), m_uniqueDialogID(0)
  10. {
  11.         static const char* BUFFERS_FILENAME = "Libs/FlowNodes/DialogFlowNodeBuffers.xml";
  12.  
  13.         XmlNodeRef xmlNodeRoot = GetISystem()->LoadXmlFromFile(BUFFERS_FILENAME);
  14.         if (xmlNodeRoot == (IXmlNode*)NULL)
  15.         {
  16.                 if (!gEnv->IsEditor())
  17.                         CryWarning(VALIDATOR_MODULE_GAME, VALIDATOR_WARNING, "CDialogFlowNodeMgr::Init() - Failed to load '%s'. dialog flownode buffers disabled.", BUFFERS_FILENAME);
  18.                 return;
  19.         }
  20.  
  21.         m_numBuffers = xmlNodeRoot->getChildCount() - 1; // first one in the file is assumed to be "nobuffer"
  22.         m_buffersList.resize(m_numBuffers);
  23.         const uint32 DEFAULT_BUFFER_SIZE = 4; // just an small size that should be big enough for almost all situations, to avoid extra memory allocations.
  24.         for (uint32 i = 0; i < m_numBuffers; ++i)
  25.         {
  26.                 m_buffersList[i].reserve(DEFAULT_BUFFER_SIZE);
  27.         }
  28.  
  29. #ifdef DEBUGINFO_DIALOGBUFFER
  30.         m_bufferNames.resize(m_numBuffers);
  31.         for (uint32 i = 0; i < m_numBuffers; ++i)
  32.         {
  33.                 XmlNodeRef xmlNodeBuffer = xmlNodeRoot->getChild(i + 1);
  34.                 m_bufferNames[i] = xmlNodeBuffer->getAttr("name");
  35.         }
  36. #endif
  37. }
  38.  
  39. ////////////////////////////////////////////////////////////////////////////
  40. void CDialogQueuesManager::Reset()
  41. {
  42.         m_uniqueDialogID = 0;
  43.         for (uint32 i = 0; i < m_numBuffers; ++i)
  44.         {
  45.                 m_buffersList[i].clear();
  46.         }
  47. #ifdef DEBUGINFO_DIALOGBUFFER
  48.         m_dialogNames.clear();
  49. #endif
  50. }
  51.  
  52. ////////////////////////////////////////////////////////////////////////////
  53. bool CDialogQueuesManager::IsBufferFree(uint32 queueID)
  54. {
  55.         if (IsQueueIDValid(queueID))
  56.                 return m_buffersList[queueID].size() == 0;
  57.         else
  58.                 return true;
  59. }
  60.  
  61. ////////////////////////////////////////////////////////////////////////////
  62. CDialogQueuesManager::TDialogId CDialogQueuesManager::Play(uint32 queueID, const string& name)
  63. {
  64.         TDialogId dialogId = CreateNewDialogId();
  65.         if (IsQueueIDValid(queueID))
  66.         {
  67.                 m_buffersList[queueID].push_back(dialogId);
  68. #ifdef DEBUGINFO_DIALOGBUFFER
  69.                 if (CCryActionCVars::Get().g_debugDialogBuffers == 1)
  70.                         m_dialogNames.insert(std::make_pair(dialogId, name));
  71. #endif
  72.         }
  73.         return dialogId;
  74. }
  75.  
  76. ////////////////////////////////////////////////////////////////////////////
  77. bool CDialogQueuesManager::IsDialogWaiting(uint32 queueID, TDialogId dialogId)
  78. {
  79.         if (IsQueueIDValid(queueID))
  80.         {
  81.                 TBuffer& buffer = m_buffersList[queueID];
  82.                 assert(!buffer.empty());
  83.                 return buffer[0] != dialogId;
  84.         }
  85.         else
  86.                 return false;
  87. }
  88.  
  89. ////////////////////////////////////////////////////////////////////////////
  90. void CDialogQueuesManager::NotifyDialogDone(uint32 queueID, TDialogId dialogId)
  91. {
  92.         if (IsQueueIDValid(queueID))
  93.         {
  94.                 TBuffer& buffer = m_buffersList[queueID];
  95.                 // this is called at most once per dialog, and the vectors are very small (usually a couple elements or 3 at most),
  96.                 // and the element we want to delete should almost always be the first one, so we dont care about performance hit
  97.                 stl::find_and_erase(buffer, dialogId);
  98. #ifdef DEBUGINFO_DIALOGBUFFER
  99.                 if (CCryActionCVars::Get().g_debugDialogBuffers == 1)
  100.                         m_dialogNames.erase(dialogId);
  101. #endif
  102.         }
  103. }
  104.  
  105. ////////////////////////////////////////////////////////////////////////////
  106. uint32 CDialogQueuesManager::BufferEnumToId(uint32 bufferEnum) // buffer enum means the values stored in the .xml definition file
  107. {
  108.         uint32 queueID = bufferEnum - 1; // this assumes that the "nobuffer" enum value is the 0
  109.         assert(IsQueueIDValid(queueID) || queueID == NO_QUEUE);
  110.         return queueID;
  111. }
  112.  
  113. ////////////////////////////////////////////////////////////////////////////
  114. void CDialogQueuesManager::Serialize(TSerialize ser)
  115. {
  116.         ser.Value("m_numBuffers", m_numBuffers);
  117.         ser.Value("m_dialogIdCount", m_uniqueDialogID);
  118.  
  119.         ser.BeginGroup("buffers");
  120.         for (int i = 0; i < m_numBuffers; ++i)
  121.         {
  122.                 ser.Value("buffer", m_buffersList[i]);
  123.         }
  124.         ser.EndGroup();
  125. }
  126.  
  127. ////////////////////////////////////////////////////////////////////////////
  128. void CDialogQueuesManager::Update()
  129. {
  130. #ifdef DEBUGINFO_DIALOGBUFFER
  131.         if (CCryActionCVars::Get().g_debugDialogBuffers == 1)
  132.         {
  133.                 for (uint32 i = 0; i < m_numBuffers; ++i)
  134.                 {
  135.                         TBuffer& buffer = m_buffersList[i];
  136.  
  137.                         float white[] = { 1.0f, 1.0f, 1.0f, 1.0f };
  138.                         float green[] = { 0.0f, 1.0f, 1.0f, 1.0f };
  139.                         float red[] = { 1.0f, 0.0f, 0.0f, 1.0f };
  140.                         float x = 300.f * i;
  141.                         float y = 100;
  142.                         IRenderAuxText::Draw2dLabel(x, y, 1.2f, white, false, "%s", m_bufferNames[i].c_str());
  143.                         IRenderAuxText::Draw2dLabel(x, y + 20, 1.2f, white, false, "------------------------------------");
  144.  
  145.                         for (uint32 j = 0; j < buffer.size(); ++j)
  146.                         {
  147.                                 const char* pName = "<UNKNOWN>";
  148.                                 TDialogNames::const_iterator iter = m_dialogNames.find(buffer[j]);
  149.                                 if (iter != m_dialogNames.end())
  150.                                         pName = iter->second.c_str();
  151.                                 IRenderAuxText::Draw2dLabel(x, y + 40 + 20 * j, 1.2f, j == 0 ? green : red, false, "%s", pName);
  152.                         }
  153.                 }
  154.         }
  155. #endif
  156. }
  157.  
downloadDialogQueuesManager.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