wrap_ParticleSystem.cpp 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  1. /**
  2. * Copyright (c) 2006-2009 LOVE Development Team
  3. *
  4. * This software is provided 'as-is', without any express or implied
  5. * warranty. In no event will the authors be held liable for any damages
  6. * arising from the use of this software.
  7. *
  8. * Permission is granted to anyone to use this software for any purpose,
  9. * including commercial applications, and to alter it and redistribute it
  10. * freely, subject to the following restrictions:
  11. *
  12. * 1. The origin of this software must not be misrepresented; you must not
  13. * claim that you wrote the original software. If you use this software
  14. * in a product, an acknowledgment in the product documentation would be
  15. * appreciated but is not required.
  16. * 2. Altered source versions must be plainly marked as such, and must not be
  17. * misrepresented as being the original software.
  18. * 3. This notice may not be removed or altered from any source distribution.
  19. **/
  20. #include "wrap_ParticleSystem.h"
  21. #include <cstring>
  22. namespace love
  23. {
  24. namespace graphics
  25. {
  26. namespace opengl
  27. {
  28. ParticleSystem * luax_checkparticlesystem(lua_State * L, int idx)
  29. {
  30. return luax_checktype<ParticleSystem>(L, idx, "ParticleSystem", GRAPHICS_PARTICLE_SYSTEM_T);
  31. }
  32. int w_ParticleSystem_setSprite(lua_State * L)
  33. {
  34. ParticleSystem * t = luax_checkparticlesystem(L, 1);
  35. Image * i = luax_checkimage(L, 2);
  36. t->setSprite(i);
  37. return 0;
  38. }
  39. int w_ParticleSystem_setBufferSize(lua_State * L)
  40. {
  41. ParticleSystem * t = luax_checkparticlesystem(L, 1);
  42. int arg1 = luaL_checkint(L, 2);
  43. t->setBufferSize((unsigned int)arg1);
  44. return 0;
  45. }
  46. int w_ParticleSystem_setEmissionRate(lua_State * L)
  47. {
  48. ParticleSystem * t = luax_checkparticlesystem(L, 1);
  49. int arg1 = luaL_checkint(L, 2);
  50. t->setEmissionRate((unsigned int)arg1);
  51. return 0;
  52. }
  53. int w_ParticleSystem_setLifetime(lua_State * L)
  54. {
  55. ParticleSystem * t = luax_checkparticlesystem(L, 1);
  56. float arg1 = (float)luaL_checknumber(L, 2);
  57. t->setLifetime(arg1);
  58. return 0;
  59. }
  60. int w_ParticleSystem_setParticleLife(lua_State * L)
  61. {
  62. ParticleSystem * t = luax_checkparticlesystem(L, 1);
  63. float arg1 = (float)luaL_checknumber(L, 2);
  64. float arg2 = (float)luaL_checknumber(L, 3);
  65. t->setParticleLife(arg1, arg2);
  66. return 0;
  67. }
  68. int w_ParticleSystem_setPosition(lua_State * L)
  69. {
  70. ParticleSystem * t = luax_checkparticlesystem(L, 1);
  71. float arg1 = (float)luaL_checknumber(L, 2);
  72. float arg2 = (float)luaL_checknumber(L, 3);
  73. t->setPosition(arg1, arg2);
  74. return 0;
  75. }
  76. int w_ParticleSystem_setDirection(lua_State * L)
  77. {
  78. ParticleSystem * t = luax_checkparticlesystem(L, 1);
  79. float arg1 = (float)luaL_checknumber(L, 2);
  80. t->setDirection(arg1);
  81. return 0;
  82. }
  83. int w_ParticleSystem_setSpread(lua_State * L)
  84. {
  85. ParticleSystem * t = luax_checkparticlesystem(L, 1);
  86. float arg1 = (float)luaL_checknumber(L, 2);
  87. t->setSpread(arg1);
  88. return 0;
  89. }
  90. int w_ParticleSystem_setRelativeDirection(lua_State * L)
  91. {
  92. ParticleSystem * t = luax_checkparticlesystem(L, 1);
  93. bool arg1 = (bool)luax_toboolean(L, 2);
  94. t->setRelativeDirection(arg1);
  95. return 0;
  96. }
  97. int w_ParticleSystem_setSpeed(lua_State * L)
  98. {
  99. ParticleSystem * t = luax_checkparticlesystem(L, 1);
  100. float arg1 = (float)luaL_checknumber(L, 2);
  101. float arg2 = (float)luaL_optnumber(L, 3, arg1);
  102. t->setSpeed(arg1, arg2);
  103. return 0;
  104. }
  105. int w_ParticleSystem_setGravity(lua_State * L)
  106. {
  107. ParticleSystem * t = luax_checkparticlesystem(L, 1);
  108. float arg1 = (float)luaL_checknumber(L, 2);
  109. float arg2 = (float)luaL_optnumber(L, 3, arg1);
  110. t->setGravity(arg1, arg2);
  111. return 0;
  112. }
  113. int w_ParticleSystem_setRadialAcceleration(lua_State * L)
  114. {
  115. ParticleSystem * t = luax_checkparticlesystem(L, 1);
  116. float arg1 = (float)luaL_checknumber(L, 2);
  117. float arg2 = (float)luaL_optnumber(L, 3, arg1);
  118. t->setRadialAcceleration(arg1, arg2);
  119. return 0;
  120. }
  121. int w_ParticleSystem_setTangentialAcceleration(lua_State * L)
  122. {
  123. ParticleSystem * t = luax_checkparticlesystem(L, 1);
  124. float arg1 = (float)luaL_checknumber(L, 2);
  125. float arg2 = (float)luaL_optnumber(L, 3, arg1);
  126. t->setTangentialAcceleration(arg1, arg2);
  127. return 0;
  128. }
  129. int w_ParticleSystem_setSize(lua_State * L)
  130. {
  131. ParticleSystem * t = luax_checkparticlesystem(L, 1);
  132. float arg1 = (float)luaL_checknumber(L, 2);
  133. float arg2 = (float)luaL_optnumber(L, 3, arg1);
  134. float arg3 = (float)luaL_optnumber(L, 3, 0);
  135. t->setSize(arg1, arg2, arg3);
  136. return 0;
  137. }
  138. int w_ParticleSystem_setSizeVariation(lua_State * L)
  139. {
  140. ParticleSystem * t = luax_checkparticlesystem(L, 1);
  141. float arg1 = (float)luaL_checknumber(L, 2);
  142. t->setSizeVariation(arg1);
  143. return 0;
  144. }
  145. int w_ParticleSystem_setRotation(lua_State * L)
  146. {
  147. ParticleSystem * t = luax_checkparticlesystem(L, 1);
  148. float arg1 = (float)luaL_checknumber(L, 2);
  149. float arg2 = (float)luaL_optnumber(L, 3, arg1);
  150. t->setRotation(arg1, arg2);
  151. return 0;
  152. }
  153. int w_ParticleSystem_setSpin(lua_State * L)
  154. {
  155. ParticleSystem * t = luax_checkparticlesystem(L, 1);
  156. float arg1 = (float)luaL_checknumber(L, 2);
  157. float arg2 = (float)luaL_optnumber(L, 3, arg1);
  158. float arg3 = (float)luaL_optnumber(L, 3, 0);
  159. t->setSpin(arg1, arg2, arg3);
  160. return 0;
  161. }
  162. int w_ParticleSystem_setSpinVariation(lua_State * L)
  163. {
  164. ParticleSystem * t = luax_checkparticlesystem(L, 1);
  165. float arg1 = (float)luaL_checknumber(L, 2);
  166. t->setSpinVariation(arg1);
  167. return 0;
  168. }
  169. int w_ParticleSystem_setColor(lua_State * L)
  170. {
  171. ParticleSystem * t = luax_checkparticlesystem(L, 1);
  172. unsigned char start[4];
  173. start[0] = (unsigned char)luaL_checkint(L, 2);
  174. start[1] = (unsigned char)luaL_checkint(L, 3);
  175. start[2] = (unsigned char)luaL_checkint(L, 4);
  176. start[3] = (unsigned char)luaL_checkint(L, 5);
  177. if(lua_gettop(L) > 5)
  178. {
  179. unsigned char end[4];
  180. end[0] = (unsigned char)luaL_checkint(L, 6);
  181. end[1] = (unsigned char)luaL_checkint(L, 7);
  182. end[2] = (unsigned char)luaL_checkint(L, 8);
  183. end[3] = (unsigned char)luaL_checkint(L, 9);
  184. t->setColor(start, end);
  185. }
  186. else
  187. t->setColor(start);
  188. return 0;
  189. }
  190. int w_ParticleSystem_getX(lua_State * L)
  191. {
  192. ParticleSystem * t = luax_checkparticlesystem(L, 1);
  193. lua_pushnumber(L, t->getX());
  194. return 1;
  195. }
  196. int w_ParticleSystem_getY(lua_State * L)
  197. {
  198. ParticleSystem * t = luax_checkparticlesystem(L, 1);
  199. lua_pushnumber(L, t->getY());
  200. return 1;
  201. }
  202. int w_ParticleSystem_getDirection(lua_State * L)
  203. {
  204. ParticleSystem * t = luax_checkparticlesystem(L, 1);
  205. lua_pushnumber(L, t->getDirection());
  206. return 1;
  207. }
  208. int w_ParticleSystem_getSpread(lua_State * L)
  209. {
  210. ParticleSystem * t = luax_checkparticlesystem(L, 1);
  211. lua_pushnumber(L, t->getSpread());
  212. return 1;
  213. }
  214. int w_ParticleSystem_count(lua_State * L)
  215. {
  216. ParticleSystem * t = luax_checkparticlesystem(L, 1);
  217. lua_pushnumber(L, t->count());
  218. return 1;
  219. }
  220. int w_ParticleSystem_start(lua_State * L)
  221. {
  222. ParticleSystem * t = luax_checkparticlesystem(L, 1);
  223. t->start();
  224. return 0;
  225. }
  226. int w_ParticleSystem_stop(lua_State * L)
  227. {
  228. ParticleSystem * t = luax_checkparticlesystem(L, 1);
  229. t->stop();
  230. return 0;
  231. }
  232. int w_ParticleSystem_pause(lua_State * L)
  233. {
  234. ParticleSystem * t = luax_checkparticlesystem(L, 1);
  235. t->pause();
  236. return 0;
  237. }
  238. int w_ParticleSystem_reset(lua_State * L)
  239. {
  240. ParticleSystem * t = luax_checkparticlesystem(L, 1);
  241. t->reset();
  242. return 0;
  243. }
  244. int w_ParticleSystem_isActive(lua_State * L)
  245. {
  246. ParticleSystem * t = luax_checkparticlesystem(L, 1);
  247. luax_pushboolean(L, t->isActive());
  248. return 1;
  249. }
  250. int w_ParticleSystem_isEmpty(lua_State * L)
  251. {
  252. ParticleSystem * t = luax_checkparticlesystem(L, 1);
  253. luax_pushboolean(L, t->isEmpty());
  254. return 1;
  255. }
  256. int w_ParticleSystem_isFull(lua_State * L)
  257. {
  258. ParticleSystem * t = luax_checkparticlesystem(L, 1);
  259. luax_pushboolean(L, t->isFull());
  260. return 1;
  261. }
  262. int w_ParticleSystem_update(lua_State * L)
  263. {
  264. ParticleSystem * t = luax_checkparticlesystem(L, 1);
  265. float dt = (float)luaL_checknumber(L, 2);
  266. t->update(dt);
  267. return 0;
  268. }
  269. static const luaL_Reg functions[] = {
  270. { "setSprite", w_ParticleSystem_setSprite },
  271. { "setBufferSize", w_ParticleSystem_setBufferSize },
  272. { "setEmissionRate", w_ParticleSystem_setEmissionRate },
  273. { "setLifeTime", w_ParticleSystem_setLifetime },
  274. { "setParticleLife", w_ParticleSystem_setParticleLife },
  275. { "setPosition", w_ParticleSystem_setPosition },
  276. { "setDirection", w_ParticleSystem_setDirection },
  277. { "setSpread", w_ParticleSystem_setSpread },
  278. { "setRelativeDirection", w_ParticleSystem_setRelativeDirection },
  279. { "setSpeed", w_ParticleSystem_setSpeed },
  280. { "setGravity", w_ParticleSystem_setGravity },
  281. { "setRadialAcceleration", w_ParticleSystem_setRadialAcceleration },
  282. { "setTangentialAcceleration", w_ParticleSystem_setTangentialAcceleration },
  283. { "setSize", w_ParticleSystem_setSize },
  284. { "setSizeVariation", w_ParticleSystem_setSizeVariation },
  285. { "setRotation", w_ParticleSystem_setRotation },
  286. { "setSpin", w_ParticleSystem_setSpin },
  287. { "setSpinVariation", w_ParticleSystem_setSpinVariation },
  288. { "setColor", w_ParticleSystem_setColor },
  289. { "getX", w_ParticleSystem_getX },
  290. { "getY", w_ParticleSystem_getY },
  291. { "getDirection", w_ParticleSystem_getDirection },
  292. { "getSpread", w_ParticleSystem_getSpread },
  293. { "count", w_ParticleSystem_count },
  294. { "start", w_ParticleSystem_start },
  295. { "stop", w_ParticleSystem_stop },
  296. { "pause", w_ParticleSystem_pause },
  297. { "reset", w_ParticleSystem_reset },
  298. { "isActive", w_ParticleSystem_isActive },
  299. { "isEmpty", w_ParticleSystem_isEmpty },
  300. { "isFull", w_ParticleSystem_isFull },
  301. { "update", w_ParticleSystem_update },
  302. { 0, 0 }
  303. };
  304. int luaopen_particlesystem(lua_State * L)
  305. {
  306. return luax_register_type(L, "ParticleSystem", functions);
  307. }
  308. } // opengl
  309. } // graphics
  310. } // love