CCPUForceFieldAffectorTranslator.cpp 9.4 KB

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