BVB Source Codes

CRYENGINE Show CentralInterestManager.h Source code

Return Download CRYENGINE: download CentralInterestManager.h Source code - Download CRYENGINE Source code - Type:.h
  1. // Copyright 2001-2016 Crytek GmbH / Crytek Group. All rights reserved.
  2.  
  3. /********************************************************************
  4.    ---------------------------------------------------------------------
  5.    File name:   CentralInterestManager.cpp
  6.    $Id$
  7.    $DateTime$
  8.    Description: Global manager that distributes interest events and
  9.              allows personal managers to work together
  10.              Effectively, this is the interface to the Interest System
  11.    ---------------------------------------------------------------------
  12.    History:
  13.    - 06:03:2007 : Created by Matthew Jack
  14.  
  15.  *********************************************************************/
  16.  
  17. #ifndef __CentralInterestManager_H__
  18. #define __CentralInterestManager_H__
  19.  
  20. #if _MSC_VER > 1000
  21.         #pragma once
  22. #endif
  23.  
  24. #include "PersonalInterestManager.h"
  25. #include <CryMemory/STLGlobalAllocator.h>
  26.  
  27. // Forward declarations
  28. struct IPersistantDebug;
  29.  
  30. // Basic structure for storing which objects are interesting and how much
  31. struct SEntityInterest
  32. {
  33.         SEntityInterest() :
  34.                 m_entityId(0), m_fRadius(0.f), m_fInterest(0.f), m_vOffset(ZERO), m_fPause(0.f), m_nbShared(0), m_eSupportedActorClasses(0)
  35.         {
  36.         }
  37.  
  38.         SEntityInterest(EntityId entityId, float fRadius, float fInterest, const char* szActionName, const Vec3& vOffset, float fPause, int nbShared)
  39.                 : m_entityId(0), m_fRadius(0.f), m_fInterest(0.f), m_vOffset(ZERO), m_fPause(0.f), m_nbShared(0), m_eSupportedActorClasses(0)
  40.         {
  41.                 Set(entityId, fRadius, fInterest, szActionName, vOffset, fPause, nbShared);
  42.         }
  43.  
  44.         ~SEntityInterest()
  45.         {
  46.                 Invalidate();
  47.         }
  48.  
  49.         bool Set(EntityId entityId, float fRadius, float fInterest, const char* szActionName, const Vec3& vOffset, float fPause, int nbShared);
  50.  
  51.         bool Set(const SEntityInterest& rhs)
  52.         {
  53.                 return Set(rhs.m_entityId, rhs.m_fRadius, rhs.m_fInterest, rhs.m_sActionName.c_str(), rhs.m_vOffset, rhs.m_fPause, rhs.m_nbShared);
  54.         }
  55.  
  56.         const char*    GetAction() const   { return m_sActionName.empty() ? "None" : m_sActionName.c_str(); }
  57.         void           SetAction(const char* szActionName);
  58.         const IEntity* GetEntity() const   { return gEnv->pEntitySystem->GetEntity(m_entityId); }
  59.         IEntity*       GetEntity()         { return gEnv->pEntitySystem->GetEntity(m_entityId); }
  60.         EntityId       GetEntityId() const { return m_entityId; }
  61.         bool           SupportsActorClass(const char* szActorClass) const;
  62.         bool           IsValid() const     { return m_entityId > 0; }
  63.  
  64.         void           Invalidate()
  65.         {
  66.                 IEntity* pEntity = GetEntity();
  67.                 if (pEntity && gAIEnv.pSmartObjectManager)
  68.                 {
  69.                         gAIEnv.pSmartObjectManager->RemoveSmartObjectState(pEntity, "Registered");
  70.                 }
  71.                 m_entityId = 0;
  72.                 m_sActionName = string();
  73.         }
  74.  
  75.         void Serialize(TSerialize ser)
  76.         {
  77.                 ser.Value("entityId", m_entityId);
  78.                 ser.Value("fRadius", m_fRadius);
  79.                 ser.Value("fInterest", m_fInterest);
  80.                 ser.Value("sActionName", m_sActionName);
  81.                 ser.Value("vOffset", m_vOffset);
  82.                 ser.Value("fPause", m_fPause);
  83.                 ser.Value("nbShared", m_nbShared);
  84.                 ser.Value("m_eSupportedActorClasses", m_eSupportedActorClasses);
  85.         }
  86.  
  87.         EntityId m_entityId;
  88.         float    m_fRadius;
  89.         float    m_fInterest;
  90.         string   m_sActionName;
  91.         Vec3     m_vOffset;
  92.         float    m_fPause;
  93.         int      m_nbShared;
  94.  
  95.         enum
  96.         {
  97.                 eACTOR_CLASS_HUMAN_GRUNT   = 1 << 0,
  98.                 eACTOR_CLASS_ALIEN_GRUNT   = 1 << 1,
  99.                 eACTOR_CLASS_ALIEN_STALKER = 1 << 2,
  100.         };
  101.  
  102.         int m_eSupportedActorClasses;
  103. };
  104.  
  105. // There need only ever be one of these in game, hence a singleton
  106. // Created on first request, which is lightweight
  107.  
  108. class CCentralInterestManager :
  109.         public ICentralInterestManager,
  110.         public IEntitySystemSink,
  111.         public IEntityEventListener
  112. {
  113. public:
  114.         // Get the CIM singleton
  115.         static CCentralInterestManager* GetInstance();
  116.  
  117.         // Reset the CIM system
  118.         // Do this when all caches should be emptied, e.g. on loading levels
  119.         // Resetting during game should do no serious harm
  120.         virtual void Reset();
  121.  
  122.         // Enable or disable (suppress) the interest system
  123.         virtual bool Enable(bool bEnable);
  124.  
  125.         // Is the Interest System enabled?
  126.         virtual bool IsEnabled()          { return m_bEnabled; }
  127.  
  128.         bool         IsDebuggingEnabled() { return m_cvDebugInterest ? (m_cvDebugInterest->GetIVal() != 0) : false; }
  129.  
  130.         // Update the CIM
  131.         virtual void Update(float fDelta);
  132.  
  133.         void         Serialize(TSerialize ser);
  134.  
  135.         // Deregister an interesting entity
  136.         virtual void DeregisterInterestingEntity(IEntity* pEntity);
  137.  
  138.         virtual void ChangeInterestingEntityProperties(IEntity* pEntity, float fRadius = -1.f, float fBaseInterest = -1.f, const char* szActionName = NULL, const Vec3& vOffset = Vec3Constants<float>::fVec3_Zero, float fPause = -1.f, int nbShared = -1);
  139.         virtual void ChangeInterestedAIActorProperties(IEntity* pEntity, float fInterestFilter = -1.f, float fAngleCos = -1.f);
  140.  
  141.         // Deregister a potential interested AI Actor
  142.         virtual bool DeregisterInterestedAIActor(IEntity* pEntity);
  143.  
  144.         // Central shared debugging function, should really be a private/friend of PIM
  145.         void AddDebugTag(EntityId id, const char* szString, float fTime = -1.f);
  146.  
  147.         // Add a class to be notified when an entity is interested or interesting
  148.         virtual void RegisterListener(IInterestListener* pInterestListener, EntityId idInterestingEntity);
  149.         virtual void UnRegisterListener(IInterestListener* pInterestListener, EntityId idInterestingEntity);
  150.  
  151.         //-------------------------------------------------------------
  152.         // IEntitySystemSink methods, for listening to moving entities
  153.         //-------------------------------------------------------------
  154.         virtual bool OnBeforeSpawn(SEntitySpawnParams&) { return true; }
  155.         virtual void OnSpawn(IEntity* pEntity, SEntitySpawnParams&);
  156.         virtual bool OnRemove(IEntity* pEntity);
  157.         virtual void OnReused(IEntity* pEntity, SEntitySpawnParams& entitySpawnParams) {}
  158.         virtual void OnEvent(IEntity* pEntity, SEntityEvent& entityEvent)              {}
  159.  
  160.         // IEntityEventListener
  161.         virtual void OnEntityEvent(IEntity* pEntity, SEntityEvent& event);
  162.         // End of IEntityEventListener
  163.  
  164.         // Expose for DebugDraw
  165.         typedef std::deque<CPersonalInterestManager, stl::STLGlobalAllocator<CPersonalInterestManager>> TVecPIMs;
  166.         const TVecPIMs* GetPIMs() const { return &m_PIMs; }
  167.  
  168.         // Expose for PIMs
  169.         typedef std::vector<SEntityInterest, stl::STLGlobalAllocator<SEntityInterest>> TVecInteresting;
  170.         TVecInteresting*          GetInterestingEntities()       { return &m_InterestingEntities; }
  171.         const TVecInteresting*    GetInterestingEntities() const { return &m_InterestingEntities; }
  172.  
  173.         CPersonalInterestManager* FindPIM(IEntity* pEntity);
  174.  
  175. protected:
  176.         friend class CPersonalInterestManager;
  177.  
  178.         void OnInterestEvent(IInterestListener::EInterestEvent eInterestEvent, EntityId idActor, EntityId idInterestingEntity);
  179.         bool CanCastRays() { return m_cvCastRays ? (m_cvCastRays->GetIVal()) != 0 : false; }
  180.  
  181. private:
  182.         // Construct/destruct
  183.         CCentralInterestManager();
  184.         ~CCentralInterestManager();
  185.  
  186.         bool RegisterInterestingEntity(IEntity* pEntity, float fRadius = -1.f, float fBaseInterest = -1.f, const char* szActionName = NULL, const Vec3& vOffset = Vec3Constants<float>::fVec3_Zero, float fPause = -1.f, int nbShared = -1);
  187.         bool RegisterInterestedAIActor(IEntity* pEntity, bool bEnablePIM, float fInterestFilter = -1.f, float fAngleCos = -1.f);
  188.  
  189.         void RegisterObject(IEntity* pEntity);
  190.         void DeregisterObject(IEntity* pEntity);
  191.  
  192.         void RegisterFromTable(IEntity* pEntity, const SmartScriptTable& ssTable);
  193.         void RegisterEntityFromTable(IEntity* pEntity, const SmartScriptTable& ssTable);
  194.         void RegisterActorFromTable(IEntity* pEntity, const SmartScriptTable& ssTable);
  195.  
  196.         bool GatherData(IEntity* pEntity, SActorInterestSettings& actorInterestSettings);
  197.         bool GatherData(IEntity* pEntity, SEntityInterest& entityInterest);
  198.  
  199.         bool ReadDataFromTable(const SmartScriptTable& ssTable, SEntityInterest& entityInterest);
  200.         bool ReadDataFromTable(const SmartScriptTable& ssTable, SActorInterestSettings& actorInterestSettings);
  201.  
  202.         void Init();                                        // Initialise as defaults
  203.  
  204. private:
  205.         // Basic
  206.         static CCentralInterestManager* m_pCIMInstance;     // The singleton
  207.         bool                            m_bEnabled;         // Toggle Interest system on/off
  208.         bool                            m_bEntityEventListenerInstalled;
  209.  
  210.         typedef std::multimap<EntityId, IInterestListener*> TMapListeners;
  211.  
  212.         // The tracking lists
  213.         TVecPIMs        m_PIMs;                   // Instantiated PIMs, no NULL, some can be unassigned
  214.         TVecInteresting m_InterestingEntities;    // Interesting objects we might consider pointing out to PIMs
  215.         TMapListeners   m_Listeners;              // Listeners to be notified when an entity is interested OR interesting
  216.  
  217.         // Performance
  218.         uint32 m_lastUpdated;
  219.         float  m_fUpdateTime;
  220.  
  221.         // Debug
  222.         ICVar*            m_cvDebugInterest;
  223.         ICVar*            m_cvCastRays;
  224.         IPersistantDebug* m_pPersistentDebug;     // The persistent debugging framework
  225. };
  226.  
  227. #endif // __CentralInterestManager_H__
  228.  
downloadCentralInterestManager.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