wrap_ParticleSystem.cpp 20 KB

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