BVB Source Codes

CRYENGINE Show DialogScript.cpp Source code

Return Download CRYENGINE: download DialogScript.cpp Source code - Download CRYENGINE Source code - Type:.cpp
  1. // Copyright 2001-2016 Crytek GmbH / Crytek Group. All rights reserved.
  2.  
  3. // -------------------------------------------------------------------------
  4. //  File name:   DialogScript.cpp
  5. //  Version:     v1.00
  6. //  Created:     07/07/2006 by AlexL
  7. //  Compilers:   Visual Studio.NET
  8. //  Description: Dialog Script
  9. // -------------------------------------------------------------------------
  10. //  History:
  11. //
  12. ////////////////////////////////////////////////////////////////////////////
  13.  
  14. #include "StdAfx.h"
  15. #include "DialogScript.h"
  16. #include "DialogCommon.h"
  17.  
  18. namespace
  19. {
  20. static const CDialogScript::TActorID MASK_ALL = ~CDialogScript::TActorID(0);
  21. static const CDialogScript::TActorID MASK_01010101 = MASK_ALL / 3;
  22. static const CDialogScript::TActorID MASK_00110011 = MASK_ALL / 5;
  23. static const CDialogScript::TActorID MASK_00001111 = MASK_ALL / 17;
  24.  
  25. ILINE void bit_set(CDialogScript::TActorID& n, int which)
  26. {
  27.         n |= (0x01 << which);
  28. }
  29.  
  30. ILINE void bit_clear(CDialogScript::TActorID& n, int which)
  31. {
  32.         n &= ~(0x01 << which);
  33. }
  34.  
  35. ILINE bool is_bit_set(CDialogScript::TActorID& n, int which)
  36. {
  37.         return (n & (0x01 << which)) != 0;
  38. }
  39.  
  40. ILINE int bit_count(CDialogScript::TActorID n)
  41. {
  42.         n = (n & MASK_01010101) + ((n >> 1) & MASK_01010101);
  43.         n = (n & MASK_00110011) + ((n >> 2) & MASK_00110011);
  44.         n = (n & MASK_00001111) + ((n >> 4) & MASK_00001111);
  45.         return n % 255;
  46. }
  47. }
  48.  
  49. void CDialogScript::SActorSet::SetActor(TActorID id)
  50. {
  51.         bit_set(m_actorBits, id);
  52. }
  53.  
  54. void CDialogScript::SActorSet::ResetActor(TActorID id)
  55. {
  56.         bit_clear(m_actorBits, id);
  57. }
  58.  
  59. bool CDialogScript::SActorSet::HasActor(TActorID id)
  60. {
  61.         return is_bit_set(m_actorBits, id);
  62. }
  63.  
  64. int CDialogScript::SActorSet::NumActors() const
  65. {
  66.         return bit_count(m_actorBits);
  67. }
  68.  
  69. bool CDialogScript::SActorSet::Matches(const CDialogScript::SActorSet& other) const
  70. {
  71.         return m_actorBits == other.m_actorBits;
  72. }
  73.  
  74. bool CDialogScript::SActorSet::Satisfies(const CDialogScript::SActorSet& other) const
  75. {
  76.         return (m_actorBits & other.m_actorBits) == other.m_actorBits;
  77. }
  78.  
  79. ////////////////////////////////////////////////////////////////////////////
  80. CDialogScript::CDialogScript(const string& dialogID) : m_id(dialogID), m_reqActorSet(0), m_bComplete(false), m_versionFlags(0)
  81. {
  82. }
  83.  
  84. ////////////////////////////////////////////////////////////////////////////
  85. CDialogScript::~CDialogScript()
  86. {
  87. }
  88.  
  89. ////////////////////////////////////////////////////////////////////////////
  90. // Add one line after another
  91. bool CDialogScript::AddLine(TActorID actorID, AudioControlId audioID, const char* anim, const char* facial, TActorID lookAtTargetID, float delay, float facialWeight, float facialFadeTime, bool bLookAtSticky, bool bResetFacial, bool bResetLookAt, bool bSoundStopsAnim, bool bUseAGSignal, bool bUseAGEP)
  92. {
  93.         SScriptLine line;
  94.         line.m_actor = actorID;
  95.         line.m_lookatActor = lookAtTargetID;
  96.         line.m_audioID = audioID;
  97.         line.m_anim = anim;
  98.         line.m_facial = facial;
  99.         line.m_delay = delay;
  100.         line.m_facialWeight = facialWeight;
  101.         line.m_facialFadeTime = facialFadeTime;
  102.         line.m_flagLookAtSticky = bLookAtSticky;
  103.         line.m_flagResetFacial = bResetFacial;
  104.         line.m_flagResetLookAt = bResetLookAt;
  105.         line.m_flagSoundStopsAnim = bSoundStopsAnim;
  106.         line.m_flagAGSignal = bUseAGSignal;
  107.         line.m_flagAGEP = bUseAGEP;
  108.         line.m_flagUnused = 0;
  109.         return AddLine(line);
  110. }
  111.  
  112. ////////////////////////////////////////////////////////////////////////////
  113. // Add one line after another
  114. bool CDialogScript::AddLine(const SScriptLine& line)
  115. {
  116.         if (line.m_actor >= MAX_ACTORS)
  117.         {
  118.                 GameWarning("CDialogScript::AddLine: Script='%s' Cannot add line because actorID %d is out of range [0..%d]", m_id.c_str(), line.m_actor, MAX_ACTORS - 1);
  119.                 return false;
  120.         }
  121.  
  122.         if (line.m_lookatActor != NO_ACTOR_ID && (line.m_lookatActor >= MAX_ACTORS))
  123.         {
  124.                 GameWarning("CDialogScript::AddLine: Script='%s' Cannot add line because lookAtTargetID %d is out of range [0..%d]", m_id.c_str(), line.m_lookatActor, MAX_ACTORS - 1);
  125.                 return false;
  126.         }
  127.  
  128.         m_lines.push_back(line);
  129.         m_reqActorSet.SetActor(line.m_actor);
  130.         if (line.m_lookatActor != NO_ACTOR_ID)
  131.                 m_reqActorSet.SetActor(line.m_lookatActor);
  132.  
  133.         m_bComplete = false;
  134.         return true;
  135. }
  136.  
  137. ////////////////////////////////////////////////////////////////////////////
  138. // Call this after all lines have been added
  139. bool CDialogScript::Complete()
  140. {
  141.         m_bComplete = true;
  142.         return true;
  143. }
  144.  
  145. ////////////////////////////////////////////////////////////////////////////
  146. // Is the dialogscript completed
  147. bool CDialogScript::IsCompleted() const
  148. {
  149.         return m_bComplete;
  150. }
  151.  
  152. ////////////////////////////////////////////////////////////////////////////
  153. // Retrieves number of required actors
  154. int CDialogScript::GetNumRequiredActors() const
  155. {
  156.         if (m_bComplete == false)
  157.                 return 0;
  158.         return m_reqActorSet.NumActors();
  159. }
  160.  
  161. ////////////////////////////////////////////////////////////////////////////
  162. // Get number of dialog lines
  163. int CDialogScript::GetNumLines() const
  164. {
  165.         if (m_bComplete == false)
  166.                 return 0;
  167.         return m_lines.size();
  168. }
  169.  
  170. #if 0
  171. ////////////////////////////////////////////////////////////////////////////
  172. // Get a certain line
  173. const CDialogScript::SScriptLine& CDialogScript::GetLine(int index) const
  174. {
  175.         assert(index >= 0 && index < m_lines.size());
  176.         if (m_bComplete && index >= 0 && index < m_lines.size())
  177.                 return m_lines[index];
  178.         else return theEmptyScriptLine;
  179. }
  180. #endif
  181.  
  182. ////////////////////////////////////////////////////////////////////////////
  183. // Get a certain line
  184. const CDialogScript::SScriptLine* CDialogScript::GetLine(int index) const
  185. {
  186.         assert(index >= 0 && index < m_lines.size());
  187.         if (m_bComplete && index >= 0 && index < m_lines.size())
  188.                 return &m_lines[index];
  189.         else return 0;
  190. }
  191.  
  192. void CDialogScript::SetVersionFlags(uint32 which, bool bSet)
  193. {
  194.         if (bSet)
  195.                 m_versionFlags |= which;
  196.         else
  197.                 m_versionFlags &= ~which;
  198. }
  199.  
  200. void CDialogScript::GetMemoryUsage(ICrySizer* pSizer) const
  201. {
  202.         pSizer->AddObject(m_id);
  203.         pSizer->AddObject(m_desc);
  204.         pSizer->AddObject(m_lines);
  205. }
  206.  
downloadDialogScript.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