From 44a1421c393632978d59c0698a93ae22243b97e9 Mon Sep 17 00:00:00 2001 From: Alexander Date: Wed, 10 Jun 2020 20:39:54 -0400 Subject: Various progress for 1klutz Added convext shape casts, still a little broken, but it might be just broken bullet side. --- src/client/lua_api/gui/iguicolorselector.hpp | 22 +- src/client/lua_api/gui/iguicombobox.cpp | 262 +++++----- src/client/lua_api/gui/iguicombobox.hpp | 22 +- src/client/lua_api/gui/iguieditbox.hpp | 24 +- src/client/lua_api/phys/cbcharactercontroller.cpp | 246 ++++----- src/client/lua_api/phys/cbcharactercontroller.hpp | 20 +- src/client/lua_api/phys/cbphysbox.cpp | 2 +- src/client/lua_api/video/draw.cpp | 58 +-- src/client/lua_api/video/draw.hpp | 16 +- src/server/lua_api/load_game.hpp | 26 +- src/server/lua_api/load_io.cpp | 126 ++--- src/server/lua_api/load_io.hpp | 26 +- src/server/lua_api/phys/sbphysmodel.cpp | 252 ++++----- src/shared/lua_api/load_common.cpp | 60 +-- src/shared/lua_api/load_common.hpp | 8 +- src/shared/lua_api/load_phys.cpp | 4 +- src/shared/lua_api/phys/bcharactercontroller.cpp | 600 +++++++++++----------- src/shared/lua_api/phys/bcharactercontroller.hpp | 24 +- src/shared/lua_api/phys/bcollider.cpp | 178 +++---- src/shared/lua_api/phys/bcollider.hpp | 14 +- src/shared/lua_api/phys/bghostobject.cpp | 421 ++++++++------- src/shared/lua_api/phys/bghostobject.hpp | 26 +- src/shared/lua_api/phys/bhingeconstraint.cpp | 122 ++--- src/shared/lua_api/phys/bhingeconstraint.hpp | 4 +- src/shared/lua_api/phys/bphysbox.cpp | 4 +- src/shared/lua_api/phys/bphysmodel.cpp | 9 +- src/shared/lua_api/phys/bshape.cpp | 104 ++-- src/shared/lua_api/phys/bshape.hpp | 22 +- src/shared/lua_api/phys/btaction.cpp | 125 ++--- src/shared/lua_api/phys/btaction.hpp | 22 +- src/shared/util/tinyobj.cpp | 6 +- src/shared/util/tinyobj.hpp | 4 +- 32 files changed, 1458 insertions(+), 1401 deletions(-) diff --git a/src/client/lua_api/gui/iguicolorselector.hpp b/src/client/lua_api/gui/iguicolorselector.hpp index 9460f3e..c0cc168 100644 --- a/src/client/lua_api/gui/iguicolorselector.hpp +++ b/src/client/lua_api/gui/iguicolorselector.hpp @@ -1,11 +1,11 @@ - -#include -#include -extern "C" { - #include - #include - #include -} -#include - -int iguicolorselector_register(lua_State* L); + +#include +#include +extern "C" { + #include + #include + #include +} +#include + +int iguicolorselector_register(lua_State* L); diff --git a/src/client/lua_api/gui/iguicombobox.cpp b/src/client/lua_api/gui/iguicombobox.cpp index 66b19d2..43c66f1 100644 --- a/src/client/lua_api/gui/iguicombobox.cpp +++ b/src/client/lua_api/gui/iguicombobox.cpp @@ -1,131 +1,131 @@ -extern "C" { - #include - #include - #include -} -#include -#include "../guiparts.hpp" -#include "iguielement.hpp" -#include "client/callbackhandeler.hpp" -#include -#include -#include - -/*** -@module gui -*/ -using namespace irr; -using namespace core; -using namespace gui; - -extern IrrlichtDevice* device; - -/*** -Creates a new combo box. -Buttons may have the following fields set for callbacks: -`.onChange(self)` -@function newcombobox() -@tparam rect dimensions The rectangle to place the button at. If the box has a parent, -it is offset from the upper-left of the parent element. -@tparam ?iguielement parent The parent element of the button. -@treturn iguicombobox The combo box element -*/ -//gui.newcombobox({{sx,sy},{ex,ey}}[,parent]) -static int newiguicombobox(lua_State* L){ - //printf("Createing gui button!\n"); - - int nargs = lua_gettop(L); - IGUIElement* parent = NULL; - if(nargs == 2){ - lua_getfield(L,-1,"guielement"); - parent = (IGUIElement*)lua_touserdata(L,-1); - lua_pop(L,2);//{{sx,sy},{ex,ey}} - } - - long sx,sy,ex,ey; - poprecti(L,&sx,&sy,&ex,&ey);// - - rect dim = rect(sx,sy,ex,ey); - IGUIEnvironment* env = device->getGUIEnvironment(); - IGUIComboBox* but = env->addComboBox(dim,parent,-1); - - lua_newtable(L);//{} - lua_pushlightuserdata(L,but);//{},ud_iguicombobox - lua_setfield(L,-2,"guielement");//{guielement} - luaL_getmetatable(L,"gui.iguicombobox");//{guielement},{m_iguicombobox} - lua_setmetatable(L,-2);//{guielement} - - setelementcallback(L,EGET_COMBO_BOX_CHANGED,"onChange");// - - return 1; -} - -//{combobox}.addItem(self,text,id) -int additem(lua_State *L){ - int id = lua_tonumber(L,-1); - lua_pop(L,1);//self,text - const char *name_c = lua_tostring(L,-1); - size_t name_c_len = strlen(name_c); - printf("adding item to combo box: %s\n",name_c); - wchar_t name_w[name_c_len + 1]; - mbstowcs(name_w,name_c,name_c_len); - name_w[name_c_len] = L'\0'; - lua_pop(L,1);//self - lua_getfield(L,-1,"guielement");//self,ud_guielement - IGUIComboBox *box = (IGUIComboBox*)lua_touserdata(L,-1); - box->addItem(name_w,id); - lua_pop(L,2);// - return 0; -} - -// {combobox}.getselected(self) -int getselected(lua_State *L){ - lua_getfield(L,-1,"guielement");//self,ud_guielement - IGUIComboBox *box = (IGUIComboBox*)lua_touserdata(L,-1); - lua_pop(L,2);// - s32 sel = box->getSelected(); - lua_pushnumber(L,sel);//num_selected - return 1; -} - -//{combobox}.removeitem(self,id) -int removeitem(lua_State *L){ - int idx = lua_tonumber(L,-1);//self,id - lua_pop(L,1);//self - lua_getfield(L,-1,"guielement");//self,ud_guielement - IGUIComboBox *box = (IGUIComboBox*)lua_touserdata(L,-1); - lua_pop(L,2);// - box->removeItem(idx); - return 0; -} - -static const luaL_reg iguicombobox_f[] = { - {"new", newiguicombobox}, - {0,0}, -}; - -static const luaL_reg iguicombobox_m[] = { - {"addItem", additem}, - {"getSelected", getselected}, - {"removeItem", removeitem}, - {0,0}, -}; - -void iguicombobox_register(lua_State* L){ - tL = L; - - luaL_newmetatable(L, "gui.iguicombobox");//{m_iguibutton} - lua_newtable(L);//{m_iguibutton},{} - luaL_register(L,NULL,iguielement_m); - luaL_register(L,NULL,iguicombobox_m);//{m_iguibutton},{} - lua_setfield(L,-2,"__index");//{m_iguibutton} - - lua_pop(L,1); - - lua_getglobal(L,"gui"); - //luaL_register(L,NULL,iguicombobox_f) - lua_pushcfunction(L,newiguicombobox); - lua_setfield(L,-2,"newcombobox"); - - lua_pop(L,1); -} +extern "C" { + #include + #include + #include +} +#include +#include "../guiparts.hpp" +#include "iguielement.hpp" +#include "client/callbackhandeler.hpp" +#include +#include +#include + +/*** +@module gui +*/ +using namespace irr; +using namespace core; +using namespace gui; + +extern IrrlichtDevice* device; + +/*** +Creates a new combo box. +Buttons may have the following fields set for callbacks: +`.onChange(self)` +@function newcombobox() +@tparam rect dimensions The rectangle to place the button at. If the box has a parent, +it is offset from the upper-left of the parent element. +@tparam ?iguielement parent The parent element of the button. +@treturn iguicombobox The combo box element +*/ +//gui.newcombobox({{sx,sy},{ex,ey}}[,parent]) +static int newiguicombobox(lua_State* L){ + //printf("Createing gui button!\n"); + + int nargs = lua_gettop(L); + IGUIElement* parent = NULL; + if(nargs == 2){ + lua_getfield(L,-1,"guielement"); + parent = (IGUIElement*)lua_touserdata(L,-1); + lua_pop(L,2);//{{sx,sy},{ex,ey}} + } + + long sx,sy,ex,ey; + poprecti(L,&sx,&sy,&ex,&ey);// + + rect dim = rect(sx,sy,ex,ey); + IGUIEnvironment* env = device->getGUIEnvironment(); + IGUIComboBox* but = env->addComboBox(dim,parent,-1); + + lua_newtable(L);//{} + lua_pushlightuserdata(L,but);//{},ud_iguicombobox + lua_setfield(L,-2,"guielement");//{guielement} + luaL_getmetatable(L,"gui.iguicombobox");//{guielement},{m_iguicombobox} + lua_setmetatable(L,-2);//{guielement} + + setelementcallback(L,EGET_COMBO_BOX_CHANGED,"onChange");// + + return 1; +} + +//{combobox}.addItem(self,text,id) +int additem(lua_State *L){ + int id = lua_tonumber(L,-1); + lua_pop(L,1);//self,text + const char *name_c = lua_tostring(L,-1); + size_t name_c_len = strlen(name_c); + printf("adding item to combo box: %s\n",name_c); + wchar_t name_w[name_c_len + 1]; + mbstowcs(name_w,name_c,name_c_len); + name_w[name_c_len] = L'\0'; + lua_pop(L,1);//self + lua_getfield(L,-1,"guielement");//self,ud_guielement + IGUIComboBox *box = (IGUIComboBox*)lua_touserdata(L,-1); + box->addItem(name_w,id); + lua_pop(L,2);// + return 0; +} + +// {combobox}.getselected(self) +int getselected(lua_State *L){ + lua_getfield(L,-1,"guielement");//self,ud_guielement + IGUIComboBox *box = (IGUIComboBox*)lua_touserdata(L,-1); + lua_pop(L,2);// + s32 sel = box->getSelected(); + lua_pushnumber(L,sel);//num_selected + return 1; +} + +//{combobox}.removeitem(self,id) +int removeitem(lua_State *L){ + int idx = lua_tonumber(L,-1);//self,id + lua_pop(L,1);//self + lua_getfield(L,-1,"guielement");//self,ud_guielement + IGUIComboBox *box = (IGUIComboBox*)lua_touserdata(L,-1); + lua_pop(L,2);// + box->removeItem(idx); + return 0; +} + +static const luaL_reg iguicombobox_f[] = { + {"new", newiguicombobox}, + {0,0}, +}; + +static const luaL_reg iguicombobox_m[] = { + {"addItem", additem}, + {"getSelected", getselected}, + {"removeItem", removeitem}, + {0,0}, +}; + +void iguicombobox_register(lua_State* L){ + tL = L; + + luaL_newmetatable(L, "gui.iguicombobox");//{m_iguibutton} + lua_newtable(L);//{m_iguibutton},{} + luaL_register(L,NULL,iguielement_m); + luaL_register(L,NULL,iguicombobox_m);//{m_iguibutton},{} + lua_setfield(L,-2,"__index");//{m_iguibutton} + + lua_pop(L,1); + + lua_getglobal(L,"gui"); + //luaL_register(L,NULL,iguicombobox_f) + lua_pushcfunction(L,newiguicombobox); + lua_setfield(L,-2,"newcombobox"); + + lua_pop(L,1); +} diff --git a/src/client/lua_api/gui/iguicombobox.hpp b/src/client/lua_api/gui/iguicombobox.hpp index ff6ba97..d3e8111 100644 --- a/src/client/lua_api/gui/iguicombobox.hpp +++ b/src/client/lua_api/gui/iguicombobox.hpp @@ -1,11 +1,11 @@ -#include -#include -#include -extern "C" { - #include - #include - #include -} -#include - -void iguicombobox_register(lua_State* L); +#include +#include +#include +extern "C" { + #include + #include + #include +} +#include + +void iguicombobox_register(lua_State* L); diff --git a/src/client/lua_api/gui/iguieditbox.hpp b/src/client/lua_api/gui/iguieditbox.hpp index 51bf832..429f119 100644 --- a/src/client/lua_api/gui/iguieditbox.hpp +++ b/src/client/lua_api/gui/iguieditbox.hpp @@ -1,12 +1,12 @@ -#include -#include -#include -extern "C" { - #include - #include - #include -} -#include - -void iguieditbox_register(lua_State* L); - +#include +#include +#include +extern "C" { + #include + #include + #include +} +#include + +void iguieditbox_register(lua_State* L); + diff --git a/src/client/lua_api/phys/cbcharactercontroller.cpp b/src/client/lua_api/phys/cbcharactercontroller.cpp index f93d01a..e116ee8 100644 --- a/src/client/lua_api/phys/cbcharactercontroller.cpp +++ b/src/client/lua_api/phys/cbcharactercontroller.cpp @@ -1,123 +1,123 @@ -#include -#include -#include -extern "C" { - #include - #include - #include -} - -#include -#include -#include -#include -#include "cbphysbox.hpp" -#include "../scene/imesh.hpp" -#include "../scene/igeneric.hpp" -#include -#include - -#include - -using namespace irr; -using namespace scene; -using namespace core; -using namespace video; - -extern IrrlichtDevice* device; - -extern btDiscreteDynamicsWorld* World; -extern std::list Objects; - - -//phys.newcharactercontroller({vector3 size},{vector3 origin}) -static int newcbcharactercontroller(lua_State* L){// - printf("Createing new cbcharactercontroller\n"); - double sx,sy,sz,x,y,z; - //Get the data - popvector3d(L,&x,&y,&z);//{v3 size} - popvector3d(L,&sx,&sy,&sz);// - - pushvector3d(L,sx,sy,sz);//{v3 size} - pushvector3d(L,x,y,z);//{v3 size},{v3 origin} - makenewbcharactercontroller(L);//ud_cc - btKinematicCharacterController* cc = (btKinematicCharacterController*)lua_touserdata(L,-1);//ud_cc - lua_pop(L,1); - - pushvector3d(L,sx,sy,sz);//{v3 size} - pushvector3d(L,x,y,z);//{v3 size},{v3 origin} - makenewiscenecube(L);//ud_iscenenode - ISceneNode* n = (ISceneNode*)lua_touserdata(L,-1);//ud_iscenenode - lua_pop(L,1); - - cc->getGhostObject()->setUserPointer(n); - //cc->setUserPointer(n);//TODO: what does this break? - - lua_newtable(L);//{} - lua_pushlightuserdata(L,cc);//{},ud_cc - lua_setfield(L,-2,"character");//{} - lua_pushlightuserdata(L,n);//{},ud_iscenenode - lua_setfield(L,-2,"node");//{} - lua_pushstring(L,"character"); - lua_setfield(L,-2,"type"); - - luaL_getmetatable(L,"phys.charactercontroller");//{},{phys.charactercontroller} - lua_setmetatable(L,-2);//{} - - return 1; -} - -//setMaterial(self,material) -//int cbsetmaterial(lua_State* L){ - //printf("Call to setmaterial\n"); - ////SMaterial* mat = (SMaterial*)lua_touserdata(L,-1);//{node=ud_ISceneNode},ud_IMaterial - //ITexture* tex = (ITexture*)lua_touserdata(L,-1); - //lua_pop(L,1);//{node=ud_ISceneNode} - //printf("About to get field node\n"); - //lua_getfield(L,-1,"node");//{node=ud_ISceneNode},ud_ISceneNode - //printf("After call to field node\n"); - //ISceneNode* i = (ISceneNode*)lua_touserdata(L,-1);//{node=ud_ISceneNode},ud_ISceneNode - //lua_pop(L,2);// - - //lua_pushlightuserdata(L,i); - //lua_pushlightuserdata(L,tex); - //printf("Finished getting everything for setmaterial\n"); - //iscenesetmaterial(L); - - //return 0; -//} - -//int cbchar - -static const luaL_reg cbcharactercontroller_m[] = { - //{"setpos", cbcharsetpos},//overload - //{"getpos", cbchargetpos}, - //{"getgravity", cbphysgetgravity}, - //{"applygravity",cbphysapplygravity}, - //{"setMaterial", cbsetmaterial}, -// {"delete", delbphysbox},//client side delete needs to delete the visual representation - {0, 0}, -}; - -void cbcharactercontroller_register(lua_State* L){ - bcharactercontroller_register(L);// - lua_getglobal(L,"phys");//{} - lua_pushcfunction(L,newcbcharactercontroller);//{},newcbphysbox() - lua_setfield(L,-2,"newccharactercontroller");//{} - - lua_pop(L,1);// - - luaL_getmetatable(L,"phys.charactercontroller");//phys.physbox - lua_newtable(L);//phys.physbox,{} - //luaL_register(L,NULL,brigidbody_m); - luaL_register(L,NULL,igeneric_m); - luaL_register(L,NULL,cbcharactercontroller_m);//phys.physbox,{} - luaL_register(L,NULL,bcharactercontroller_m); - lua_setfield(L,-2,"__index");//phys.physbox - - lua_pop(L,1); - - //printf("When registering physbox, new() is %p\n",newcbphysbox); - //printf("setpos is %p\n",cbphyssetpos); - -} +#include +#include +#include +extern "C" { + #include + #include + #include +} + +#include +#include +#include +#include +#include "cbphysbox.hpp" +#include "../scene/imesh.hpp" +#include "../scene/igeneric.hpp" +#include +#include + +#include + +using namespace irr; +using namespace scene; +using namespace core; +using namespace video; + +extern IrrlichtDevice* device; + +extern btDiscreteDynamicsWorld* World; +extern std::list Objects; + + +//phys.newcharactercontroller({vector3 size},{vector3 origin}) +static int newcbcharactercontroller(lua_State* L){// + printf("Createing new cbcharactercontroller\n"); + double sx,sy,sz,x,y,z; + //Get the data + popvector3d(L,&x,&y,&z);//{v3 size} + popvector3d(L,&sx,&sy,&sz);// + + pushvector3d(L,sx,sy,sz);//{v3 size} + pushvector3d(L,x,y,z);//{v3 size},{v3 origin} + makenewbcharactercontroller(L);//ud_cc + btKinematicCharacterController* cc = (btKinematicCharacterController*)lua_touserdata(L,-1);//ud_cc + lua_pop(L,1); + + pushvector3d(L,sx,sy,sz);//{v3 size} + pushvector3d(L,x,y,z);//{v3 size},{v3 origin} + makenewiscenecube(L);//ud_iscenenode + ISceneNode* n = (ISceneNode*)lua_touserdata(L,-1);//ud_iscenenode + lua_pop(L,1); + + cc->getGhostObject()->setUserPointer(n); + //cc->setUserPointer(n);//TODO: what does this break? + + lua_newtable(L);//{} + lua_pushlightuserdata(L,cc);//{},ud_cc + lua_setfield(L,-2,"character");//{} + lua_pushlightuserdata(L,n);//{},ud_iscenenode + lua_setfield(L,-2,"node");//{} + lua_pushstring(L,"character"); + lua_setfield(L,-2,"type"); + + luaL_getmetatable(L,"phys.charactercontroller");//{},{phys.charactercontroller} + lua_setmetatable(L,-2);//{} + + return 1; +} + +//setMaterial(self,material) +//int cbsetmaterial(lua_State* L){ + //printf("Call to setmaterial\n"); + ////SMaterial* mat = (SMaterial*)lua_touserdata(L,-1);//{node=ud_ISceneNode},ud_IMaterial + //ITexture* tex = (ITexture*)lua_touserdata(L,-1); + //lua_pop(L,1);//{node=ud_ISceneNode} + //printf("About to get field node\n"); + //lua_getfield(L,-1,"node");//{node=ud_ISceneNode},ud_ISceneNode + //printf("After call to field node\n"); + //ISceneNode* i = (ISceneNode*)lua_touserdata(L,-1);//{node=ud_ISceneNode},ud_ISceneNode + //lua_pop(L,2);// + + //lua_pushlightuserdata(L,i); + //lua_pushlightuserdata(L,tex); + //printf("Finished getting everything for setmaterial\n"); + //iscenesetmaterial(L); + + //return 0; +//} + +//int cbchar + +static const luaL_reg cbcharactercontroller_m[] = { + //{"setpos", cbcharsetpos},//overload + //{"getpos", cbchargetpos}, + //{"getgravity", cbphysgetgravity}, + //{"applygravity",cbphysapplygravity}, + //{"setMaterial", cbsetmaterial}, +// {"delete", delbphysbox},//client side delete needs to delete the visual representation + {0, 0}, +}; + +void cbcharactercontroller_register(lua_State* L){ + bcharactercontroller_register(L);// + lua_getglobal(L,"phys");//{} + lua_pushcfunction(L,newcbcharactercontroller);//{},newcbphysbox() + lua_setfield(L,-2,"newccharactercontroller");//{} + + lua_pop(L,1);// + + luaL_getmetatable(L,"phys.charactercontroller");//phys.physbox + lua_newtable(L);//phys.physbox,{} + //luaL_register(L,NULL,brigidbody_m); + luaL_register(L,NULL,igeneric_m); + luaL_register(L,NULL,cbcharactercontroller_m);//phys.physbox,{} + luaL_register(L,NULL,bcharactercontroller_m); + lua_setfield(L,-2,"__index");//phys.physbox + + lua_pop(L,1); + + //printf("When registering physbox, new() is %p\n",newcbphysbox); + //printf("setpos is %p\n",cbphyssetpos); + +} diff --git a/src/client/lua_api/phys/cbcharactercontroller.hpp b/src/client/lua_api/phys/cbcharactercontroller.hpp index d7b76eb..d86701f 100644 --- a/src/client/lua_api/phys/cbcharactercontroller.hpp +++ b/src/client/lua_api/phys/cbcharactercontroller.hpp @@ -1,10 +1,10 @@ -#include -#include -extern "C" { - #include - #include - #include -} -#include - -void cbcharactercontroller_register(lua_State* L); +#include +#include +extern "C" { + #include + #include + #include +} +#include + +void cbcharactercontroller_register(lua_State* L); diff --git a/src/client/lua_api/phys/cbphysbox.cpp b/src/client/lua_api/phys/cbphysbox.cpp index 6763945..5fcba3b 100644 --- a/src/client/lua_api/phys/cbphysbox.cpp +++ b/src/client/lua_api/phys/cbphysbox.cpp @@ -48,7 +48,7 @@ static int newcbphysbox(lua_State* L){// btRigidBody* r = (btRigidBody*)lua_touserdata(L,-1);//ud_btRigidbody lua_pop(L,1); - pushvector3d(L,sx,sy,sz);//{v3 size} + pushvector3d(L,sx*2,sy*2,sz*2);//{v3 size} pushvector3d(L,x,y,z);//{v3 size},{v3 origin} makenewiscenecube(L);//ud_iscenenode ISceneNode* n = (ISceneNode*)lua_touserdata(L,-1);//ud_iscenenode diff --git a/src/client/lua_api/video/draw.cpp b/src/client/lua_api/video/draw.cpp index 1f38f34..7140162 100644 --- a/src/client/lua_api/video/draw.cpp +++ b/src/client/lua_api/video/draw.cpp @@ -1,29 +1,29 @@ - -#include -#include -#include "draw.hpp" - -using namespace irr; -using namespace video; -using namespace core; - -extern IrrlichtDevice* device; -extern IVideoDriver* driver; -//drawline2d {startx,starty},{endx,endy},{r,g,b,a} -int drawline2d(lua_State *L){ - long r,g,b,a; - popvector4i(L, &r, &g, &b, &a); - long endx, endy; - popvector2i(L, &endx, &endy); - long startx, starty; - popvector2i(L, &startx, &starty); - driver->draw2DLine(position2d(startx, starty), position2d(endx,endy), SColor(r,g,b,a)); - return 0; -} - -void draw_register(lua_State *L){ - lua_getglobal(L,"video");//{video} - lua_pushcfunction(L,drawline2d);//{video},drawline2d() - lua_setfield(L,-2,"drawline2d");//{video} - lua_pop(L,1);// -} + +#include +#include +#include "draw.hpp" + +using namespace irr; +using namespace video; +using namespace core; + +extern IrrlichtDevice* device; +extern IVideoDriver* driver; +//drawline2d {startx,starty},{endx,endy},{r,g,b,a} +int drawline2d(lua_State *L){ + long r,g,b,a; + popvector4i(L, &r, &g, &b, &a); + long endx, endy; + popvector2i(L, &endx, &endy); + long startx, starty; + popvector2i(L, &startx, &starty); + driver->draw2DLine(position2d(startx, starty), position2d(endx,endy), SColor(r,g,b,a)); + return 0; +} + +void draw_register(lua_State *L){ + lua_getglobal(L,"video");//{video} + lua_pushcfunction(L,drawline2d);//{video},drawline2d() + lua_setfield(L,-2,"drawline2d");//{video} + lua_pop(L,1);// +} diff --git a/src/client/lua_api/video/draw.hpp b/src/client/lua_api/video/draw.hpp index eb5a9a7..836cd3d 100644 --- a/src/client/lua_api/video/draw.hpp +++ b/src/client/lua_api/video/draw.hpp @@ -1,8 +1,8 @@ - -extern "C" { - #include - #include - #include -} - -void draw_register(lua_State* L); + +extern "C" { + #include + #include + #include +} + +void draw_register(lua_State* L); diff --git a/src/server/lua_api/load_game.hpp b/src/server/lua_api/load_game.hpp index 7937b15..23b9e81 100644 --- a/src/server/lua_api/load_game.hpp +++ b/src/server/lua_api/load_game.hpp @@ -1,13 +1,13 @@ -#ifndef __H_loadgame -#define __H_loadgame -#include -#include -#include -extern "C" { - #include - #include - #include -} - -void load_gamefuncs(lua_State* L); -#endif +#ifndef __H_loadgame +#define __H_loadgame +#include +#include +#include +extern "C" { + #include + #include + #include +} + +void load_gamefuncs(lua_State* L); +#endif diff --git a/src/server/lua_api/load_io.cpp b/src/server/lua_api/load_io.cpp index af471b1..278d7a7 100644 --- a/src/server/lua_api/load_io.cpp +++ b/src/server/lua_api/load_io.cpp @@ -1,63 +1,63 @@ - -extern "C" { - #include - #include - #include -} -#include -//STL -#include -#include -#include - -#define epath "../data" -#define epathlen sizeof(epath) - -/*Add an io.dir(path) function, which lists all the files in (path)*/ -int dirpath(lua_State *L){ - if(!lua_isstring(L,-1)){ - lua_pushstring(L,"io.dir() requires a string as argument #1"); - lua_error(L); - } - size_t pathstrlen; - const char *pathstr = lua_tolstring(L,-1,&pathstrlen); - //printf("got pathstr: %s\n",pathstr); - //char tpathstr[pathstrlen + epathlen + 1 + 1]; //+1 for null, +1 for / - //memcpy(tpathstr,epath,epathlen); - //tpathstr[epathlen] = '/'; - //memcpy(tpathstr+epathlen,pathstr,pathstrlen); - //tpathstr[pathstrlen + epathlen + 1] = '\0'; - //printf("tpathstr is: \"%s\"\n",tpathstr); - //lua_pop(L,1); - DIR *dir; - struct dirent *ent; - const char *tpathstr = pathstr; - dir = opendir(tpathstr); - if(dir == NULL){ - perror("Cannot open"); - lua_pushstring(L,"Failed to open directory: "); - lua_pushstring(L,tpathstr); - lua_concat(L,2); - lua_error(L); - } - int i = 1; - ent = readdir(dir); - lua_newtable(L); - while( (ent = readdir(dir)) != NULL){ - lua_pushinteger(L,i); - lua_pushstring(L,ent->d_name); - lua_settable(L,-3); - i++; - } - closedir(dir); - return 1; -} - - -void load_iofuncs(lua_State* L){ - lua_getglobal(L,"io"); - - lua_pushcfunction(L,dirpath); - lua_setfield(L,-2,"dir"); - lua_pop(L,1); -} + +extern "C" { + #include + #include + #include +} +#include +//STL +#include +#include +#include + +#define epath "../data" +#define epathlen sizeof(epath) + +/*Add an io.dir(path) function, which lists all the files in (path)*/ +int dirpath(lua_State *L){ + if(!lua_isstring(L,-1)){ + lua_pushstring(L,"io.dir() requires a string as argument #1"); + lua_error(L); + } + size_t pathstrlen; + const char *pathstr = lua_tolstring(L,-1,&pathstrlen); + //printf("got pathstr: %s\n",pathstr); + //char tpathstr[pathstrlen + epathlen + 1 + 1]; //+1 for null, +1 for / + //memcpy(tpathstr,epath,epathlen); + //tpathstr[epathlen] = '/'; + //memcpy(tpathstr+epathlen,pathstr,pathstrlen); + //tpathstr[pathstrlen + epathlen + 1] = '\0'; + //printf("tpathstr is: \"%s\"\n",tpathstr); + //lua_pop(L,1); + DIR *dir; + struct dirent *ent; + const char *tpathstr = pathstr; + dir = opendir(tpathstr); + if(dir == NULL){ + perror("Cannot open"); + lua_pushstring(L,"Failed to open directory: "); + lua_pushstring(L,tpathstr); + lua_concat(L,2); + lua_error(L); + } + int i = 1; + ent = readdir(dir); + lua_newtable(L); + while( (ent = readdir(dir)) != NULL){ + lua_pushinteger(L,i); + lua_pushstring(L,ent->d_name); + lua_settable(L,-3); + i++; + } + closedir(dir); + return 1; +} + + +void load_iofuncs(lua_State* L){ + lua_getglobal(L,"io"); + + lua_pushcfunction(L,dirpath); + lua_setfield(L,-2,"dir"); + lua_pop(L,1); +} diff --git a/src/server/lua_api/load_io.hpp b/src/server/lua_api/load_io.hpp index 19f7a77..e4e29b1 100644 --- a/src/server/lua_api/load_io.hpp +++ b/src/server/lua_api/load_io.hpp @@ -1,13 +1,13 @@ -#ifndef __H_loadio -#define __H_loadio -#include -#include -#include -extern "C" { - #include - #include - #include -} - -void load_iofuncs(lua_State* L); -#endif +#ifndef __H_loadio +#define __H_loadio +#include +#include +#include +extern "C" { + #include + #include + #include +} + +void load_iofuncs(lua_State* L); +#endif diff --git a/src/server/lua_api/phys/sbphysmodel.cpp b/src/server/lua_api/phys/sbphysmodel.cpp index 4d81b2c..0371b93 100644 --- a/src/server/lua_api/phys/sbphysmodel.cpp +++ b/src/server/lua_api/phys/sbphysmodel.cpp @@ -1,126 +1,126 @@ -//#include -//#include -//#include -//#include -//#include -//#include -//#include -//extern "C" { - //#include - //#include - //#include -//} -//#include -//#include -//#include "../gameparts.hpp" -//#include "cbphysbox.hpp" -//#include "cbphysmodel.hpp" -//#include -//#include -//#include -//#include - - -//using namespace irr; -//using namespace scene; -//using namespace core; -//using namespace video; - -//extern IrrlichtDevice* device; - -//extern btDiscreteDynamicsWorld* World; -//extern std::list Objects; - -////newbphysmodel("graphicfile","physicfile",mass,[,{position}][,{lookat}]) -//static int newbphysmodel(lua_State* L){ - //printf("Creating bphysmodel\n"); - //int nargs = lua_gettop(L); - //double lx,ly,lz; - //double x,y,z; - //if(nargs > 4){ - ////"graphicsfile","physicsfile",{position},{lookat} - //popvector3d(L,&lx,&ly,&lz); - //}else{ - //lx = 1; ly = 1; lz = 1; - //} - - //if(nargs > 3){ - ////"graphicsfile","physicsfile",{position} - //popvector3d(L,&x,&y,&z); - //}else{ - //x = 0; y = 0; z = 0; - //} - ////"graphicsfile","physicsfile",mass - - //double mass = lua_tonumber(L,-1); - //const char *ppath = lua_tostring(L,-2); - //const char *gpath = lua_tostring(L,-3); - //lua_pop(L,3);// - - //ISceneManager *smgr = device->getSceneManager(); - - //printf("bphysnode, creating the scene node\n"); - - ////Create the scene node - //IMesh *gmesh = smgr->getMesh(gpath); - //ISceneNode *node = smgr->addMeshSceneNode(gmesh,0,-1,vector3df(x,y,z)); - - //printf("bphysnode, createing the physics body\n"); - ////Create the physics body - //lua_pushstring(L,ppath); - //lua_pushnumber(L,mass); - //pushvector3d(L,x,y,z); - //pushvector3d(L,lx,ly,lz); - //printf("About to makebphysmodel\n"); - //makebphysmodel(L); - //printf("done makebphysmodel\n"); - - //btRigidBody *rb = (btRigidBody*)lua_touserdata(L,-1); - ////Create the lua representation - //lua_newtable(L);// - - //lua_pushlightuserdata(L,rb); - //lua_setfield(L,-2,"collider");//{rb=ud_rb} - - //lua_pushstring(L,"rigidbody"); - //lua_setfield(L,-2,"type");//{rb=ud_rb, type="rigidbody"} - - //lua_pushlightuserdata(L,node); - //lua_setfield(L,-2,"node");//{rb=ud_rb, node=ud_node, type="rigidbody"} - - //luaL_getmetatable(L,"phys.physmodel"); - //lua_setmetatable(L,-2); - - //lua_getglobal(L,"phys");//{rb},{phys} - //lua_getfield(L,-1,"colliders");//{rb},{phys},{colliders} - //lua_pushlightuserdata(L,rb);//{rb},{phys},{colliders},ud_rb - //lua_pushvalue(L,-4);//{rb},{phys},{colliders},ud_rb,{rb} - //lua_settable(L,-3);//{rb},{phys},{colliders} - //lua_pop(L,2);//{rb} - //printf("finished creating the lua representation\n"); - - //return 1; -//} - -//static const luaL_reg bphysmodel_f[] = { - //{"newphysmodel", newbphysmodel}, - //{0,0}, -//}; - -//static const luaL_reg bphysmodel_m[] = { - //{0, 0}, -//}; - -//int cbphysmodel_register(lua_State* L){ - ////printf("bphysmodel registered\n"); - - //luaL_newmetatable(L, "phys.physmodel");//{} - //luaL_register(L,NULL,bcollider_m); - //luaL_register(L,NULL,bphysmodel_m); - //luaL_register(L,NULL,igeneric_m); //Inherit all the things to do with scene nodes - - //lua_getglobal(L,"phys"); - //luaL_register(L,NULL,bphysmodel_f); - - //return 1; -//} +//#include +//#include +//#include +//#include +//#include +//#include +//#include +//extern "C" { + //#include + //#include + //#include +//} +//#include +//#include +//#include "../gameparts.hpp" +//#include "cbphysbox.hpp" +//#include "cbphysmodel.hpp" +//#include +//#include +//#include +//#include + + +//using namespace irr; +//using namespace scene; +//using namespace core; +//using namespace video; + +//extern IrrlichtDevice* device; + +//extern btDiscreteDynamicsWorld* World; +//extern std::list Objects; + +////newbphysmodel("graphicfile","physicfile",mass,[,{position}][,{lookat}]) +//static int newbphysmodel(lua_State* L){ + //printf("Creating bphysmodel\n"); + //int nargs = lua_gettop(L); + //double lx,ly,lz; + //double x,y,z; + //if(nargs > 4){ + ////"graphicsfile","physicsfile",{position},{lookat} + //popvector3d(L,&lx,&ly,&lz); + //}else{ + //lx = 1; ly = 1; lz = 1; + //} + + //if(nargs > 3){ + ////"graphicsfile","physicsfile",{position} + //popvector3d(L,&x,&y,&z); + //}else{ + //x = 0; y = 0; z = 0; + //} + ////"graphicsfile","physicsfile",mass + + //double mass = lua_tonumber(L,-1); + //const char *ppath = lua_tostring(L,-2); + //const char *gpath = lua_tostring(L,-3); + //lua_pop(L,3);// + + //ISceneManager *smgr = device->getSceneManager(); + + //printf("bphysnode, creating the scene node\n"); + + ////Create the scene node + //IMesh *gmesh = smgr->getMesh(gpath); + //ISceneNode *node = smgr->addMeshSceneNode(gmesh,0,-1,vector3df(x,y,z)); + + //printf("bphysnode, createing the physics body\n"); + ////Create the physics body + //lua_pushstring(L,ppath); + //lua_pushnumber(L,mass); + //pushvector3d(L,x,y,z); + //pushvector3d(L,lx,ly,lz); + //printf("About to makebphysmodel\n"); + //makebphysmodel(L); + //printf("done makebphysmodel\n"); + + //btRigidBody *rb = (btRigidBody*)lua_touserdata(L,-1); + ////Create the lua representation + //lua_newtable(L);// + + //lua_pushlightuserdata(L,rb); + //lua_setfield(L,-2,"collider");//{rb=ud_rb} + + //lua_pushstring(L,"rigidbody"); + //lua_setfield(L,-2,"type");//{rb=ud_rb, type="rigidbody"} + + //lua_pushlightuserdata(L,node); + //lua_setfield(L,-2,"node");//{rb=ud_rb, node=ud_node, type="rigidbody"} + + //luaL_getmetatable(L,"phys.physmodel"); + //lua_setmetatable(L,-2); + + //lua_getglobal(L,"phys");//{rb},{phys} + //lua_getfield(L,-1,"colliders");//{rb},{phys},{colliders} + //lua_pushlightuserdata(L,rb);//{rb},{phys},{colliders},ud_rb + //lua_pushvalue(L,-4);//{rb},{phys},{colliders},ud_rb,{rb} + //lua_settable(L,-3);//{rb},{phys},{colliders} + //lua_pop(L,2);//{rb} + //printf("finished creating the lua representation\n"); + + //return 1; +//} + +//static const luaL_reg bphysmodel_f[] = { + //{"newphysmodel", newbphysmodel}, + //{0,0}, +//}; + +//static const luaL_reg bphysmodel_m[] = { + //{0, 0}, +//}; + +//int cbphysmodel_register(lua_State* L){ + ////printf("bphysmodel registered\n"); + + //luaL_newmetatable(L, "phys.physmodel");//{} + //luaL_register(L,NULL,bcollider_m); + //luaL_register(L,NULL,bphysmodel_m); + //luaL_register(L,NULL,igeneric_m); //Inherit all the things to do with scene nodes + + //lua_getglobal(L,"phys"); + //luaL_register(L,NULL,bphysmodel_f); + + //return 1; +//} diff --git a/src/shared/lua_api/load_common.cpp b/src/shared/lua_api/load_common.cpp index dc61ef1..1eca598 100644 --- a/src/shared/lua_api/load_common.cpp +++ b/src/shared/lua_api/load_common.cpp @@ -1,30 +1,30 @@ -#include -#include -extern "C" { - #include - #include - #include -} -using namespace std::chrono; - -//Gets the time -int get_time(lua_State* L){ - std::chrono::high_resolution_clock::time_point now = high_resolution_clock::now(); - std::chrono::high_resolution_clock::duration since_epoch = now.time_since_epoch(); - double dc = std::chrono::duration_cast(since_epoch).count(); - lua_pushnumber(L,dc); - return 1; -} - -void loadCommonLibs(lua_State* L){ - lua_getglobal(L,"GAME"); - lua_pushcfunction(L,make_crashy); - lua_setfield(L,-2,"crashy"); - lua_pop(L,1); - lua_pushcfunction(L,get_time); - lua_setglobal(L,"get_time"); -} - -void gameloop_common(lua_State* L){ - -} +#include +#include +extern "C" { + #include + #include + #include +} +using namespace std::chrono; + +//Gets the time +int get_time(lua_State* L){ + std::chrono::high_resolution_clock::time_point now = high_resolution_clock::now(); + std::chrono::high_resolution_clock::duration since_epoch = now.time_since_epoch(); + double dc = std::chrono::duration_cast(since_epoch).count(); + lua_pushnumber(L,dc); + return 1; +} + +void loadCommonLibs(lua_State* L){ + lua_getglobal(L,"GAME"); + lua_pushcfunction(L,make_crashy); + lua_setfield(L,-2,"crashy"); + lua_pop(L,1); + lua_pushcfunction(L,get_time); + lua_setglobal(L,"get_time"); +} + +void gameloop_common(lua_State* L){ + +} diff --git a/src/shared/lua_api/load_common.hpp b/src/shared/lua_api/load_common.hpp index 759ba85..c8741c5 100644 --- a/src/shared/lua_api/load_common.hpp +++ b/src/shared/lua_api/load_common.hpp @@ -1,4 +1,4 @@ -#include - -void loadCommonLibs(lua_State* L); -void gameloop_common(lua_State* L); +#include + +void loadCommonLibs(lua_State* L); +void gameloop_common(lua_State* L); diff --git a/src/shared/lua_api/load_phys.cpp b/src/shared/lua_api/load_phys.cpp index 33a59fe..d20545e 100644 --- a/src/shared/lua_api/load_phys.cpp +++ b/src/shared/lua_api/load_phys.cpp @@ -31,7 +31,7 @@ int shapecast(lua_State *L){ //hw = cb->m_hitPointWorld; //hn = cb->m_hitNormalWorld; //printf("before getting results\n\tHasHit:%d\n\tHit:%f,%f,%f\n\tNor:%f,%f,%f\n",cb->hasHit() ? 1 : 0,hw.x(),hw.y(),hw.z(),hn.x(),hn.y(),hn.z()); - World->convexSweepTest(cs,ft,tt,*cb,0.f); + World->convexSweepTest(cs,ft,tt,*cb,1.f); hw = cb->m_hitPointWorld; hn = cb->m_hitNormalWorld; //printf("Got sweep results\n\tHasHit:%d\n\tHit:%f,%f,%f\n\tNor:%f,%f,%f\n",cb->hasHit() ? 1 : 0,hw.x(),hw.y(),hw.z(),hn.x(),hn.y(),hn.z()); @@ -42,7 +42,7 @@ int shapecast(lua_State *L){ lua_setfield(L,-2,"pos"); pushvector3d(L,hn.x(),hn.y(),hn.z()); lua_setfield(L,-2,"normal"); - + delete cb; return 1; } diff --git a/src/shared/lua_api/phys/bcharactercontroller.cpp b/src/shared/lua_api/phys/bcharactercontroller.cpp index f61aca5..09941c8 100644 --- a/src/shared/lua_api/phys/bcharactercontroller.cpp +++ b/src/shared/lua_api/phys/bcharactercontroller.cpp @@ -1,300 +1,300 @@ - - -#include -#include -#include -extern "C" { - #include - #include - #include -} -#include -#include -#include -#include "bcharactercontroller.hpp" -#include - -extern btDiscreteDynamicsWorld* World; -extern std::list Objects; -extern std::list Chars; - -//{character} :: btKinematicCharacterController* -btKinematicCharacterController *popCharacter(lua_State *L){ - lua_getfield(L,-1,"type");//{char},"type" - if(lua_isnil(L,-1)){ - lua_pushstring(L,"Tried to call a character method on something that had not 'type'"); - lua_error(L); - } - const char *s = lua_tostring(L,-1);//{char},"type" - if(strcmp(s,"character")!= 0){ - printf("Tried to pop character when it was not a character!\n"); - lua_pushstring(L,"Tried to call a character method on a "); - lua_pushstring(L,s); - lua_concat(L,2); - lua_error(L); - } - lua_getfield(L,-2,"character");//{char},"type",ud_character - if(lua_isnil(L,-1)){ - printf("Failed to get a \"character\" field\n"); - lua_pushstring(L,"Character object was not set up correctly\n"); - lua_error(L); - } - btKinematicCharacterController *c = (btKinematicCharacterController*)lua_touserdata(L,-1); - lua_pop(L,3); - return c; - -} -/* -static LBPhysNode* checkisbphysbox(lua_State* L, int index){ - void* ud = luaL_checkudata(L,index,"phys.physbox"); - luaL_argcheck(L,ud != NULL, index, "'phys.physbox' expected"); - return (LBPhysNode*) ud; -} -*/ - -/* -static LISceneNode* checkismesh(lua_State* L){ - return checkismesh(L,1); -} -*/ -// ud_character :: ({v3 size}, {v3 origin}) -void makenewbcharactercontroller(lua_State* L){ - printf("Creating new character controller\n"); - //lua_pushstring(L,"Character controller is totally fucking broken for now\n"); - //lua_error(L); - double px,py,pz; //position - double sx,sy,sz; //size - //double mass; - - //mass = lua_tonumber(L,-1);//{v3_size},{v3_origin},mass - //lua_pop(L,1);//{v3_size},{v3_origin} - //printf("Got mass: %f\n",mass); - - popvector3d(L,&px,&py,&pz);//{v3_size} - printf("Got position: (%f,%f,%f)\n",px,py,pz); - popvector3d(L,&sx,&sy,&sz);// - - btVector3 vshape = btVector3(sx * 0.5f, sy * 0.5f, sz * 0.5f); - printf("Got size: (%f,%f,%f)\n",sx,sy,sz); - btVector3 pos = btVector3(px,py,pz); - btTransform transform = btTransform(btQuaternion(0,0,0,1),pos); - - // Create the shape - btConvexShape* cshape = new btBoxShape(vshape); - - - - // Add mass - //btVector3 localinertia = btVector3(0,0,0); - //shape->calculateLocalInertia(mass, localinertia); - - // Create the rigid body object - //btRigidBody::btRigidBodyConstructionInfo cinfo = btRigidBody::btRigidBodyConstructionInfo( - //mass, - //motionstate, - //shape, - //localinertia - //); - btPairCachingGhostObject *ghost = new btPairCachingGhostObject(); - ghost->setWorldTransform(transform); - ghost->setCollisionShape(cshape); - World->addCollisionObject(ghost,btBroadphaseProxy::CharacterFilter, btBroadphaseProxy::StaticFilter|btBroadphaseProxy::DefaultFilter); - //ghost->setCollisionFlags(btCollisionObject::CF_CHARACTER_OBJECT); - printf("Character controller created\n"); - btKinematicCharacterController *cc = new btKinematicCharacterController(ghost, cshape, 1, btVector3(0,1,0)); - //cc->setMaxSlope(3.14 / 4.0); - //cinfo.m_friction = 0; - - // Add it to the world - printf("About to add action\n"); - World->addAction(cc); - printf("Finished adding action\n"); - //printf("Added rigid body to world: %p\n",World); - printf("Added to Chars\n"); - //Chars.push_back(cc); - //Objects.push_back(ghost); - - lua_pushlightuserdata(L,cc);//ud_cc -} - -// char:getvelocity() -int bcharactergetvelocity(lua_State *L){ - btKinematicCharacterController *r = popCharacter(L); - btVector3 v = r->getLinearVelocity(); - pushvector3d(L,v.x(),v.y(),v.z()); - return 1; -} - -// char:setvelocity(v3 vel) -int bcharactersetvelocity(lua_State *L){ - double x,y,z; - popvector3d(L,&x,&y,&z); - btKinematicCharacterController *r = popCharacter(L); - r->setLinearVelocity(btVector3(x,y,z)); - return 0; -} - -// phys.newphysbox(vector3 size, vector3 origin, double mass) -int newbcharactercontroller(lua_State* L){ - //printf("Createing bphysbox!\n"); - //Create it's lua representation - makenewbcharactercontroller(L);//ud_cc - btKinematicCharacterController* r = (btKinematicCharacterController*)lua_touserdata(L,-1);//ud_cc - lua_pop(L,1);// - lua_newtable(L);//{} - lua_pushlightuserdata(L,r);//{},ud_cc - lua_setfield(L,-2,"character");//{character=ud_cc} - - lua_pushstring(L,"character"); - lua_setfield(L,-2,"type");//{character=ud_cc,type="character"} - - //Set it's metatable - luaL_getmetatable(L, "phys.charactercontroller");//{},{phys.charactercontroller} - lua_setmetatable(L, -2);//{cc} - - return 1; -} - -// char:setgravity(v3 gravity) -int bcharactersetgravity(lua_State *L){ - double x,y,z; - popvector3d(L,&x,&y,&z); - btKinematicCharacterController *c = popCharacter(L); - c->setGravity(btVector3(x,y,z)); - return 0; -} - -// char:getpos() :: v3 -int bcharactergetpos(lua_State *L){ - btKinematicCharacterController *c = popCharacter(L); - btVector3 pos = c->getGhostObject()->getWorldTransform().getOrigin(); - pushvector3d(L,pos.x(),pos.y(),pos.z()); - return 1; -} - -// char:setpos(v3 pos) -int bcharactersetpos(lua_State *L){ - double x,y,z; - popvector3d(L,&x,&y,&z); - btKinematicCharacterController *c = popCharacter(L); - c->warp(btVector3(x,y,z)); - //btTransform t = c->getGhostObject()->getWorldTransform(); - //t.setOrigin(btVector3(x,y,z)); - //c->getGhostObject()->setWorldTransform(t); - return 0; -} - -// char:onground() -int bcharacteronground(lua_State *L){ - btKinematicCharacterController *c = popCharacter(L); - lua_pushboolean(L,c->onGround() == true ? 1 : 0); - return 1; -} - -// char:jump(v3 jump) -int bcharacterjump(lua_State *L){ - //printf("Jump called\n"); - double x,y,z; - popvector3d(L,&x,&y,&z); - btKinematicCharacterController *c = popCharacter(L); - //printf("About to jump\n"); - c->jump(btVector3(x,y,z)); - //printf("Done jumping\n"); - return 0; -} - -//{phys.physbox}:delete() -static int delbcharactercontroller(lua_State* L){//self - //printf("Attempting to delete physbox\n"); - lua_getfield(L,-1,"character");//self,ud_character - btKinematicCharacterController* r = (btKinematicCharacterController*)lua_touserdata(L,-1);//self,ud_character - lua_pop(L,2); - delete r->getGhostObject(); - delete r; - return 0; -} - -//{char},{v3_dir} :: -int bcharsetwalkdirection(lua_State *L){ - double x,y,z; - popvector3d(L,&x,&y,&z);//{char} - lua_getfield(L,-1,"character");//{char},ud_cc - btKinematicCharacterController* cc = (btKinematicCharacterController*)lua_touserdata(L,-1); - lua_pop(L,2); - cc->setWalkDirection(btVector3(x,y,z)); - return 0; -} - -// char:setfallspeed(n) -int bcharactersetfallspeed(lua_State *L){ - double speed = luaL_optnumber(L,-1,1); - printf("Got number: %f\n",speed); - lua_pop(L,1); - btKinematicCharacterController *c = popCharacter(L); - printf("About to set speed\n"); - c->setFallSpeed(speed); - printf("Done setting speed\n"); - return 0; -} - -// char:getmaxslope() -int bcharactergetmaxslope(lua_State *L){ - btKinematicCharacterController *c = popCharacter(L); - btScalar s = c->getMaxSlope(); - lua_pushnumber(L,s); - return 1; -} - -// char:setmaxslope(slope) -int bcharactersetmaxslope(lua_State *L){ - btScalar s = lua_tonumber(L,-1); - lua_pop(L,1); - btKinematicCharacterController *c = popCharacter(L); - c->setMaxSlope(s); - return 0; -} - -// char:setvelocityforinterval(vec3 {velocity},number interval) -int bcharactersetvelocityforinterval(lua_State *L){ - double interval = lua_tonumber(L,-1); - lua_pop(L,1); - double x,y,z; - popvector3d(L,&x,&y,&z); - btKinematicCharacterController *c = popCharacter(L); - c->setVelocityForTimeInterval(btVector3(x,y,z),interval); - return 0; -} - -extern const luaL_reg bcharactercontroller_m[] = { - {"setwalkdir", bcharsetwalkdirection}, - {"remove", delbcharactercontroller}, - {"getvelocity", bcharactergetvelocity}, - {"setvelocity", bcharactersetvelocity}, - {"setgravity", bcharactersetgravity}, - {"getpos", bcharactergetpos}, - {"setpos", bcharactersetpos}, - {"onground", bcharacteronground}, - {"jump", bcharacterjump}, - {"setfallspeed", bcharactersetfallspeed}, - {"getmaxslope", bcharactergetmaxslope}, - {"setmaxslope", bcharactersetmaxslope}, - {"setvelocityforinterval",bcharactersetvelocityforinterval}, - {0, 0}, -}; - -void bcharactercontroller_register(lua_State* L){// - //printf("Registered bphysbox\n"); - - luaL_newmetatable(L, "phys.charactercontroller");//{phys.characontroller} - lua_newtable(L);//{phys.charcontroller},{} - luaL_register(L,NULL,bcharactercontroller_m);//{phys.charcontroller},{} - lua_setfield(L,-2,"__index");//{phys.charcontroller} - - lua_pop(L,1);// - - lua_getglobal(L,"phys");//{} - lua_pushcfunction(L,newbcharactercontroller);//{},newbcharactercontroller() - lua_setfield(L,-2,"newbcharactercontroller");//{} - - lua_pop(L,1); -} + + +#include +#include +#include +extern "C" { + #include + #include + #include +} +#include +#include +#include +#include "bcharactercontroller.hpp" +#include + +extern btDiscreteDynamicsWorld* World; +extern std::list Objects; +extern std::list Chars; + +//{character} :: btKinematicCharacterController* +btKinematicCharacterController *popCharacter(lua_State *L){ + lua_getfield(L,-1,"type");//{char},"type" + if(lua_isnil(L,-1)){ + lua_pushstring(L,"Tried to call a character method on something that had not 'type'"); + lua_error(L); + } + const char *s = lua_tostring(L,-1);//{char},"type" + if(strcmp(s,"character")!= 0){ + printf("Tried to pop character when it was not a character!\n"); + lua_pushstring(L,"Tried to call a character method on a "); + lua_pushstring(L,s); + lua_concat(L,2); + lua_error(L); + } + lua_getfield(L,-2,"character");//{char},"type",ud_character + if(lua_isnil(L,-1)){ + printf("Failed to get a \"character\" field\n"); + lua_pushstring(L,"Character object was not set up correctly\n"); + lua_error(L); + } + btKinematicCharacterController *c = (btKinematicCharacterController*)lua_touserdata(L,-1); + lua_pop(L,3); + return c; + +} +/* +static LBPhysNode* checkisbphysbox(lua_State* L, int index){ + void* ud = luaL_checkudata(L,index,"phys.physbox"); + luaL_argcheck(L,ud != NULL, index, "'phys.physbox' expected"); + return (LBPhysNode*) ud; +} +*/ + +/* +static LISceneNode* checkismesh(lua_State* L){ + return checkismesh(L,1); +} +*/ +// ud_character :: ({v3 size}, {v3 origin}) +void makenewbcharactercontroller(lua_State* L){ + printf("Creating new character controller\n"); + //lua_pushstring(L,"Character controller is totally fucking broken for now\n"); + //lua_error(L); + double px,py,pz; //position + double sx,sy,sz; //size + //double mass; + + //mass = lua_tonumber(L,-1);//{v3_size},{v3_origin},mass + //lua_pop(L,1);//{v3_size},{v3_origin} + //printf("Got mass: %f\n",mass); + + popvector3d(L,&px,&py,&pz);//{v3_size} + printf("Got position: (%f,%f,%f)\n",px,py,pz); + popvector3d(L,&sx,&sy,&sz);// + + btVector3 vshape = btVector3(sx * 0.5f, sy * 0.5f, sz * 0.5f); + printf("Got size: (%f,%f,%f)\n",sx,sy,sz); + btVector3 pos = btVector3(px,py,pz); + btTransform transform = btTransform(btQuaternion(0,0,0,1),pos); + + // Create the shape + btConvexShape* cshape = new btBoxShape(vshape); + + + + // Add mass + //btVector3 localinertia = btVector3(0,0,0); + //shape->calculateLocalInertia(mass, localinertia); + + // Create the rigid body object + //btRigidBody::btRigidBodyConstructionInfo cinfo = btRigidBody::btRigidBodyConstructionInfo( + //mass, + //motionstate, + //shape, + //localinertia + //); + btPairCachingGhostObject *ghost = new btPairCachingGhostObject(); + ghost->setWorldTransform(transform); + ghost->setCollisionShape(cshape); + World->addCollisionObject(ghost,btBroadphaseProxy::CharacterFilter, btBroadphaseProxy::StaticFilter|btBroadphaseProxy::DefaultFilter); + //ghost->setCollisionFlags(btCollisionObject::CF_CHARACTER_OBJECT); + printf("Character controller created\n"); + btKinematicCharacterController *cc = new btKinematicCharacterController(ghost, cshape, 1, btVector3(0,1,0)); + //cc->setMaxSlope(3.14 / 4.0); + //cinfo.m_friction = 0; + + // Add it to the world + printf("About to add action\n"); + World->addAction(cc); + printf("Finished adding action\n"); + //printf("Added rigid body to world: %p\n",World); + printf("Added to Chars\n"); + //Chars.push_back(cc); + //Objects.push_back(ghost); + + lua_pushlightuserdata(L,cc);//ud_cc +} + +// char:getvelocity() +int bcharactergetvelocity(lua_State *L){ + btKinematicCharacterController *r = popCharacter(L); + btVector3 v = r->getLinearVelocity(); + pushvector3d(L,v.x(),v.y(),v.z()); + return 1; +} + +// char:setvelocity(v3 vel) +int bcharactersetvelocity(lua_State *L){ + double x,y,z; + popvector3d(L,&x,&y,&z); + btKinematicCharacterController *r = popCharacter(L); + r->setLinearVelocity(btVector3(x,y,z)); + return 0; +} + +// phys.newphysbox(vector3 size, vector3 origin, double mass) +int newbcharactercontroller(lua_State* L){ + //printf("Createing bphysbox!\n"); + //Create it's lua representation + makenewbcharactercontroller(L);//ud_cc + btKinematicCharacterController* r = (btKinematicCharacterController*)lua_touserdata(L,-1);//ud_cc + lua_pop(L,1);// + lua_newtable(L);//{} + lua_pushlightuserdata(L,r);//{},ud_cc + lua_setfield(L,-2,"character");//{character=ud_cc} + + lua_pushstring(L,"character"); + lua_setfield(L,-2,"type");//{character=ud_cc,type="character"} + + //Set it's metatable + luaL_getmetatable(L, "phys.charactercontroller");//{},{phys.charactercontroller} + lua_setmetatable(L, -2);//{cc} + + return 1; +} + +// char:setgravity(v3 gravity) +int bcharactersetgravity(lua_State *L){ + double x,y,z; + popvector3d(L,&x,&y,&z); + btKinematicCharacterController *c = popCharacter(L); + c->setGravity(btVector3(x,y,z)); + return 0; +} + +// char:getpos() :: v3 +int bcharactergetpos(lua_State *L){ + btKinematicCharacterController *c = popCharacter(L); + btVector3 pos = c->getGhostObject()->getWorldTransform().getOrigin(); + pushvector3d(L,pos.x(),pos.y(),pos.z()); + return 1; +} + +// char:setpos(v3 pos) +int bcharactersetpos(lua_State *L){ + double x,y,z; + popvector3d(L,&x,&y,&z); + btKinematicCharacterController *c = popCharacter(L); + c->warp(btVector3(x,y,z)); + //btTransform t = c->getGhostObject()->getWorldTransform(); + //t.setOrigin(btVector3(x,y,z)); + //c->getGhostObject()->setWorldTransform(t); + return 0; +} + +// char:onground() +int bcharacteronground(lua_State *L){ + btKinematicCharacterController *c = popCharacter(L); + lua_pushboolean(L,c->onGround() == true ? 1 : 0); + return 1; +} + +// char:jump(v3 jump) +int bcharacterjump(lua_State *L){ + //printf("Jump called\n"); + double x,y,z; + popvector3d(L,&x,&y,&z); + btKinematicCharacterController *c = popCharacter(L); + //printf("About to jump\n"); + c->jump(btVector3(x,y,z)); + //printf("Done jumping\n"); + return 0; +} + +//{phys.physbox}:delete() +static int delbcharactercontroller(lua_State* L){//self + //printf("Attempting to delete physbox\n"); + lua_getfield(L,-1,"character");//self,ud_character + btKinematicCharacterController* r = (btKinematicCharacterController*)lua_touserdata(L,-1);//self,ud_character + lua_pop(L,2); + delete r->getGhostObject(); + delete r; + return 0; +} + +//{char},{v3_dir} :: +int bcharsetwalkdirection(lua_State *L){ + double x,y,z; + popvector3d(L,&x,&y,&z);//{char} + lua_getfield(L,-1,"character");//{char},ud_cc + btKinematicCharacterController* cc = (btKinematicCharacterController*)lua_touserdata(L,-1); + lua_pop(L,2); + cc->setWalkDirection(btVector3(x,y,z)); + return 0; +} + +// char:setfallspeed(n) +int bcharactersetfallspeed(lua_State *L){ + double speed = luaL_optnumber(L,-1,1); + printf("Got number: %f\n",speed); + lua_pop(L,1); + btKinematicCharacterController *c = popCharacter(L); + printf("About to set speed\n"); + c->setFallSpeed(speed); + printf("Done setting speed\n"); + return 0; +} + +// char:getmaxslope() +int bcharactergetmaxslope(lua_State *L){ + btKinematicCharacterController *c = popCharacter(L); + btScalar s = c->getMaxSlope(); + lua_pushnumber(L,s); + return 1; +} + +// char:setmaxslope(slope) +int bcharactersetmaxslope(lua_State *L){ + btScalar s = lua_tonumber(L,-1); + lua_pop(L,1); + btKinematicCharacterController *c = popCharacter(L); + c->setMaxSlope(s); + return 0; +} + +// char:setvelocityforinterval(vec3 {velocity},number interval) +int bcharactersetvelocityforinterval(lua_State *L){ + double interval = lua_tonumber(L,-1); + lua_pop(L,1); + double x,y,z; + popvector3d(L,&x,&y,&z); + btKinematicCharacterController *c = popCharacter(L); + c->setVelocityForTimeInterval(btVector3(x,y,z),interval); + return 0; +} + +extern const luaL_reg bcharactercontroller_m[] = { + {"setwalkdir", bcharsetwalkdirection}, + {"remove", delbcharactercontroller}, + {"getvelocity", bcharactergetvelocity}, + {"setvelocity", bcharactersetvelocity}, + {"setgravity", bcharactersetgravity}, + {"getpos", bcharactergetpos}, + {"setpos", bcharactersetpos}, + {"onground", bcharacteronground}, + {"jump", bcharacterjump}, + {"setfallspeed", bcharactersetfallspeed}, + {"getmaxslope", bcharactergetmaxslope}, + {"setmaxslope", bcharactersetmaxslope}, + {"setvelocityforinterval",bcharactersetvelocityforinterval}, + {0, 0}, +}; + +void bcharactercontroller_register(lua_State* L){// + //printf("Registered bphysbox\n"); + + luaL_newmetatable(L, "phys.charactercontroller");//{phys.characontroller} + lua_newtable(L);//{phys.charcontroller},{} + luaL_register(L,NULL,bcharactercontroller_m);//{phys.charcontroller},{} + lua_setfield(L,-2,"__index");//{phys.charcontroller} + + lua_pop(L,1);// + + lua_getglobal(L,"phys");//{} + lua_pushcfunction(L,newbcharactercontroller);//{},newbcharactercontroller() + lua_setfield(L,-2,"newbcharactercontroller");//{} + + lua_pop(L,1); +} diff --git a/src/shared/lua_api/phys/bcharactercontroller.hpp b/src/shared/lua_api/phys/bcharactercontroller.hpp index 1c920de..02e5afb 100644 --- a/src/shared/lua_api/phys/bcharactercontroller.hpp +++ b/src/shared/lua_api/phys/bcharactercontroller.hpp @@ -1,12 +1,12 @@ -#include -#include -extern "C" { - #include - #include - #include -} -#include - -void bcharactercontroller_register(lua_State* L); -void makenewbcharactercontroller(lua_State* L); -extern const luaL_reg bcharactercontroller_m[]; +#include +#include +extern "C" { + #include + #include + #include +} +#include + +void bcharactercontroller_register(lua_State* L); +void makenewbcharactercontroller(lua_State* L); +extern const luaL_reg bcharactercontroller_m[]; diff --git a/src/shared/lua_api/phys/bcollider.cpp b/src/shared/lua_api/phys/bcollider.cpp index 0a87af3..91c34fd 100644 --- a/src/shared/lua_api/phys/bcollider.cpp +++ b/src/shared/lua_api/phys/bcollider.cpp @@ -1,89 +1,89 @@ -extern "C" { - #include - #include - #include -} -#include -#include -#include "bcollider.hpp" - - -/*Collider things from lua have the form of: -{ - type = "ghost" | "multi" | "rigidbody" | "softbody" - collider = ud_btCollisionObject, - node = ud_ISceneNode, --Optional, on client -} -*/ -btCollisionObject* popCollider(lua_State *L){ - lua_getfield(L,-1,"collider"); - btCollisionObject *r = (btCollisionObject*)lua_touserdata(L,-1); - lua_pop(L,2); - return r; -} - -/*** -Activates this object. -If this object was sleeping, it will move again. If you are using -applyforce or setvelocity, you will need to activate() the rigidbody for it -to move. -@function collider:activate() -*/ -//collider:activate() -int activate(lua_State *L){ - btCollisionObject *r = popCollider(L); - - r->activate(true); - - return 0; -} - -//collider:getfriction() -int getfriction(lua_State *L){ - btCollisionObject *r = popCollider(L); - double fric = r->getFriction(); - lua_pushnumber(L, fric); - return 1; -} - -//collider:setfriction(number) -int setfriction(lua_State *L){ - double friction = lua_tonumber(L,-1); - lua_pop(L,1); - btCollisionObject *r = popCollider(L); - r->setFriction(friction); - return 0; -} - -//collider:setpos({x,y,z}) -int setpos(lua_State *L){ - double x,y,z; - popvector3d(L,&x,&y,&z); - lua_getfield(L,-1,"collider"); - btCollisionObject *c = (btCollisionObject*)lua_touserdata(L,-1); - lua_pop(L,1); - btTransform t = c->getWorldTransform(); - t.setOrigin(btVector3(x,y,z)); - c->setWorldTransform(t); - c->activate(); - return 0; -} - -//collider:getpos() :: {x,y,z} -int getpos(lua_State *L){ - lua_getfield(L,-1,"collider"); - btCollisionObject *c = (btCollisionObject*)lua_touserdata(L,-1); - btTransform t = c->getWorldTransform(); - btVector3 o = t.getOrigin(); - pushvector3d(L,o.x(), o.y(), o.z()); - return 1; -} - -extern const luaL_reg bcollider_m[] = { - {"activate", activate}, - {"getpos", getpos}, - {"setpos", setpos}, - {"getfriction", getfriction}, - {"setfriction", setfriction}, - {NULL, NULL} -}; +extern "C" { + #include + #include + #include +} +#include +#include +#include "bcollider.hpp" + + +/*Collider things from lua have the form of: +{ + type = "ghost" | "multi" | "rigidbody" | "softbody" + collider = ud_btCollisionObject, + node = ud_ISceneNode, --Optional, on client +} +*/ +btCollisionObject* popCollider(lua_State *L){ + lua_getfield(L,-1,"collider"); + btCollisionObject *r = (btCollisionObject*)lua_touserdata(L,-1); + lua_pop(L,2); + return r; +} + +/*** +Activates this object. +If this object was sleeping, it will move again. If you are using +applyforce or setvelocity, you will need to activate() the rigidbody for it +to move. +@function collider:activate() +*/ +//collider:activate() +int activate(lua_State *L){ + btCollisionObject *r = popCollider(L); + + r->activate(true); + + return 0; +} + +//collider:getfriction() +int getfriction(lua_State *L){ + btCollisionObject *r = popCollider(L); + double fric = r->getFriction(); + lua_pushnumber(L, fric); + return 1; +} + +//collider:setfriction(number) +int setfriction(lua_State *L){ + double friction = lua_tonumber(L,-1); + lua_pop(L,1); + btCollisionObject *r = popCollider(L); + r->setFriction(friction); + return 0; +} + +//collider:setpos({x,y,z}) +int setpos(lua_State *L){ + double x,y,z; + popvector3d(L,&x,&y,&z); + lua_getfield(L,-1,"collider"); + btCollisionObject *c = (btCollisionObject*)lua_touserdata(L,-1); + lua_pop(L,1); + btTransform t = c->getWorldTransform(); + t.setOrigin(btVector3(x,y,z)); + c->setWorldTransform(t); + c->activate(); + return 0; +} + +//collider:getpos() :: {x,y,z} +int getpos(lua_State *L){ + lua_getfield(L,-1,"collider"); + btCollisionObject *c = (btCollisionObject*)lua_touserdata(L,-1); + btTransform t = c->getWorldTransform(); + btVector3 o = t.getOrigin(); + pushvector3d(L,o.x(), o.y(), o.z()); + return 1; +} + +extern const luaL_reg bcollider_m[] = { + {"activate", activate}, + {"getpos", getpos}, + {"setpos", setpos}, + {"getfriction", getfriction}, + {"setfriction", setfriction}, + {NULL, NULL} +}; diff --git a/src/shared/lua_api/phys/bcollider.hpp b/src/shared/lua_api/phys/bcollider.hpp index 3882df6..f5164b7 100644 --- a/src/shared/lua_api/phys/bcollider.hpp +++ b/src/shared/lua_api/phys/bcollider.hpp @@ -1,7 +1,7 @@ -extern "C" { - #include - #include - #include -} - -extern const luaL_reg bcollider_m[]; +extern "C" { + #include + #include + #include +} + +extern const luaL_reg bcollider_m[]; diff --git a/src/shared/lua_api/phys/bghostobject.cpp b/src/shared/lua_api/phys/bghostobject.cpp index 8174b21..63f790c 100644 --- a/src/shared/lua_api/phys/bghostobject.cpp +++ b/src/shared/lua_api/phys/bghostobject.cpp @@ -1,185 +1,236 @@ -#include -#include -#include -extern "C" { - #include - #include - #include -} -#include -#include "bghostobject.hpp" -#include - -extern btDiscreteDynamicsWorld* World; -extern std::list Objects; -//extern std::list Ghosts; - -/* -static LBPhysNode* checkisbphysbox(lua_State* L, int index){ - void* ud = luaL_checkudata(L,index,"phys.physbox"); - luaL_argcheck(L,ud != NULL, index, "'phys.physbox' expected"); - return (LBPhysNode*) ud; -} -*/ - -/* -static LISceneNode* checkismesh(lua_State* L){ - return checkismesh(L,1); -} -*/ -// ud_btGhostObject :: ({v3 size}, {v3 origin}) -void makeghostobject(lua_State* L){ - double px,py,pz; //position - double sx,sy,sz; //size - - popvector3d(L,&px,&py,&pz);//{v3_size} - //printf("Got position: (%f,%f,%f)\n",px,py,pz); - popvector3d(L,&sx,&sy,&sz);// - - btVector3 vshape = btVector3(sx * 0.5f, sy * 0.5f, sz * 0.5f); - //printf("Got size: (%f,%f,%f)\n",sx,sy,sz); - btVector3 pos = btVector3(px,py,pz); - - // Set the initial position of the object - btTransform transform = btTransform(btQuaternion(0,0,0,1),pos); - //transform.setIdentity(); - //transform.setOrigin(pos); - - // Create the shape - btCollisionShape* shape = new btBoxShape(vshape); - if(!shape){ - //printf("no shape\n"); - } - - // Add mass - btVector3 localinertia = btVector3(0,0,0); - shape->calculateLocalInertia(1, localinertia); - - //cinfo.m_friction = 0; - btGhostObject *ghost = new btGhostObject(); - ghost->setCollisionShape(shape); - ghost->setWorldTransform(transform); - //ghost->setCollisionFlags( - //btCollisionObject::CollisionFlags::CF_NO_CONTACT_RESPONSE | - //btCollisionObject::CollisionFlags::CF_KINEMATIC_OBJECT - //); - World->addCollisionObject(ghost, btBroadphaseProxy::SensorTrigger, btBroadphaseProxy::AllFilter & ~btBroadphaseProxy::SensorTrigger); - - //printf("Added rigid body to world: %p\n",World); - //Objects.push_back(ghost); - - lua_pushlightuserdata(L,ghost);//ud_ghost -} - -// phys.newghostobject(vector3 size, vector3 origin) -int newghostobject(lua_State* L){ - //printf("Createing bphysbox!\n"); - //Create it's lua representation - makeghostobject(L);//ud_btGhostObject - btGhostObject* ghost = (btGhostObject*)lua_touserdata(L,-1); - lua_pop(L,1); - lua_newtable(L);//{} - lua_pushlightuserdata(L,ghost);//ud_btGhostObject - lua_setfield(L,-2,"collider");//{} - - //Set it's metatable - luaL_getmetatable(L, "phys.ghost");//{},{phys.ghost} - lua_setmetatable(L, -2);//{} - - return 1; -} - -//{phys.physbox}:delete() -static int delbghostobject(lua_State* L){//self - //printf("Attempting to delete physbox\n"); - lua_getfield(L,-1,"collider");//self,ud_rigidbody - btGhostObject* r = (btGhostObject*)lua_touserdata(L,-1);//self,ud_rigidbody - delete r->getCollisionShape(); - delete r; - - return 0; -} - -// physbox:setpos({v3 pos}) -static int bghostsetpos(lua_State *L){//self,{v3 pos} - double nx,ny,nz; - popvector3d(L,&nx,&ny,&nz);//self - - lua_getfield(L,-1,"collider");//self,ud_ghost - btGhostObject *ghost = (btGhostObject*)lua_touserdata(L,-1);//self - btTransform bt = ghost->getWorldTransform(); - - btVector3 to = btVector3(nx,ny,nz); - bt.setOrigin(to); - ghost->setWorldTransform(bt); - ghost->activate(); - - lua_pop(L,1);// - return 0; -} - -// {v3 pos} :: physbox:getpos() -static int bghostgetpos(lua_State *L){//self - //printf("Physics box set pos called\n"); - lua_getfield(L,-1,"collider");//self,ud_ghost - btGhostObject* i = (btGhostObject*)lua_touserdata(L,-1);//self,ud_ghost - btTransform bt = i->getWorldTransform(); - btVector3 bv = bt.getOrigin(); - lua_pop(L,2);// - pushvector3d(L,bv.x(),bv.y(),bv.z());//{} - - return 1; -} - -//ghost:getoverlapping() -int bghostoverlapping(lua_State *L){ - lua_getfield(L,-1,"collider");//{ghost} - btGhostObject *ghost = (btGhostObject*)lua_touserdata(L,-1);//{ghost},ud_ghost - lua_pop(L,2);// - lua_newtable(L);//{} - btAlignedObjectArray ob = ghost->getOverlappingPairs(); - printf("Getting %d overlapping object\n",ob.size()); - for(int i = 0; i < ob.size(); i++){ - printf("Looking at object %d\n",i); - btCollisionObject *co = ob[i]; - lua_getglobal(L,"phys");//{},{phys} - lua_getfield(L,-1,"colliders");//{},{phys},{phys.colliders} - lua_pushnumber(L,i+1);//}{},{phys},{phys.colliders},i - lua_pushlightuserdata(L,co);//{},{phys},{phys.colliders},i,ud_co - lua_gettable(L,-3);//{},{phys},{phys.colliders},i,{collider=ud_co} - if(lua_isnil(L,-1)){ - printf("Failed to find object of collider %p\n", (void*)co); - lua_pushstring(L,"Failed to find collider we are overlapping"); - lua_error(L); - } - lua_settable(L,-5);//{i={collider=co}},{phys},{phys.colliders} - lua_pop(L,2);//{i={...}} - } - printf("Finished adding %d overlapping objects to array...\n",(int)lua_objlen(L,-1)); - return 1; -} - -static const luaL_reg bghost_m[] = { - {"getpos", bghostgetpos}, - {"setpos", bghostsetpos}, - {"getoverlapping", bghostoverlapping}, - {"delete", delbghostobject}, - {0, 0}, -}; - -void bghostobject_register(lua_State* L){// - //printf("Registered bphysbox\n"); - - luaL_newmetatable(L, "phys.ghost");//{phys.physbox} - lua_newtable(L);//{phys.physbox},{} - luaL_register(L,NULL,bghost_m);//{phys.physbox},{} - lua_setfield(L,-2,"__index");//{phys.physbox} - - lua_pop(L,1);// - - lua_getglobal(L,"phys");//{} - lua_pushcfunction(L,newghostobject);//{},newghostobject() - lua_setfield(L,-2,"newghostbox");//{} - - lua_pop(L,1); -} +#include +#include +#include +extern "C" { + #include + #include + #include +} +#include +#include "bghostobject.hpp" +#include + +extern btDiscreteDynamicsWorld* World; +extern std::list Objects; +//extern std::list Ghosts; + +/* +static LBPhysNode* checkisbphysbox(lua_State* L, int index){ + void* ud = luaL_checkudata(L,index,"phys.physbox"); + luaL_argcheck(L,ud != NULL, index, "'phys.physbox' expected"); + return (LBPhysNode*) ud; +} +*/ + +/* +static LISceneNode* checkismesh(lua_State* L){ + return checkismesh(L,1); +} +*/ +// ud_btGhostObject :: ({v3 size}, {v3 origin}) +void makeghostobject(lua_State* L){ + double px,py,pz; //position + double sx,sy,sz; //size + + popvector3d(L,&px,&py,&pz);//{v3_size} + //printf("Got position: (%f,%f,%f)\n",px,py,pz); + popvector3d(L,&sx,&sy,&sz);// + + btVector3 vshape = btVector3(sx * 0.5f, sy * 0.5f, sz * 0.5f); + //printf("Got size: (%f,%f,%f)\n",sx,sy,sz); + btVector3 pos = btVector3(px,py,pz); + + // Set the initial position of the object + btTransform transform = btTransform(btQuaternion(0,0,0,1),pos); + //transform.setIdentity(); + //transform.setOrigin(pos); + + // Create the shape + btCollisionShape* shape = new btBoxShape(vshape); + if(!shape){ + //printf("no shape\n"); + } + + // Add mass + btVector3 localinertia = btVector3(0,0,0); + shape->calculateLocalInertia(1, localinertia); + + //cinfo.m_friction = 0; + btGhostObject *ghost = new btGhostObject(); + ghost->setCollisionShape(shape); + ghost->setWorldTransform(transform); + //ghost->setCollisionFlags( + //btCollisionObject::CollisionFlags::CF_NO_CONTACT_RESPONSE | + //btCollisionObject::CollisionFlags::CF_KINEMATIC_OBJECT + //); + World->addCollisionObject(ghost, btBroadphaseProxy::SensorTrigger, btBroadphaseProxy::AllFilter & ~btBroadphaseProxy::SensorTrigger); + + //printf("Added rigid body to world: %p\n",World); + //Objects.push_back(ghost); + + lua_pushlightuserdata(L,ghost);//ud_ghost +} + +// phys.newghostbox(vector3 size, vector3 origin) +int newghostobject(lua_State* L){ + //printf("Createing bphysbox!\n"); + //Create it's lua representation + makeghostobject(L);//ud_btGhostObject + btGhostObject* ghost = (btGhostObject*)lua_touserdata(L,-1); + lua_pop(L,1); + lua_newtable(L);//{} + lua_pushlightuserdata(L,ghost);//ud_btGhostObject + lua_setfield(L,-2,"collider");//{} + + //Set it's metatable + luaL_getmetatable(L, "phys.ghost");//{},{phys.ghost} + lua_setmetatable(L, -2);//{} + + return 1; +} + +//ghost:sweep(shape, v3 start, v3 end) +int bghostconvexsweep(lua_State *L){ + double sx,sy,sz,ex,ey,ez; + popvector3d(L,&ex,&ey,&ez);//self,shape,v3start + popvector3d(L,&sx,&sy,&sz);//self,shape + lua_getfield(L,-1,"shape");//self,shape,ud_shape + btBoxShape *cs = (btBoxShape*)lua_touserdata(L,-1);//self,shape,ud_shape + lua_pop(L,2);//self + lua_getfield(L,-1,"collider"); + btGhostObject* r = (btGhostObject*)lua_touserdata(L,-1);//self,ud_rigidbody + lua_pop(L,2);// + //btCollisionShape *cs = r->getCollisionShape(); + btTransform ft,tt; + ft = btTransform(btQuaternion(0,0,0),btVector3(sx,sy,sz)); + tt = btTransform(btQuaternion(0,0,0),btVector3(ex,ey,ez)); + btCollisionWorld::ClosestConvexResultCallback *cb = new btCollisionWorld::ClosestConvexResultCallback(ft.getOrigin(),tt.getOrigin()); + r->convexSweepTest(cs,ft,tt,*cb,0.f); + btVector3 hw, hn; + hw = cb->m_hitPointWorld; + hn = cb->m_hitNormalWorld; + btCollisionObject *co = cb->m_hitCollisionObject; + + lua_newtable(L);//{} + lua_pushboolean(L,cb->hasHit() ? 1 : 0); + lua_setfield(L,-2,"hit"); + pushvector3d(L,hw.x(),hw.y(),hw.z()); + lua_setfield(L,-2,"pos"); + pushvector3d(L,hn.x(),hn.y(),hn.z()); + lua_setfield(L,-2,"normal"); + lua_getglobal(L,"phys");//{},{phys} + lua_getfield(L,-1,"colliders");//{},{phys},{phys.colliders} + lua_pushlightuserdata(L,co);//{},{phys},{phys.colliders},ud_collisionobject + lua_gettable(L,-2);//{},{phys},{phys.colliders},ud_collisionobject,{rb} or nil + lua_setfield(L,-5,"what");//{},{phys},{phys.colliders},ud_collisionobject + lua_pop(L,3);//{} + + delete cb; + return 1; +} + +//{phys.physbox}:delete() +static int delbghostobject(lua_State* L){//self + //printf("Attempting to delete physbox\n"); + lua_getfield(L,-1,"collider");//self,ud_rigidbody + btGhostObject* r = (btGhostObject*)lua_touserdata(L,-1);//self,ud_rigidbody + delete r->getCollisionShape(); + delete r; + + return 0; +} + +// physbox:setpos({v3 pos}) +static int bghostsetpos(lua_State *L){//self,{v3 pos} + double nx,ny,nz; + popvector3d(L,&nx,&ny,&nz);//self + + lua_getfield(L,-1,"collider");//self,ud_ghost + btGhostObject *ghost = (btGhostObject*)lua_touserdata(L,-1);//self + btTransform bt = ghost->getWorldTransform(); + + btVector3 to = btVector3(nx,ny,nz); + bt.setOrigin(to); + ghost->setWorldTransform(bt); + ghost->activate(); + + lua_pop(L,1);// + return 0; +} + +// {v3 pos} :: physbox:getpos() +static int bghostgetpos(lua_State *L){//self + //printf("Physics box set pos called\n"); + lua_getfield(L,-1,"collider");//self,ud_ghost + btGhostObject* i = (btGhostObject*)lua_touserdata(L,-1);//self,ud_ghost + btTransform bt = i->getWorldTransform(); + btVector3 bv = bt.getOrigin(); + lua_pop(L,2);// + pushvector3d(L,bv.x(),bv.y(),bv.z());//{} + + return 1; +} + +//ghost:getoverlapping() +int bghostoverlapping(lua_State *L){ + lua_getfield(L,-1,"collider");//{ghost} + btGhostObject *ghost = (btGhostObject*)lua_touserdata(L,-1);//{ghost},ud_ghost + lua_pop(L,2);// + lua_newtable(L);//{} + btAlignedObjectArray ob = ghost->getOverlappingPairs(); + //printf("Getting %d overlapping object\n",ob.size()); + for(int i = 0; i < ob.size(); i++){ + //printf("Looking at object %d\n",i); + btCollisionObject *co = ob[i]; + lua_getglobal(L,"phys");//{},{phys} + lua_getfield(L,-1,"colliders");//{},{phys},{phys.colliders} + lua_pushnumber(L,i+1);//}{},{phys},{phys.colliders},i + lua_pushlightuserdata(L,co);//{},{phys},{phys.colliders},i,ud_co + lua_gettable(L,-3);//{},{phys},{phys.colliders},i,{collider=ud_co} + if(lua_isnil(L,-1)){ + printf("Failed to find object of collider %p\n", (void*)co); + lua_pushstring(L,"Failed to find collider we are overlapping"); + lua_error(L); + } + lua_settable(L,-5);//{i={collider=co}},{phys},{phys.colliders} + lua_pop(L,2);//{i={...}} + } + //printf("Finished adding %d overlapping objects to array...\n",(int)lua_objlen(L,-1)); + return 1; +} + +int bghostnumoverlapping(lua_State *L){ + lua_getfield(L,-1,"collider");//{ghost} + btGhostObject *ghost = (btGhostObject*)lua_touserdata(L,-1);//{ghost},ud_ghost + lua_pop(L,2);// + btAlignedObjectArray ob = ghost->getOverlappingPairs(); + lua_pushnumber(L,ob.size()); + return 1; +} + +static const luaL_reg bghost_m[] = { + {"getpos", bghostgetpos}, + {"setpos", bghostsetpos}, + {"getoverlapping", bghostoverlapping}, + {"getnumoverlapping", bghostnumoverlapping}, + {"shapecast", bghostconvexsweep}, + {"delete", delbghostobject}, + {0, 0}, +}; + +void bghostobject_register(lua_State* L){// + //printf("Registered bphysbox\n"); + + luaL_newmetatable(L, "phys.ghost");//{phys.physbox} + lua_newtable(L);//{phys.physbox},{} + luaL_register(L,NULL,bghost_m);//{phys.physbox},{} + lua_setfield(L,-2,"__index");//{phys.physbox} + + lua_pop(L,1);// + + lua_getglobal(L,"phys");//{} + lua_pushcfunction(L,newghostobject);//{},newghostobject() + lua_setfield(L,-2,"newghostbox");//{} + + lua_pop(L,1); +} diff --git a/src/shared/lua_api/phys/bghostobject.hpp b/src/shared/lua_api/phys/bghostobject.hpp index 5c96f7e..547aacb 100644 --- a/src/shared/lua_api/phys/bghostobject.hpp +++ b/src/shared/lua_api/phys/bghostobject.hpp @@ -1,13 +1,13 @@ - -#include -#include -extern "C" { - #include - #include - #include -} -#include -#include - -void bghostobject_register(lua_State* L); -void makeghostobject(lua_State* L); + +#include +#include +extern "C" { + #include + #include + #include +} +#include +#include + +void bghostobject_register(lua_State* L); +void makeghostobject(lua_State* L); diff --git a/src/shared/lua_api/phys/bhingeconstraint.cpp b/src/shared/lua_api/phys/bhingeconstraint.cpp index a8c6567..5045cb7 100644 --- a/src/shared/lua_api/phys/bhingeconstraint.cpp +++ b/src/shared/lua_api/phys/bhingeconstraint.cpp @@ -1,61 +1,61 @@ - -#include -#include -#include -extern "C" { - #include - #include - #include -} -#include -#include -#include - -extern btDiscreteDynamicsWorld* World; -extern std::list Objects; - -//newhingeconstraint(phys1,v3 axis, refrencephys1) -int newbhingeconstraint(lua_State *L){ - bool phys1 = lua_toboolean(L,-1) == 1; - lua_pop(L,1); - - double x,y,z; - popvector3d(L,&x,&y,&z); - - lua_getfield(L,-1,"rigidbody"); - btRigidBody *p1 = (btRigidBody*)lua_touserdata(L,-1); - btTransform frame = p1->getCenterOfMassTransform(); - frame.setRotation(btQuaternion(x,y,z,0)); - lua_pop(L,2); - - btHingeConstraint(*p1,frame,phys1); - printf("Done makeing new hinge constraint\n"); - - return 0; -} - -static const luaL_reg hingeconstraint_m[] = { -// {"delete", delbphysbox},//client side delete needs to delete the visual representation - {0, 0}, -}; - -void bhingeconstraint_register(lua_State* L){ - lua_getglobal(L,"phys");//{} - lua_pushcfunction(L,newbhingeconstraint);//{},newhingeconstraint() - lua_setfield(L,-2,"newhingeconstraint");//{} - - lua_pop(L,1);// - - luaL_newmetatable(L,"phys.hingeconstraint"); - lua_newtable(L);//phys.hingeconstraint,{} - luaL_register(L,NULL,hingeconstraint_m); - //luaL_register(L,NULL,cbphysbox_m);//phys.hingeconstraint,{} - lua_setfield(L,-2,"__index");//phys.physbox - - lua_pop(L,1); - - //printf("When registering physbox, new() is %p\n",newcbphysbox); - //printf("setpos is %p\n",cbphyssetpos); - - lua_pop(L,1); -} + +#include +#include +#include +extern "C" { + #include + #include + #include +} +#include +#include +#include + +extern btDiscreteDynamicsWorld* World; +extern std::list Objects; + +//newhingeconstraint(phys1,v3 axis, refrencephys1) +int newbhingeconstraint(lua_State *L){ + bool phys1 = lua_toboolean(L,-1) == 1; + lua_pop(L,1); + + double x,y,z; + popvector3d(L,&x,&y,&z); + + lua_getfield(L,-1,"rigidbody"); + btRigidBody *p1 = (btRigidBody*)lua_touserdata(L,-1); + btTransform frame = p1->getCenterOfMassTransform(); + frame.setRotation(btQuaternion(x,y,z,0)); + lua_pop(L,2); + + btHingeConstraint(*p1,frame,phys1); + printf("Done makeing new hinge constraint\n"); + + return 0; +} + +static const luaL_reg hingeconstraint_m[] = { +// {"delete", delbphysbox},//client side delete needs to delete the visual representation + {0, 0}, +}; + +void bhingeconstraint_register(lua_State* L){ + lua_getglobal(L,"phys");//{} + lua_pushcfunction(L,newbhingeconstraint);//{},newhingeconstraint() + lua_setfield(L,-2,"newhingeconstraint");//{} + + lua_pop(L,1);// + + luaL_newmetatable(L,"phys.hingeconstraint"); + lua_newtable(L);//phys.hingeconstraint,{} + luaL_register(L,NULL,hingeconstraint_m); + //luaL_register(L,NULL,cbphysbox_m);//phys.hingeconstraint,{} + lua_setfield(L,-2,"__index");//phys.physbox + + lua_pop(L,1); + + //printf("When registering physbox, new() is %p\n",newcbphysbox); + //printf("setpos is %p\n",cbphyssetpos); + + lua_pop(L,1); +} diff --git a/src/shared/lua_api/phys/bhingeconstraint.hpp b/src/shared/lua_api/phys/bhingeconstraint.hpp index 4e8d72c..88b33cb 100644 --- a/src/shared/lua_api/phys/bhingeconstraint.hpp +++ b/src/shared/lua_api/phys/bhingeconstraint.hpp @@ -1,2 +1,2 @@ - -void bhingeconstraint_register(lua_State* L); + +void bhingeconstraint_register(lua_State* L); diff --git a/src/shared/lua_api/phys/bphysbox.cpp b/src/shared/lua_api/phys/bphysbox.cpp index 4564c6e..569f3f9 100644 --- a/src/shared/lua_api/phys/bphysbox.cpp +++ b/src/shared/lua_api/phys/bphysbox.cpp @@ -9,6 +9,7 @@ extern "C" { } #include #include "bphysbox.hpp" +#include "bphysgeneric.hpp" #include extern btDiscreteDynamicsWorld* World; @@ -40,7 +41,7 @@ void makenewbphysbox(lua_State* L){ //printf("Got position: (%f,%f,%f)\n",px,py,pz); popvector3d(L,&sx,&sy,&sz);// - btVector3 vshape = btVector3(sx * 0.5f, sy * 0.5f, sz * 0.5f); + btVector3 vshape = btVector3(sx, sy, sz); //printf("Got size: (%f,%f,%f)\n",sx,sy,sz); btVector3 pos = btVector3(px,py,pz); @@ -168,6 +169,7 @@ void bphysbox_register(lua_State* L){// luaL_newmetatable(L, "phys.physbox");//{phys.physbox} lua_newtable(L);//{phys.physbox},{} luaL_register(L,NULL,bphysbox_m);//{phys.physbox},{} + luaL_register(L,NULL,brigidbody_m); lua_setfield(L,-2,"__index");//{phys.physbox} lua_pop(L,1);// diff --git a/src/shared/lua_api/phys/bphysmodel.cpp b/src/shared/lua_api/phys/bphysmodel.cpp index d56adb5..0c8e3bf 100644 --- a/src/shared/lua_api/phys/bphysmodel.cpp +++ b/src/shared/lua_api/phys/bphysmodel.cpp @@ -81,6 +81,7 @@ void makebphysmodel(lua_State *L){ float v2 = vs[1]; float v3 = vs[2]; vertexes[i] = btVector3(v1,v2,v3); + printf("Adding vertex %lld at (%f,%f,%f)\n",i,v1,v2,v3); } //printf("Finished finding or adding vertexes\n"); for(size_t i = 0; i < attrib.num_faces - 1; i+= 3){ //0 - y to num_faces - 1 @@ -92,13 +93,15 @@ void makebphysmodel(lua_State *L){ v1 = vertexes[i1.v_idx]; v2 = vertexes[i2.v_idx]; v3 = vertexes[i3.v_idx]; - trimesh->addTriangle(vertexes[i1.v_idx],vertexes[i2.v_idx],vertexes[i3.v_idx],true);//Some triangles are "the wrong way round", + trimesh->addTriangle(vertexes[i1.v_idx],vertexes[i2.v_idx],vertexes[i3.v_idx],false);//Some triangles are "the wrong way round", + printf("Adding triangle:(%d,%d,%d)\n",i1.v_idx,i2.v_idx,i3.v_idx); //trimesh->addTriangle(vertexes[i3.v_idx],vertexes[i2.v_idx],vertexes[i1.v_idx],true);//double-side all triangles } //printf("Finished adding triangle indicies\n"); //printf("Done building trimesh\n"); - btGImpactShapeInterface *shape = new btGImpactMeshShape(trimesh); - shape->updateBound(); + //btGImpactShapeInterface *shape = new btGImpactMeshShape(trimesh); + btConvexTriangleMeshShape *shape = new btConvexTriangleMeshShape(trimesh); + //shape->updateBound(); //btCollisionShape *shape = new btBvhTriangleMeshShape(trimesh,true); btTransform tr; tr.setIdentity(); diff --git a/src/shared/lua_api/phys/bshape.cpp b/src/shared/lua_api/phys/bshape.cpp index 5533b42..f7d73d3 100644 --- a/src/shared/lua_api/phys/bshape.cpp +++ b/src/shared/lua_api/phys/bshape.cpp @@ -1,52 +1,52 @@ -extern "C" { - #include - #include - #include -} -#include -#include -#include - -extern btDiscreteDynamicsWorld* World; - -//phys.newboxshape({ax,ay,az}) -static int newboxshape(lua_State* L){ - double ax,ay,az; - popvector3d(L,&ax,&ay,&az); - ax *= 0.5; - ay *= 0.5; - az *= 0.5; - btBoxShape *bs = new btBoxShape(btVector3(ax,ay,az)); - printf("Created shape: %p\n",(void*)bs); - lua_newtable(L);//{} - lua_pushlightuserdata(L,bs);//{},ud_bs - lua_setfield(L,-2,"shape");//{} - luaL_getmetatable(L,"phys.shape");//{},{m_shape} - lua_setmetatable(L,-2);//{} - - return 1; -} - -static const luaL_reg bshape_f[] = { - {"newboxshape", newboxshape}, - {0,0}, -}; - -static const luaL_reg bshape_m[] = { - {0,0}, -}; - -int bshape_register(lua_State* L){ - - luaL_newmetatable(L, "phys.shape");//{m_physshape} - lua_newtable(L);//{m_physshape},{} - luaL_register(L,NULL,bshape_m); - lua_setfield(L,-2,"__index");//{m_physshape} - lua_pop(L,1);// - - lua_getglobal(L,"phys");//{} - luaL_register(L,NULL,bshape_f);//{} - lua_pop(L,1);// - - return 0; -} +extern "C" { + #include + #include + #include +} +#include +#include +#include + +extern btDiscreteDynamicsWorld* World; + +//phys.newboxshape({ax,ay,az}) +static int newboxshape(lua_State* L){ + double ax,ay,az; + popvector3d(L,&ax,&ay,&az); + ax *= 0.5; + ay *= 0.5; + az *= 0.5; + btBoxShape *bs = new btBoxShape(btVector3(ax,ay,az)); + printf("Created shape: %p\n",(void*)bs); + lua_newtable(L);//{} + lua_pushlightuserdata(L,bs);//{},ud_bs + lua_setfield(L,-2,"shape");//{} + luaL_getmetatable(L,"phys.shape");//{},{m_shape} + lua_setmetatable(L,-2);//{} + + return 1; +} + +static const luaL_reg bshape_f[] = { + {"newboxshape", newboxshape}, + {0,0}, +}; + +static const luaL_reg bshape_m[] = { + {0,0}, +}; + +int bshape_register(lua_State* L){ + + luaL_newmetatable(L, "phys.shape");//{m_physshape} + lua_newtable(L);//{m_physshape},{} + luaL_register(L,NULL,bshape_m); + lua_setfield(L,-2,"__index");//{m_physshape} + lua_pop(L,1);// + + lua_getglobal(L,"phys");//{} + luaL_register(L,NULL,bshape_f);//{} + lua_pop(L,1);// + + return 0; +} diff --git a/src/shared/lua_api/phys/bshape.hpp b/src/shared/lua_api/phys/bshape.hpp index ef3c48a..633e7a4 100644 --- a/src/shared/lua_api/phys/bshape.hpp +++ b/src/shared/lua_api/phys/bshape.hpp @@ -1,11 +1,11 @@ -#ifndef _BSHAPE_HPP_ -#include -#include -extern "C" { - #include - #include - #include -} - -int bshape_register(lua_State* L); -#endif +#ifndef _BSHAPE_HPP_ +#include +#include +extern "C" { + #include + #include + #include +} + +int bshape_register(lua_State* L); +#endif diff --git a/src/shared/lua_api/phys/btaction.cpp b/src/shared/lua_api/phys/btaction.cpp index afd2371..4f6a184 100644 --- a/src/shared/lua_api/phys/btaction.cpp +++ b/src/shared/lua_api/phys/btaction.cpp @@ -1,62 +1,63 @@ -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; -} +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,-5);//{},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; +} diff --git a/src/shared/lua_api/phys/btaction.hpp b/src/shared/lua_api/phys/btaction.hpp index e295b77..9593fda 100644 --- a/src/shared/lua_api/phys/btaction.hpp +++ b/src/shared/lua_api/phys/btaction.hpp @@ -1,11 +1,11 @@ -#ifndef _BTACTION_HPP_ -#include -#include -extern "C" { - #include - #include - #include -} -int baction_register(lua_State* L); -void makeaction(lua_State *L); -#endif +#ifndef _BTACTION_HPP_ +#include +#include +extern "C" { + #include + #include + #include +} +int baction_register(lua_State* L); +void makeaction(lua_State *L); +#endif diff --git a/src/shared/util/tinyobj.cpp b/src/shared/util/tinyobj.cpp index a5dfe73..ffb5db8 100644 --- a/src/shared/util/tinyobj.cpp +++ b/src/shared/util/tinyobj.cpp @@ -1,3 +1,3 @@ -/* Includes the tinyobjloader library */ -#define TINYOBJ_LOADER_C_IMPLEMENTATION -#include "tinyobj.hpp" +/* Includes the tinyobjloader library */ +#define TINYOBJ_LOADER_C_IMPLEMENTATION +#include "tinyobj.hpp" diff --git a/src/shared/util/tinyobj.hpp b/src/shared/util/tinyobj.hpp index 6e4cc74..8db7fea 100644 --- a/src/shared/util/tinyobj.hpp +++ b/src/shared/util/tinyobj.hpp @@ -1,2 +1,2 @@ -/* Includes the tinyobjloader library */ -#include +/* Includes the tinyobjloader library */ +#include -- cgit v1.2.3-70-g09d2