From 0d2de2ba9c616862d7881f089382db772d034f89 Mon Sep 17 00:00:00 2001 From: Alexander Date: Sun, 27 Oct 2019 17:25:16 -0400 Subject: Various updates --- src/client/callbackhandeler.cpp | 24 ++++++++--- src/client/initdevice.cpp | 35 ++++++++-------- src/client/lua_api/gui/iguibutton.cpp | 10 ++--- src/client/lua_api/gui/iguifiledialog.cpp | 16 +++++--- src/client/lua_api/gui/iguiimage.cpp | 14 +++++++ src/client/lua_api/load_cphys.cpp | 13 +++++- src/client/lua_api/load_video.cpp | 20 ++++++++- src/client/lua_api/phys/cbcharactercontroller.cpp | 2 - src/client/lua_api/phys/cbphysbox.cpp | 13 +++--- src/client/lua_api/phys/cbphysmodel.cpp | 12 ++++-- src/client/lua_api/phys/cbphysmodel.hpp | 2 +- src/client/lua_api/scene/igeneric.cpp | 18 +++++++++ src/client/lua_api/scene/ilight.cpp | 23 +++++++++-- src/client/lua_api/video/draw.cpp | 29 ++++++++++++++ src/client/lua_api/video/draw.hpp | 8 ++++ src/client/lua_api/video/smaterial.cpp | 14 +++++++ src/client/main.cpp | 49 ++++++++++++++++++----- 17 files changed, 241 insertions(+), 61 deletions(-) create mode 100644 src/client/lua_api/video/draw.cpp create mode 100644 src/client/lua_api/video/draw.hpp (limited to 'src/client') diff --git a/src/client/callbackhandeler.cpp b/src/client/callbackhandeler.cpp index 0f1f87f..d522e84 100644 --- a/src/client/callbackhandeler.cpp +++ b/src/client/callbackhandeler.cpp @@ -1,6 +1,7 @@ #include #include #include +#include extern "C" { #include #include @@ -38,8 +39,10 @@ GlobalEventReceiver::GlobalEventReceiver(IrrlichtDevice* d){ //device = d; } + int callMouse(lua_State* L, const char* funcname, double x, double y, double event){ int consume = 0; + assert(lua_gettop(L) == 0); lua_getglobal(L,"GAME");//GAME pusherrorfunc(L);//{GAME},errfun lua_getfield(L,-2,funcname);//{GAME},errfunc,funcname? @@ -53,18 +56,22 @@ int callMouse(lua_State* L, const char* funcname, double x, double y, double eve }else{ if(!lua_isnil(L,-1)){ consume = lua_toboolean(L,-1); - lua_pop(L,-1); } } - lua_pop(L,2); + lua_pop(L,3); + assert(lua_gettop(L) == 0); }else{ //{GAME},errfunc,nil lua_pop(L,3);// + assert(lua_gettop(L) == 0); } + assert(lua_gettop(L) == 0); return consume; } bool GlobalEventReceiver::OnEvent(const SEvent& e){ + //printf("Onevent triggered when top was %d\n", lua_gettop(L)); + assert(lua_gettop(L) == 0); //lua_State* L = this->L; EEVENT_TYPE type = e.EventType; SEvent::SMouseInput se = e.MouseInput; @@ -95,7 +102,7 @@ bool GlobalEventReceiver::OnEvent(const SEvent& e){ case EGET_LISTBOX_SELECTED_AGAIN: fieldname = "onSame"; break; case EGET_FILE_SELECTED: fieldname = "onFileSelect"; break; case EGET_DIRECTORY_SELECTED: fieldname = "onDirectorySelect"; break; - case EGET_FILE_CHOOSE_DIALOG_CANCELLED: fieldname = "onFileChooserCancel"; break; + case EGET_FILE_CHOOSE_DIALOG_CANCELLED: fieldname = "onCanceled"; break; case EGET_MESSAGEBOX_YES: fieldname = "onYes"; break; case EGET_MESSAGEBOX_NO: fieldname = "onNo"; break; case EGET_MESSAGEBOX_OK: fieldname = "onOk"; break; @@ -122,6 +129,7 @@ bool GlobalEventReceiver::OnEvent(const SEvent& e){ if(lua_isnil(L,-1)){ printf("Element did not have a function %s, returning\n",fieldname); lua_pop(L,3);// + assert(lua_gettop(L) == 0); return false; } lua_rawgeti(L,LUA_REGISTRYINDEX,ref);//{guielement},errfunc(),func(),{guielement} @@ -130,9 +138,12 @@ bool GlobalEventReceiver::OnEvent(const SEvent& e){ if(!lua_isnil(L,-1)){ printf("Got an argument back!\n"); int ans = lua_toboolean(L,-1); + lua_pop(L,3); + assert(lua_gettop(L) == 0); return ans; } lua_pop(L,3);// + assert(lua_gettop(L) == 0); return false; } break; @@ -199,6 +210,7 @@ Detects any key presses from the game. case EET_KEY_INPUT_EVENT:{ //printf("Got input event\n"); SEvent::SKeyInput se = e.KeyInput; + assert(lua_gettop(L) == 0); lua_getglobal(L,"GAME");//{} lua_getfield(L,-1,"onKeyDown");//{},()|nil if(!lua_isnil(L,-1)){ @@ -210,10 +222,9 @@ Detects any key presses from the game. lua_pushboolean(L,se.Control);//{GAME},GAME.onKeyDown(),errfunc,onKeyDown(),key_number,is_down,is_ctrl lua_pushboolean(L,se.Shift);//{GAME},GAME.onKeyDown(),errfunc,onKeyDown(),key_number,is_down,is_ctrl,is_shift lua_pcall(L,4,0,-6);//GAME,GAME.onKeyDown() - lua_pop(L,2); - }else{ - lua_pop(L,2); } + lua_pop(L,lua_gettop(L)); + assert(lua_gettop(L) == 0); return false; break; } @@ -222,5 +233,6 @@ Detects any key presses from the game. return false; } } + assert(lua_gettop(L) == 0); return true; } diff --git a/src/client/initdevice.cpp b/src/client/initdevice.cpp index 3720d49..40a1e30 100644 --- a/src/client/initdevice.cpp +++ b/src/client/initdevice.cpp @@ -144,7 +144,7 @@ void parseSetting(const char* settingname, lua_State* L, settings* set){ } void settingsFromTable(lua_State *L, SIrrlichtCreationParameters* p){ - lua_pushnil(L); + lua_pushnil(L);//nil settings* set = (settings*)malloc(sizeof(settings)); printf("Loading settings..."); while(lua_next(L,-2) != 0){ @@ -172,20 +172,21 @@ void settingsFromTable(lua_State *L, SIrrlichtCreationParameters* p){ } IrrlichtDevice* spawnIrrDevice(lua_State* L, char *path){ - //printf("Attempting to load settings...\n"); - char initname[] = "deviceinit.lua"; - size_t pathlen = strlen(initname) + strlen(path); - char filename[pathlen + 1]; - sprintf(filename,"%s/%s",path,initname); - int iErr = luaL_dofile(L,filename); - SIrrlichtCreationParameters p = SIrrlichtCreationParameters(); - if(iErr != 0){ - printf("Failed to open lua file:%s\n", filename); - } - settingsFromTable(L,&p); - IrrlichtDevice* dev = createDeviceEx(p); - if(!dev) - exit(1); - dev->setWindowCaption(L"Borkengin"); - return dev; + //printf("Attempting to load settings...\n"); + char initname[] = "deviceinit.lua"; + size_t pathlen = strlen(initname) + strlen(path); + char filename[pathlen + 1]; + sprintf(filename,"%s/%s",path,initname); + int iErr = luaL_dofile(L,filename);//ret + SIrrlichtCreationParameters p = SIrrlichtCreationParameters(); + if(iErr != 0){ + printf("Failed to open lua file:%s\n", filename); + } + settingsFromTable(L,&p); + IrrlichtDevice* dev = createDeviceEx(p); + if(!dev) + exit(1); + dev->setWindowCaption(L"Brokengine"); + lua_pop(L,1); + return dev; } diff --git a/src/client/lua_api/gui/iguibutton.cpp b/src/client/lua_api/gui/iguibutton.cpp index 42d2846..b8ff517 100644 --- a/src/client/lua_api/gui/iguibutton.cpp +++ b/src/client/lua_api/gui/iguibutton.cpp @@ -30,11 +30,11 @@ char lhashkey[20]; /*** Creates a new button. Buttons may have the following fields set for callbacks: -`.onClick(self)` -`.onFocus(self)` -`.onUnfocus(self)` -`.onHover(self)` -`.onLeave(self)` + .onClick(self) + .onFocus(self) + .onUnfocus(self) + .onHover(self) + .onLeave(self) @function newbutton() @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. diff --git a/src/client/lua_api/gui/iguifiledialog.cpp b/src/client/lua_api/gui/iguifiledialog.cpp index 6303230..d717673 100644 --- a/src/client/lua_api/gui/iguifiledialog.cpp +++ b/src/client/lua_api/gui/iguifiledialog.cpp @@ -28,7 +28,11 @@ extern IrrlichtDevice* device; /*** @function newfileopendialog() -Creates a new dialog to open a file +Creates a new dialog to open a file. +The file creation window may have the following fields set for callbacks: + .onDirectorySelect(self) + .onFileSelect(self) + .onCanceled(self) @tparam ?string title 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 ?string path The path to open the file dialog to @@ -66,10 +70,10 @@ static int newfileopendialog(lua_State* L){ mbstowcs(title,titlec,titlecslen); title[titlecslen] = L'\0'; } - + //printf("Got all arguments\n"); IGUIEnvironment *env = device->getGUIEnvironment(); IGUIFileOpenDialog *but = env->addFileOpenDialog(title,modal,parent,-1,false,path); - + //printf("Created file open dialog\n"); //printf("Added file open dialog\n"); lua_newtable(L);//{} lua_pushlightuserdata(L,but);//{},ud_iguibutton @@ -78,13 +82,13 @@ static int newfileopendialog(lua_State* L){ lua_setmetatable(L,-2);//{guielement} //printf("Created lua representation\n"); - setelementcallback(L,EGET_DIRECTORY_SELECTED,"onDirectory");// - setelementcallback(L,EGET_FILE_SELECTED,"onFileSelected"); + setelementcallback(L,EGET_DIRECTORY_SELECTED,"onDirectorySelect");// + setelementcallback(L,EGET_FILE_SELECTED,"onFileSelect"); setelementcallback(L,EGET_FILE_CHOOSE_DIALOG_CANCELLED,"onCanceled"); //printf("Finished registering callback\n"); free(title); - free(path); + //printf("Freed everything\n"); return 1; } diff --git a/src/client/lua_api/gui/iguiimage.cpp b/src/client/lua_api/gui/iguiimage.cpp index 1d0f4dc..267cbd2 100644 --- a/src/client/lua_api/gui/iguiimage.cpp +++ b/src/client/lua_api/gui/iguiimage.cpp @@ -21,6 +21,7 @@ extern "C" { @module gui */ using namespace irr; +using namespace video; using namespace gui; extern IrrlichtDevice* device; @@ -80,8 +81,21 @@ int setcolor(lua_State* L){ return 0; } +//setimage(self,itexture) +int setimage(lua_State *L){ + lua_getfield(L,-1,"texture");//{iguiimg},{itex} + ITexture* img = (ITexture*)lua_touserdata(L,-1);//{iguiimg},{itex},ud_itexture + lua_pop(L,2);//{iguiimg} + lua_getfield(L,-1,"guielement");//{iguiimg},ud_guiimg + IGUIImage *gimg = (IGUIImage*)lua_touserdata(L,-1);//{iguiimg},ud_guiimg + lua_pop(L,2);// + gimg->setImage(img); + return 0; +} + static const luaL_reg iguiimage_m[] = { {"setcolor", setcolor}, + {"setimage", setimage}, {0, 0}, }; diff --git a/src/client/lua_api/load_cphys.cpp b/src/client/lua_api/load_cphys.cpp index 92eaff0..2e2d18a 100644 --- a/src/client/lua_api/load_cphys.cpp +++ b/src/client/lua_api/load_cphys.cpp @@ -2,6 +2,7 @@ #include #include #include +#include extern "C" { #include #include @@ -31,8 +32,8 @@ extern btBroadphaseInterface *BroadPhase; int raytest(lua_State *L){ double fx,fy,fz; double tx,ty,tz; - popvector3d(L, &fx, &fy, &fz); popvector3d(L, &tx, &ty, &tz); + popvector3d(L, &fx, &fy, &fz); btVector3 from(fx, fy, fz); btVector3 to(tx, ty, tz); @@ -44,15 +45,23 @@ int raytest(lua_State *L){ } void load_cphysfuncs(lua_State* L){ - + assert(lua_gettop(L) == 0); + printf("Registering cphysbox\n"); //phys things + assert(lua_gettop(L) == 0); cbphysbox_register(L); + assert(lua_gettop(L) == 0); cbcharactercontroller_register(L); + assert(lua_gettop(L) == 0); cbphysmodel_register(L); + assert(lua_gettop(L) == 0); bghostobject_register(L); + assert(lua_gettop(L) == 0); + assert(lua_gettop(L) == 0); lua_getglobal(L,"phys");//{} lua_pushcfunction(L,raytest);//{},raytest() lua_setfield(L,-2,"raytest");//{} lua_pop(L,1); + assert(lua_gettop(L) == 0); } diff --git a/src/client/lua_api/load_video.cpp b/src/client/lua_api/load_video.cpp index f309180..b3487ca 100644 --- a/src/client/lua_api/load_video.cpp +++ b/src/client/lua_api/load_video.cpp @@ -8,6 +8,7 @@ extern "C" { #include "video/smaterial.hpp" #include "video/itexture.hpp" #include "video/iimage.hpp" +#include "video/draw.hpp" #include @@ -79,6 +80,20 @@ int draw2dline(lua_State* L){ return 0; } +//{sx,sy,sz},{ex,ey,ez},{color} +int draw3dline(lua_State* L){ + double sx,sy,sz; + double ex,ey,ez; + long r,g,b,a; + popvector4i(L,&r,&g,&b,&a); + popvector3d(L,&ex,&ey,&ez); + popvector3d(L,&sx,&sy,&sz); + + driver->draw3DLine(vector3df(sx,sy,sz),vector3df(ex,ey,ez),SColor(a,r,g,b)); + + return 0; +} + void load_videofuncs(lua_State* L){ //printf("Loading video libraries...\n"); lua_newtable(L);//{} @@ -88,11 +103,14 @@ void load_videofuncs(lua_State* L){ lua_pushcfunction(L,draw2dimage);//{},draw2dimage() lua_setfield(L,-2,"drawtexture");//{} lua_pushcfunction(L,draw2dline);//{},draw2dline() - lua_setfield(L,-2,"drawline");//{} + lua_setfield(L,-2,"draw2dline");//{} + lua_pushcfunction(L,draw3dline); + lua_setfield(L,-2,"draw3dline"); lua_pop(L,1);// smaterial_register(L); itexture_register(L); iimage_register(L); + draw_register(L); } diff --git a/src/client/lua_api/phys/cbcharactercontroller.cpp b/src/client/lua_api/phys/cbcharactercontroller.cpp index 6a6da96..16ad1ad 100644 --- a/src/client/lua_api/phys/cbcharactercontroller.cpp +++ b/src/client/lua_api/phys/cbcharactercontroller.cpp @@ -115,6 +115,4 @@ void cbcharactercontroller_register(lua_State* L){ //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/phys/cbphysbox.cpp b/src/client/lua_api/phys/cbphysbox.cpp index 3c0f97d..e675a04 100644 --- a/src/client/lua_api/phys/cbphysbox.cpp +++ b/src/client/lua_api/phys/cbphysbox.cpp @@ -2,6 +2,7 @@ #include #include #include +#include extern "C" { #include #include @@ -163,12 +164,15 @@ static const luaL_reg cbphysbox_m[] = { }; void cbphysbox_register(lua_State* L){ + assert(lua_gettop(L) == 0); bphysbox_register(L);// + assert(lua_gettop(L) == 0); lua_getglobal(L,"phys");//{} lua_pushcfunction(L,newcbphysbox);//{},newcbphysbox() - lua_setfield(L,-2,"newcphysbox");//{} + lua_setfield(L,-2,"newphysbox");//{phys} lua_pop(L,1);// + assert(lua_gettop(L) == 0); luaL_getmetatable(L,"phys.physbox");//phys.physbox lua_newtable(L);//phys.physbox,{} @@ -176,15 +180,14 @@ void cbphysbox_register(lua_State* L){ luaL_register(L,NULL,brigidbody_m); luaL_register(L,NULL,igeneric_m); luaL_register(L,NULL,cbphysbox_m);//phys.physbox,{} - lua_pushstring(L,"rigidbody"); - lua_setfield(L,-2,"type"); + lua_pushstring(L,"rigidbody");//phys.physbox,{},"rigidbody" + lua_setfield(L,-2,"type");//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); + assert(lua_gettop(L) == 0); } diff --git a/src/client/lua_api/phys/cbphysmodel.cpp b/src/client/lua_api/phys/cbphysmodel.cpp index ac27288..ae2559e 100644 --- a/src/client/lua_api/phys/cbphysmodel.cpp +++ b/src/client/lua_api/phys/cbphysmodel.cpp @@ -6,6 +6,7 @@ #include #include #include +#include extern "C" { #include #include @@ -260,9 +261,12 @@ static const luaL_reg bphysmodel_m[] = { {0, 0}, }; -int cbphysmodel_register(lua_State* L){ +void cbphysmodel_register(lua_State* L){ + assert(lua_gettop(L) == 0); bphysmodel_register(L); + assert(lua_gettop(L) == 0); + assert(lua_gettop(L) == 0); luaL_getmetatable(L,"phys.physmodel");//{physmodel_m} lua_getfield(L,-1,"__index");//{physmodel_m},{} luaL_register(L,NULL,igeneric_m); //Inherit all the things to do with scene nodes @@ -270,9 +274,11 @@ int cbphysmodel_register(lua_State* L){ luaL_register(L,NULL,brigidbody_m);//Add rigidbody things luaL_register(L,NULL,bphysmodel_m);//anything specific? lua_pop(L,2); + assert(lua_gettop(L) == 0); + assert(lua_gettop(L) == 0); lua_getglobal(L,"phys"); luaL_register(L,NULL,bphysmodel_f); - - return 1; + lua_pop(L,1); + assert(lua_gettop(L) == 0); } diff --git a/src/client/lua_api/phys/cbphysmodel.hpp b/src/client/lua_api/phys/cbphysmodel.hpp index 5ea42a8..d8495d2 100644 --- a/src/client/lua_api/phys/cbphysmodel.hpp +++ b/src/client/lua_api/phys/cbphysmodel.hpp @@ -8,5 +8,5 @@ extern "C" { } #include -int cbphysmodel_register(lua_State* L); +void cbphysmodel_register(lua_State* L); #endif diff --git a/src/client/lua_api/scene/igeneric.cpp b/src/client/lua_api/scene/igeneric.cpp index 63bf4bc..dcac022 100644 --- a/src/client/lua_api/scene/igeneric.cpp +++ b/src/client/lua_api/scene/igeneric.cpp @@ -160,6 +160,23 @@ int iscenesetscale(lua_State *L){ return 1; } +/*** +Sets the visibility of this scene element +@function iscenenode:setvisible(bool) +@tparam boolean visible Sets the visibility for this element +*/ +//setvisible(true|false) +int iscenesetvisible(lua_State *L){ + int visible = lua_toboolean(L,-1); + lua_pop(L,1); + lua_getfield(L, -1, "node"); + ISceneNode *i = (ISceneNode*)lua_touserdata(L,-1);//{node=ud_ISceneNode}, ud_ISceneNode + lua_pop(L,2); + + i->setVisible(visible == 1); + return 0; +} + /*** Get the scale of this scene element. @function iscenenode:getscale() @@ -208,5 +225,6 @@ extern const luaL_reg igeneric_m[] = { {"setscale", iscenesetscale}, {"getscale", iscenegetscale}, {"remove", isceneremove}, + {"setvisible", iscenesetvisible}, {0, 0}, }; diff --git a/src/client/lua_api/scene/ilight.cpp b/src/client/lua_api/scene/ilight.cpp index 972de83..1e292ee 100644 --- a/src/client/lua_api/scene/ilight.cpp +++ b/src/client/lua_api/scene/ilight.cpp @@ -17,6 +17,7 @@ extern "C" { #include using namespace irr; +using namespace video; using namespace scene; using namespace core; @@ -27,9 +28,9 @@ static int newiscenelight(lua_State* L){ printf("Createing light!\n"); double x,y,z; popvector3d(L,&x,&y,&z);//radius - double radius = lua_tonumber(L,-1); + double radius = lua_tonumber(L,-1); lua_pop(L,1);// - + //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); @@ -45,11 +46,23 @@ static int newiscenelight(lua_State* L){ return 1; - } +} + +//settype(self,const) +int settype(lua_State *L){ + video::E_LIGHT_TYPE type = (video::E_LIGHT_TYPE)lua_tonumber(L,-1);//self,type + lua_pop(L,1);//self + lua_getfield(L,-1,"node");//self,ud_ILightSceneNode + ILightSceneNode *light = (ILightSceneNode*)lua_touserdata(L,-1); + lua_pop(L,2);// + light->setLightType(type); + return 0; +} static const luaL_reg ilight_m[] = { {"getpos", iscenegetpos}, {"setpos", iscenesetpos}, + {"settype", settype}, {0, 0}, }; @@ -59,6 +72,10 @@ void ilight_register(lua_State* L){ lua_pushcfunction(L,newiscenelight);//{scene},newiscenelight() lua_setfield(L,-2,"newlight");//{scene} + set_const(L,ELT_POINT); + set_const(L,ELT_SPOT); + set_const(L,ELT_DIRECTIONAL); + lua_pop(L,1);// luaL_newmetatable(L,"scene.ilight");//scene.ilight diff --git a/src/client/lua_api/video/draw.cpp b/src/client/lua_api/video/draw.cpp new file mode 100644 index 0000000..1f38f34 --- /dev/null +++ b/src/client/lua_api/video/draw.cpp @@ -0,0 +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);// +} diff --git a/src/client/lua_api/video/draw.hpp b/src/client/lua_api/video/draw.hpp new file mode 100644 index 0000000..eb5a9a7 --- /dev/null +++ b/src/client/lua_api/video/draw.hpp @@ -0,0 +1,8 @@ + +extern "C" { + #include + #include + #include +} + +void draw_register(lua_State* L); diff --git a/src/client/lua_api/video/smaterial.cpp b/src/client/lua_api/video/smaterial.cpp index 2ef7053..510748c 100644 --- a/src/client/lua_api/video/smaterial.cpp +++ b/src/client/lua_api/video/smaterial.cpp @@ -38,8 +38,22 @@ int setTexture(lua_State* L){ return 0; } +//{Material},flag,state +int setFlag(lua_State* L){ + int b = lua_toboolean(L,-1);//{material},flag,state + lua_pop(L,1);//{material},flag + int flag = lua_tonumber(L,-1);//{material},flag + lua_pop(L,1);//{material} + lua_getfield(L,-1,"smaterial");//{material},ud_material + SMaterial* mat = (SMaterial*)lua_touserdata(L,-1); + lua_pop(L,2); + mat->setFlag((E_MATERIAL_FLAG)flag,b == 1 ? true : false); + return 0; +} + static const luaL_reg smaterial_m[] = { {"setTexture", setTexture}, + {"setFlag", setFlag}, {0,0}, }; diff --git a/src/client/main.cpp b/src/client/main.cpp index f08862c..98b2f61 100644 --- a/src/client/main.cpp +++ b/src/client/main.cpp @@ -1,5 +1,6 @@ #include #include +#include extern "C" { #include #include @@ -134,7 +135,9 @@ int main(int argc, char *argv[]){ L = state; printf("Created lua state at %p\n",L); //Load the lua libraries + assert(lua_gettop(L) == 0); loadLLibs(state); + assert(lua_gettop(L) == 0); //Defined in initdevice.cpp, creates the irrlicht device printf("Argc: %d\n",argc); char *path; @@ -143,7 +146,9 @@ int main(int argc, char *argv[]){ }else{ path = (char*)"../data"; } + assert(lua_gettop(L) == 0); device = spawnIrrDevice(state,path); + assert(lua_gettop(L) == 0); if (!device){ printf("Failed to initalize device\n"); return 1; @@ -152,19 +157,24 @@ int main(int argc, char *argv[]){ //ILogger* log = device->getLogger(); //log->setLogLevel(ELL_NONE); //Loads libraries for interfaceing with irrlicht + assert(lua_gettop(L) == 0); luaL_openlibs(state); + assert(lua_gettop(L) == 0); loadIrrLibs(state,device); + assert(lua_gettop(L) == 0); loadNetLibs(state); + assert(lua_gettop(L) == 0); loadCommonLibs(state); + assert(lua_gettop(L) == 0); printf("Loadded irr libs...\n"); //Sets the global event handeler printf("Creating event receiver\n"); GlobalEventReceiver ger = GlobalEventReceiver(device); printf("Created event receiver\n"); device->setEventReceiver(&ger); - + assert(lua_gettop(L) == 0); pusherrorfunc(L);//errfunc - int err = luaL_loadfile(state,"init.lua"); + int err = luaL_loadfile(state,"init.lua");//errfunc,init() printf("Error loading init.lua: %d\n",err); switch(err){//errmsg or nothing case 0: @@ -181,8 +191,10 @@ int main(int argc, char *argv[]){ } //errfunc,initfile() printf("Loaded file\n"); - lua_pcall(state,0,0,-2); + lua_pcall(state,0,0,-2);//errfunc() + lua_pop(L,1);// printf("Finished running init.lua"); + assert(lua_gettop(L) == 0); //int iErr = luaL_dofile(state,"init.lua"); //if(iErr != 0){ //printf("Failed to open lua file:%s/init.lua\n",path); @@ -205,14 +217,21 @@ int main(int argc, char *argv[]){ printf("Device is %p\n",device); while(device->run()){ //printf("Start gameloop net\n"); + assert(lua_gettop(L) == 0); gameloop_net(L); + assert(lua_gettop(L) == 0); //printf("End gameloop net\n"); //printf("Start gameloop phys\n"); + assert(lua_gettop(L) == 0); gameloop_phys(UpdateElement); + assert(lua_gettop(L) == 0); //printf("End gameloop phys\n"); if(device->isWindowActive()){ + assert(lua_gettop(L) == 0); driver->beginScene(true, true, background); + assert(lua_gettop(L) == 0); //printf("Device active, began scene\n"); + assert(lua_gettop(L) == 0); pusherrorfunc(state); lua_getglobal(state,"GAME");//err(),{GAME} lua_getfield(state,-1,"draw");//err(),{GAME},GAME.draw() @@ -222,10 +241,12 @@ int main(int argc, char *argv[]){ }else{ lua_pop(state,3); } + assert(lua_gettop(L) == 0); //printf("Finished calling GAME.draw()\n"); smgr->drawAll(); //printf("Scene manager drew all\n"); + assert(lua_gettop(L) == 0); lua_getglobal(state,"GAME"); lua_getfield(state,-1,"drawPostScene"); if(!lua_isnil(state,-1)){ @@ -234,9 +255,11 @@ int main(int argc, char *argv[]){ }else{ lua_pop(state,2); } + assert(lua_gettop(L) == 0); //printf("Post draw scene completed\n"); guienv->drawAll(); //printf("Gui draw all completed\n"); + assert(lua_gettop(L) == 0); lua_getglobal(state,"GAME"); lua_getfield(state,-1,"drawPostGui"); if(!lua_isnil(state,-1)){ @@ -245,23 +268,29 @@ int main(int argc, char *argv[]){ }else{ lua_pop(state,2); } + assert(lua_gettop(L) == 0); //printf("GAME.drawPostGui completed\n"); driver->endScene(); }else{ + assert(lua_gettop(L) == 0); device->yield(); + assert(lua_gettop(L) == 0); } - lua_getglobal(state,"GAME");//{} - lua_getfield(state,-1,"tick");//{},function_tick() + assert(lua_gettop(L) == 0); + pusherrorfunc(L);//errfunc() + lua_getglobal(state,"GAME");//errfunc(),{} + lua_getfield(state,-1,"tick");//errfunc(),{},function_tick() if(!lua_isnil(state,-1)){ - lua_call(state,0,0); - lua_pop(state,1); - }else{ - lua_pop(state,2); + lua_pcall(state,0,0,-3);//errfunc(),{} + lua_pop(state,2);// + }else{//errfunc(),{},nil + lua_pop(state,3);// } + assert(lua_gettop(L) == 0); } + assert(lua_gettop(L) == 0); //phys_shutdown(RemoveISceneNode); phys_shutdown(); - device->drop(); printf("Goodbye\n"); return 0; -- cgit v1.2.3-70-g09d2