BVB Source Codes

CRYENGINE Show SerializeDirHelper.h Source code

Return Download CRYENGINE: download SerializeDirHelper.h Source code - Download CRYENGINE Source code - Type:.h
  1. // Copyright 2001-2016 Crytek GmbH / Crytek Group. All rights reserved.
  2.  
  3. #ifndef __DIR_SERIALIZE_HELPER_H__
  4. #define __DIR_SERIALIZE_HELPER_H__
  5.  
  6. #include "SerializeBits.h"
  7.  
  8. // Ideaally this could go into the network layer as a policy
  9.  
  10. static inline void SerializeDirHelper(TSerialize ser, Vec3& dir, int policyYaw, int policyElev)
  11. {
  12.         // Serialise look direction as yaw and elev. Gives better compression
  13.         float yaw, elev;
  14.  
  15.         if (!ser.IsReading())
  16.         {
  17.                 float xy = dir.GetLengthSquared2D();
  18.                 if (xy > 0.001f)
  19.                 {
  20.                         yaw = atan2_tpl(dir.y, dir.x);
  21.                         elev = asin_tpl(dir.z);
  22.                 }
  23.                 else
  24.                 {
  25.                         yaw = 0.f;
  26.                         elev = (float)__fsel(dir.z, +1.f, -1.f) * (gf_PI * 0.5f);
  27.                 }
  28.         }
  29.  
  30.         ser.Value("playerLookYaw", yaw, policyYaw);
  31.         ser.Value("playerLookElev", elev, policyElev);
  32.  
  33.         if (ser.IsReading())
  34.         {
  35.                 float sinYaw, cosYaw;
  36.                 float sinElev, cosElev;
  37.  
  38.                 sincos_tpl(yaw, &sinYaw, &cosYaw);
  39.                 sincos_tpl(elev, &sinElev, &cosElev);
  40.  
  41.                 dir.x = cosYaw * cosElev;
  42.                 dir.y = sinYaw * cosElev;
  43.                 dir.z = sinElev;
  44.         }
  45. }
  46.  
  47. static inline void SerializeDirHelper(CBitArray& array, Vec3& dir, int nYawBits, int nElevBits)
  48. {
  49.         // Serialise look direction as yaw and elev. Gives better compression
  50.         float yaw, elev;
  51.  
  52.         if (array.IsReading() == 0)
  53.         {
  54.                 float xy = dir.GetLengthSquared2D();
  55.                 if (xy > 0.001f)
  56.                 {
  57.                         yaw = atan2_tpl(dir.y, dir.x);
  58.                         elev = asin_tpl(dir.z);
  59.                 }
  60.                 else
  61.                 {
  62.                         yaw = 0.f;
  63.                         elev = (float)__fsel(dir.z, +1.f, -1.f) * (gf_PI * 0.5f);
  64.                 }
  65.         }
  66.  
  67.         array.Serialize(yaw, -gf_PI, +gf_PI, nYawBits, 1);    // NB: reduce range by 1 so that zero is correctly replicated
  68.         array.Serialize(elev, -gf_PI * 0.5f, +gf_PI * 0.5f, nElevBits, 1);
  69.  
  70.         if (array.IsReading())
  71.         {
  72.                 float sinYaw, cosYaw;
  73.                 float sinElev, cosElev;
  74.  
  75.                 sincos_tpl(yaw, &sinYaw, &cosYaw);
  76.                 sincos_tpl(elev, &sinElev, &cosElev);
  77.  
  78.                 dir.x = cosYaw * cosElev;
  79.                 dir.y = sinYaw * cosElev;
  80.                 dir.z = sinElev;
  81.         }
  82. }
  83.  
  84. static inline void SerializeDirVector(CBitArray& array, Vec3& dir, float maxLength, int nScaleBits, int nYawBits, int nElevBits)
  85. {
  86.         float length;
  87.         if (array.IsReading())
  88.         {
  89.                 SerializeDirHelper(array, dir, nYawBits, nElevBits);
  90.                 array.Serialize(length, 0.f, maxLength, nScaleBits);
  91.                 dir = dir * length;
  92.         }
  93.         else
  94.         {
  95.                 length = dir.GetLength();
  96.                 Vec3 tmp = (length > 0.f) ? dir / length : dir;
  97.                 SerializeDirHelper(array, tmp, nYawBits, nElevBits);
  98.                 array.Serialize(length, 0.f, maxLength, nScaleBits);
  99.         }
  100. }
  101.  
  102. #endif
  103.  
downloadSerializeDirHelper.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