BVB Source Codes

CRYENGINE Show DialogSession.h Source code

Return Download CRYENGINE: download DialogSession.h Source code - Download CRYENGINE Source code - Type:.h
  1. // Copyright 2001-2016 Crytek GmbH / Crytek Group. All rights reserved.
  2.  
  3. // -------------------------------------------------------------------------
  4. //  File name:   DialogSession.h
  5. //  Version:     v1.00
  6. //  Created:     07/07/2006 by AlexL
  7. //  Compilers:   Visual Studio.NET
  8. //  Description: Dialog System
  9. // -------------------------------------------------------------------------
  10. //  History:
  11. //
  12. ////////////////////////////////////////////////////////////////////////////
  13.  
  14. #ifndef __DIALOGSESSION_H__
  15. #define __DIALOGSESSION_H__
  16.  
  17. #pragma once
  18.  
  19. #include "DialogScript.h"
  20. #include "DialogSystem.h"
  21. #include <CryNetwork/SerializeFwd.h>
  22.  
  23. struct IDialogSessionListener;
  24. class CDialogActorContext;
  25.  
  26. // A Dialog Session uses a DialogScript together with dialog parameters
  27. // to play the script
  28. class CDialogSession
  29. {
  30. public:
  31.         typedef _smart_ptr<CDialogActorContext>                           CDialogActorContextPtr;
  32.         typedef std::map<CDialogScript::TActorID, EntityId>               TIdToEntityMap;
  33.         typedef std::vector<IDialogSessionListener*>                      TListenerVec;
  34.         typedef std::map<CDialogScript::TActorID, CDialogActorContextPtr> TActorContextMap;
  35.         typedef uint16                                                    TActorFlags;
  36.  
  37.         enum EDialogSessionEvent
  38.         {
  39.                 eDSE_SessionStart = 0, // Session is about to be started
  40.                 eDSE_EndOfDialog,      // Session stopped normally
  41.                 eDSE_UserStopped,      // Session stopped on user request
  42.                 eDSE_Aborted,          // Session aborted
  43.                 eDSE_SessionDeleted,   // Session is Deleted
  44.                 eDSE_LineStarted       // Called when a new line starts to play
  45.         };
  46.  
  47.         enum EAbortReason
  48.         {
  49.                 eAR_None = 0,          // Not aborted
  50.                 eAR_ActorDead,         // Actor died during dialog
  51.                 eAR_AIAborted,         // AI aborted it
  52.                 eAR_PlayerOutOfRange,  // Player was not aware
  53.                 eAR_PlayerOutOfView,   // Player out of view
  54.                 eAR_EntityDestroyed    // Entity was destroyed/removed
  55.         };
  56.  
  57.         enum EDialogActorContextFlags
  58.         {
  59.                 eDACF_None             = 0x0000,
  60.                 eDACF_NoAIAbort        = 0x0001,  // Don't abort when AI selects different goal pipe
  61.                 eDACF_NoAbortSound     = 0x0002,  // Don't abort sound when AI/Player aborts. But if actor dies, sound is aborted anyway!
  62.                 eDACF_NoActorDeadAbort = 0x0004,  // Don't abort when an Actor is dead
  63.  
  64.                 eDACF_Default          = eDACF_None
  65.         };
  66.  
  67.         enum EDialogAIInterruptBehaviour
  68.         {
  69.                 eDIB_InterruptAlways = 0,     // ACT_ANIM signal and interrupt by goal-pipe deselection
  70.                 eDIB_InterruptMedium = 1,     // ACT_DIALOG signal and interrupt by goal-pipe deselection
  71.                 eDIB_InterruptNever  = 2,     // no signal, and no animation/lookat possible
  72.         };
  73.  
  74.         enum AlertnessInterruptMode
  75.         {
  76.                 None   = 0,
  77.                 Alert  = 1,
  78.                 Combat = 2,
  79.         };
  80.  
  81. public:
  82.         bool SetActor(CDialogScript::TActorID actorID, EntityId id);
  83.  
  84.         // Call this after all params have been setup. Will be called by Play as well.
  85.         bool Validate();
  86.  
  87.         // All params o.k.
  88.         bool IsOK() const { return m_bOK; }
  89.  
  90.         // Play the Session [advanced usage can
  91.         bool Play(int fromScriptLine = 0);
  92.  
  93.         // Stop the Session
  94.         bool Stop();
  95.  
  96.         // Delete the Session when stopped manually, aborted, ...
  97.         void SetAutoDelete(bool bAutoDelete);
  98.  
  99.         void SetPlayerAwarenessDistance(float distance)
  100.         {
  101.                 m_playerAwareDistance = distance;
  102.         }
  103.  
  104.         void SetPlayerAwarenessAngle(float angleDeg)
  105.         {
  106.                 m_playerAwareAngle = angleDeg;
  107.         }
  108.  
  109.         void GetPlayerAwarenessValues(float& distance, float& angleDeg) const
  110.         {
  111.                 distance = m_playerAwareDistance;
  112.                 angleDeg = m_playerAwareAngle;
  113.         }
  114.  
  115.         float GetPlayerAwarenessGraceTime() const
  116.         {
  117.                 return m_playerAwareGraceTime;
  118.         }
  119.  
  120.         void SetPlayerAwarenessGraceTime(float graceTime)
  121.         {
  122.                 m_playerAwareGraceTime = graceTime;
  123.         }
  124.  
  125.         void        SetActorFlags(CDialogScript::TActorID actorID, TActorFlags inFlags);
  126.         TActorFlags GetActorFlags(CDialogScript::TActorID actorID) const;
  127.  
  128.         void        SetAIBehaviourMode(EDialogAIInterruptBehaviour mode)
  129.         {
  130.                 assert(m_bPlaying == false);
  131.                 if (m_bPlaying)
  132.                         return;
  133.                 m_aiBehaviourMode = mode;
  134.         }
  135.  
  136.         EDialogAIInterruptBehaviour GetAIBehaviourMode() const
  137.         {
  138.                 return (EDialogAIInterruptBehaviour) m_aiBehaviourMode;
  139.         }
  140.  
  141.         int                      GetCurrentLine() const     { return m_curScriptLine; }
  142.         CDialogScript::SActorSet GetCurrentActorSet() const { return m_actorSet; }
  143.         const CDialogScript*     GetScript() const          { return m_pScript; }
  144.  
  145.         const char*              GetEventName(EDialogSessionEvent event);
  146.  
  147.         bool                     AddListener(IDialogSessionListener* pListener);
  148.         bool                     RemoveListener(IDialogSessionListener* pListener);
  149.  
  150.         CDialogSystem::SessionID GetSessionID() const   { return m_sessionID; }
  151.         EAbortReason             GetAbortReason() const { return m_abortReason; }
  152.         EAbortReason             GetAbortReasonForActor(CDialogScript::TActorID actorID) const;
  153.  
  154.         // used by CDialogActorContext
  155.         CDialogActorContextPtr  GetContext(CDialogScript::TActorID actorID) const;
  156.         CDialogActorContextPtr  GetContext(CDialogSystem::ActorContextID contextID) const;
  157.         const TActorContextMap& GetAllContexts() const { return m_actorContextMap; }
  158.  
  159.         IEntity*                GetActorEntity(CDialogScript::TActorID actorID) const;
  160.         EntityId                GetActorEntityId(CDialogScript::TActorID actorID) const;
  161.         CDialogScript::TActorID GetActorIdForEntity(EntityId entityId) const;
  162.         IEntityAudioComponent*      GetEntityAudioProxy(IEntity* pEntity) const;
  163.         int                     ScheduleNextLine(float dt); // schedule next line to be played. returns index of line
  164.         float                   GetCurTime() const
  165.         {
  166.                 return m_curTime;
  167.         }
  168.         const char* GetDebugName() const { return m_debugName.c_str(); }
  169.  
  170.         void        GetMemoryUsage(ICrySizer* pSizer) const;
  171.  
  172.         void        SetAlertnessInterruptMode(AlertnessInterruptMode alertnessInterruptMode)
  173.         {
  174.                 m_alertnessInterruptMode = alertnessInterruptMode;
  175.         }
  176.  
  177.         AlertnessInterruptMode GetAlertnessInterruptMode() const
  178.         {
  179.                 return m_alertnessInterruptMode;
  180.         }
  181.  
  182. protected:
  183.         friend class CDialogSystem;
  184.  
  185.         CDialogSession(CDialogSystem* pDS, const CDialogScript* pScript, CDialogSystem::SessionID id);
  186.         ~CDialogSession();
  187.  
  188.         // Deletes this session. Called from CDialogSystem
  189.         void Release();
  190.  
  191.         // Called from CDialogSystem to update every frame
  192.         bool Update(float dt);
  193.  
  194.         // Called from CDialogSystem after serialization
  195.         bool RestoreAndPlay();
  196.  
  197.         bool InternalPlay(int fromScriptLine, bool bNotify);
  198.  
  199.         void DoPlay(float dt);
  200.         bool PlayLine(const CDialogScript::SScriptLine* pLine);
  201.  
  202.         bool DoStop();
  203.  
  204.         void NotifyListeners(EDialogSessionEvent event);
  205.  
  206.         void Serialize(TSerialize ser);
  207. protected:
  208.         IEntitySystem*           m_pEntitySystem;
  209.         CDialogSystem*           m_pDS;
  210.         const CDialogScript*     m_pScript;
  211.         TIdToEntityMap           m_idToEntityMap;
  212.         TListenerVec             m_listenerVec;
  213.         TListenerVec             m_listenerVecTemp;
  214.         TActorContextMap         m_actorContextMap;
  215.         CDialogSystem::SessionID m_sessionID;
  216.         string                   m_debugName;
  217.         CDialogScript::SActorSet m_actorSet;
  218.  
  219.         float                    m_curTime;
  220.         float                    m_nextTimeDelay;
  221.         float                    m_endGraceTimeOut;
  222.         int                      m_curScriptLine;
  223.         int                      m_nextScriptLine;
  224.         int                      m_pendingActors;
  225.         EAbortReason             m_abortReason;
  226.  
  227.         float                    m_playerAwareAngle;
  228.         float                    m_playerAwareDistance;
  229.         float                    m_playerAwareGraceTime;
  230.  
  231.         TActorFlags              m_actorFlags[CDialogScript::MAX_ACTORS];
  232.         int8                     m_aiBehaviourMode;
  233.  
  234.         uint16                   m_bPlaying      : 1;  // currently playing
  235.         uint16                   m_bValidated    : 1;  // session is validated (does not mean ok, though)
  236.         uint16                   m_bOK           : 1;  // session validated & ok
  237.         uint16                   m_bHaveSchedule : 1;  // new line scheduled
  238.         uint16                   m_bAutoDelete   : 1;  // auto delete session when stopped/aborted: false by default
  239.         uint16                   m_bReachedEnd   : 1;  // whether dialog has reached end [may still wait for pending contexts]
  240.         uint16                   m_bFirstUpdate  : 1;  // first update done
  241.  
  242.         AlertnessInterruptMode   m_alertnessInterruptMode;
  243. };
  244.  
  245. struct IDialogSessionListener
  246. {
  247.         virtual ~IDialogSessionListener(){}
  248.         virtual void SessionEvent(CDialogSession* pSession, CDialogSession::EDialogSessionEvent event) = 0;
  249.         void         GetMemoryUsage(ICrySizer* pSizer) const {}
  250. };
  251.  
  252. #endif
  253.  
downloadDialogSession.h 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