diff options
Diffstat (limited to 'src/client/main.cpp')
| -rw-r--r-- | src/client/main.cpp | 49 |
1 files changed, 39 insertions, 10 deletions
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 <stdio.h> #include <stdlib.h> +#include <assert.h> extern "C" { #include <lua.h> #include <lauxlib.h> @@ -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; |
