NodeMemPool.hpp 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. /****************************************************************************
  2. Copyright (c) 2018 Xiamen Yaji Software Co., Ltd.
  3. http://www.cocos2d-x.org
  4. Permission is hereby granted, free of charge, to any person obtaining a copy
  5. of this software and associated documentation files (the "Software"), to deal
  6. in the Software without restriction, including without limitation the rights
  7. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. copies of the Software, and to permit persons to whom the Software is
  9. furnished to do so, subject to the following conditions:
  10. The above copyright notice and this permission notice shall be included in
  11. all copies or substantial portions of the Software.
  12. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  13. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  14. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  15. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  16. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  17. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  18. THE SOFTWARE.
  19. ****************************************************************************/
  20. #pragma once
  21. #include "MemPool.hpp"
  22. #include "math/Mat4.h"
  23. RENDERER_BEGIN
  24. class NodeProxy;
  25. struct TRS {
  26. float x = 0.0f;
  27. float y = 0.0f;
  28. float z = 0.0f;
  29. float qx = 0.0f;
  30. float qy = 0.0f;
  31. float qz = 0.0f;
  32. float qw = 0.0f;
  33. float sx = 0.0f;
  34. float sy = 0.0f;
  35. float sz = 0.0f;
  36. };
  37. #define PARENT_INVALID 0xffffffff
  38. struct ParentInfo {
  39. uint32_t unitID = 0;
  40. uint32_t index = 0;
  41. };
  42. struct Skew {
  43. float_t x = 0.0f;
  44. float_t y = 0.0f;
  45. };
  46. class UnitNode: public UnitBase {
  47. public:
  48. UnitNode();
  49. virtual ~UnitNode();
  50. void setDirty(se::Object* jsData);
  51. void setTRS(se::Object* jsData);
  52. void setLocalMat(se::Object* jsData);
  53. void setWorldMat(se::Object* jsData);
  54. void setParent(se::Object* jsData);
  55. void setZOrder(se::Object* jsData);
  56. void setCullingMask(se::Object* jsData);
  57. void setOpacity(se::Object* jsData);
  58. void setIs3D(se::Object* jsData);
  59. void setNode(se::Object* jsData);
  60. void setLevel(se::Object* jsData);
  61. void setSkew(se::Object* jsData);
  62. uint32_t* getDirty(std::size_t index) const
  63. {
  64. return dirtyData + index;
  65. }
  66. TRS* getTRS(std::size_t index) const
  67. {
  68. return (TRS*)trsData + index;
  69. }
  70. cocos2d::Mat4* getLocalMat(std::size_t index) const
  71. {
  72. return (cocos2d::Mat4*)localMatData + index;
  73. }
  74. cocos2d::Mat4* getWorldMat(std::size_t index) const
  75. {
  76. return (cocos2d::Mat4*)worldMatData + index;
  77. }
  78. ParentInfo* getParent(std::size_t index) const
  79. {
  80. return (ParentInfo*)parentData + index;
  81. }
  82. int32_t* getZOrder(std::size_t index) const
  83. {
  84. return zOrderData + index;
  85. }
  86. int32_t* getCullingMask(std::size_t index) const
  87. {
  88. return cullingMaskData + index;
  89. }
  90. uint8_t* getOpacity(std::size_t index) const
  91. {
  92. return opacityData + index;
  93. }
  94. uint8_t* getIs3D(std::size_t index) const
  95. {
  96. return is3DData + index;
  97. }
  98. uint64_t* getNode(std::size_t index) const
  99. {
  100. return nodeData + index;
  101. }
  102. Skew* getSkew(std::size_t index) const
  103. {
  104. return (Skew*)skewData + index;
  105. }
  106. protected:
  107. se::Object* dirty = nullptr;
  108. uint32_t* dirtyData = nullptr;
  109. std::size_t dirtyLen = 0;
  110. se::Object* trs = nullptr;
  111. float_t* trsData = nullptr;
  112. std::size_t trsLen = 0;
  113. se::Object* localMat = nullptr;
  114. float_t* localMatData = nullptr;
  115. std::size_t localMatLen = 0;
  116. se::Object* worldMat = nullptr;
  117. float_t* worldMatData = nullptr;
  118. std::size_t worldMatLen = 0;
  119. se::Object* parent = nullptr;
  120. uint32_t* parentData = nullptr;
  121. std::size_t parentLen = 0;
  122. se::Object* zOrder = nullptr;
  123. int32_t* zOrderData = nullptr;
  124. std::size_t zOrderLen = 0;
  125. se::Object* cullingMask = nullptr;
  126. int32_t* cullingMaskData = nullptr;
  127. std::size_t cullingMaskLen = 0;
  128. se::Object* opacity = nullptr;
  129. uint8_t* opacityData = nullptr;
  130. std::size_t opacityLen = 0;
  131. se::Object* is3D = nullptr;
  132. uint8_t* is3DData = nullptr;
  133. std::size_t is3DLen = 0;
  134. se::Object* node = nullptr;
  135. uint64_t* nodeData = nullptr;
  136. std::size_t nodeLen = 0;
  137. se::Object* skew = nullptr;
  138. float_t* skewData = nullptr;
  139. std::size_t skewLen = 0;
  140. };
  141. class NodeMemPool: public MemPool {
  142. public:
  143. NodeMemPool();
  144. virtual ~NodeMemPool();
  145. static NodeMemPool* getInstance()
  146. {
  147. return _instance;
  148. }
  149. void removeNodeData(std::size_t unitID);
  150. void updateNodeData(std::size_t unitID, se_object_ptr dirty, se_object_ptr trs, se_object_ptr localMat, se_object_ptr worldMat, se_object_ptr parent, se_object_ptr zOrder, se_object_ptr cullingMask, se_object_ptr opacity, se_object_ptr is3D, se_object_ptr node, se_object_ptr skew);
  151. UnitNode* getUnit(std::size_t unitID) const;
  152. const std::vector<UnitNode*>& getNodePool() const;
  153. private:
  154. static NodeMemPool* _instance;
  155. std::vector<UnitNode*> _nodePool;
  156. };
  157. RENDERER_END