BVB Source Codes

CRYENGINE Show ParticleSpline.h Source code

Return Download CRYENGINE: download ParticleSpline.h Source code - Download CRYENGINE Source code - Type:.h
  1. // Copyright 2001-2016 Crytek GmbH / Crytek Group. All rights reserved.
  2.  
  3. // -------------------------------------------------------------------------
  4. //  Created:     04/03/2015 by Filipe amim
  5. //  Description:
  6. // -------------------------------------------------------------------------
  7. //
  8. ////////////////////////////////////////////////////////////////////////////
  9.  
  10. #ifndef PARTICLESPLINE_H
  11. #define PARTICLESPLINE_H
  12.  
  13. #pragma once
  14.  
  15. #include <CryMath/ISplines.h>
  16. #include <CrySerialization/IArchive.h>
  17. #include <CryMath/Range.h>
  18.  
  19. namespace pfx2
  20. {
  21.  
  22. class CParticleSpline : public ISplineEvaluator
  23. {
  24. public:
  25.         CParticleSpline();
  26.  
  27.         void         MakeFlatLine(float v) { return MakeLinear(v, v); }
  28.         void         MakeLinear(float v0 = 0.0f, float v1 = 1.0f);
  29.  
  30.         size_t       GetNumKeys() const { return m_keys.size(); }
  31.         bool         HasKeys() const    { return GetNumKeys() > 0; }
  32.  
  33.         float        Interpolate(float time) const;
  34. #ifdef CRY_PFX2_USE_SSE
  35.         floatv       Interpolate(const floatv time) const;
  36. #endif
  37.         const Range& GetValueRange() const { return m_valueRange; }
  38.  
  39.         // ISplineEvaluator
  40.         virtual int        GetKeyCount() const override { return GetNumKeys(); }
  41.         virtual void       GetKey(int i, KeyType& key) const override;
  42.         virtual void       FromSpline(const ISplineEvaluator& spline) override;
  43.  
  44.         virtual void       Interpolate(float time, ValueType& value) override;
  45.  
  46.         static  Formatting StringFormatting()             { return Formatting(";,:"); }
  47.         virtual Formatting GetFormatting() const override { return StringFormatting(); }
  48.  
  49.         virtual bool       FromString(cstr str) override;
  50.         virtual bool       Serialize(Serialization::IArchive& ar, const char* name, const char* label) override;
  51.  
  52.         struct CSourceSpline : public spline::CSplineKeyInterpolator<spline::ClampedKey<float>>
  53.         {
  54.                 typedef spline::ClampedKey<float> key_type;
  55.                 virtual Formatting GetFormatting() const override { return CParticleSpline::StringFormatting(); }
  56.         };
  57.  
  58. private:
  59.         void  Resize(size_t size);
  60.         float DefaultSlope(size_t keyIdx) const;
  61.         float StartSlope(size_t keyIdx) const;
  62.         float EndSlope(size_t keyIdx) const;
  63.  
  64.         struct SplineKey
  65.         {
  66.                 float time;
  67.                 float timeMult;
  68.                 float value;
  69.                 float coeff0;
  70.                 float coeff1;
  71.         };
  72.  
  73.         std::vector<SplineKey>     m_keys;
  74.         std::vector<spline::Flags> m_keyFlags;
  75.         Range                      m_valueRange;
  76. };
  77.  
  78. // Automatically creates a global Serialize() for Type, which invokes Type.Serialize
  79. // This serializes Type is a single node, rather than the default for structs,
  80. // which creates a node with nested members.
  81. #define SERIALIZATION_WITH_MEMBER_FUNCTION(Type)                                                       \
  82.   inline bool Serialize(Serialization::IArchive & ar, Type & val, const char* name, const char* label) \
  83.   { return val.Serialize(ar, name, label); }                                                           \
  84.  
  85.  
  86. SERIALIZATION_WITH_MEMBER_FUNCTION(CParticleSpline)
  87.  
  88. template<int DIMS>
  89. class CParticleMultiSpline : public spline::CMultiSplineEvaluator<CParticleSpline, DIMS>
  90. {
  91. public:
  92.         bool HasKeys() const
  93.         {
  94.                 for (const auto& spline : m_splines)
  95.                         if (spline.HasKeys())
  96.                                 return true;
  97.                 return false;
  98.         }
  99.         Range GetValueRange() const
  100.         {
  101.                 Range range(Range::EMPTY);
  102.                 for (const auto& spline : m_splines)
  103.                         range |= spline.GetValueRange();
  104.                 return range;
  105.         }
  106.         float GetMaxValue() const { return GetValueRange().start; }
  107.         float GetMinValue() const { return GetValueRange().end; }
  108.  
  109.         bool  Serialize(Serialization::IArchive& ar, const char* name, const char* label) override
  110.         {
  111.                 if (ar.isEdit())
  112.                 {
  113.                         return ar(static_cast<IMultiSplineEvaluator&>(*this), name, label);
  114.                 }
  115.                 else
  116.                 {
  117.                         return ar(m_splines, name, label);
  118.                 }
  119.         }
  120.  
  121. protected:
  122.         using spline::CMultiSplineEvaluator<CParticleSpline, DIMS>::m_splines;        // Help the compiler understand what it already should
  123. };
  124.  
  125. template<int DIMS> SERIALIZATION_WITH_MEMBER_FUNCTION(CParticleMultiSpline<DIMS> )
  126.  
  127. class CParticleDoubleSpline : public CParticleMultiSpline<2>
  128. {
  129. public:
  130.         ILINE float  Interpolate(float time, float unormRand) const;
  131. #ifdef CRY_PFX2_USE_SSE
  132.         ILINE floatv Interpolate(floatv time, floatv unormRand) const;
  133. #endif
  134. };
  135.  
  136. SERIALIZATION_WITH_MEMBER_FUNCTION(CParticleDoubleSpline)
  137.  
  138. class CParticleColorSpline : public CParticleMultiSpline<3>
  139. {
  140. public:
  141.         ILINE ColorF  Interpolate(float time) const;
  142. #ifdef CRY_PFX2_USE_SSE
  143.         ILINE ColorFv Interpolate(floatv time) const;
  144. #endif
  145. };
  146.  
  147. SERIALIZATION_WITH_MEMBER_FUNCTION(CParticleColorSpline)
  148.  
  149. }
  150.  
  151. #include "ParticleSplineImpl.h"
  152.  
  153. #endif
  154.  
downloadParticleSpline.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