RParticleMacros.h 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. //
  2. // RParticleMacros.h
  3. // cocos2d_libs
  4. //
  5. // Created by 徐俊杰 on 2020/4/27.
  6. //
  7. #ifndef RParticleMacros_h
  8. #define RParticleMacros_h
  9. //#include "cocos2d.h"
  10. #include "math/CCAffineTransform.h"
  11. #include "math/CCGeometry.h"
  12. #include "math/CCVertex.h"
  13. #include "math/Mat4.h"
  14. #include "math/MathUtil.h"
  15. #include "math/Quaternion.h"
  16. #include "math/Vec2.h"
  17. #include "math/Vec3.h"
  18. #include "math/Vec4.h"
  19. #include "3d/CCAABB.h"
  20. #include "platform/CCPlatformConfig.h"
  21. /// @name namespace RRP
  22. /// @{
  23. #ifdef __cplusplus
  24. #define NS_RRP_BEGIN namespace RRP {
  25. #define NS_RRP_END }
  26. #define USING_NS_RRP using namespace RRP
  27. #define NS_RRP ::RRP
  28. #else
  29. #define NS_RRP_BEGIN
  30. #define NS_RRP_END
  31. #define USING_NS_RRP
  32. #define NS_RRP
  33. #endif
  34. // end of namespace group
  35. /// @}
  36. /******************************************************************************************/
  37. /** LittleEndian Sense Macro, from google protobuf see: **/
  38. /** https://github.com/google/protobuf/blob/master/src/google/protobuf/io/coded_stream.h **/
  39. /******************************************************************************************/
  40. #ifdef _MSC_VER
  41. #if defined(_M_IX86)
  42. #define RRP_LITTLE_ENDIAN 1
  43. #else
  44. #define RRP_LITTLE_ENDIAN 0
  45. #endif
  46. #if _MSC_VER >= 1300 && !defined(__INTEL_COMPILER)
  47. #pragma runtime_checks("c", off)
  48. #endif
  49. #else
  50. #include <sys/param.h>
  51. #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
  52. #include <sys/endian.h>
  53. #endif // CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID
  54. #if ((defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__)) || \
  55. (defined(__BYTE_ORDER) && __BYTE_ORDER == __LITTLE_ENDIAN))
  56. #define RRP_LITTLE_ENDIAN 1
  57. #else
  58. #define RRP_LITTLE_ENDIAN 0
  59. #endif
  60. #endif
  61. // MemoryMacros.h
  62. #if defined(__GNUC__)
  63. #define ALIGN_OF(T) __alignof__(T)
  64. #define ALIGN_TYPE(val) __attribute__((aligned(val)))
  65. #define FORCE_INLINE inline __attribute__ ((always_inline))
  66. #elif defined(_MSC_VER)
  67. #define ALIGN_OF(T) __alignof(T)
  68. #define ALIGN_TYPE(val) __declspec(align(val))
  69. #define FORCE_INLINE __forceinline
  70. #else
  71. #define ALIGN_TYPE(size)
  72. #define FORCE_INLINE inline
  73. #endif
  74. #define UNITY_MALLOC_ALIGNED(l,s,a) ::malloc(s)
  75. #define UNITY_REALLOC_ALIGNED(l,p,s,a) ::realloc(p, s)
  76. #define FREE_TEMP_MANUAL(ptr) ::free(ptr)
  77. // LogAssert.h
  78. #define AssertIf(x) do { (void)sizeof(x); } while(0)
  79. #define AssertIfObject(x,o) do { (void)sizeof(x); (void)sizeof(o); } while(0)
  80. #define Assert(x) do { (void)sizeof(x); } while(0)
  81. #define AssertMsg(x,...) do { (void)sizeof(x); } while(0)
  82. #define AssertMsgObject(x,o,...) do { (void)sizeof(x); } while(0)
  83. #define DebugAssertIf(x) AssertIf(x)
  84. #define DebugAssert(x) Assert(x)
  85. #define DebugAssertMsg(x, ...) AssertMsg(x, __VA_ARGS__)
  86. #define DEBUG_BREAK
  87. #define AssertBreak(x) \
  88. do { \
  89. if(!(x)) \
  90. { \
  91. DEBUG_BREAK; \
  92. Assert(x); \
  93. } \
  94. } while(0)
  95. // ExportModules.h
  96. #define EXPORT_COREMODULE CC_DLL
  97. #define EXPORT_MODULE CC_DLL
  98. // ObjectDefines.h
  99. #define INSTANTIATE_TEMPLATE_TRANSFER_WITH_DECL(x, decl) \
  100. template decl void x::Transfer(JsonRead& transfer); \
  101. template decl void x::Transfer(JsonWrite& transfer); \
  102. template decl void x::Transfer(StreamedBinaryRead& transfer); \
  103. template decl void x::Transfer(StreamedBinaryWrite& transfer);
  104. #define INSTANTIATE_TEMPLATE_TRANSFER(x) INSTANTIATE_TEMPLATE_TRANSFER_WITH_DECL(x, )
  105. #define FOR_QY_TEST 1
  106. #define ENABLE_PHYSICS 1
  107. enum {
  108. // @TBD: tweak to ideal values per platform / device / rendering API
  109. kDynamicBatchingVerticesThreshold = 300, // verts (needed at build time since required channels isn't known)
  110. kDynamicBatchingVertsByChannelThreshold = 300 * 3, // verts * channels
  111. kDynamicBatchingIndicesThreshold = 32000 // >32k causes a slowdown on MBPs with AMD cards (Case 394520)
  112. };
  113. // AllocatorLabels.h
  114. struct MemLabelId {
  115. // GetRootHeader
  116. };
  117. enum ObjectCreationMode
  118. {
  119. // Create the object from the main thread in a perfectly normal way
  120. kCreateObjectDefault = 0,
  121. // Create the object from another thread. Might assign an instance ID but will not register with IDToPointer map.
  122. // Objects created like this, need to call, AwakeFromLoadThraded, and Object::RegisterInstanceID and AwakeFromLoad (kDidLoadThreaded); from the main thread
  123. kCreateObjectFromNonMainThread = 1,
  124. // Create the object and register the instance id but do not lock the object
  125. // creation mutex because the code calling it already called LockObjectCreation mutex.
  126. kCreateObjectDefaultNoLock = 2
  127. };
  128. // Types
  129. typedef cocos2d::Vec2 Vector2f;
  130. typedef cocos2d::Vec3 Vector3f;
  131. typedef cocos2d::Vec4 Vector4f;
  132. typedef cocos2d::Color4B ColorRGBA32;
  133. typedef cocos2d::Color4F ColorRGBAf;
  134. typedef cocos2d::Mat4 Matrix4x4f;
  135. typedef cocos2d::AABB MinMaxAABB;
  136. typedef cocos2d::Quaternion Quaternionf;
  137. #ifndef kPI
  138. #define kPI 3.14159265358979323846264338327950288419716939937510F
  139. #endif
  140. #define GET_SET_DIRTY(TYPE,PROP_NAME,VAR_NAME) void Set##PROP_NAME (TYPE val) { VAR_NAME = val; SetDirty(); } const TYPE Get##PROP_NAME () const {return (const TYPE)VAR_NAME; }
  141. // Vector3.h
  142. const float Vector3f_Epsilon = 0.00001F;
  143. //inline float Dot(const Vector3f &lhs, const Vector3f &rhs)
  144. //{
  145. // return lhs.x * rhs.x + lhs.y * rhs.y + lhs.z * rhs.z;
  146. //}
  147. //inline float SqrtImpl (float f)
  148. //{
  149. // return sqrt (f);
  150. //}
  151. //inline float SqrMagnitude (const Vector3f& inV){ return Dot (inV, inV); }
  152. //inline bool CompareApproximately (float f0, float f1, float epsilon = 0.000001F)
  153. //{
  154. // float dist = (f0 - f1);
  155. // dist = abs (dist);
  156. // return dist < epsilon;
  157. //}
  158. //inline Vector3f Lerp (const Vector3f& from, const Vector3f& to, float t) { return to * t + from * (1.0F - t); }
  159. //inline Vector3f Cross (const Vector3f& lhs, const Vector3f& rhs)
  160. //{
  161. // return Vector3f (
  162. // lhs.y * rhs.z - lhs.z * rhs.y,
  163. // lhs.z * rhs.x - lhs.x * rhs.z,
  164. // lhs.x * rhs.y - lhs.y * rhs.x);
  165. //}
  166. //inline float Magnitude (const Vector3f& inV){return SqrtImpl(Dot (inV, inV));}
  167. // FloatConversion.h
  168. //inline float Lerp (float from, float to, float t)
  169. //{
  170. // return to * t + from * (1.0F - t);
  171. //}
  172. //#define k1OverSqrt2 float(0.7071067811865475244008443621048490)
  173. // Calculates a vector that is orthonormal to n.
  174. // Assumes that n is normalized
  175. //Vector3f OrthoNormalVectorFast (const Vector3f& n);
  176. //Vector3f OrthoNormalVectorFast (const Vector3f& n)
  177. //{
  178. // Vector3f res;
  179. // if (abs (n.z) > k1OverSqrt2)
  180. // {
  181. // // choose p in y-z plane
  182. // float a = n.y*n.y + n.z*n.z;
  183. // float k = 1.0F / sqrt (a);
  184. // res.x = 0;
  185. // res.y = -n.z*k;
  186. // res.z = n.y*k;
  187. // }
  188. // else
  189. // {
  190. // // choose p in x-y plane
  191. // float a = n.x*n.x + n.y*n.y;
  192. // float k = 1.0F / sqrt (a);
  193. // res.x = -n.y*k;
  194. // res.y = n.x*k;
  195. // res.z = 0;
  196. // }
  197. // return res;
  198. //}
  199. // Orthonormalizes the three vectors, returns false if no orthonormal basis could be formed.
  200. //EXPORT_COREMODULE void OrthoNormalize (Vector3f* inU, Vector3f* inV, Vector3f* inW);
  201. //void OrthoNormalize (Vector3f* inU, Vector3f* inV, Vector3f* inW)
  202. //{
  203. // // compute u0
  204. // float mag = Magnitude (*inU);
  205. // if (mag > Vector3f_Epsilon)
  206. // *inU = *inU /mag;
  207. // else
  208. // *inU = Vector3f (1.0F, 0.0F, 0.0F);
  209. //
  210. // // compute u1
  211. // float dot0 = Dot (*inU, *inV);
  212. // *inV -= dot0 * *inU;
  213. // mag = Magnitude (*inV);
  214. // if (mag > Vector3f_Epsilon)
  215. // *inV = *inV / mag;
  216. // else
  217. // *inV = OrthoNormalVectorFast (*inU);
  218. //
  219. // // compute u2
  220. // float dot1 = Dot (*inV, *inW);
  221. // dot0 = Dot (*inU, *inW);
  222. // *inW -= dot0 * *inU + dot1 * *inV;
  223. // mag = Magnitude (*inW);
  224. // if (mag > Vector3f_Epsilon)
  225. // *inW = *inW / mag;
  226. // else
  227. // *inW = Cross (*inU, *inV);
  228. //}
  229. // AABB
  230. /// This version is much slower but works correctly with non-uniform scale
  231. //void TransformAABBSlow (const AABB& aabb, const Matrix4x4f& transform, AABB& result);
  232. //void TransformAABBSlow (const AABB& aabb, const Matrix4x4f& transform, AABB& result)
  233. //{
  234. // MinMaxAABB transformed;
  235. // transformed.reset ();
  236. //
  237. // Vector3f v[8];
  238. // aabb.GetVertices (v);
  239. //// for (int i=0;i<8;i++)
  240. //// transformed.Encapsulate (transform.MultiplyPoint3 (v[i]));
  241. //
  242. // result = transformed;
  243. //}
  244. // OSTypes.h
  245. typedef unsigned char UInt8;
  246. typedef unsigned short UInt16;
  247. # if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
  248. typedef unsigned int UInt32;
  249. #else
  250. # if __LP64__
  251. typedef unsigned int UInt32;
  252. # else
  253. typedef unsigned long UInt32;
  254. # endif
  255. #endif
  256. typedef unsigned long long UInt64;
  257. typedef signed char SInt8;
  258. typedef signed short SInt16;
  259. # if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
  260. typedef signed int SInt32;
  261. # else
  262. # if __LP64__
  263. typedef signed int SInt32;
  264. # else
  265. typedef signed long SInt32;
  266. # endif
  267. #endif
  268. typedef signed long long SInt64;
  269. #endif /* RParticleMacros_h */