diff options
author | chai <chaifix@163.com> | 2018-12-06 20:04:05 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2018-12-06 20:04:05 +0800 |
commit | 37f1d11f9e1f7b9f336b509f3afb6dd61bb5ffee (patch) | |
tree | 23085471a30b4756923aba6b907832e5d5271845 /src/lua/modules/graphics/je_lua_particle_system.cpp | |
parent | 0085588ebb89f8655081c98efcb3b988f4be1d76 (diff) |
*misc
Diffstat (limited to 'src/lua/modules/graphics/je_lua_particle_system.cpp')
-rw-r--r-- | src/lua/modules/graphics/je_lua_particle_system.cpp | 387 |
1 files changed, 386 insertions, 1 deletions
diff --git a/src/lua/modules/graphics/je_lua_particle_system.cpp b/src/lua/modules/graphics/je_lua_particle_system.cpp index b0cb221..53611a9 100644 --- a/src/lua/modules/graphics/je_lua_particle_system.cpp +++ b/src/lua/modules/graphics/je_lua_particle_system.cpp @@ -1,11 +1,396 @@ +#include <vector> + +#include "common/je_lua_object.h" +#include "common/je_lua_common.h" #include "libjin/jin.h" +#include "je_lua_sprite.h" +#include "je_lua_particle_system.h" + +using namespace std; +using namespace JinEngine::Math; +using namespace JinEngine::Graphics; +using namespace JinEngine::Graphics::Particles; + namespace JinEngine { namespace Lua { + const char* Jin_Lua_ParticleSystem = "ParticleSystem"; + + typedef Shared<ParticleSystem>& SharedParticleSystem; + + LUA_IMPLEMENT inline SharedParticleSystem checkPS(lua_State* L) + { + LuaObject* luaObj = luax_checkobject(L, 1, Jin_Lua_ParticleSystem); + return luaObj->getShared<ParticleSystem>(); + } + + LUA_IMPLEMENT int l_gc(lua_State* L) + { + LuaObject* luaObj = luax_checkobject(L, 1, Jin_Lua_ParticleSystem); + luaObj->release(); + return 0; + } + + LUA_IMPLEMENT int l_update(lua_State* L) + { + SharedParticleSystem ps = checkPS(L); + float dt = luax_checknumber(L, 2); + ps->update(dt); + return 0; + } + + LUA_IMPLEMENT int l_render(lua_State* L) + { + SharedParticleSystem ps = checkPS(L); + ps->render(); + return 0; + } + + LUA_IMPLEMENT int l_setPosition(lua_State* L) + { + SharedParticleSystem ps = checkPS(L); + float x = luax_checknumber(L, 2); + float y = luax_checknumber(L, 3); + ps->setPosition(x, y); + return 0; + } + + LUA_IMPLEMENT int l_setScale(lua_State* L) + { + SharedParticleSystem ps = checkPS(L); + float sx = luax_checknumber(L, 2); + float sy = luax_checknumber(L, 3); + ps->setScale(sx, sy); + return 0; + } + + LUA_IMPLEMENT int l_pause(lua_State* L) + { + SharedParticleSystem ps = checkPS(L); + bool b = luax_checkbool(L, 2); + ps->pause(b); + return 0; + } + + LUA_IMPLEMENT int l_clear(lua_State* L) + { + SharedParticleSystem ps = checkPS(L); + ps->clear(); + return 0; + } + + LUA_IMPLEMENT int l_setEmitRate(lua_State* L) + { + SharedParticleSystem ps = checkPS(L); + if (luax_gettop(L) >= 3) + { + float floor = luax_checknumber(L, 2); + float ceil = luax_checknumber(L, 3); + ps->setEmitRate(floor, ceil); + } + else if (luax_gettop(L) >= 2) + { + float n = luax_checknumber(L, 2); + ps->setEmitRate(n); + } + return 0; + } + + LUA_IMPLEMENT int l_setEmitForce(lua_State* L) + { + SharedParticleSystem ps = checkPS(L); + if (luax_gettop(L) >= 3) + { + float floor = luax_checknumber(L, 2); + float ceil = luax_checknumber(L, 3); + ps->setEmitForce(floor, ceil); + } + else if (luax_gettop(L) >= 2) + { + float n = luax_checknumber(L, 2); + ps->setEmitForce(n); + } + return 0; + } + + LUA_IMPLEMENT int l_setEmitDirection(lua_State* L) + { + SharedParticleSystem ps = checkPS(L); + if (luax_gettop(L) >= 3) + { + float floor = luax_checknumber(L, 2); + float ceil = luax_checknumber(L, 3); + ps->setEmitDirection(floor, ceil); + } + else if (luax_gettop(L) >= 2) + { + float n = luax_checknumber(L, 2); + ps->setEmitDirection(n); + } + return 0; + } + + LUA_IMPLEMENT int l_setEmitPosition(lua_State* L) + { + SharedParticleSystem ps = checkPS(L); + if (luax_gettop(L) >= 3) + { + if (!luax_istable(L, 2)) + { + luax_typerror(L, 2, "table"); + return 1; + } + if (!luax_istable(L, 3)) + { + luax_typerror(L, 3, "table"); + return 1; + } + Vector2<float> floor, ceil; + floor.x = luax_rawgetnumber(L, 2, 1); + floor.y = luax_rawgetnumber(L, 2, 2); + ceil.x = luax_rawgetnumber(L, 3, 1); + ceil.y = luax_rawgetnumber(L, 3, 2); + ps->setEmitPosition(floor, ceil); + } + else if (luax_gettop(L) >= 2) + { + if (!luax_istable(L, 2)) + { + luax_typerror(L, 2, "table"); + return 1; + } + Vector2<float> pos; + pos.x = luax_rawgetnumber(L, 2, 1); + pos.y = luax_rawgetnumber(L, 2, 2); + ps->setEmitPosition(pos); + } + return 0; + } + + LUA_IMPLEMENT int l_setParticleLife(lua_State* L) + { + SharedParticleSystem ps = checkPS(L); + if (luax_gettop(L) >= 3) + { + float floor = luax_checknumber(L, 2); + float ceil = luax_checknumber(L, 3); + ps->setParticleLife(floor, ceil); + } + else if (luax_gettop(L) >= 2) + { + float n = luax_checknumber(L, 2); + ps->setParticleLife(n); + } + return 0; + } + + LUA_IMPLEMENT int l_setParticleLinearAccelaration(lua_State* L) + { + SharedParticleSystem ps = checkPS(L); + if (!luax_istable(L, 2)) + { + luax_typerror(L, 2, "table"); + return 1; + } + Vector2<float> ac; + ac.x = luax_rawgetnumber(L, 2, 1); + ac.y = luax_rawgetnumber(L, 2, 2); + ps->setParticleLinearAccelaration(ac); + return 0; + } + + LUA_IMPLEMENT int l_setParticleRadialAccelaration(lua_State* L) + { + SharedParticleSystem ps = checkPS(L); + float ra = luax_checknumber(L, 2); + ps->setParticleRadialAccelaration(ra); + return 0; + } + + LUA_IMPLEMENT int l_setParticleAngularSpeed(lua_State* L) + { + SharedParticleSystem ps = checkPS(L); + if (luax_gettop(L) >= 3) + { + float floor = luax_checknumber(L, 2); + float ceil = luax_checknumber(L, 3); + ps->setParticleAngularSpeed(floor, ceil); + } + else if (luax_gettop(L) >= 2) + { + float n = luax_checknumber(L, 2); + ps->setParticleAngularSpeed(n); + } + return 0; + } + + LUA_IMPLEMENT int l_setParticleSpritesMode(lua_State* L) + { + SharedParticleSystem ps = checkPS(L); + int n = luax_checkinteger(L, 2); + SpriteMode mode = static_cast<SpriteMode>(n); + ps->setParticleSpritesMode(mode); + return 0; + } + + LUA_IMPLEMENT int l_addParticleSprite(lua_State* L) + { + LuaObject* obj = luax_checkobject(L, 1, Jin_Lua_ParticleSystem); + SharedParticleSystem ps = obj->getShared<ParticleSystem>(); + LuaObject* objSpr = luax_checkobject(L, 2, Jin_Lua_Sprite); + Sprite* spr = objSpr->getObject<Sprite>(); + ps->addParticleSprite(spr); + int depn = (*obj).getDependenciesCount(); + (*obj).setDependency((int)ParticleSystemDependency::DEP_SPRITES + depn, objSpr->getSharedBase()); + return 0; + } + + LUA_IMPLEMENT int l_addParticleSprites(lua_State* L) + { + LuaObject* obj = luax_checkobject(L, 1, Jin_Lua_ParticleSystem); + SharedParticleSystem ps = obj->getShared<ParticleSystem>(); + if (!luax_istable(L, 2)) + { + luax_typerror(L, 2, "sprites table"); + return 1; + } + int n = luax_tableidxlen(L, 2); + int depn = (*obj).getDependenciesCount(); + for (int i = 1; i <= n; ++i) + { + luax_rawgeti(L, 2, i); + LuaObject* objSpr = luax_checkobject(L, -1, Jin_Lua_Sprite); + luax_pop(L, 1); + Sprite* spr = objSpr->getObject<Sprite>(); + ps->addParticleSprite(spr); + (*obj).setDependency((int)ParticleSystemDependency::DEP_SPRITES + depn + i - 1, objSpr->getSharedBase()); + } + return 0; + } + + // From 0 + LUA_IMPLEMENT int l_removeParticleSprite(lua_State* L) + { + LuaObject* obj = luax_checkobject(L, 1, Jin_Lua_ParticleSystem); + SharedParticleSystem ps = obj->getShared<ParticleSystem>(); + int n = luax_checkinteger(L, 2); + ps->removeParticleSprite(n); + (*obj).removeDependency((int)ParticleSystemDependency::DEP_SPRITES + n); + return 0; + } + + LUA_IMPLEMENT int l_enableParticleBlendAdditive(lua_State* L) + { + SharedParticleSystem ps = checkPS(L); + bool enable = luax_checkbool(L, 2); + ps->enableParticleBlendAdditive(enable); + return 0; + } + + LUA_IMPLEMENT int l_setParticleScale(lua_State* L) + { + SharedParticleSystem ps = checkPS(L); + float scale = luax_checknumber(L, 2); + ps->setParticleScale(scale); + return 0; + } + + LUA_IMPLEMENT int l_addParticleScalePoint(lua_State* L) + { + SharedParticleSystem ps = checkPS(L); + float scale = luax_checknumber(L, 2); + float t = luax_checknumber(L, 3); + ps->addParticleScalePoint(scale, t); + return 0; + } + + LUA_IMPLEMENT int l_removeParticleScalePoint(lua_State* L) + { + SharedParticleSystem ps = checkPS(L); + int i = luax_checkinteger(L, 2); + ps->removeParticleScalePoint(i); + return 0; + } + + LUA_IMPLEMENT int l_setParticleColor(lua_State* L) + { + SharedParticleSystem ps = checkPS(L); + if (!luax_istable(L, 2)) + { + luax_typerror(L, 2, "color table"); + return 1; + } + Color c; + c.r = luax_rawgetnumber(L, 2, 1); + c.g = luax_rawgetnumber(L, 2, 2); + c.b = luax_rawgetnumber(L, 2, 3); + c.a = luax_rawgetnumber(L, 2, 4); + ps->setParticleColor(c); + return 0; + } + + LUA_IMPLEMENT int l_addParticleColorPoint(lua_State* L) + { + SharedParticleSystem ps = checkPS(L); + if (!luax_istable(L, 2)) + { + luax_typerror(L, 2, "color table"); + return 1; + } + Color c; + c.r = luax_rawgetnumber(L, 2, 1); + c.g = luax_rawgetnumber(L, 2, 2); + c.b = luax_rawgetnumber(L, 2, 3); + c.a = luax_rawgetnumber(L, 2, 4); + float t = luax_checknumber(L, 3); + ps->addParticleColorPoint(c, t); + return 0; + } + + LUA_IMPLEMENT int l_removeParticleColorPoint(lua_State* L) + { + SharedParticleSystem ps = checkPS(L); + int i = luax_checkinteger(L, 2); + ps->removeParticleColorPoint(i); + return 0; + } + + LUA_IMPLEMENT int l_setParticleTransparency(lua_State* L) + { + SharedParticleSystem ps = checkPS(L); + float transparency = luax_checknumber(L, 2); + ps->setParticleTransparency(transparency); + return 0; + } + + LUA_IMPLEMENT int l_addParticleTransparencyPoint(lua_State* L) + { + SharedParticleSystem ps = checkPS(L); + float transparency = luax_checknumber(L, 2); + float t = luax_checknumber(L, 3); + ps->addParticleTransparencyPoint(transparency, t); + return 0; + } + + LUA_IMPLEMENT int l_removeParticleTransparencyPoint(lua_State* L) + { + SharedParticleSystem ps = checkPS(L); + int i = luax_checkinteger(L, 2); + ps->removeParticleTransparencyPoint(i); + return 0; + } + LUA_EXPORT void luaopen_ParticleSystem(lua_State* L) + { + luaL_Reg methods[] = { + { "__gc", l_gc }, + { 0, 0 } + }; + luax_newtype(L, Jin_Lua_ParticleSystem, methods); + } - } // Lua + } // namespace Lua } // namespace JinEngine
\ No newline at end of file |