BVB Source Codes

CRYENGINE Show ProceduralClipAISignal.cpp Source code

Return Download CRYENGINE: download ProceduralClipAISignal.cpp Source code - Download CRYENGINE Source code - Type:.cpp
  1. // Copyright 2001-2016 Crytek GmbH / Crytek Group. All rights reserved.
  2.  
  3. //
  4. ////////////////////////////////////////////////////////////////////////////
  5.  
  6. #include "StdAfx.h"
  7.  
  8. #include "ICryMannequin.h"
  9. #include <CryAISystem/IAIObject.h>
  10. #include <CryAISystem/IAIActor.h>
  11.  
  12. #include <Mannequin/Serialization.h>
  13.  
  14. struct SProceduralClipAISignalParams
  15.         : public IProceduralParams
  16. {
  17.         TProcClipString dataString;
  18.  
  19.         virtual void Serialize(Serialization::IArchive& ar) override
  20.         {
  21.                 ar(dataString, "EnterAndExitSignalNames", "EnterAndExitSignalNames");
  22.         }
  23.  
  24.         virtual void GetExtraDebugInfo(StringWrapper& extraInfoOut) const override
  25.         {
  26.                 extraInfoOut = dataString.c_str();
  27.         }
  28. };
  29.  
  30. // This procedural clip will send a signal directly to the AI actor interface
  31. // of the entity on which the clip is playing.
  32. class CProceduralClipAISignal : public TProceduralClip<SProceduralClipAISignalParams>
  33. {
  34. public:
  35.  
  36.         CProceduralClipAISignal()
  37.         {
  38.         }
  39.  
  40.         virtual void OnEnter(float blendTime, float duration, const SProceduralClipAISignalParams& params)
  41.         {
  42.                 // TODO: Temporary work-around: we need to be able to store 2 signal
  43.                 // names because the params.dataCRC string is not available in
  44.                 // release/console builds, and also used a CRC generator that is
  45.                 // incompatible with the one used by the AI signal systems.
  46.                 // This work-around uses a separator '|' character, so that we don't
  47.                 // need to add extra string support throughout the Mannequin editors and
  48.                 // such.
  49.                 CryFixedStringT<64> onEnterSignalName;
  50.                 ExtractSignalNames(params.dataString.c_str(), &onEnterSignalName, &m_onExitSignalName);
  51.  
  52.                 IAIActor* aiActor = GetAIActor();
  53.                 IF_UNLIKELY (aiActor == NULL)
  54.                 {
  55.                         return;
  56.                 }
  57.  
  58.                 if (!onEnterSignalName.empty())
  59.                 {
  60.                         aiActor->SetSignal(
  61.                           AISIGNAL_DEFAULT,
  62.                           onEnterSignalName.c_str(),
  63.                           NULL,  // Sender.
  64.                           NULL); // No additional data.
  65.                 }
  66.         }
  67.  
  68.         virtual void OnExit(float blendTime)
  69.         {
  70.                 if (m_onExitSignalName.empty())
  71.                 {
  72.                         return;
  73.                 }
  74.  
  75.                 IAIActor* aiActor = GetAIActor();
  76.                 IF_UNLIKELY (aiActor == NULL)
  77.                 {
  78.                         return;
  79.                 }
  80.  
  81.                 aiActor->SetSignal(
  82.                   AISIGNAL_DEFAULT,
  83.                   m_onExitSignalName.c_str(),
  84.                   NULL,  // Sender.
  85.                   NULL); // No additional data.
  86.         }
  87.  
  88.         virtual void Update(float timePassed) {}
  89.  
  90. private:
  91.  
  92.         IAIActor* GetAIActor() const
  93.         {
  94.                 IF_UNLIKELY (m_entity == NULL)
  95.                 {
  96.                         return NULL;
  97.                 }
  98.                 IAIObject* aiObject = m_entity->GetAI();
  99.                 IF_UNLIKELY (aiObject == NULL)
  100.                 {
  101.                         return NULL;
  102.                 }
  103.                 return aiObject->CastToIAIActor();
  104.         }
  105.  
  106.         // TODO: Create proper separate signal names in the procedural clip.
  107.         inline void ExtractSignalNames(const char* dataString, CryFixedStringT<64>* onEnterSignalString, CryFixedStringT<64>* onExitSignalString)
  108.         {
  109.                 assert(onEnterSignalString != NULL);
  110.                 assert(onExitSignalString != NULL);
  111.  
  112.                 // It is allowed to omit any of the signal names in the data string.
  113.                 onEnterSignalString->clear();
  114.                 onExitSignalString->clear();
  115.  
  116.                 IF_UNLIKELY (dataString == NULL)
  117.                 {
  118.                         return;
  119.                 }
  120.  
  121. #if !defined(_RELEASE)
  122.                 const char* dataStringStart = dataString;
  123. #endif
  124.                 char chr;
  125.                 while ((chr = *dataString) != '\0')
  126.                 {
  127.                         if (chr == '|')
  128.                         {
  129.                                 // Switch to parsing the exit signal name.
  130.                                 break;
  131.                         }
  132.                         *onEnterSignalString += chr;
  133.                         dataString++;
  134.                 }
  135. #if !defined(_RELEASE)
  136.                 assert((dataString - dataStringStart) < onExitSignalString->MAX_SIZE);
  137. #endif
  138.                 if (chr == '\0')
  139.                 {
  140.                         // No exit signal name specified apparently.
  141.                         return;
  142.                 }
  143.  
  144.                 dataString++; // Skip the separator character.
  145.  
  146. #if !defined(_RELEASE)
  147.                 assert(strlen(dataString) <= onExitSignalString->MAX_SIZE);
  148. #endif
  149.  
  150.                 *onExitSignalString = dataString;
  151.                 return;
  152.         }
  153.  
  154. private:
  155.  
  156.         CryFixedStringT<64> m_onExitSignalName;
  157. };
  158.  
  159. REGISTER_PROCEDURAL_CLIP(CProceduralClipAISignal, "AISignal");
  160.  
downloadProceduralClipAISignal.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