BVB Source Codes

CRYENGINE Show ParamTraits.h Source code

Return Download CRYENGINE: download ParamTraits.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 PARAMTRAITS_H
  11. #define PARAMTRAITS_H
  12.  
  13. #pragma once
  14.  
  15. #include "../ParticleCommon.h"
  16. #include "../ParticleSpline.h"
  17. #include <CrySerialization/Enum.h>
  18. #include <CrySerialization/Decorators/Range.h>
  19.  
  20. namespace pfx2
  21. {
  22.  
  23. template<typename T>
  24. ILINE T RemoveNegZero(T val)
  25. {
  26.         return val;
  27. }
  28.  
  29. template<>
  30. ILINE float RemoveNegZero(float val)
  31. {
  32.         return val == -0.0f ? 0.0f : val;
  33. }
  34.  
  35. struct ConvertIdentity
  36. {
  37.         template<typename T>
  38.         static T To(T val)
  39.         {
  40.                 return RemoveNegZero(val);
  41.         }
  42.         template<typename T>
  43.         static T From(T val)
  44.         {
  45.                 return RemoveNegZero(val);
  46.         }
  47. };
  48.  
  49. struct SEnable
  50. {
  51. public:
  52.         SEnable() : m_value(true) {}
  53.         ILINE             operator bool() const { return m_value; }
  54.         ILINE void        Set(bool value)       { m_value = value; }
  55. private:
  56.         ILINE friend bool Serialize(Serialization::IArchive& ar, SEnable& val, const char* name, const char* label);
  57.         bool m_value;
  58. };
  59.  
  60. template<typename T, typename TLimits, typename TConvert = ConvertIdentity>
  61. struct TValue
  62. {
  63. public:
  64.         typedef T TType;
  65.         TValue(TType var = TType(0)) { Set(var); }
  66.         void Set(TType value) { m_value = CLAMP(TConvert::To(value), HardMin(), HardMax()); }
  67.  
  68.         operator TType() const { return m_value; }
  69.         TType        Get() const  { return m_value; }
  70.         TType        Base() const { return m_value; }
  71.         TType        Min() const  { return m_value; }
  72.         TType        Max() const  { return m_value; }
  73.  
  74.         static TType HardMin()    { return TLimits::isHardMin ? TType(TLimits::minValue) : std::numeric_limits<TType>::lowest(); }
  75.         static TType HardMax()    { return TLimits::isHardMax ? TType(TLimits::maxValue) : std::numeric_limits<TType>::max(); }
  76.         static TType SoftMin()    { return TType(TLimits::minValue); }
  77.         static TType SoftMax()    { return TType(TLimits::maxValue); }
  78.  
  79. private:
  80.  
  81.         friend bool Serialize(Serialization::IArchive& ar, TValue& val, const char* name, const char* label)
  82.         {
  83.                 TType v = TConvert::From(val.m_value);
  84.                 bool res = ar(
  85.                   Serialization::Range(v, (TType)HardMin(), (TType)HardMax()),
  86.                   name, label);
  87.                 val.m_value = TConvert::To(v);
  88.                 return res;
  89.         }
  90.  
  91.         TType m_value;
  92. };
  93.  
  94. // Specify value limits
  95. template<int L, int H>
  96. struct TLimits
  97. {
  98.         static const int minValue = L;
  99.         static const int maxValue = H;
  100. };
  101.  
  102. template<int L, int H>
  103. struct THardLimits : TLimits<L, H>
  104. {
  105.         static const bool isHardMin = true;
  106.         static const bool isHardMax = true;
  107. };
  108.  
  109. template<int L, int H>
  110. struct THardMin : TLimits<L, H>
  111. {
  112.         static const bool isHardMin = true;
  113.         static const bool isHardMax = false;
  114. };
  115.  
  116. template<int L, int H>
  117. struct TSoftLimits : TLimits<L, H>
  118. {
  119.         static const bool isHardMin = false;
  120.         static const bool isHardMax = false;
  121. };
  122.  
  123. template<int H>
  124. struct SSoftLimit : TSoftLimits<-H, H> {};
  125.  
  126. template<int H>
  127. struct USoftLimit : TLimits<0, H>
  128. {
  129.         static const bool isHardMin = true;
  130.         static const bool isHardMax = false;
  131. };
  132.  
  133. typedef TValue<float, SSoftLimit<1>>      SFloat;
  134. typedef TValue<float, SSoftLimit<10>>     SFloat10;
  135. typedef TValue<float, USoftLimit<1>>      UFloat;
  136. typedef TValue<float, USoftLimit<10>>     UFloat10;
  137. typedef TValue<float, USoftLimit<100>>    UFloat100;
  138.  
  139. typedef TValue<float, THardLimits<-1, 1>> SUnitFloat;
  140. typedef TValue<float, THardLimits<0, 1>>  UUnitFloat;
  141.  
  142. typedef TValue<uint, THardLimits<0, 255>> UByte;
  143. typedef TValue<uint, THardLimits<1, 256>> UBytePos;
  144.  
  145. struct ConvertDegrees
  146. {
  147.         static float From(float val) { return RemoveNegZero(RAD2DEG(val)); }
  148.         static float To(float val)   { return RemoveNegZero(DEG2RAD(val)); }
  149. };
  150. typedef TValue<float, SSoftLimit<360>, ConvertDegrees>        SAngle;
  151. typedef TValue<float, USoftLimit<360>, ConvertDegrees>        UAngle;
  152. typedef TValue<float, THardLimits<-360, 360>, ConvertDegrees> SAngle360;
  153. typedef TValue<float, THardLimits<0, 180>, ConvertDegrees>    UAngle180;
  154.  
  155. }
  156.  
  157. #include "ParamTraitsImpl.h"
  158.  
  159. #endif // PARAMTRAITS_H
  160.  
downloadParamTraits.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