diff options
| author | Alexander Pickering <alexandermpickering@gmail.com> | 2017-12-26 00:57:52 -0500 |
|---|---|---|
| committer | Alexander Pickering <alexandermpickering@gmail.com> | 2017-12-26 00:57:52 -0500 |
| commit | 35b7c646fd7f80b64c1ef49b6d81f9df9bc1b940 (patch) | |
| tree | d345f620b51ae1ad1d7923e572a6b07ed8731ee5 /src/client/lua_api | |
| parent | cc12503339004bae2f945e7f7339fc845b2a194f (diff) | |
| download | brokengine-35b7c646fd7f80b64c1ef49b6d81f9df9bc1b940.tar.gz brokengine-35b7c646fd7f80b64c1ef49b6d81f9df9bc1b940.tar.bz2 brokengine-35b7c646fd7f80b64c1ef49b6d81f9df9bc1b940.zip | |
Major update
Diffstat (limited to 'src/client/lua_api')
| -rw-r--r-- | src/client/lua_api/gui/iguicheckbox.cpp | 55 | ||||
| -rw-r--r-- | src/client/lua_api/gui/iguicheckbox.hpp | 10 | ||||
| -rw-r--r-- | src/client/lua_api/gui/iguiwindow.cpp | 133 | ||||
| -rw-r--r-- | src/client/lua_api/guiparts.hpp | 1 | ||||
| -rw-r--r-- | src/client/lua_api/load_gui.cpp | 6 | ||||
| -rw-r--r-- | src/client/lua_api/load_scene.cpp | 16 | ||||
| -rw-r--r-- | src/client/lua_api/phys/bphysbox.cpp | 49 | ||||
| -rw-r--r-- | src/client/lua_api/phys/cbphysbox.cpp | 93 | ||||
| -rw-r--r-- | src/client/lua_api/scene/icamera.cpp | 76 | ||||
| -rw-r--r-- | src/client/lua_api/scene/icamera.hpp | 2 | ||||
| -rw-r--r-- | src/client/lua_api/scene/icube.cpp | 68 | ||||
| -rw-r--r-- | src/client/lua_api/scene/icube.hpp | 11 | ||||
| -rw-r--r-- | src/client/lua_api/scene/igeneric.cpp | 80 | ||||
| -rw-r--r-- | src/client/lua_api/scene/igeneric.hpp | 3 | ||||
| -rw-r--r-- | src/client/lua_api/scene/ilight.cpp | 96 | ||||
| -rw-r--r-- | src/client/lua_api/scene/ilight.hpp | 2 | ||||
| -rw-r--r-- | src/client/lua_api/scene/imesh.cpp | 162 | ||||
| -rw-r--r-- | src/client/lua_api/scene/imesh.hpp | 5 |
18 files changed, 502 insertions, 366 deletions
diff --git a/src/client/lua_api/gui/iguicheckbox.cpp b/src/client/lua_api/gui/iguicheckbox.cpp new file mode 100644 index 0000000..c6e5955 --- /dev/null +++ b/src/client/lua_api/gui/iguicheckbox.cpp @@ -0,0 +1,55 @@ +/*This file defines some things that all igui stuff can do*/ +extern "C" { + #include <lua.h> + #include <lauxlib.h> + #include <lualib.h> +} +#include <irrlicht.h> +#include "../guiparts.hpp" +#include "iguielement.hpp" +#include "../../../shared/lua_api/common.h" + +using namespace irr; +using namespace core; + +extern IrrlichtDevice* device; + +//new({startx,starty},{endx,endy},"checkbox_name",parent) +int newiguicheckbox(lua_State* L){ + int parentid = lua_tointeger(L,-1); + lua_pop(L,1);//{startx,starty},{endx,endy},"checkbox_name" + const char* text = lua_tostring(L,-1); + int tlen = strlen(text); + lua_pop(L,1);//{startx,starty},{endx,endy} + long startx,starty,endx,endy; + popvector2i(L,&endx,&endy);//{startx,starty} + popvector2i(L,&startx, &starty);// + irr::gui::IGUICheckBox* cb = device->getGUIEnvironment()->addCheckBox(false,core::rect<int>(startx,starty,endx,endy),0,-1,stringw(text).c_str()); + lua_pushlightuserdata(L,cb);//*checkbox + luaL_getmetatable(L,"gui.checkbox");//*checkbox,m{gui.checkbox} + lua_setmetatable(L,-2);//*checkbox + + return 1; +} + +static const luaL_reg iguicheckbox_m[] = { + {"move", moveiguielement}, + {"setText", setiguitext}, + {"remove", guisethandeler}, + {0,0}, +}; + +int iguicheckbox_register(lua_State* L){// + + luaL_newmetatable(L,"gui.checkbox");//m{gui.checkbox} + luaL_register(L,NULL,iguicheckbox_m); + lua_pop(L,1);// + + lua_getglobal(L,"gui");//{gui} + lua_pushstring(L,"newcheckbox");//{gui},new(),"newcheckbox" + lua_pushcfunction(L,newiguicheckbox);//{gui},new() + printf("I have registered the newcheckbox function\n"); + lua_settable(L,-3);//{gui} + lua_pop(L,1); + return 0; +} diff --git a/src/client/lua_api/gui/iguicheckbox.hpp b/src/client/lua_api/gui/iguicheckbox.hpp new file mode 100644 index 0000000..ee2f2bc --- /dev/null +++ b/src/client/lua_api/gui/iguicheckbox.hpp @@ -0,0 +1,10 @@ +#include <stdio.h> +#include <stdlib.h> +extern "C" { + #include <lua.h> + #include <lauxlib.h> + #include <lualib.h> +} +#include <irrlicht.h> + +int iguicheckbox_register(lua_State* L); diff --git a/src/client/lua_api/gui/iguiwindow.cpp b/src/client/lua_api/gui/iguiwindow.cpp index 34b6cfa..038c9f7 100644 --- a/src/client/lua_api/gui/iguiwindow.cpp +++ b/src/client/lua_api/gui/iguiwindow.cpp @@ -15,6 +15,7 @@ extern "C" { #include "iguiwindow.hpp" #include "iguiutil.hpp" #include "../../callbackhandeler.hpp" +#include "../../../shared/lua_api/common.h" using namespace irr; using namespace gui; @@ -58,110 +59,84 @@ static bool iguiwindowevent(irr::SEvent e){ return false; } +//new({posx,posy},{width,height}[,"title"][,parent]) static int newiguiwindow(lua_State* L){ - printf("Createing label!\n"); - int nargs = lua_gettop(L); - //The position of the text + printf("Creating window\n"); - //Frame position - int x,y; - lua_popvector2i(L,1,&x,&y); - - printf("got xy\n"); + int parentid = lua_tointeger(L,-1); + lua_pop(L,1); + const char* title_c = lua_tostring(L,-1); + const wchar_t* title_w = irr::core::stringw(title_c).c_str(); + lua_pop(L,1); - //Frame size - int w,h; - lua_popvector2i(L,2,&w,&h); + //Frame position + long x,y,w,h; + popvector2i(L,&x,&y); + popvector2i(L,&w,&h); printf("I want to make a frame at (%d,%d) size (%d,%d)\n",x,y,w,h); - - // int startx = luaL_optint(L,1,0); - // int starty = luaL_optint(L,2,0); - // int endx = luaL_optint(L,3,startx+100); - // int endy = luaL_optint(L,4,starty+100); - - //Label - wchar_t* label; - const char* labelopt = luaL_optstring(L,3,"Label"); - int bls = strlen(labelopt); - label = (wchar_t*)calloc(sizeof(wchar_t),(bls)); - mbstowcs(label,labelopt,bls); - printf("Got the string option\n"); - // - //If the element has a parrent - int parent = luaL_optint(L,4,0); - // - // - // //Create the button + + //Create the window IGUIEnvironment* env = guidevice->getGUIEnvironment(); IGUIWindow* wi = env->addWindow( core::rect<s32>(x,y,x+w,y+h), false, - label, - guielements[parent], + title_w, + guielements[parentid], -1 ); - // /Create the label - // IGUIStaticText* llabel = (IGUIStaticText*) env->addStaticText(label,core::rect<s32>(startx,starty,endx,endy),false,false, guielements[parent], gui_elenum++, false); - // printf("Created the button\n"); - // - // /Register it's callback + + lua_newtable(L);//{} + lua_pushlightuserdata(L,wi); + lua_setfield(L,-2,"element"); + + luaL_getmetatable(L,"gui.window"); + lua_setmetatable(L,-2); + registerguicallback(wi,EGET_ELEMENT_CLOSED,iguiwindowevent); - // - //Create it's lua representation - LIGUIElement* lwindow = (LIGUIElement*)lua_newuserdata(L, sizeof(LIGUIElement)); - int tref = luaL_ref(L,LUA_REGISTRYINDEX); - iguielements[wi] = tref; - lua_rawgeti(L,LUA_REGISTRYINDEX,tref);//Put it back on the stack since luaL_ref pops the object. - // - //Set it's metatable - luaL_getmetatable(L, "gui.iguiwindow"); - lua_setmetatable(L, -2); - // - //Create the struct - lwindow->e = wi; - lwindow->funcmap = hashmap_new(); - lwindow->type = "iguiwindow"; - // - // /Free up anything made in this function - free(label); - // - // /Put it on top and return it - lua_rawgeti(L,LUA_REGISTRYINDEX,tref); - return 1; + return 1; } static const luaL_reg iguiwindow_f[] = { - {"new", newiguiwindow}, - {"gethandeler", guigethandeler}, - {"sethandeler", guisethandeler}, - {0,0}, + {"new", newiguiwindow}, + {0,0}, }; static const luaL_reg iguiwindow_m[] = { - {"move", moveiguielement}, - {"settext", setiguitext}, - {"remove", removeiguielement}, - {0, 0}, + {"move", moveiguielement}, + {"settext", setiguitext}, + {"remove", removeiguielement}, + {0, 0}, }; int iguiwindow_register(lua_State* L, IrrlichtDevice* d){ + printf("Loading window\n"); + luaL_newmetatable(L,"gui.window");//m{gui.checkbox} + luaL_register(L,NULL,iguiwindow_m); + lua_pop(L,1);// + + lua_getglobal(L,"gui"); + lua_pushstring(L,"newwindow"); + lua_pushcfunction(L,newiguiwindow); + lua_settable(L,-3); + lua_pop(L,1); - luaL_newmetatable(L, "gui.iguiwindow"); + return 0; + //luaL_newmetatable(L, "gui.iguiwindow"); - luaL_register(L,"iguiwindow",iguiwindow_f); + //luaL_register(L,"iguiwindow",iguiwindow_f); - lua_pushstring(L,"__index"); - lua_pushstring(L,"gethandeler"); - lua_gettable(L,-3); - lua_settable(L,-4); + //lua_pushstring(L,"__index"); + //lua_pushstring(L,"gethandeler"); + //lua_gettable(L,-3); + //lua_settable(L,-4); - lua_pushstring(L,"__newindex"); - lua_pushstring(L,"sethandeler"); - lua_gettable(L,-3); - lua_settable(L,-4); + //lua_pushstring(L,"__newindex"); + //lua_pushstring(L,"sethandeler"); + //lua_gettable(L,-3); + //lua_settable(L,-4); - luaL_register(L, NULL, iguiwindow_m); + //luaL_register(L, NULL, iguiwindow_m); - return 1; + //return 1; } diff --git a/src/client/lua_api/guiparts.hpp b/src/client/lua_api/guiparts.hpp index fba3862..ea369b7 100644 --- a/src/client/lua_api/guiparts.hpp +++ b/src/client/lua_api/guiparts.hpp @@ -20,7 +20,6 @@ typedef struct LIGUIElement { const char* type; } LIGUIElement; - extern lua_State* tL; extern irr::IrrlichtDevice* guidevice; extern long gui_elenum; diff --git a/src/client/lua_api/load_gui.cpp b/src/client/lua_api/load_gui.cpp index a282d34..f8e8dc0 100644 --- a/src/client/lua_api/load_gui.cpp +++ b/src/client/lua_api/load_gui.cpp @@ -14,6 +14,7 @@ extern "C" { #include "gui/iguigeneric.hpp" #include "gui/iguiwindow.hpp" #include "gui/iguiskin.hpp" +#include "gui/iguicheckbox.hpp" #include "../callbackhandeler.hpp" #include "guiparts.hpp" @@ -42,7 +43,6 @@ void load_guifuncs(lua_State* L){ iguibutton_register(L,device); iguilabel_register(L,device); iguigeneric_register(L,device); - iguiwindow_register(L,device); lua_pop(L, 1); //Various enums @@ -50,7 +50,9 @@ void load_guifuncs(lua_State* L){ lua_newtable(L); lua_setglobal(L,"gui"); - + iguicheckbox_register(L); + iguiwindow_register(L,device); + lua_pushcfunction(L,screenwidth); lua_setglobal(L,"scrw"); diff --git a/src/client/lua_api/load_scene.cpp b/src/client/lua_api/load_scene.cpp index 6d02a2d..342bc9a 100644 --- a/src/client/lua_api/load_scene.cpp +++ b/src/client/lua_api/load_scene.cpp @@ -21,13 +21,17 @@ extern IrrlichtDevice* device; void load_scenefuncs(lua_State* L){ lua_newtable(L);//{} lua_setglobal(L,"scene");// - icamera_register(L,device); - - imesh_register(L,device); - ilight_register(L,device); - lua_newtable(L); - lua_setglobal(L,"phys"); + + //scene things + icamera_register(L); + imesh_register(L); + ilight_register(L); + + lua_newtable(L);//{} + lua_setglobal(L,"phys");// + //phys things cbphysbox_register(L); + bphysmodel_register(L,device); //lua_pop(L, 1); diff --git a/src/client/lua_api/phys/bphysbox.cpp b/src/client/lua_api/phys/bphysbox.cpp deleted file mode 100644 index c15646f..0000000 --- a/src/client/lua_api/phys/bphysbox.cpp +++ /dev/null @@ -1,49 +0,0 @@ - -#include <stdio.h> -#include <stdlib.h> -#include <list> -extern "C" { - #include <lua.h> - #include <lauxlib.h> - #include <lualib.h> -} - -#include <btBulletDynamicsCommon.h> -#include <irrlicht.h> -#include "bphysbox.hpp" -#include "../../../shared/lua_api/phys/bphysbox.hpp" - -using namespace irr; -using namespace scene; -using namespace core; -using namespace video; - -extern IrrlichtDevice* device; - -extern btDiscreteDynamicsWorld* World; -extern std::list<btRigidBody*> Objects; -/* -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); -} -*/ - -//phys.newphysbox({vector3 size},{vector3 origin},mass) -/* -static int newcbphysbox(lua_State* L){// - newbphysbox(L);//{phys.physbox} - LBPhysNode -} -*/ - -void cbphysbox_register(lua_State* L){ - bphysbox_register(L); -} diff --git a/src/client/lua_api/phys/cbphysbox.cpp b/src/client/lua_api/phys/cbphysbox.cpp index 0da9939..029e6ab 100644 --- a/src/client/lua_api/phys/cbphysbox.cpp +++ b/src/client/lua_api/phys/cbphysbox.cpp @@ -11,6 +11,7 @@ extern "C" { #include <btBulletDynamicsCommon.h> #include <irrlicht.h> #include "cbphysbox.hpp" +#include "../scene/imesh.hpp" #include "../../../shared/lua_api/phys/bphysbox.hpp" using namespace irr; @@ -22,6 +23,7 @@ extern IrrlichtDevice* device; extern btDiscreteDynamicsWorld* World; extern std::list<btRigidBody*> Objects; + /* static LBPhysNode* checkisbphysbox(lua_State* L, int index){ void* ud = luaL_checkudata(L,index,"phys.physbox"); @@ -37,13 +39,94 @@ static LISceneNode* checkismesh(lua_State* L){ */ //phys.newphysbox({vector3 size},{vector3 origin},mass) -/* static int newcbphysbox(lua_State* L){// - newbphysbox(L);//{phys.physbox} - LBPhysNode + printf("Createing new cbphysbox\n"); + double sx,sy,sz,x,y,z,mass; + //Get the data + mass = lua_tonumber(L,-1);//{v3 size}, {v3 origin}, mass + lua_pop(L,1);//{v3 size}, {v3 origin} + 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} + lua_pushnumber(L,mass);//{v3 size}, {v3 origin}, mass + makenewbphysbox(L);//ud_btRigidbody + btRigidBody* r = (btRigidBody*)lua_touserdata(L,-1);//ud_btRigidbody + 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); + + lua_newtable(L);//{} + lua_pushlightuserdata(L,r);//{},ud_rigidbody + lua_setfield(L,-2,"rigidbody");//{} + lua_pushlightuserdata(L,n);//{},ud_iscenenode + lua_setfield(L,-2,"node");//{} + + luaL_getmetatable(L,"phys.physbox");//{},{phys.physbox} + lua_setmetatable(L,-2);//{} + + return 1; } -*/ + +//bphysbox:setpos({v3 pos}) +int cbphyssetpos(lua_State* L){//{rigidbody=ud_btRigidbody,node=ud_iscenenode},{v3 pos} + printf("calling cbphysbox setpos\n"); + double x,y,z; + popvector3d(L,&x,&y,&z);//{rigidbody=ud_btRigidbody,node=ud_iscenenode} + + printf("Getting rigidbody\n"); + lua_getfield(L,-1,"rigidbody");//{rigidbody=ud_btRigidbody,node=ud_iscenenode},ud_btRigidbody + btRigidBody* r = (btRigidBody*)lua_touserdata(L,-1);//{rigidbody=ud_btRigidbody,node=ud_iscenenode},ud_btRigidbody + printf("Got rigidbody, it was %p\n",r); + lua_pop(L,1);//{rigidbody=ud_btRigidbody,node=ud_iscenenode} + lua_getfield(L,-1,"node");//{rigidbody=ud_btRigidbody,node=ud_iscenenode},ud_iscenenode + ISceneNode* i = (ISceneNode*)lua_touserdata(L,-1);//{btRigidBody=ud_btRigidbody,node=ud_iscenenode},ud_iscenenode + printf("Got node, it was %p\n",i); + lua_pop(L,2);// + + btTransform bt; + btMotionState* ms = r->getMotionState(); + ms->getWorldTransform(bt); + bt.setOrigin(btVector3(x,y,z)); + ms->setWorldTransform(bt); + r->activate(); + + i->setPosition(vector3df(x,y,z)); + i->updateAbsolutePosition(); + + return 0; + +} + +static const luaL_reg cbphysbox_m[] = { + {"setcpos", cbphyssetpos},//overload +// {"delete", delbphysbox},//client side delete needs to delete the visual representation + {0, 0}, +}; void cbphysbox_register(lua_State* L){ - bphysbox_register(L); + bphysbox_register(L);// + lua_getglobal(L,"phys");//{} + lua_pushcfunction(L,newcbphysbox);//{},newcbphysbox() + lua_setfield(L,-2,"newcphysbox");//{} + + lua_pop(L,1);// + + luaL_getmetatable(L,"phys.physbox");//phys.physbox + lua_newtable(L);//phys.physbox,{} + luaL_register(L,NULL,cbphysbox_m);//phys.physbox,{} + 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/client/lua_api/scene/icamera.cpp b/src/client/lua_api/scene/icamera.cpp index 14f9283..3c5e2b0 100644 --- a/src/client/lua_api/scene/icamera.cpp +++ b/src/client/lua_api/scene/icamera.cpp @@ -21,7 +21,6 @@ using namespace core; extern IrrlichtDevice* device; - static LISceneNode* checkiscenecamera(lua_State* L, int index){ void* ud = luaL_checkudata(L,index,"scene.iscenecamera"); luaL_argcheck(L,ud != NULL, index, "'scene.iscenecamera' expected"); @@ -46,49 +45,51 @@ static LISceneNode* checkismayacamera(lua_State* L){ */ static int newiscenemayacamera(lua_State* L){ - printf("createing maya camera!\n"); - ISceneManager* smgr = device->getSceneManager(); - ICameraSceneNode* cam = smgr->addCameraSceneNodeMaya(); - printf("cam is %p",cam); - LISceneNode* lcam = (LISceneNode*)lua_newuserdata(L, sizeof(LISceneNode)); - int tref = luaL_ref(L,LUA_REGISTRYINDEX); - - //Set it's metatable - luaL_getmetatable(L, "scene.iscenemayacamera"); - lua_setmetatable(L, -2); - - //Create the struct - lcam->n = cam; - lcam->funcmap = hashmap_new(); - lcam->type = "iscenemayacamera"; - - //Free up anything made in this function - //free(label); - - //Put it on top and return it - lua_rawgeti(L,LUA_REGISTRYINDEX,tref); - return 1; + printf("createing maya camera!\n"); + ISceneManager* smgr = device->getSceneManager(); + ICameraSceneNode* cam = smgr->addCameraSceneNodeMaya(); + printf("cam is %p",cam); + lua_newtable(L);//{} + lua_pushlightuserdata(L,cam); + lua_setfield(L,-2,"node"); + //LISceneNode* lcam = (LISceneNode*)lua_newuserdata(L, sizeof(LISceneNode)); + //int tref = luaL_ref(L,LUA_REGISTRYINDEX); + + //Set it's metatable + luaL_getmetatable(L, "scene.iscenemayacamera"); + lua_setmetatable(L, -2); + + //Create the struct + //lcam->n = cam; + //lcam->funcmap = hashmap_new(); + //lcam->type = "iscenemayacamera"; + + //Free up anything made in this function + //free(label); + + //Put it on top and return it + //lua_rawgeti(L,LUA_REGISTRYINDEX,tref); + return 1; } // ifpscamera.new() static int newiscenefpscamera(lua_State* L){// ISceneManager* smgr = device->getSceneManager(); ICameraSceneNode* cam = smgr->addCameraSceneNodeFPS(); - LISceneNode* lcam = (LISceneNode*)lua_newuserdata(L, sizeof(LISceneNode));//userdata_scenenode - int tref = luaL_ref(L,LUA_REGISTRYINDEX);// - lua_rawgeti(L,LUA_REGISTRYINDEX,tref);//userdata_scenenode + lua_newtable(L);//{} + lua_pushlightuserdata(L,cam);//{},ud_cam + lua_setfield(L,-2,"node"); + //LISceneNode* lcam = (LISceneNode*)lua_newuserdata(L, sizeof(LISceneNode));//userdata_scenenode //Set it's metatable luaL_getmetatable(L, "scene.ifpscamera");//userdata_scenenode,scene.ifpscamera lua_setmetatable(L, -2);//userdata_scenenode //Create the struct - lcam->n = cam; - lcam->funcmap = hashmap_new(); - lcam->type = "iscenefpscamera"; + //lcam->n = cam; + //lcam->funcmap = hashmap_new(); + //lcam->type = "iscenefpscamera"; - //Put it on top and return it - //lua_rawgeti(L,LUA_REGISTRYINDEX,tref); return 1; } @@ -154,9 +155,10 @@ static int newiscenecamera(lua_State* L){ } static const luaL_reg icamera_m[] = { - {"getpos", iscenegetpos}, - {"setpos", iscenesetpos}, -// {"remove", removeiguielement}, + {"getpos", iscenegetpos}, + {"setpos", iscenesetpos}, + {"getangle", iscenegetangle}, + {"setangle", iscenesetangle}, {0, 0}, }; @@ -168,8 +170,7 @@ static const luaL_reg ifpscamera_m[] = { {0,0}, }; -void icamera_register(lua_State* L, IrrlichtDevice* d){ - device = d; +void icamera_register(lua_State* L){ luaL_newmetatable(L, "scene.icamera");//scene.icamera lua_newtable(L);//scene.icamera, {} @@ -180,6 +181,7 @@ void icamera_register(lua_State* L, IrrlichtDevice* d){ luaL_newmetatable(L, "scene.imayacamera");//scene.imayacamera lua_newtable(L);//scene.imayascamera,{} luaL_register(L,NULL,imayacamera_m);//scene.imayascamera,{} + luaL_register(L,NULL,icamera_m);//scene.imayascamera,{} lua_setfield(L,-2,"__index");//scene.imayascamera lua_pop(L,1);// @@ -198,5 +200,5 @@ void icamera_register(lua_State* L, IrrlichtDevice* d){ lua_pushcfunction(L,newiscenemayacamera);//{},newiscenemayacamera() lua_setfield(L,-2,"newmayacamera");//{} printf("\"scene\" was set!\n"); - //lua_pop(L,1); + lua_pop(L,1);// } diff --git a/src/client/lua_api/scene/icamera.hpp b/src/client/lua_api/scene/icamera.hpp index 38874e3..ada1e98 100644 --- a/src/client/lua_api/scene/icamera.hpp +++ b/src/client/lua_api/scene/icamera.hpp @@ -8,4 +8,4 @@ extern "C" { } #include <irrlicht.h> -void icamera_register(lua_State* L, irr::IrrlichtDevice* d); +void icamera_register(lua_State* L); diff --git a/src/client/lua_api/scene/icube.cpp b/src/client/lua_api/scene/icube.cpp new file mode 100644 index 0000000..d18db2a --- /dev/null +++ b/src/client/lua_api/scene/icube.cpp @@ -0,0 +1,68 @@ + +extern "C" { + #include <lua.h> + #include <lauxlib.h> + #include <lualib.h> +} +#include <irrlicht.h> + +extern IrrlichtDevice* device; + +using namespace irr; + +// {} :: scene.newcube(num_size, {v3 pos}) +int newiscenecube(lua_StatE* L){//num_size, {v3 pos} + double x,y,z; + popvector3d(L,&x, &y, &z);//num_size + double size = lua_tonumber(L,-1);//num_size + lua_pop(L,1);// + IMeshSceneNode* n = device->getSceneManager()->addCubeSceneNode(size,0,-1,core::vector3df(x,y,z)); + + lua_newtable(L);//{} + lua_pushlightuserdata(L,n);//{},ud_node + lua_setfield(L,-2,"node");//{} + + luaL_getmetatable(L,"scene.inode");//{},sene.inode + lua_setmetatable(L,-2); + + return 1; +} + +static const luaL_reg iscenenode_m[] = { + {"getpos", iscenegetpos}, + {"setpos", iscenesetpos}, +// {"remove", removeiguielement}, + {0, 0}, +}; + +void icube_register(lua_State* L){ + + luaL_newmetatable(L, "scene.icamera");//scene.icamera + lua_newtable(L);//scene.icamera, {} + luaL_register(L,NULL,icamera_m);//scene.icamera, {} + lua_setfield(L,-2,"__index");//scene.icamera + lua_pop(L,1);// + + luaL_newmetatable(L, "scene.imayacamera");//scene.imayacamera + lua_newtable(L);//scene.imayascamera,{} + luaL_register(L,NULL,imayacamera_m);//scene.imayascamera,{} + lua_setfield(L,-2,"__index");//scene.imayascamera + lua_pop(L,1);// + + luaL_newmetatable(L,"scene.ifpscamera");//scene.ifpscamera + lua_newtable(L);//scene.ifpscamera, {} + luaL_register(L,NULL,ifpscamera_m);//scene.ifpscamera,{} + luaL_register(L,NULL,icamera_m);//scene.ifpscamera,{} + lua_setfield(L,-2,"__index");//scene.ifpscamera + lua_pop(L,1);// + + lua_getglobal(L,"scene");//{} + lua_pushcfunction(L,newiscenecamera);//{},newiscenecamera() + lua_setfield(L,-2,"newcamera");//{} + lua_pushcfunction(L,newiscenefpscamera);//{},newiscenefpscamera() + lua_setfield(L,-2,"newfpscamera");//{} + lua_pushcfunction(L,newiscenemayacamera);//{},newiscenemayacamera() + lua_setfield(L,-2,"newmayacamera");//{} + printf("\"scene\" was set!\n"); + //lua_pop(L,1); +} diff --git a/src/client/lua_api/scene/icube.hpp b/src/client/lua_api/scene/icube.hpp new file mode 100644 index 0000000..ffb4d3b --- /dev/null +++ b/src/client/lua_api/scene/icube.hpp @@ -0,0 +1,11 @@ + +#include <stdio.h> +#include <stdlib.h> +extern "C" { + #include <lua.h> + #include <lauxlib.h> + #include <lualib.h> +} +#include <irrlicht.h> + +void icube_register(lua_State* L); diff --git a/src/client/lua_api/scene/igeneric.cpp b/src/client/lua_api/scene/igeneric.cpp index fc32e83..0d061d2 100644 --- a/src/client/lua_api/scene/igeneric.cpp +++ b/src/client/lua_api/scene/igeneric.cpp @@ -7,6 +7,7 @@ extern "C" { #include <irrlicht.h> #include "igeneric.hpp" #include "../gameparts.hpp" +#include "../../../shared/lua_api/common.h" using namespace irr; using namespace core; @@ -15,63 +16,57 @@ using namespace video; extern IrrlichtDevice* device; +/* static LISceneNode* toiscenenode(lua_State* L, int index){ LISceneNode* ret = (LISceneNode*)lua_touserdata(L,index); if(ret == NULL) luaL_typerror(L,index,"LISceneNode"); return ret; } +*/ -int iscenegetpos(lua_State* L){ - ISceneNode* i = toiscenenode(L,1)->n; +int iscenegetpos(lua_State* L){//{node=ud_IMeshSceneNode} + lua_getfield(L,-1,"node");//{node=ud_IMeshSceneNode},ud_IMeshSceneNode + ISceneNode* i = (ISceneNode*)lua_touserdata(L,-1);//{node=ud_IMeshSceneNode},ud_IMeshSceneNode vector3df pos = i->getAbsolutePosition(); + lua_pop(L,2); + pushvector3d(L,pos.X,pos.Y,pos.Z); - lua_createtable(L,3,0); - - lua_pushnumber(L,1); - lua_pushnumber(L,pos.X); - lua_settable(L,-3); - - lua_pushnumber(L,2); - lua_pushnumber(L,pos.Y); - lua_settable(L,-3); + return 1; +} - lua_pushnumber(L,3); - lua_pushnumber(L,pos.Z); - lua_settable(L,-3); - +int iscenesetpos(lua_State* L){//{node=ud_IMeshSceneNode},{x,y,z} + double x,y,z; + popvector3d(L,&x,&y,&z);//{node=ud_IMeshSceneNode} + lua_getfield(L,-1,"node");//{node=ud_IMeshSceneNode},ud_IMeshSceneNode + ISceneNode* i = (ISceneNode*)lua_touserdata(L,-1);//{node=ud_IMeshSceneNode},ud_IMeshSceneNode + i->setPosition(vector3df(x,y,z)); + i->updateAbsolutePosition(); + vector3df pos = i->getAbsolutePosition(); + printf("After setting pos, new pos is %f %f %f",pos.X,pos.Y,pos.Z); + lua_pop(L,2);// + return 0; +} + +int iscenegetangle(lua_State* L){//{node=ud-IMeshSceneNode} + lua_getfield(L,-1,"node"); + ISceneNode* i = (ISceneNode*)lua_touserdata(L,-1); + irr::core::vector3df ang = i->getRotation(); + pushvector3d(L,ang.X, ang.Y, ang.Z); return 1; } -int iscenesetpos(lua_State* L){ - - ISceneNode* i = toiscenenode(L,1)->n; - - lua_pushnumber(L,1); - lua_gettable(L,-2); - f32 x = (f32)lua_tonumber(L,-1); - lua_pop(L,1); - - lua_pushnumber(L,2); - lua_gettable(L,-2); - f32 y = (f32)lua_tonumber(L,-1); - lua_pop(L,1); - - lua_pushnumber(L,3); - lua_gettable(L,-2); - f32 z = (f32)lua_tonumber(L,-1); - lua_pop(L,1); - - printf("Trying to set pos of %p to %f %f %f",i,x,y,z); - - i->setPosition(vector3df(x,y,z)); - i->updateAbsolutePosition(); - vector3df pos = i->getAbsolutePosition(); - printf("After setting pos, new pos is %f %f %f",pos.X,pos.Y,pos.Z); - - return 0; +int iscenesetangle(lua_State* L){//{node=ud_ISceneNode},{x,y,z} + double x,y,z; + popvector3d(L,&x,&y,&z); + lua_getfield(L,-1,"node"); + ISceneNode* i = (ISceneNode*)lua_touserdata(L,-1); + irr::core::vector3df ang = irr::core::vector3df(x,y,z); + i->setRotation(ang); + return 0; } +/* int iscenesetmaterial(lua_State* L){ ISceneNode* i = toiscenenode(L,1)->n; const char* s = luaL_optstring(L,2,"error.png"); @@ -81,3 +76,4 @@ int iscenesetmaterial(lua_State* L){ return 0; } +*/ diff --git a/src/client/lua_api/scene/igeneric.hpp b/src/client/lua_api/scene/igeneric.hpp index 85a9d3e..c60b169 100644 --- a/src/client/lua_api/scene/igeneric.hpp +++ b/src/client/lua_api/scene/igeneric.hpp @@ -11,6 +11,9 @@ extern "C" { int iscenegetpos(lua_State* L); int iscenesetpos(lua_State* L); +int iscenegetangle(lua_State* L); +int iscenesetangle(lua_State* L); + int iscenesetmaterial(lua_State* L); diff --git a/src/client/lua_api/scene/ilight.cpp b/src/client/lua_api/scene/ilight.cpp index 2511999..451280a 100644 --- a/src/client/lua_api/scene/ilight.cpp +++ b/src/client/lua_api/scene/ilight.cpp @@ -14,6 +14,7 @@ extern "C" { #include "../gameparts.hpp" #include "ilight.hpp" #include "igeneric.hpp" +#include "../../../shared/lua_api/common.h" using namespace irr; using namespace scene; @@ -31,100 +32,49 @@ static LISceneNode* checkilight(lua_State* L){ return checkiscenelight(L,1); } -//iscenelight.new(Vector position, parrent = nil) +//{} :: scene.newlight(radius, {v3 position}) static int newiscenelight(lua_State* L){ printf("Createing light!\n"); - int nargs = lua_gettop(L); - //lua_pop(L,1); - // float radius = 100; - // if(nargs == 2){ - // radius = luaL_optnumber(L,2,100); - // } - float radius = lua_tonumber(L,-1); - printf("radius was %f\n" ,radius); - lua_pop(L,1); + double x,y,z; + popvector3d(L,&x,&y,&z);//radius + double radius = lua_tonumber(L,-1); + lua_pop(L,1);// - //The position of the light - lua_pushnumber(L,1); - lua_gettable(L,-2); - float x = lua_tonumber(L,-1); - printf("got x: %f\n",x); - lua_pop(L,1); - lua_pushnumber(L,2); - lua_gettable(L,-2); - float y = lua_tonumber(L,-1); - lua_pop(L,1); - lua_pushnumber(L,3); - lua_gettable(L,-2); - float z = lua_tonumber(L,-1); - lua_pop(L,1); - printf("Found position for light: %f %f %f\n",x,y,z); - //Create the mesh ISceneManager* smgr = device->getSceneManager(); ILightSceneNode* light = smgr->addLightSceneNode(0,vector3df(x,y,z),video::SColor(1.0f,1.0f,1.0f,1.0f),(f32)radius,(s32)-1); - printf("Registered the light!\n"); - - //Register it's callback - //registerguicallback(llabel,EGET_ELEMENT_HOVERED,iguilabelevent); //Create it's lua representation - LISceneNode* lnode = (LISceneNode*)lua_newuserdata(L, sizeof(LISceneNode)); - int tref = luaL_ref(L,LUA_REGISTRYINDEX); - //iguielements[lcam] = tref; - lua_rawgeti(L,LUA_REGISTRYINDEX,tref);//Put it back on the stack since luaL_ref pops the object. + lua_newtable(L);//{} + lua_pushlightuserdata(L,light); + lua_setfield(L,-2,"node"); //Set it's metatable luaL_getmetatable(L, "scene.imesh"); lua_setmetatable(L, -2); - lnode->n = light; - lnode->funcmap = hashmap_new(); - lnode->type = "ilight"; - - //Put it on top and return it - lua_rawgeti(L,LUA_REGISTRYINDEX,tref); return 1; } -static const luaL_reg icamera_f[] = { - {"new", newiscenelight}, -// {"gethandeler", guigethandeler}, -// {"sethandeler", guisethandeler}, - {0,0}, -}; - -static const luaL_reg icamera_m[] = { - {"getpos", iscenegetpos}, - {"setpos", iscenesetpos}, -// {"move", moveiguielement}, -// {"settext", setiguitext}, -// {"remove", removeiguielement}, - {0, 0}, +static const luaL_reg ilight_m[] = { + {"getpos", iscenegetpos}, + {"setpos", iscenesetpos}, + {0, 0}, }; -int ilight_register(lua_State* L, IrrlichtDevice* d){ - - device = d; - - printf("ilight registered\n"); +void ilight_register(lua_State* L){ - luaL_newmetatable(L, "scene.ilight"); + lua_getglobal(L,"scene");//{scene} + lua_pushcfunction(L,newiscenelight);//{scene},newiscenelight() + lua_setfield(L,-2,"newlight");//{scene} - luaL_register(L,"ilight",icamera_f); + lua_pop(L,1);// - lua_pushstring(L,"__index"); - lua_pushstring(L,"gethandeler"); - lua_gettable(L,-3); - lua_settable(L,-4); + luaL_newmetatable(L,"scene.ilight");//scene.ilight + lua_newtable(L);//scene.ilight,{} + luaL_register(L, NULL, ilight_m);//scene.ilight,{} + lua_setfield(L,-2,"__index");//scene.ilight - lua_pushstring(L,"__newindex"); - lua_pushstring(L,"sethandeler"); - lua_gettable(L,-3); - lua_settable(L,-4); - - luaL_register(L, NULL, icamera_m); - - return 1; + lua_pop(L,1); } diff --git a/src/client/lua_api/scene/ilight.hpp b/src/client/lua_api/scene/ilight.hpp index 87d2841..af9c084 100644 --- a/src/client/lua_api/scene/ilight.hpp +++ b/src/client/lua_api/scene/ilight.hpp @@ -8,4 +8,4 @@ extern "C" { } #include <irrlicht.h> -int ilight_register(lua_State* L, irr::IrrlichtDevice* d); +void ilight_register(lua_State* L); diff --git a/src/client/lua_api/scene/imesh.cpp b/src/client/lua_api/scene/imesh.cpp index 1a1c28b..3f3ae24 100644 --- a/src/client/lua_api/scene/imesh.cpp +++ b/src/client/lua_api/scene/imesh.cpp @@ -14,6 +14,7 @@ extern "C" { #include "../gameparts.hpp" #include "imesh.hpp" #include "igeneric.hpp" +#include "../../../shared/lua_api/common.h" using namespace irr; using namespace scene; @@ -22,7 +23,6 @@ using namespace video; extern IrrlichtDevice* device; - static LISceneNode* checkismesh(lua_State* L, int index){ void* ud = luaL_checkudata(L,index,"scene.imesh"); luaL_argcheck(L,ud != NULL, index, "'scene.imesh' expected"); @@ -35,83 +35,107 @@ static LISceneNode* checkismesh(lua_State* L){ } */ -static int newiscenemesh(lua_State* L){ - printf("Createing mesh!\n"); - int nargs = lua_gettop(L); - if(nargs != 1){ - printf("Incorrect # of args to create a mesh!"); - } - //The model for the mesh - const char* modelpath = luaL_optstring(L,1,"error"); - - //Create the mesh - ISceneManager* smgr = device->getSceneManager(); - IAnimatedMesh* amesh = smgr->getMesh(modelpath); - IAnimatedMeshSceneNode* mesh = smgr->addAnimatedMeshSceneNode( amesh ); - mesh->setMaterialFlag(EMF_GOURAUD_SHADING,true); - printf("Registered the mesh!\n"); - - //Register it's callback - //registerguicallback(llabel,EGET_ELEMENT_HOVERED,iguilabelevent); - - //Create it's lua representation - LISceneNode* lmesh = (LISceneNode*)lua_newuserdata(L, sizeof(LISceneNode)); - int tref = luaL_ref(L,LUA_REGISTRYINDEX); - //iguielements[lcam] = tref; - lua_rawgeti(L,LUA_REGISTRYINDEX,tref);//Put it back on the stack since luaL_ref pops the object. - - //Set it's metatable - luaL_getmetatable(L, "scene.imesh"); - lua_setmetatable(L, -2); - - //Create the struct - lmesh->n = mesh; - lmesh->funcmap = hashmap_new(); - lmesh->type = "imesh"; - - //Free up anything made in this function - //free(label); - - //Put it on top and return it - lua_rawgeti(L,LUA_REGISTRYINDEX,tref); - return 1; +//{} :: scene.newmesh("/path/to/model") +static int newiscenemesh(lua_State* L){//"path/to" + + printf("Createing mesh!\n"); + int nargs = lua_gettop(L); + if(nargs != 1){ + lua_pushfstring(L,"scene.newmesh got %d arguments, expecting 1",nargs); + lua_error(L); + } + //The model for the mesh + const char* modelpath = luaL_optstring(L,1,"error");//"path/to" + lua_pop(L,1);// + + //Create the mesh + ISceneManager* smgr = device->getSceneManager(); + IAnimatedMesh* amesh = smgr->getMesh(modelpath); + IAnimatedMeshSceneNode* mesh = smgr->addAnimatedMeshSceneNode( amesh ); + mesh->setMaterialFlag(EMF_GOURAUD_SHADING,true); + printf("Registered the mesh!\n"); + + lua_newtable(L);//{} + luaL_getmetatable(L,"scene.imesh");//{},scene.imesh + lua_setmetatable(L,-2);//{} + + lua_pushlightuserdata(L,mesh);//{},ud_mesh + lua_setfield(L,-2,"node");//{} + + return 1; } -static const luaL_reg imesh_f[] = { - {"new", newiscenemesh}, -// {"gethandeler", guigethandeler}, -// {"sethandeler", guisethandeler}, - {0,0}, -}; +// ud_node :: ({v3 size}, {v3 origin}) +void makenewiscenecube(lua_State* L){ + double x,y,z; + popvector3d(L,&x,&y,&z);//{v3 size} + double sx,sy,sz; + popvector3d(L,&sx,&sy,&sz);//{} + IMeshSceneNode* n = device->getSceneManager()->addCubeSceneNode(10,0,-1,core::vector3df(x,y,z),core::vector3df(0,0,0),core::vector3df(sx,sy,sz)); + lua_pushlightuserdata(L,n); +} -static const luaL_reg imesh_m[] = { - {"setMaterial", iscenesetmaterial}, - {"getpos", iscenegetpos}, - {"setpos", iscenesetpos}, -// {"settext", setiguitext}, -// {"remove", removeiguielement}, - {0, 0}, -}; +// {} :: scene.newcube({v3 size}, {v3 origin}) +int newiscenecube(lua_State* L){//{v3 size}, {v3 origin} + makenewiscenecube(L);//ud_node + ISceneNode* n = (ISceneNode*)lua_touserdata(L,-1);//ud_node + lua_pop(L,1);// + lua_newtable(L);//{} + luaL_getmetatable(L,"scene.icube");//{},scene.icube + lua_setmetatable(L,-2);//{} -int imesh_register(lua_State* L, IrrlichtDevice* d){ + lua_pushlightuserdata(L,n);//{},ud_mesh + lua_setfield(L,-2,"node");//{} - device = d; + return 1; +} - luaL_newmetatable(L, "scene.imesh"); +// self:setMaterial("path/to/material") +int iscenesetmaterial(lua_State* L){//self,"path/to" + ISceneNode* node = (IMeshSceneNode*)lua_touserdata(L,-2); + const char* s = lua_tostring(L,-1); + //ISceneNode* i = toiscenenode(L,1)->n; + //const char* s = luaL_optstring(L,2,"error.png"); + //printf("Setting material to %s",s); - luaL_register(L,"imesh",imesh_f); + IVideoDriver* driver = device->getVideoDriver(); + node->setMaterialTexture(0, driver->getTexture(s)); - lua_pushstring(L,"__index"); - lua_pushstring(L,"gethandeler"); - lua_gettable(L,-3); - lua_settable(L,-4); + lua_pop(L,2); + return 0; +} - lua_pushstring(L,"__newindex"); - lua_pushstring(L,"sethandeler"); - lua_gettable(L,-3); - lua_settable(L,-4); +static const luaL_reg imesh_m[] = { + {"setMaterial", iscenesetmaterial}, + {"getpos", iscenegetpos}, + {"setpos", iscenesetpos}, + // {"remove", removeiguielement}, + {0, 0}, +}; + +static const luaL_reg icube_m[] = { + {0,0}, +}; - luaL_register(L, NULL, imesh_m); +void imesh_register(lua_State* L){ + + luaL_newmetatable(L, "scene.imesh");//scene.icamera + lua_newtable(L);//scene.icamera,{} + luaL_register(L,NULL,imesh_m);//scene.icamera,{} + lua_setfield(L,-2,"__index");//scene.icamera + lua_pop(L,1);// + + luaL_newmetatable(L,"scene.icube");//scene.icube + lua_newtable(L);//scene.icube, {} + luaL_register(L,NULL,imesh_m);//scene.icube,{} + luaL_register(L,NULL,icube_m);//scene.icube,{} + lua_setfield(L,-2,"__index");//scene.icube + lua_pop(L,1);// + + lua_getglobal(L,"scene"); + lua_pushcfunction(L,newiscenemesh); + lua_setfield(L,-2,"newmesh"); + lua_pushcfunction(L,newiscenecube); + lua_setfield(L,-2,"newcube"); - return 1; } diff --git a/src/client/lua_api/scene/imesh.hpp b/src/client/lua_api/scene/imesh.hpp index bd33c07..925f12e 100644 --- a/src/client/lua_api/scene/imesh.hpp +++ b/src/client/lua_api/scene/imesh.hpp @@ -8,4 +8,7 @@ extern "C" { } #include <irrlicht.h> -int imesh_register(lua_State* L, irr::IrrlichtDevice* d); + +void makenewiscenecube(lua_State* L); +int newiscenecube(lua_State* L);//{v3 size}, {v3 origin}, mass +void imesh_register(lua_State* L); |
