BVB Source Codes

CRYENGINE Show CoverSystem.h Source code

Return Download CRYENGINE: download CoverSystem.h Source code - Download CRYENGINE Source code - Type:.h
  1. // Copyright 2001-2016 Crytek GmbH / Crytek Group. All rights reserved.
  2.  
  3. #ifndef __CoverSystem_h__
  4. #define __CoverSystem_h__
  5.  
  6. #pragma once
  7.  
  8. #include "Cover.h"
  9. #include "CoverSurface.h"
  10. #include "DynamicCoverManager.h"
  11.  
  12. #include <CryAISystem/HashGrid.h>
  13.  
  14. struct CachedCoverLocationValues
  15. {
  16.         CachedCoverLocationValues()
  17.                 : location(ZERO)
  18.                 , normal(ZERO)
  19.                 , height(.0f)
  20.         {};
  21.  
  22.         Vec3  location;
  23.         Vec3  normal;
  24.         float height;
  25. };
  26.  
  27. typedef VectorMap<CoverID, CachedCoverLocationValues> CoverLocationCache;
  28.  
  29. class CCoverSystem
  30.         : public ICoverSystem
  31. {
  32.         enum
  33.         {
  34.                 PreallocatedDynamicCount = 64,
  35.         };
  36. public:
  37.         CCoverSystem(const char* configFileName);
  38.         ~CCoverSystem();
  39.  
  40.         typedef std::vector<CoverID> CoverCollection;
  41.  
  42.         // ICoverSystem
  43.         virtual ICoverSampler* CreateCoverSampler(const char* samplerName = "default");
  44.  
  45.         virtual bool           ReloadConfig();
  46.  
  47.         virtual void           Reset();
  48.         virtual void           Clear();
  49.         virtual bool           ReadSurfacesFromFile(const char* fileName);
  50.  
  51.         virtual void           BreakEvent(const Vec3& position, float radius);
  52.         virtual void           AddCoverEntity(EntityId entityID);
  53.         virtual void           RemoveCoverEntity(EntityId entityID);
  54.  
  55.         virtual CoverSurfaceID AddSurface(const SurfaceInfo& surfaceInfo);
  56.         virtual void           RemoveSurface(const CoverSurfaceID& surfaceID);
  57.         virtual void           UpdateSurface(const CoverSurfaceID& surfaceID, const SurfaceInfo& surfaceInfo);
  58.  
  59.         virtual uint32         GetSurfaceCount() const;
  60.         virtual bool           GetSurfaceInfo(const CoverSurfaceID& surfaceID, SurfaceInfo* surfaceInfo) const;
  61.  
  62.         virtual void           SetCoverOccupied(const CoverID& coverID, bool occupied, const tAIObjectID& occupant);
  63.         virtual bool           IsCoverOccupied(const CoverID& coverID) const;
  64.         virtual tAIObjectID    GetCoverOccupant(const CoverID& coverID) const;
  65.  
  66.         virtual uint32         GetCover(const Vec3& center, float range, const Vec3* eyes, uint32 eyeCount, float distanceToCover,
  67.                                         Vec3* locations, uint32 maxLocationCount, uint32 maxLocationsPerSurface) const;
  68.  
  69.         virtual void DrawSurface(const CoverSurfaceID& surfaceID);
  70.         //~ICoverSystem
  71.  
  72.         void                      Update(float updateTime);
  73.         void                      DebugDraw();
  74.  
  75.         bool                      IsDynamicSurfaceEntity(IEntity* entity) const;
  76.  
  77.         ILINE const CoverSurface& GetCoverSurface(const CoverID& coverID) const
  78.         {
  79.                 return m_surfaces[(coverID >> CoverIDSurfaceIDShift) - 1];
  80.         }
  81.  
  82.         ILINE const CoverSurface& GetCoverSurface(const CoverSurfaceID& surfaceID) const
  83.         {
  84.                 return m_surfaces[surfaceID - 1];
  85.         }
  86.  
  87.         ILINE CoverSurface& GetCoverSurface(const CoverSurfaceID& surfaceID)
  88.         {
  89.                 return m_surfaces[surfaceID - 1];
  90.         }
  91.  
  92.         ILINE const CoverPath& GetCoverPath(const CoverSurfaceID& surfaceID, float distanceToCover) const
  93.         {
  94.                 return CacheCoverPath(surfaceID, m_surfaces[surfaceID - 1], distanceToCover);
  95.         }
  96.  
  97.         ILINE uint32 GetCover(const Vec3& center, float radius, CoverCollection& locations) const
  98.         {
  99.                 return m_locations.query_sphere(center, radius, locations);
  100.         }
  101.  
  102.         ILINE Vec3 GetCoverLocation(const CoverID& coverID, float offset = 0.0f, float* height = 0, Vec3* normal = 0) const
  103.         {
  104.                 return GetAndCacheCoverLocation(coverID, offset, height, normal);
  105.         }
  106.  
  107.         ILINE CoverID GetCoverID(const CoverSurfaceID& surfaceID, uint16 location) const
  108.         {
  109.                 return CoverID((surfaceID << CoverIDSurfaceIDShift) | location);
  110.         }
  111.  
  112.         ILINE uint16 GetLocationID(const CoverID& coverID) const
  113.         {
  114.                 return (coverID & CoverIDLocationIDMask);
  115.         }
  116.  
  117.         ILINE CoverSurfaceID GetSurfaceID(const CoverID& coverID) const
  118.         {
  119.                 return CoverSurfaceID(coverID >> CoverIDSurfaceIDShift);
  120.         }
  121.  
  122. private:
  123.         void             AddLocations(const CoverSurfaceID& surfaceID, const CoverSurface& surface);
  124.         void             RemoveLocations(const CoverSurfaceID& surfaceID, const CoverSurface& surface);
  125.         void             AddDynamicSurface(const CoverSurfaceID& surfaceID, const CoverSurface& surface);
  126.         void             ResetDynamicSurface(const CoverSurfaceID& surfaceID, CoverSurface& surface);
  127.         void             ResetDynamicCover();
  128.         void             NotifyCoverUsers(const CoverSurfaceID& surfaceID);
  129.  
  130.         Vec3             GetAndCacheCoverLocation(const CoverID& coverID, float offset = 0.0f, float* height = 0, Vec3* normal = 0) const;
  131.         void             ClearAndReserveCoverLocationCache();
  132.  
  133.         const CoverPath& CacheCoverPath(const CoverSurfaceID& surfaceID, const CoverSurface& surface, float distanceToCover) const;
  134.  
  135.         typedef std::vector<CoverSurface> Surfaces;
  136.         Surfaces m_surfaces;
  137.  
  138.         struct location_position
  139.         {
  140.                 Vec3 operator()(const CoverID& coverID) const
  141.                 {
  142.                         return gAIEnv.pCoverSystem->GetCoverLocation(coverID, 0.0f);
  143.                 }
  144.         };
  145.  
  146.         typedef hash_grid<256, CoverID, hash_grid_2d<Vec3, Vec3i>, location_position> Locations;
  147.         Locations m_locations;
  148.  
  149.         typedef std::map<float, CoverPath> Paths;
  150.  
  151.         struct PathCacheEntry
  152.         {
  153.                 CoverSurfaceID surfaceID;
  154.                 Paths          paths;
  155.         };
  156.  
  157.         typedef std::deque<PathCacheEntry> PathCache;
  158.         mutable PathCache       m_pathCache;
  159.  
  160.         mutable CoverCollection m_externalQueryBuffer;
  161.  
  162.         typedef std::unordered_map<CoverID, tAIObjectID, stl::hash_uint32> OccupiedCover;
  163.         OccupiedCover m_occupied;
  164.  
  165.         typedef std::vector<CoverSurfaceID> FreeIDs;
  166.         FreeIDs m_freeIDs;
  167.  
  168.         typedef std::vector<IEntityClass*> DynamicSurfaceEntityClasses;
  169.         DynamicSurfaceEntityClasses m_dynamicSurfaceEntityClasses;
  170.  
  171.         DynamicCoverManager         m_dynamicCoverManager;
  172.  
  173.         string                      m_configName;
  174.  
  175.         mutable CoverLocationCache  m_coverLocationCache;
  176. };
  177.  
  178. #endif //__CoverSystem_h__
  179.  
downloadCoverSystem.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