1 /** 2 * Copyright (c) 2006-2011 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 21 #include "wrap_ParticleSystem.h" 22 23 #include <cstring> 24 25 namespace love 26 { 27 namespace graphics 28 { 29 namespace opengl 30 { luax_checkparticlesystem(lua_State * L,int idx)31 ParticleSystem * luax_checkparticlesystem(lua_State * L, int idx) 32 { 33 return luax_checktype<ParticleSystem>(L, idx, "ParticleSystem", GRAPHICS_PARTICLE_SYSTEM_T); 34 } 35 w_ParticleSystem_setSprite(lua_State * L)36 int w_ParticleSystem_setSprite(lua_State * L) 37 { 38 ParticleSystem * t = luax_checkparticlesystem(L, 1); 39 Image * i = luax_checkimage(L, 2); 40 t->setSprite(i); 41 return 0; 42 } 43 w_ParticleSystem_setBufferSize(lua_State * L)44 int w_ParticleSystem_setBufferSize(lua_State * L) 45 { 46 ParticleSystem * t = luax_checkparticlesystem(L, 1); 47 int arg1 = luaL_checkint(L, 2); 48 t->setBufferSize((unsigned int)arg1); 49 return 0; 50 } 51 w_ParticleSystem_setEmissionRate(lua_State * L)52 int w_ParticleSystem_setEmissionRate(lua_State * L) 53 { 54 ParticleSystem * t = luax_checkparticlesystem(L, 1); 55 int arg1 = luaL_checkint(L, 2); 56 t->setEmissionRate((unsigned int)arg1); 57 return 0; 58 } 59 w_ParticleSystem_setLifetime(lua_State * L)60 int w_ParticleSystem_setLifetime(lua_State * L) 61 { 62 ParticleSystem * t = luax_checkparticlesystem(L, 1); 63 float arg1 = (float)luaL_checknumber(L, 2); 64 t->setLifetime(arg1); 65 return 0; 66 } 67 w_ParticleSystem_setParticleLife(lua_State * L)68 int w_ParticleSystem_setParticleLife(lua_State * L) 69 { 70 ParticleSystem * t = luax_checkparticlesystem(L, 1); 71 float arg1 = (float)luaL_checknumber(L, 2); 72 float arg2 = (float)luaL_optnumber(L, 3, arg1); 73 t->setParticleLife(arg1, arg2); 74 return 0; 75 } 76 w_ParticleSystem_setPosition(lua_State * L)77 int w_ParticleSystem_setPosition(lua_State * L) 78 { 79 ParticleSystem * t = luax_checkparticlesystem(L, 1); 80 float arg1 = (float)luaL_checknumber(L, 2); 81 float arg2 = (float)luaL_checknumber(L, 3); 82 t->setPosition(arg1, arg2); 83 return 0; 84 } 85 w_ParticleSystem_setDirection(lua_State * L)86 int w_ParticleSystem_setDirection(lua_State * L) 87 { 88 ParticleSystem * t = luax_checkparticlesystem(L, 1); 89 float arg1 = (float)luaL_checknumber(L, 2); 90 t->setDirection(arg1); 91 return 0; 92 } 93 w_ParticleSystem_setSpread(lua_State * L)94 int w_ParticleSystem_setSpread(lua_State * L) 95 { 96 ParticleSystem * t = luax_checkparticlesystem(L, 1); 97 float arg1 = (float)luaL_checknumber(L, 2); 98 t->setSpread(arg1); 99 return 0; 100 } 101 w_ParticleSystem_setRelativeDirection(lua_State * L)102 int w_ParticleSystem_setRelativeDirection(lua_State * L) 103 { 104 ParticleSystem * t = luax_checkparticlesystem(L, 1); 105 bool arg1 = (bool)luax_toboolean(L, 2); 106 t->setRelativeDirection(arg1); 107 return 0; 108 } 109 w_ParticleSystem_setSpeed(lua_State * L)110 int w_ParticleSystem_setSpeed(lua_State * L) 111 { 112 ParticleSystem * t = luax_checkparticlesystem(L, 1); 113 float arg1 = (float)luaL_checknumber(L, 2); 114 float arg2 = (float)luaL_optnumber(L, 3, arg1); 115 t->setSpeed(arg1, arg2); 116 return 0; 117 } 118 w_ParticleSystem_setGravity(lua_State * L)119 int w_ParticleSystem_setGravity(lua_State * L) 120 { 121 ParticleSystem * t = luax_checkparticlesystem(L, 1); 122 float arg1 = (float)luaL_checknumber(L, 2); 123 float arg2 = (float)luaL_optnumber(L, 3, arg1); 124 t->setGravity(arg1, arg2); 125 return 0; 126 } 127 w_ParticleSystem_setRadialAcceleration(lua_State * L)128 int w_ParticleSystem_setRadialAcceleration(lua_State * L) 129 { 130 ParticleSystem * t = luax_checkparticlesystem(L, 1); 131 float arg1 = (float)luaL_checknumber(L, 2); 132 float arg2 = (float)luaL_optnumber(L, 3, arg1); 133 t->setRadialAcceleration(arg1, arg2); 134 return 0; 135 } 136 w_ParticleSystem_setTangentialAcceleration(lua_State * L)137 int w_ParticleSystem_setTangentialAcceleration(lua_State * L) 138 { 139 ParticleSystem * t = luax_checkparticlesystem(L, 1); 140 float arg1 = (float)luaL_checknumber(L, 2); 141 float arg2 = (float)luaL_optnumber(L, 3, arg1); 142 t->setTangentialAcceleration(arg1, arg2); 143 return 0; 144 } 145 w_ParticleSystem_setSize(lua_State * L)146 int w_ParticleSystem_setSize(lua_State * L) 147 { 148 ParticleSystem * t = luax_checkparticlesystem(L, 1); 149 float arg1 = (float)luaL_checknumber(L, 2); 150 float arg2 = (float)luaL_optnumber(L, 3, arg1); 151 float arg3 = (float)luaL_optnumber(L, 4, 0); 152 t->setSize(arg1, arg2, arg3); 153 return 0; 154 } 155 w_ParticleSystem_setSizeVariation(lua_State * L)156 int w_ParticleSystem_setSizeVariation(lua_State * L) 157 { 158 ParticleSystem * t = luax_checkparticlesystem(L, 1); 159 float arg1 = (float)luaL_checknumber(L, 2); 160 t->setSizeVariation(arg1); 161 return 0; 162 } 163 w_ParticleSystem_setRotation(lua_State * L)164 int w_ParticleSystem_setRotation(lua_State * L) 165 { 166 ParticleSystem * t = luax_checkparticlesystem(L, 1); 167 float arg1 = (float)luaL_checknumber(L, 2); 168 float arg2 = (float)luaL_optnumber(L, 3, arg1); 169 t->setRotation(arg1, arg2); 170 return 0; 171 } 172 w_ParticleSystem_setSpin(lua_State * L)173 int w_ParticleSystem_setSpin(lua_State * L) 174 { 175 ParticleSystem * t = luax_checkparticlesystem(L, 1); 176 float arg1 = (float)luaL_checknumber(L, 2); 177 float arg2 = (float)luaL_optnumber(L, 3, arg1); 178 float arg3 = (float)luaL_optnumber(L, 3, 0); 179 t->setSpin(arg1, arg2, arg3); 180 return 0; 181 } 182 w_ParticleSystem_setSpinVariation(lua_State * L)183 int w_ParticleSystem_setSpinVariation(lua_State * L) 184 { 185 ParticleSystem * t = luax_checkparticlesystem(L, 1); 186 float arg1 = (float)luaL_checknumber(L, 2); 187 t->setSpinVariation(arg1); 188 return 0; 189 } 190 w_ParticleSystem_setColor(lua_State * L)191 int w_ParticleSystem_setColor(lua_State * L) 192 { 193 ParticleSystem * t = luax_checkparticlesystem(L, 1); 194 195 unsigned char start[4]; 196 197 start[0] = (unsigned char)luaL_checkint(L, 2); 198 start[1] = (unsigned char)luaL_checkint(L, 3); 199 start[2] = (unsigned char)luaL_checkint(L, 4); 200 start[3] = (unsigned char)luaL_checkint(L, 5); 201 202 if(lua_gettop(L) > 5) 203 { 204 unsigned char end[4]; 205 end[0] = (unsigned char)luaL_checkint(L, 6); 206 end[1] = (unsigned char)luaL_checkint(L, 7); 207 end[2] = (unsigned char)luaL_checkint(L, 8); 208 end[3] = (unsigned char)luaL_checkint(L, 9); 209 t->setColor(start, end); 210 } 211 else 212 t->setColor(start); 213 214 return 0; 215 } 216 w_ParticleSystem_setOffset(lua_State * L)217 int w_ParticleSystem_setOffset(lua_State * L) 218 { 219 ParticleSystem * t = luax_checkparticlesystem(L, 1); 220 float x = (float)luaL_checknumber(L, 2); 221 float y = (float)luaL_checknumber(L, 3); 222 t->setOffset(x, y); 223 return 0; 224 } 225 w_ParticleSystem_getX(lua_State * L)226 int w_ParticleSystem_getX(lua_State * L) 227 { 228 ParticleSystem * t = luax_checkparticlesystem(L, 1); 229 lua_pushnumber(L, t->getX()); 230 return 1; 231 } 232 w_ParticleSystem_getY(lua_State * L)233 int w_ParticleSystem_getY(lua_State * L) 234 { 235 ParticleSystem * t = luax_checkparticlesystem(L, 1); 236 lua_pushnumber(L, t->getY()); 237 return 1; 238 } 239 w_ParticleSystem_getDirection(lua_State * L)240 int w_ParticleSystem_getDirection(lua_State * L) 241 { 242 ParticleSystem * t = luax_checkparticlesystem(L, 1); 243 lua_pushnumber(L, t->getDirection()); 244 return 1; 245 } 246 w_ParticleSystem_getSpread(lua_State * L)247 int w_ParticleSystem_getSpread(lua_State * L) 248 { 249 ParticleSystem * t = luax_checkparticlesystem(L, 1); 250 lua_pushnumber(L, t->getSpread()); 251 return 1; 252 } 253 w_ParticleSystem_getOffsetX(lua_State * L)254 int w_ParticleSystem_getOffsetX(lua_State * L) 255 { 256 ParticleSystem * t = luax_checkparticlesystem(L, 1); 257 lua_pushnumber(L, t->getOffsetX()); 258 return 1; 259 } 260 w_ParticleSystem_getOffsetY(lua_State * L)261 int w_ParticleSystem_getOffsetY(lua_State * L) 262 { 263 ParticleSystem * t = luax_checkparticlesystem(L, 1); 264 lua_pushnumber(L, t->getOffsetY()); 265 return 1; 266 } 267 w_ParticleSystem_count(lua_State * L)268 int w_ParticleSystem_count(lua_State * L) 269 { 270 ParticleSystem * t = luax_checkparticlesystem(L, 1); 271 lua_pushnumber(L, t->count()); 272 return 1; 273 } 274 w_ParticleSystem_start(lua_State * L)275 int w_ParticleSystem_start(lua_State * L) 276 { 277 ParticleSystem * t = luax_checkparticlesystem(L, 1); 278 t->start(); 279 return 0; 280 } 281 w_ParticleSystem_stop(lua_State * L)282 int w_ParticleSystem_stop(lua_State * L) 283 { 284 ParticleSystem * t = luax_checkparticlesystem(L, 1); 285 t->stop(); 286 return 0; 287 } 288 w_ParticleSystem_pause(lua_State * L)289 int w_ParticleSystem_pause(lua_State * L) 290 { 291 ParticleSystem * t = luax_checkparticlesystem(L, 1); 292 t->pause(); 293 return 0; 294 } 295 w_ParticleSystem_reset(lua_State * L)296 int w_ParticleSystem_reset(lua_State * L) 297 { 298 ParticleSystem * t = luax_checkparticlesystem(L, 1); 299 t->reset(); 300 return 0; 301 } 302 w_ParticleSystem_isActive(lua_State * L)303 int w_ParticleSystem_isActive(lua_State * L) 304 { 305 ParticleSystem * t = luax_checkparticlesystem(L, 1); 306 luax_pushboolean(L, t->isActive()); 307 return 1; 308 } 309 w_ParticleSystem_isEmpty(lua_State * L)310 int w_ParticleSystem_isEmpty(lua_State * L) 311 { 312 ParticleSystem * t = luax_checkparticlesystem(L, 1); 313 luax_pushboolean(L, t->isEmpty()); 314 return 1; 315 } 316 w_ParticleSystem_isFull(lua_State * L)317 int w_ParticleSystem_isFull(lua_State * L) 318 { 319 ParticleSystem * t = luax_checkparticlesystem(L, 1); 320 luax_pushboolean(L, t->isFull()); 321 return 1; 322 } 323 w_ParticleSystem_update(lua_State * L)324 int w_ParticleSystem_update(lua_State * L) 325 { 326 ParticleSystem * t = luax_checkparticlesystem(L, 1); 327 float dt = (float)luaL_checknumber(L, 2); 328 t->update(dt); 329 return 0; 330 } 331 332 static const luaL_Reg functions[] = { 333 { "setSprite", w_ParticleSystem_setSprite }, 334 { "setBufferSize", w_ParticleSystem_setBufferSize }, 335 { "setEmissionRate", w_ParticleSystem_setEmissionRate }, 336 { "setLifetime", w_ParticleSystem_setLifetime }, 337 { "setParticleLife", w_ParticleSystem_setParticleLife }, 338 { "setPosition", w_ParticleSystem_setPosition }, 339 { "setDirection", w_ParticleSystem_setDirection }, 340 { "setSpread", w_ParticleSystem_setSpread }, 341 { "setRelativeDirection", w_ParticleSystem_setRelativeDirection }, 342 { "setSpeed", w_ParticleSystem_setSpeed }, 343 { "setGravity", w_ParticleSystem_setGravity }, 344 { "setRadialAcceleration", w_ParticleSystem_setRadialAcceleration }, 345 { "setTangentialAcceleration", w_ParticleSystem_setTangentialAcceleration }, 346 { "setSize", w_ParticleSystem_setSize }, 347 { "setSizeVariation", w_ParticleSystem_setSizeVariation }, 348 { "setRotation", w_ParticleSystem_setRotation }, 349 { "setSpin", w_ParticleSystem_setSpin }, 350 { "setSpinVariation", w_ParticleSystem_setSpinVariation }, 351 { "setColor", w_ParticleSystem_setColor }, 352 { "setOffset", w_ParticleSystem_setOffset }, 353 { "getX", w_ParticleSystem_getX }, 354 { "getY", w_ParticleSystem_getY }, 355 { "getDirection", w_ParticleSystem_getDirection }, 356 { "getSpread", w_ParticleSystem_getSpread }, 357 { "getOffsetX", w_ParticleSystem_getOffsetX }, 358 { "getOffsetY", w_ParticleSystem_getOffsetY }, 359 { "count", w_ParticleSystem_count }, 360 { "start", w_ParticleSystem_start }, 361 { "stop", w_ParticleSystem_stop }, 362 { "pause", w_ParticleSystem_pause }, 363 { "reset", w_ParticleSystem_reset }, 364 { "isActive", w_ParticleSystem_isActive }, 365 { "isEmpty", w_ParticleSystem_isEmpty }, 366 { "isFull", w_ParticleSystem_isFull }, 367 { "update", w_ParticleSystem_update }, 368 { 0, 0 } 369 }; 370 luaopen_particlesystem(lua_State * L)371 int luaopen_particlesystem(lua_State * L) 372 { 373 return luax_register_type(L, "ParticleSystem", functions); 374 } 375 376 } // opengl 377 } // graphics 378 } // love 379