BVB Source Codes

CRYENGINE Show ParticleDataTypes.h Source code

Return Download CRYENGINE: download ParticleDataTypes.h Source code - Download CRYENGINE Source code - Type:.h
  1. // Copyright 2001-2016 Crytek GmbH / Crytek Group. All rights reserved.
  2.  
  3. // -------------------------------------------------------------------------
  4. //  Created:     24/09/2014 by Filipe amim
  5. //  Description:
  6. // -------------------------------------------------------------------------
  7. //
  8. ////////////////////////////////////////////////////////////////////////////
  9.  
  10. #ifndef PARTICLEDATATYPES_H
  11. #define PARTICLEDATATYPES_H
  12.  
  13. #pragma once
  14.  
  15. #include <CryMath/FinalizingSpline.h>
  16. #include <CrySerialization/Enum.h>
  17. #include <CryCore/DynamicEnum.h>
  18. #include "ParticleCommon.h"
  19. #include "ParticleMath.h"
  20.  
  21. namespace pfx2
  22. {
  23.  
  24. struct SChaosKey
  25. {
  26. public:
  27.         explicit SChaosKey(uint32 key) : m_key(key) {}
  28.         SChaosKey(const SChaosKey& key) : m_key(key.m_key) {}
  29.         SChaosKey(SChaosKey key1, SChaosKey key2);
  30.         SChaosKey(SChaosKey key1, SChaosKey key2, SChaosKey key3);
  31.  
  32.         uint32 Rand();
  33.         uint32 Rand(uint32 range);
  34.         float  RandUNorm();
  35.         float  RandSNorm();
  36.  
  37.         struct Range
  38.         {
  39.                 float scale, bias;
  40.                 Range(float lo, float hi);
  41.         };
  42.         float Rand(Range range);
  43.  
  44.         Vec2  RandCircle();
  45.         Vec2  RandDisc();
  46.         Vec3  RandSphere();
  47.  
  48. private:
  49.         uint32 m_key;
  50. };
  51.  
  52. #ifdef CRY_PFX2_USE_SSE
  53.  
  54. struct SChaosKeyV
  55. {
  56.         explicit SChaosKeyV(SChaosKey key);
  57.         explicit SChaosKeyV(uint32 key);
  58.         explicit SChaosKeyV(uint32v keys) : m_keys(keys) {}
  59.         uint32v Rand();
  60.         uint32v Rand(uint32 range);
  61.         floatv  RandUNorm();
  62.         floatv  RandSNorm();
  63.  
  64.         struct Range
  65.         {
  66.                 floatv scale, bias;
  67.                 Range(float lo, float hi);
  68.         };
  69.         floatv Rand(Range range);
  70.  
  71. private:
  72.         uint32v m_keys;
  73. };
  74.  
  75. #else
  76.  
  77. typedef SChaosKey SChaosKeyV;
  78.  
  79. #endif
  80.  
  81. enum EState
  82. {
  83.         ESB_Alive   = BIT(0),   // this particle is alive
  84.         ESB_Dead    = BIT(1),   // this particle is either dead or expired
  85.         ESB_NewBorn = BIT(2),   // this particle appeared this frame
  86.         ESB_Update  = BIT(7),   // this particle can be updated
  87.  
  88.         ES_Empty    = 0,                                    // nobody home
  89.         ES_Dead     = ESB_Dead,                             // particle allocated but dead
  90.         ES_Alive    = ESB_Update | ESB_Alive,               // regular living particle
  91.         ES_Expired  = ESB_Update | ESB_Dead,                // passed the age time but will only be dead next frame
  92.         ES_NewBorn  = ESB_Update | ESB_NewBorn | ESB_Alive, // particle appeared this frame
  93. };
  94.  
  95. ///////////////////////////////////////////////////////////////////////////////
  96. // Implement EParticleDataTypes (size, position, etc) with DynamicEnum.
  97. // Data type entries can be declared in multiple source files, with info about the data type (float, Vec3, etc)
  98.  
  99. enum BHasInit {}; // boolean argument indicating data type has an extra init field
  100.  
  101. //! Info associated with each EParticleDataType
  102. struct SParticleDataInfo
  103. {
  104.         typedef yasli::TypeID TypeID;
  105.  
  106.         TypeID   type;
  107.         size_t   sizeOf;
  108.         uint     dimension;
  109.         BHasInit hasInit;
  110.  
  111.         SParticleDataInfo()
  112.                 : dimension(0), hasInit(BHasInit(false)) {}
  113.  
  114.         template<typename T>
  115.         SParticleDataInfo(T*, uint dim = 1, BHasInit init = BHasInit(false))
  116.                 : type(TypeID::get<T>()), sizeOf(sizeof(T)), dimension(dim), hasInit(init) {}
  117.  
  118.         template<typename T>
  119.         bool isType() const { return type == TypeID::get<T>(); }
  120.  
  121.         template<typename T>
  122.         bool   isType(uint dim) const { return type == TypeID::get<T>() && dimension == dim; }
  123.  
  124.         uint   step() const           { return dimension * (1 + hasInit); }
  125.         size_t typeSize() const       { return sizeOf; }
  126. };
  127.  
  128. template<typename T = float, uint dim = 1, BHasInit init = BHasInit(false)>
  129. struct TParticleDataInfo : SParticleDataInfo
  130. {
  131.         TParticleDataInfo()
  132.                 : SParticleDataInfo((T*)0, dim, init) {}
  133. };
  134.  
  135. //! EParticleDataType implemented as a DynamicEnum, with SParticleDataInfo
  136. typedef DynamicEnum<SParticleDataInfo, uint, SParticleDataInfo>
  137.   EParticleDataType;
  138.  
  139. ILINE EParticleDataType InitType(EParticleDataType type)
  140. {
  141.         return type + type.info().dimension;
  142. }
  143.  
  144. // Convenient initialization of EParticleDataType
  145. //  EParticleDataType PDT(EPDT_SpawnID, TParticleID, 1)
  146. //  EParticleDataType PDT(EPVF_Velocity, float, 3)
  147.  
  148. #define PDT(Name, ...) \
  149.   Name(SkipPrefix( # Name), 0, TParticleDataInfo<__VA_ARGS__>())
  150.  
  151. inline cstr SkipPrefix(cstr name)
  152. {
  153.         for (int i = 0; name[i]; ++i)
  154.                 if (name[i] == '_')
  155.                         return name + i + 1;
  156.         return name;
  157. }
  158.  
  159. // Standard data types
  160. extern EParticleDataType
  161.   EPDT_SpawnId,
  162.   EPDT_ParentId,
  163.   EPDT_State,
  164.   EPDT_NormalAge,
  165.   EPDT_LifeTime,
  166.   EPDT_InvLifeTime,
  167.   EPDT_SpawnFraction,
  168.   EPDT_Random,
  169.   EPDT_Size,
  170.   EPDT_Angle2D,
  171.   EPDT_Spin2D;
  172.  
  173. // pose data types
  174. extern EParticleDataType
  175.   EPVF_Position,
  176.   EPVF_Velocity,
  177.   EPQF_Orientation,
  178.   EPVF_AngularVelocity,
  179.   EPVF_LocalPosition,
  180.   EPVF_LocalVelocity,
  181.   EPQF_LocalOrientation;
  182.  
  183. }
  184.  
  185. #include "ParticleDataTypesImpl.h"
  186.  
  187. #endif // PARTICLEDATATYPES_H
  188.  
downloadParticleDataTypes.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