CCPUForceFieldAffectorTranslator.cpp 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. /****************************************************************************
  2. Copyright (C) 2013 Henry van Merode. All rights reserved.
  3. Copyright (c) 2015-2016 Chukong Technologies Inc.
  4. Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
  5. http://www.cocos2d-x.org
  6. Permission is hereby granted, free of charge, to any person obtaining a copy
  7. of this software and associated documentation files (the "Software"), to deal
  8. in the Software without restriction, including without limitation the rights
  9. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  10. copies of the Software, and to permit persons to whom the Software is
  11. furnished to do so, subject to the following conditions:
  12. The above copyright notice and this permission notice shall be included in
  13. all copies or substantial portions of the Software.
  14. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. THE SOFTWARE.
  21. ****************************************************************************/
  22. #include "CCPUForceFieldAffectorTranslator.h"
  23. #include "extensions/Particle3D/PU/CCPUParticleSystem3D.h"
  24. #include "extensions/Particle3D/PU/CCPUDynamicAttribute.h"
  25. #include "extensions/Particle3D/PU/CCPUDynamicAttributeTranslator.h"
  26. NS_CC_BEGIN
  27. PUForceFieldAffectorTranslator::PUForceFieldAffectorTranslator()
  28. {
  29. }
  30. //-------------------------------------------------------------------------
  31. bool PUForceFieldAffectorTranslator::translateChildProperty( PUScriptCompiler* compiler, PUAbstractNode *node )
  32. {
  33. PUPropertyAbstractNode* prop = reinterpret_cast<PUPropertyAbstractNode*>(node);
  34. PUAffector* af = static_cast<PUAffector*>(prop->parent->context);
  35. PUForceFieldAffector* affector = static_cast<PUForceFieldAffector*>(af);
  36. if (prop->name == token[TOKEN_FORCEFIELD_TYPE])
  37. {
  38. // Property: forcefield_type
  39. if (passValidateProperty(compiler, prop, token[TOKEN_FORCEFIELD_TYPE], VAL_STRING))
  40. {
  41. std::string val;
  42. if(getString(*prop->values.front(), &val))
  43. {
  44. affector->suppressGeneration(true);
  45. if (val == token[TOKEN_REALTIME])
  46. {
  47. affector->setForceFieldType(PUForceField::FF_REALTIME_CALC);
  48. return true;
  49. }
  50. else if (val == token[TOKEN_MATRIX])
  51. {
  52. affector->setForceFieldType(PUForceField::FF_MATRIX_CALC);
  53. return true;
  54. }
  55. affector->suppressGeneration(false);
  56. }
  57. }
  58. }
  59. else if (prop->name == token[TOKEN_DELTA])
  60. {
  61. // Property: delta
  62. if (passValidateProperty(compiler, prop, token[TOKEN_DELTA], VAL_REAL))
  63. {
  64. float val = 0.0f;
  65. if(getFloat(*prop->values.front(), &val))
  66. {
  67. affector->suppressGeneration(true);
  68. affector->setDelta(val);
  69. affector->suppressGeneration(false);
  70. return true;
  71. }
  72. }
  73. }
  74. else if (prop->name == token[TOKEN_FORCE])
  75. {
  76. // Property: force
  77. if (passValidateProperty(compiler, prop, token[TOKEN_FORCE], VAL_REAL))
  78. {
  79. float val = 0.0f;
  80. if(getFloat(*prop->values.front(), &val))
  81. {
  82. affector->suppressGeneration(true);
  83. affector->setScaleForce(val);
  84. affector->suppressGeneration(false);
  85. return true;
  86. }
  87. }
  88. }
  89. else if (prop->name == token[TOKEN_OCTAVES])
  90. {
  91. // Property: octaves
  92. if (passValidateProperty(compiler, prop, token[TOKEN_OCTAVES], VAL_UINT))
  93. {
  94. unsigned int val = 0;
  95. if(getUInt(*prop->values.front(), &val))
  96. {
  97. affector->suppressGeneration(true);
  98. affector->setOctaves(val);
  99. affector->suppressGeneration(false);
  100. return true;
  101. }
  102. }
  103. }
  104. else if (prop->name == token[TOKEN_FREQUENCY])
  105. {
  106. // Property: frequency
  107. if (passValidateProperty(compiler, prop, token[TOKEN_FREQUENCY], VAL_REAL))
  108. {
  109. float val = 0.0f;
  110. if(getFloat(*prop->values.front(), &val))
  111. {
  112. affector->suppressGeneration(true);
  113. affector->setFrequency(val);
  114. affector->suppressGeneration(false);
  115. return true;
  116. }
  117. }
  118. }
  119. else if (prop->name == token[TOKEN_AMPLITUDE])
  120. {
  121. // Property: amplitude
  122. if (passValidateProperty(compiler, prop, token[TOKEN_AMPLITUDE], VAL_REAL))
  123. {
  124. float val = 0.0f;
  125. if(getFloat(*prop->values.front(), &val))
  126. {
  127. affector->suppressGeneration(true);
  128. affector->setAmplitude(val);
  129. affector->suppressGeneration(false);
  130. return true;
  131. }
  132. }
  133. }
  134. else if (prop->name == token[TOKEN_PERSISTENCE])
  135. {
  136. // Property: persistence
  137. if (passValidateProperty(compiler, prop, token[TOKEN_PERSISTENCE], VAL_REAL))
  138. {
  139. float val = 0.0f;
  140. if(getFloat(*prop->values.front(), &val))
  141. {
  142. affector->suppressGeneration(true);
  143. affector->setPersistence(val);
  144. affector->suppressGeneration(false);
  145. return true;
  146. }
  147. }
  148. }
  149. else if (prop->name == token[TOKEN_FORCEFIELDSIZE])
  150. {
  151. // Property: forcefield_size
  152. if (passValidateProperty(compiler, prop, token[TOKEN_FORCEFIELDSIZE], VAL_UINT))
  153. {
  154. unsigned int val = 0;
  155. if(getUInt(*prop->values.front(), &val))
  156. {
  157. affector->suppressGeneration(true);
  158. affector->setForceFieldSize(val);
  159. affector->suppressGeneration(false);
  160. return true;
  161. }
  162. }
  163. }
  164. else if (prop->name == token[TOKEN_WORLDSIZE])
  165. {
  166. // Property: worldsize
  167. if (passValidateProperty(compiler, prop, token[TOKEN_WORLDSIZE], VAL_VECTOR3))
  168. {
  169. Vec3 val;
  170. if(getVector3(prop->values.begin(), prop->values.end(), &val))
  171. {
  172. affector->suppressGeneration(true);
  173. affector->setWorldSize(val);
  174. affector->suppressGeneration(false);
  175. return true;
  176. }
  177. }
  178. }
  179. else if (prop->name == token[TOKEN_IGNORE_NEGATIVE_X])
  180. {
  181. // Property: ignore_negative_x
  182. if (passValidateProperty(compiler, prop, token[TOKEN_IGNORE_NEGATIVE_X], VAL_BOOL))
  183. {
  184. bool val;
  185. if(getBoolean(*prop->values.front(), &val))
  186. {
  187. affector->suppressGeneration(true);
  188. affector->setIgnoreNegativeX(val);
  189. affector->suppressGeneration(false);
  190. return true;
  191. }
  192. }
  193. }
  194. else if (prop->name == token[TOKEN_IGNORE_NEGATIVE_Y])
  195. {
  196. // Property: ignore_negative_y
  197. if (passValidateProperty(compiler, prop, token[TOKEN_IGNORE_NEGATIVE_Y], VAL_BOOL))
  198. {
  199. bool val;
  200. if(getBoolean(*prop->values.front(), &val))
  201. {
  202. affector->suppressGeneration(true);
  203. affector->setIgnoreNegativeY(val);
  204. affector->suppressGeneration(false);
  205. return true;
  206. }
  207. }
  208. }
  209. else if (prop->name == token[TOKEN_IGNORE_NEGATIVE_Z])
  210. {
  211. // Property: ignore_negative_z
  212. if (passValidateProperty(compiler, prop, token[TOKEN_IGNORE_NEGATIVE_Z], VAL_BOOL))
  213. {
  214. bool val;
  215. if(getBoolean(*prop->values.front(), &val))
  216. {
  217. affector->suppressGeneration(true);
  218. affector->setIgnoreNegativeZ(val);
  219. affector->suppressGeneration(false);
  220. return true;
  221. }
  222. }
  223. }
  224. else if (prop->name == token[TOKEN_MOVEMENT])
  225. {
  226. // Property: movement
  227. if (passValidateProperty(compiler, prop, token[TOKEN_MOVEMENT], VAL_VECTOR3))
  228. {
  229. Vec3 val;
  230. if(getVector3(prop->values.begin(), prop->values.end(), &val))
  231. {
  232. affector->suppressGeneration(true);
  233. affector->setMovement(val);
  234. affector->suppressGeneration(false);
  235. return true;
  236. }
  237. }
  238. }
  239. else if (prop->name == token[TOKEN_MOVEMENT_FREQUENCY])
  240. {
  241. // Property: movement_frequency
  242. if (passValidateProperty(compiler, prop, token[TOKEN_MOVEMENT_FREQUENCY], VAL_REAL))
  243. {
  244. float val = 0.0f;
  245. if(getFloat(*prop->values.front(), &val))
  246. {
  247. affector->suppressGeneration(true);
  248. affector->setMovementFrequency(val);
  249. affector->suppressGeneration(false);
  250. return true;
  251. }
  252. }
  253. }
  254. return false;
  255. }
  256. bool PUForceFieldAffectorTranslator::translateChildObject( PUScriptCompiler* /*compiler*/, PUAbstractNode* /*node*/ )
  257. {
  258. // No objects
  259. return false;
  260. }
  261. NS_CC_END