From ececf2c8624f4d95d9413686839f7fa6e5bb5044 Mon Sep 17 00:00:00 2001 From: Alexander Date: Tue, 2 Jun 2020 08:54:14 -0400 Subject: Add a shape cast Add a raycast like function, which can cast shapes. phys.shapecast(), along with a shape structure needed to call this function. --- src/shared/lua_api/phys/btaction.cpp | 62 ++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 src/shared/lua_api/phys/btaction.cpp (limited to 'src/shared/lua_api/phys/btaction.cpp') diff --git a/src/shared/lua_api/phys/btaction.cpp b/src/shared/lua_api/phys/btaction.cpp new file mode 100644 index 0000000..afd2371 --- /dev/null +++ b/src/shared/lua_api/phys/btaction.cpp @@ -0,0 +1,62 @@ +extern "C" { + #include + #include + #include +} +#include +#include + +#include + +extern btDiscreteDynamicsWorld* World; + +struct BActionItem: public btActionInterface{ + int ref; + lua_State *L; + void updateAction(btCollisionWorld *world, btScalar delta){ + lua_rawgeti(this->L,LUA_REGISTRYINDEX,this->ref);//{} + pusherrorfunc(this->L);//{},errfunc() + lua_getfield(this->L,-2,"action");//{},errfunc(),action() + if(lua_isnil(this->L,-1)){//no .action method + lua_pop(this->L,3); + return; + } + lua_pushvalue(this->L,-3);//{},errfunc(),action(),{} + lua_pushlightuserdata(this->L,world);//{},errfunc(),action(),{},ud_world + lua_pushnumber(this->L,delta);//{},errfunc(),action(),{},ud_world,delta + lua_pcall(this->L,3,0,-4);//{},errfunc() + //printf("error:%d\n",err); + lua_pop(this->L,2); + return; + } + void debugDraw(btIDebugDraw *d){ + //no debug draw I guess + } +}; + +int makeaction(lua_State *L){ + lua_newtable(L);//{} + int r = luaL_ref(L,LUA_REGISTRYINDEX); + lua_rawgeti(L,LUA_REGISTRYINDEX,r); + BActionItem *a = new BActionItem(); + a->ref = r; + a->L = L; + World->addAction(a); + lua_pushlightuserdata(L,a);//{},ud_action + lua_setfield(L,-2,"action");//{} + return 1; +} + +int newaction(lua_State *L){ + lua_newtable(L);//{} + return 0; +} + +int baction_register(lua_State *L){ + lua_getglobal(L,"phys"); + lua_pushcfunction(L,makeaction); + lua_setfield(L,-2,"makeaction"); + + lua_pop(L,1); + return 0; +} -- cgit v1.2.3-70-g09d2