wrap_ParticleSystem.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792
  1. /**
  2. * Copyright (c) 2006-2014 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. // LOVE
  21. #include "wrap_ParticleSystem.h"
  22. #include "common/Vector.h"
  23. #include "Image.h"
  24. #include "Canvas.h"
  25. #include "wrap_Texture.h"
  26. // C
  27. #include <cstring>
  28. // C++
  29. #include <typeinfo>
  30. namespace love
  31. {
  32. namespace graphics
  33. {
  34. namespace opengl
  35. {
  36. ParticleSystem *luax_checkparticlesystem(lua_State *L, int idx)
  37. {
  38. return luax_checktype<ParticleSystem>(L, idx, "ParticleSystem", GRAPHICS_PARTICLE_SYSTEM_T);
  39. }
  40. int w_ParticleSystem_clone(lua_State *L)
  41. {
  42. ParticleSystem *t = luax_checkparticlesystem(L, 1);
  43. ParticleSystem *clone = nullptr;
  44. luax_catchexcept(L, [&](){ clone = t->clone(); });
  45. luax_pushtype(L, "ParticleSystem", GRAPHICS_PARTICLE_SYSTEM_T, clone);
  46. clone->release();
  47. return 1;
  48. }
  49. int w_ParticleSystem_setTexture(lua_State *L)
  50. {
  51. ParticleSystem *t = luax_checkparticlesystem(L, 1);
  52. Texture *tex = luax_checktexture(L, 2);
  53. t->setTexture(tex);
  54. return 0;
  55. }
  56. int w_ParticleSystem_getTexture(lua_State *L)
  57. {
  58. ParticleSystem *t = luax_checkparticlesystem(L, 1);
  59. Texture *tex = t->getTexture();
  60. // FIXME: big hack right here.
  61. if (typeid(*tex) == typeid(Image))
  62. luax_pushtype(L, "Image", GRAPHICS_IMAGE_T, tex);
  63. else if (typeid(*tex) == typeid(Canvas))
  64. luax_pushtype(L, "Canvas", GRAPHICS_CANVAS_T, tex);
  65. else
  66. return luaL_error(L, "Unable to determine texture type.");
  67. return 1;
  68. }
  69. int w_ParticleSystem_setBufferSize(lua_State *L)
  70. {
  71. ParticleSystem *t = luax_checkparticlesystem(L, 1);
  72. lua_Number arg1 = luaL_checknumber(L, 2);
  73. if (arg1 < 1.0 || arg1 > ParticleSystem::MAX_PARTICLES)
  74. return luaL_error(L, "Invalid buffer size");
  75. luax_catchexcept(L, [&](){ t->setBufferSize((uint32) arg1); });
  76. return 0;
  77. }
  78. int w_ParticleSystem_getBufferSize(lua_State *L)
  79. {
  80. ParticleSystem *t = luax_checkparticlesystem(L, 1);
  81. lua_pushinteger(L, t->getBufferSize());
  82. return 1;
  83. }
  84. int w_ParticleSystem_setInsertMode(lua_State *L)
  85. {
  86. ParticleSystem *t = luax_checkparticlesystem(L, 1);
  87. ParticleSystem::InsertMode mode;
  88. const char *str = luaL_checkstring(L, 2);
  89. if (!ParticleSystem::getConstant(str, mode))
  90. return luaL_error(L, "Invalid insert mode: '%s'", str);
  91. t->setInsertMode(mode);
  92. return 0;
  93. }
  94. int w_ParticleSystem_getInsertMode(lua_State *L)
  95. {
  96. ParticleSystem *t = luax_checkparticlesystem(L, 1);
  97. ParticleSystem::InsertMode mode;
  98. mode = t->getInsertMode();
  99. const char *str;
  100. if (!ParticleSystem::getConstant(mode, str))
  101. return luaL_error(L, "Unknown insert mode");
  102. lua_pushstring(L, str);
  103. return 1;
  104. }
  105. int w_ParticleSystem_setEmissionRate(lua_State *L)
  106. {
  107. ParticleSystem *t = luax_checkparticlesystem(L, 1);
  108. float arg1 = (float) luaL_checknumber(L, 2);
  109. luax_catchexcept(L, [&](){ t->setEmissionRate(arg1); });
  110. return 0;
  111. }
  112. int w_ParticleSystem_getEmissionRate(lua_State *L)
  113. {
  114. ParticleSystem *t = luax_checkparticlesystem(L, 1);
  115. lua_pushnumber(L, t->getEmissionRate());
  116. return 1;
  117. }
  118. int w_ParticleSystem_setEmitterLifetime(lua_State *L)
  119. {
  120. ParticleSystem *t = luax_checkparticlesystem(L, 1);
  121. float arg1 = (float)luaL_checknumber(L, 2);
  122. t->setEmitterLifetime(arg1);
  123. return 0;
  124. }
  125. int w_ParticleSystem_getEmitterLifetime(lua_State *L)
  126. {
  127. ParticleSystem *t = luax_checkparticlesystem(L, 1);
  128. lua_pushnumber(L, t->getEmitterLifetime());
  129. return 1;
  130. }
  131. int w_ParticleSystem_setParticleLifetime(lua_State *L)
  132. {
  133. ParticleSystem *t = luax_checkparticlesystem(L, 1);
  134. float arg1 = (float)luaL_checknumber(L, 2);
  135. float arg2 = (float)luaL_optnumber(L, 3, arg1);
  136. t->setParticleLifetime(arg1, arg2);
  137. return 0;
  138. }
  139. int w_ParticleSystem_getParticleLifetime(lua_State *L)
  140. {
  141. ParticleSystem *t = luax_checkparticlesystem(L, 1);
  142. float min, max;
  143. t->getParticleLifetime(min, max);
  144. lua_pushnumber(L, min);
  145. lua_pushnumber(L, max);
  146. return 2;
  147. }
  148. int w_ParticleSystem_setPosition(lua_State *L)
  149. {
  150. ParticleSystem *t = luax_checkparticlesystem(L, 1);
  151. float arg1 = (float)luaL_checknumber(L, 2);
  152. float arg2 = (float)luaL_checknumber(L, 3);
  153. t->setPosition(arg1, arg2);
  154. return 0;
  155. }
  156. int w_ParticleSystem_getPosition(lua_State *L)
  157. {
  158. ParticleSystem *t = luax_checkparticlesystem(L, 1);
  159. love::Vector pos = t->getPosition();
  160. lua_pushnumber(L, pos.getX());
  161. lua_pushnumber(L, pos.getY());
  162. return 2;
  163. }
  164. int w_ParticleSystem_moveTo(lua_State *L)
  165. {
  166. ParticleSystem *t = luax_checkparticlesystem(L, 1);
  167. float arg1 = (float)luaL_checknumber(L, 2);
  168. float arg2 = (float)luaL_checknumber(L, 3);
  169. t->moveTo(arg1, arg2);
  170. return 0;
  171. }
  172. int w_ParticleSystem_setAreaSpread(lua_State *L)
  173. {
  174. ParticleSystem *t = luax_checkparticlesystem(L, 1);
  175. ParticleSystem::AreaSpreadDistribution distribution = ParticleSystem::DISTRIBUTION_NONE;
  176. float x = 0.f, y = 0.f;
  177. const char *str = lua_isnoneornil(L, 2) ? 0 : luaL_checkstring(L, 2);
  178. if (str && !ParticleSystem::getConstant(str, distribution))
  179. return luaL_error(L, "Invalid particle distribution: %s", str);
  180. if (distribution != ParticleSystem::DISTRIBUTION_NONE)
  181. {
  182. x = (float) luaL_checknumber(L, 3);
  183. y = (float) luaL_checknumber(L, 4);
  184. if (x < 0.0f || y < 0.0f)
  185. return luaL_error(L, "Invalid area spread parameters (must be >= 0)");
  186. }
  187. t->setAreaSpread(distribution, x, y);
  188. return 0;
  189. }
  190. int w_ParticleSystem_getAreaSpread(lua_State *L)
  191. {
  192. ParticleSystem *t = luax_checkparticlesystem(L, 1);
  193. ParticleSystem::AreaSpreadDistribution distribution = t-> getAreaSpreadDistribution();
  194. const char *str;
  195. ParticleSystem::getConstant(distribution, str);
  196. const love::Vector &p = t->getAreaSpreadParameters();
  197. lua_pushstring(L, str);
  198. lua_pushnumber(L, p.x);
  199. lua_pushnumber(L, p.y);
  200. return 3;
  201. }
  202. int w_ParticleSystem_setDirection(lua_State *L)
  203. {
  204. ParticleSystem *t = luax_checkparticlesystem(L, 1);
  205. float arg1 = (float)luaL_checknumber(L, 2);
  206. t->setDirection(arg1);
  207. return 0;
  208. }
  209. int w_ParticleSystem_getDirection(lua_State *L)
  210. {
  211. ParticleSystem *t = luax_checkparticlesystem(L, 1);
  212. lua_pushnumber(L, t->getDirection());
  213. return 1;
  214. }
  215. int w_ParticleSystem_setSpread(lua_State *L)
  216. {
  217. ParticleSystem *t = luax_checkparticlesystem(L, 1);
  218. float arg1 = (float)luaL_checknumber(L, 2);
  219. t->setSpread(arg1);
  220. return 0;
  221. }
  222. int w_ParticleSystem_getSpread(lua_State *L)
  223. {
  224. ParticleSystem *t = luax_checkparticlesystem(L, 1);
  225. lua_pushnumber(L, t->getSpread());
  226. return 1;
  227. }
  228. int w_ParticleSystem_setSpeed(lua_State *L)
  229. {
  230. ParticleSystem *t = luax_checkparticlesystem(L, 1);
  231. float arg1 = (float)luaL_checknumber(L, 2);
  232. float arg2 = (float)luaL_optnumber(L, 3, arg1);
  233. t->setSpeed(arg1, arg2);
  234. return 0;
  235. }
  236. int w_ParticleSystem_getSpeed(lua_State *L)
  237. {
  238. ParticleSystem *t = luax_checkparticlesystem(L, 1);
  239. float min, max;
  240. t->getSpeed(min, max);
  241. lua_pushnumber(L, min);
  242. lua_pushnumber(L, max);
  243. return 2;
  244. }
  245. int w_ParticleSystem_setLinearAcceleration(lua_State *L)
  246. {
  247. ParticleSystem *t = luax_checkparticlesystem(L, 1);
  248. float xmin = (float) luaL_checknumber(L, 2);
  249. float ymin = (float) luaL_checknumber(L, 3);
  250. float xmax = (float) luaL_optnumber(L, 4, xmin);
  251. float ymax = (float) luaL_optnumber(L, 5, ymin);
  252. t->setLinearAcceleration(xmin, ymin, xmax, ymax);
  253. return 0;
  254. }
  255. int w_ParticleSystem_getLinearAcceleration(lua_State *L)
  256. {
  257. ParticleSystem *t = luax_checkparticlesystem(L, 1);
  258. love::Vector min, max;
  259. t->getLinearAcceleration(min, max);
  260. lua_pushnumber(L, min.x);
  261. lua_pushnumber(L, min.y);
  262. lua_pushnumber(L, max.x);
  263. lua_pushnumber(L, max.y);
  264. return 4;
  265. }
  266. int w_ParticleSystem_setRadialAcceleration(lua_State *L)
  267. {
  268. ParticleSystem *t = luax_checkparticlesystem(L, 1);
  269. float arg1 = (float)luaL_checknumber(L, 2);
  270. float arg2 = (float)luaL_optnumber(L, 3, arg1);
  271. t->setRadialAcceleration(arg1, arg2);
  272. return 0;
  273. }
  274. int w_ParticleSystem_getRadialAcceleration(lua_State *L)
  275. {
  276. ParticleSystem *t = luax_checkparticlesystem(L, 1);
  277. float min, max;
  278. t->getRadialAcceleration(min, max);
  279. lua_pushnumber(L, min);
  280. lua_pushnumber(L, max);
  281. return 2;
  282. }
  283. int w_ParticleSystem_setTangentialAcceleration(lua_State *L)
  284. {
  285. ParticleSystem *t = luax_checkparticlesystem(L, 1);
  286. float arg1 = (float)luaL_checknumber(L, 2);
  287. float arg2 = (float)luaL_optnumber(L, 3, arg1);
  288. t->setTangentialAcceleration(arg1, arg2);
  289. return 0;
  290. }
  291. int w_ParticleSystem_getTangentialAcceleration(lua_State *L)
  292. {
  293. ParticleSystem *t = luax_checkparticlesystem(L, 1);
  294. float min, max;
  295. t->getTangentialAcceleration(min, max);
  296. lua_pushnumber(L, min);
  297. lua_pushnumber(L, max);
  298. return 2;
  299. }
  300. int w_ParticleSystem_setLinearDamping(lua_State *L)
  301. {
  302. ParticleSystem *t = luax_checkparticlesystem(L, 1);
  303. float arg1 = (float)luaL_checknumber(L, 2);
  304. float arg2 = (float)luaL_optnumber(L, 3, arg1);
  305. t->setLinearDamping(arg1, arg2);
  306. return 0;
  307. }
  308. int w_ParticleSystem_getLinearDamping(lua_State *L)
  309. {
  310. ParticleSystem *t = luax_checkparticlesystem(L, 1);
  311. float min, max;
  312. t->getLinearDamping(min, max);
  313. lua_pushnumber(L, min);
  314. lua_pushnumber(L, max);
  315. return 2;
  316. }
  317. int w_ParticleSystem_setSizes(lua_State *L)
  318. {
  319. ParticleSystem *t = luax_checkparticlesystem(L, 1);
  320. size_t nSizes = lua_gettop(L) - 1;
  321. if (nSizes > 8)
  322. return luaL_error(L, "At most eight (8) sizes may be used.");
  323. if (nSizes <= 1)
  324. {
  325. float size = luax_checkfloat(L, 2);
  326. t->setSize(size);
  327. }
  328. else
  329. {
  330. std::vector<float> sizes(nSizes);
  331. for (size_t i = 0; i < nSizes; ++i)
  332. sizes[i] = luax_checkfloat(L, 1 + i + 1);
  333. t->setSizes(sizes);
  334. }
  335. return 0;
  336. }
  337. int w_ParticleSystem_getSizes(lua_State *L)
  338. {
  339. ParticleSystem *t = luax_checkparticlesystem(L, 1);
  340. const std::vector<float> &sizes = t->getSizes();
  341. for (size_t i = 0; i < sizes.size(); i++)
  342. lua_pushnumber(L, sizes[i]);
  343. return sizes.size();
  344. }
  345. int w_ParticleSystem_setSizeVariation(lua_State *L)
  346. {
  347. ParticleSystem *t = luax_checkparticlesystem(L, 1);
  348. float arg1 = (float)luaL_checknumber(L, 2);
  349. if (arg1 < 0.0f || arg1 > 1.0f)
  350. return luaL_error(L, "Size variation has to be between 0 and 1, inclusive.");
  351. t->setSizeVariation(arg1);
  352. return 0;
  353. }
  354. int w_ParticleSystem_getSizeVariation(lua_State *L)
  355. {
  356. ParticleSystem *t = luax_checkparticlesystem(L, 1);
  357. lua_pushnumber(L, t->getSizeVariation());
  358. return 1;
  359. }
  360. int w_ParticleSystem_setRotation(lua_State *L)
  361. {
  362. ParticleSystem *t = luax_checkparticlesystem(L, 1);
  363. float arg1 = (float)luaL_checknumber(L, 2);
  364. float arg2 = (float)luaL_optnumber(L, 3, arg1);
  365. t->setRotation(arg1, arg2);
  366. return 0;
  367. }
  368. int w_ParticleSystem_getRotation(lua_State *L)
  369. {
  370. ParticleSystem *t = luax_checkparticlesystem(L, 1);
  371. float min, max;
  372. t->getRotation(min, max);
  373. lua_pushnumber(L, min);
  374. lua_pushnumber(L, max);
  375. return 2;
  376. }
  377. int w_ParticleSystem_setSpin(lua_State *L)
  378. {
  379. ParticleSystem *t = luax_checkparticlesystem(L, 1);
  380. float arg1 = (float)luaL_checknumber(L, 2);
  381. float arg2 = (float)luaL_optnumber(L, 3, arg1);
  382. t->setSpin(arg1, arg2);
  383. return 0;
  384. }
  385. int w_ParticleSystem_getSpin(lua_State *L)
  386. {
  387. ParticleSystem *t = luax_checkparticlesystem(L, 1);
  388. float start, end;
  389. t->getSpin(start, end);
  390. lua_pushnumber(L, start);
  391. lua_pushnumber(L, end);
  392. return 2;
  393. }
  394. int w_ParticleSystem_setSpinVariation(lua_State *L)
  395. {
  396. ParticleSystem *t = luax_checkparticlesystem(L, 1);
  397. float arg1 = (float)luaL_checknumber(L, 2);
  398. t->setSpinVariation(arg1);
  399. return 0;
  400. }
  401. int w_ParticleSystem_getSpinVariation(lua_State *L)
  402. {
  403. ParticleSystem *t = luax_checkparticlesystem(L, 1);
  404. lua_pushnumber(L, t->getSpinVariation());
  405. return 1;
  406. }
  407. int w_ParticleSystem_setOffset(lua_State *L)
  408. {
  409. ParticleSystem *t = luax_checkparticlesystem(L, 1);
  410. float x = (float)luaL_checknumber(L, 2);
  411. float y = (float)luaL_checknumber(L, 3);
  412. t->setOffset(x, y);
  413. return 0;
  414. }
  415. int w_ParticleSystem_getOffset(lua_State *L)
  416. {
  417. ParticleSystem *t = luax_checkparticlesystem(L, 1);
  418. love::Vector offset = t->getOffset();
  419. lua_pushnumber(L, offset.getX());
  420. lua_pushnumber(L, offset.getY());
  421. return 2;
  422. }
  423. int w_ParticleSystem_setColors(lua_State *L)
  424. {
  425. ParticleSystem *t = luax_checkparticlesystem(L, 1);
  426. if (lua_istable(L, 2)) // setColors({r,g,b,a}, {r,g,b,a}, ...)
  427. {
  428. size_t nColors = lua_gettop(L) - 1;
  429. if (nColors > 8)
  430. return luaL_error(L, "At most eight (8) colors may be used.");
  431. std::vector<Color> colors(nColors);
  432. for (size_t i = 0; i < nColors; i++)
  433. {
  434. luaL_checktype(L, i + 2, LUA_TTABLE);
  435. if (lua_objlen(L, i + 2) < 3)
  436. return luaL_argerror(L, i + 2, "expected 4 color components");
  437. for (int j = 0; j < 4; j++)
  438. // push args[i+2][j+1] onto the stack
  439. lua_rawgeti(L, i + 2, j + 1);
  440. unsigned char r = (unsigned char) luaL_checkinteger(L, -4);
  441. unsigned char g = (unsigned char) luaL_checkinteger(L, -3);
  442. unsigned char b = (unsigned char) luaL_checkinteger(L, -2);
  443. unsigned char a = (unsigned char) luaL_optinteger(L, -1, 255);
  444. // pop the color components from the stack
  445. lua_pop(L, 4);
  446. colors[i] = Color(r, g, b, a);
  447. }
  448. t->setColor(colors);
  449. }
  450. else // setColors(r,g,b,a, r,g,b,a, ...)
  451. {
  452. int cargs = lua_gettop(L) - 1;
  453. size_t nColors = (cargs + 3) / 4; // nColors = ceil(color_args / 4)
  454. if (cargs != 3 && (cargs % 4 != 0 || cargs == 0))
  455. return luaL_error(L, "Expected red, green, blue, and alpha. Only got %d of 4 components.", cargs % 4);
  456. if (nColors > 8)
  457. return luaL_error(L, "At most eight (8) colors may be used.");
  458. if (nColors == 1)
  459. {
  460. unsigned char r = (unsigned char) luaL_checkinteger(L, 2);
  461. unsigned char g = (unsigned char) luaL_checkinteger(L, 3);
  462. unsigned char b = (unsigned char) luaL_checkinteger(L, 4);
  463. unsigned char a = (unsigned char) luaL_optinteger(L, 5, 255);
  464. t->setColor(Color(r,g,b,a));
  465. }
  466. else
  467. {
  468. std::vector<Color> colors(nColors);
  469. for (size_t i = 0; i < nColors; ++i)
  470. {
  471. unsigned char r = (unsigned char) luaL_checkinteger(L, 1 + i*4 + 1);
  472. unsigned char g = (unsigned char) luaL_checkinteger(L, 1 + i*4 + 2);
  473. unsigned char b = (unsigned char) luaL_checkinteger(L, 1 + i*4 + 3);
  474. unsigned char a = (unsigned char) luaL_checkinteger(L, 1 + i*4 + 4);
  475. colors[i] = Color(r,g,b,a);
  476. }
  477. t->setColor(colors);
  478. }
  479. }
  480. return 0;
  481. }
  482. int w_ParticleSystem_getColors(lua_State *L)
  483. {
  484. ParticleSystem *t = luax_checkparticlesystem(L, 1);
  485. const std::vector<Color> &colors =t->getColor();
  486. for (size_t i = 0; i < colors.size(); i++)
  487. {
  488. lua_createtable(L, 4, 0);
  489. lua_pushinteger(L, colors[i].r);
  490. lua_rawseti(L, -2, 1);
  491. lua_pushinteger(L, colors[i].g);
  492. lua_rawseti(L, -2, 2);
  493. lua_pushinteger(L, colors[i].b);
  494. lua_rawseti(L, -2, 3);
  495. lua_pushinteger(L, colors[i].a);
  496. lua_rawseti(L, -2, 4);
  497. }
  498. return colors.size();
  499. }
  500. int w_ParticleSystem_setQuads(lua_State *L)
  501. {
  502. ParticleSystem *t = luax_checkparticlesystem(L, 1);
  503. std::vector<Quad *> quads;
  504. if (lua_istable(L, 2))
  505. {
  506. for (size_t i = 1; i <= lua_objlen(L, 2); i++)
  507. {
  508. lua_rawgeti(L, 2, i);
  509. Quad *q = luax_checktype<Quad>(L, -1, "Quad", GRAPHICS_QUAD_T);
  510. quads.push_back(q);
  511. lua_pop(L, 1);
  512. }
  513. }
  514. else
  515. {
  516. for (int i = 2; i <= lua_gettop(L); i++)
  517. {
  518. Quad *q = luax_checktype<Quad>(L, i, "Quad", GRAPHICS_QUAD_T);
  519. quads.push_back(q);
  520. }
  521. }
  522. t->setQuads(quads);
  523. return 0;
  524. }
  525. int w_ParticleSystem_getQuads(lua_State *L)
  526. {
  527. ParticleSystem *t = luax_checkparticlesystem(L, 1);
  528. const std::vector<Quad *> quads = t->getQuads();
  529. lua_createtable(L, (int) quads.size(), 0);
  530. for (size_t i = 0; i < quads.size(); i++)
  531. {
  532. luax_pushtype(L, "Quad", GRAPHICS_QUAD_T, quads[i]);
  533. lua_rawseti(L, -2, i + 1);
  534. }
  535. return 1;
  536. }
  537. int w_ParticleSystem_setRelativeRotation(lua_State *L)
  538. {
  539. ParticleSystem *t = luax_checkparticlesystem(L, 1);
  540. t->setRelativeRotation(luax_toboolean(L, 2));
  541. return 0;
  542. }
  543. int w_ParticleSystem_hasRelativeRotation(lua_State *L)
  544. {
  545. ParticleSystem *t = luax_checkparticlesystem(L, 1);
  546. luax_pushboolean(L, t->hasRelativeRotation());
  547. return 1;
  548. }
  549. int w_ParticleSystem_getCount(lua_State *L)
  550. {
  551. ParticleSystem *t = luax_checkparticlesystem(L, 1);
  552. lua_pushnumber(L, t->getCount());
  553. return 1;
  554. }
  555. int w_ParticleSystem_start(lua_State *L)
  556. {
  557. ParticleSystem *t = luax_checkparticlesystem(L, 1);
  558. t->start();
  559. return 0;
  560. }
  561. int w_ParticleSystem_stop(lua_State *L)
  562. {
  563. ParticleSystem *t = luax_checkparticlesystem(L, 1);
  564. t->stop();
  565. return 0;
  566. }
  567. int w_ParticleSystem_pause(lua_State *L)
  568. {
  569. ParticleSystem *t = luax_checkparticlesystem(L, 1);
  570. t->pause();
  571. return 0;
  572. }
  573. int w_ParticleSystem_reset(lua_State *L)
  574. {
  575. ParticleSystem *t = luax_checkparticlesystem(L, 1);
  576. t->reset();
  577. return 0;
  578. }
  579. int w_ParticleSystem_emit(lua_State *L)
  580. {
  581. ParticleSystem *t = luax_checkparticlesystem(L, 1);
  582. int num = luaL_checkint(L, 2);
  583. t->emit(num);
  584. return 0;
  585. }
  586. int w_ParticleSystem_isActive(lua_State *L)
  587. {
  588. ParticleSystem *t = luax_checkparticlesystem(L, 1);
  589. luax_pushboolean(L, t->isActive());
  590. return 1;
  591. }
  592. int w_ParticleSystem_isPaused(lua_State *L)
  593. {
  594. ParticleSystem *t = luax_checkparticlesystem(L, 1);
  595. luax_pushboolean(L, t->isPaused());
  596. return 1;
  597. }
  598. int w_ParticleSystem_isStopped(lua_State *L)
  599. {
  600. ParticleSystem *t = luax_checkparticlesystem(L, 1);
  601. luax_pushboolean(L, t->isStopped());
  602. return 1;
  603. }
  604. int w_ParticleSystem_update(lua_State *L)
  605. {
  606. ParticleSystem *t = luax_checkparticlesystem(L, 1);
  607. float dt = (float)luaL_checknumber(L, 2);
  608. t->update(dt);
  609. return 0;
  610. }
  611. static const luaL_Reg functions[] =
  612. {
  613. { "clone", w_ParticleSystem_clone },
  614. { "setTexture", w_ParticleSystem_setTexture },
  615. { "getTexture", w_ParticleSystem_getTexture },
  616. { "setBufferSize", w_ParticleSystem_setBufferSize },
  617. { "getBufferSize", w_ParticleSystem_getBufferSize },
  618. { "setInsertMode", w_ParticleSystem_setInsertMode },
  619. { "getInsertMode", w_ParticleSystem_getInsertMode },
  620. { "setEmissionRate", w_ParticleSystem_setEmissionRate },
  621. { "getEmissionRate", w_ParticleSystem_getEmissionRate },
  622. { "setEmitterLifetime", w_ParticleSystem_setEmitterLifetime },
  623. { "getEmitterLifetime", w_ParticleSystem_getEmitterLifetime },
  624. { "setParticleLifetime", w_ParticleSystem_setParticleLifetime },
  625. { "getParticleLifetime", w_ParticleSystem_getParticleLifetime },
  626. { "setPosition", w_ParticleSystem_setPosition },
  627. { "getPosition", w_ParticleSystem_getPosition },
  628. { "moveTo", w_ParticleSystem_moveTo },
  629. { "setAreaSpread", w_ParticleSystem_setAreaSpread },
  630. { "getAreaSpread", w_ParticleSystem_getAreaSpread },
  631. { "setDirection", w_ParticleSystem_setDirection },
  632. { "getDirection", w_ParticleSystem_getDirection },
  633. { "setSpread", w_ParticleSystem_setSpread },
  634. { "getSpread", w_ParticleSystem_getSpread },
  635. { "setSpeed", w_ParticleSystem_setSpeed },
  636. { "getSpeed", w_ParticleSystem_getSpeed },
  637. { "setLinearAcceleration", w_ParticleSystem_setLinearAcceleration },
  638. { "getLinearAcceleration", w_ParticleSystem_getLinearAcceleration },
  639. { "setRadialAcceleration", w_ParticleSystem_setRadialAcceleration },
  640. { "getRadialAcceleration", w_ParticleSystem_getRadialAcceleration },
  641. { "setTangentialAcceleration", w_ParticleSystem_setTangentialAcceleration },
  642. { "getTangentialAcceleration", w_ParticleSystem_getTangentialAcceleration },
  643. { "setLinearDamping", w_ParticleSystem_setLinearDamping },
  644. { "getLinearDamping", w_ParticleSystem_getLinearDamping },
  645. { "setSizes", w_ParticleSystem_setSizes },
  646. { "getSizes", w_ParticleSystem_getSizes },
  647. { "setSizeVariation", w_ParticleSystem_setSizeVariation },
  648. { "getSizeVariation", w_ParticleSystem_getSizeVariation },
  649. { "setRotation", w_ParticleSystem_setRotation },
  650. { "getRotation", w_ParticleSystem_getRotation },
  651. { "setSpin", w_ParticleSystem_setSpin },
  652. { "getSpin", w_ParticleSystem_getSpin },
  653. { "setSpinVariation", w_ParticleSystem_setSpinVariation },
  654. { "getSpinVariation", w_ParticleSystem_getSpinVariation },
  655. { "setColors", w_ParticleSystem_setColors },
  656. { "getColors", w_ParticleSystem_getColors },
  657. { "setQuads", w_ParticleSystem_setQuads },
  658. { "getQuads", w_ParticleSystem_getQuads },
  659. { "setOffset", w_ParticleSystem_setOffset },
  660. { "getOffset", w_ParticleSystem_getOffset },
  661. { "setRelativeRotation", w_ParticleSystem_setRelativeRotation },
  662. { "hasRelativeRotation", w_ParticleSystem_hasRelativeRotation },
  663. { "getCount", w_ParticleSystem_getCount },
  664. { "start", w_ParticleSystem_start },
  665. { "stop", w_ParticleSystem_stop },
  666. { "pause", w_ParticleSystem_pause },
  667. { "reset", w_ParticleSystem_reset },
  668. { "emit", w_ParticleSystem_emit },
  669. { "isActive", w_ParticleSystem_isActive },
  670. { "isPaused", w_ParticleSystem_isPaused },
  671. { "isStopped", w_ParticleSystem_isStopped },
  672. { "update", w_ParticleSystem_update },
  673. { 0, 0 }
  674. };
  675. extern "C" int luaopen_particlesystem(lua_State *L)
  676. {
  677. return luax_register_type(L, "ParticleSystem", functions);
  678. }
  679. } // opengl
  680. } // graphics
  681. } // love