BVB Source Codes

CRYENGINE Show AIHash.h Source code

Return Download CRYENGINE: download AIHash.h Source code - Download CRYENGINE Source code - Type:.h
  1. // Copyright 2001-2016 Crytek GmbH / Crytek Group. All rights reserved.
  2.  
  3. #ifndef AI_HASH_H
  4. #define AI_HASH_H
  5.  
  6. //===================================================================
  7. // HashFromFloat
  8. //===================================================================
  9. ILINE size_t HashFromFloat(float key, float tol, float invTol)
  10. {
  11.         float val = key;
  12.  
  13.         if (tol > 0.0f)
  14.         {
  15.                 val *= invTol;
  16.                 val = floor_tpl(val);
  17.                 val *= tol;
  18.         }
  19.  
  20.         union f32_u
  21.         {
  22.                 float  floatVal;
  23.                 size_t uintVal;
  24.         };
  25.  
  26.         f32_u u;
  27.         u.floatVal = val;
  28.  
  29.         size_t hash = u.uintVal;
  30.         hash += ~(hash << 15);
  31.         hash ^= (hash >> 10);
  32.         hash += (hash << 3);
  33.         hash ^= (hash >> 6);
  34.         hash += ~(hash << 11);
  35.         hash ^= (hash >> 16);
  36.  
  37.         return hash;
  38. }
  39.  
  40. ILINE size_t HashFromUInt(size_t value)
  41. {
  42.         size_t hash = value;
  43.         hash += ~(hash << 15);
  44.         hash ^= (hash >> 10);
  45.         hash += (hash << 3);
  46.         hash ^= (hash >> 6);
  47.         hash += ~(hash << 11);
  48.         hash ^= (hash >> 16);
  49.  
  50.         return hash;
  51. }
  52.  
  53. //===================================================================
  54. // HashFromVec3
  55. //===================================================================
  56. inline size_t HashFromVec3(const Vec3& v, float tol, float invTol)
  57. {
  58.         return HashFromFloat(v.x, tol, invTol) + HashFromFloat(v.y, tol, invTol) + HashFromFloat(v.z, tol, invTol);
  59. }
  60.  
  61. //===================================================================
  62. // HashFromQuat
  63. //===================================================================
  64. inline size_t HashFromQuat(const Quat& q, float tol, float invTol)
  65. {
  66.         return HashFromFloat(q.v.x, tol, invTol) + HashFromFloat(q.v.y, tol, invTol) +
  67.                HashFromFloat(q.v.z, tol, invTol) + HashFromFloat(q.w, tol, invTol);
  68. }
  69.  
  70. //===================================================================
  71. // GetHashFromEntities
  72. //===================================================================
  73. inline size_t GetHashFromEntities(const IPhysicalEntity* const* entities, size_t entityCount)
  74. {
  75.         size_t hash = 0;
  76.         pe_status_pos status;
  77.  
  78.         for (size_t i = 0; i < entityCount; ++i)
  79.         {
  80.                 const IPhysicalEntity* entity = entities[i];
  81.                 entity->GetStatus(&status);
  82.  
  83.                 hash += HashFromUInt((size_t)(UINT_PTR)entity);
  84.                 hash += HashFromVec3(status.pos, 0.05f, 1.0f / 0.05f);
  85.                 hash += HashFromQuat(status.q, 0.01f, 1.0f / 0.01f);
  86.         }
  87.  
  88.         if (hash == 0)
  89.                 hash = 0x1337d00d;
  90.  
  91.         return hash;
  92. }
  93.  
  94. #endif // AI_HASH_H
  95.  
downloadAIHash.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