diff options
| author | Alexander <alex@cogarr.net> | 2019-02-10 18:10:14 -0500 |
|---|---|---|
| committer | Alexander <alex@cogarr.net> | 2019-02-10 18:10:14 -0500 |
| commit | 5478f357b62062ffccfecb4c7b5fc607f0e7a518 (patch) | |
| tree | c850f7137cd350962c3911ce11f94da55f41d0d0 /src/client | |
| parent | 6326eba6d844d079edf51b44bab8b9f9c21a8fb7 (diff) | |
| download | brokengine-5478f357b62062ffccfecb4c7b5fc607f0e7a518.tar.gz brokengine-5478f357b62062ffccfecb4c7b5fc607f0e7a518.tar.bz2 brokengine-5478f357b62062ffccfecb4c7b5fc607f0e7a518.zip | |
Corrected networking examples
changed the api for interacting with sockets, sockets
now have a callback, `socket:receive(function(stream) ... end)`, which
they can use to decide what to do when called.
Sockets also have a block:recv() function, which will block EVERYTHING
until the socket receives data. This should probably not be used.
Diffstat (limited to 'src/client')
| -rw-r--r-- | src/client/main.cpp | 56 |
1 files changed, 42 insertions, 14 deletions
diff --git a/src/client/main.cpp b/src/client/main.cpp index e8533d8..6e515ad 100644 --- a/src/client/main.cpp +++ b/src/client/main.cpp @@ -109,12 +109,6 @@ void UpdateElement(btRigidBody* TObject){ SColor background = SColor(255,100,101,140); //setbackgroundcolor(r,g,b) -int setbackgroundcolor(lua_State* L){ - long r,g,b; - popvector3i(L,&r,&g,&b); - background = SColor(255,r,g,b); - return 0; -} int main(int argc, char *argv[]){ printf("Brok[en]gine Client\n"); @@ -125,6 +119,7 @@ int main(int argc, char *argv[]){ //Create a new lua state, this gets shared everywhere //Set the path for lua putenv("LUA_PATH=?.lua"); + putenv("LUA_CPATH=../bin/?.dll"); lua_State *state = luaL_newstate(); L = state; printf("Created lua state at %p\n",L); @@ -156,11 +151,29 @@ int main(int argc, char *argv[]){ GlobalEventReceiver ger = GlobalEventReceiver(device); printf("Created event receiver\n"); device->setEventReceiver(&ger); - int iErr = luaL_dofile(state,"init.lua"); - if(iErr != 0){ - printf("Failed to open lua file:%s/init.lua\n",path); - lua_error(state); + + pusherrorfunc(L);//errfunc + switch(luaL_loadfile(state,"init.lua")){//errmsg or nothing + case 0: + break; //no error + case LUA_ERRSYNTAX: + printf("Syntax error, failed to load: %s\n%s","../data/init.lua",lua_tostring(L,-1)); + break; + case LUA_ERRMEM: + printf("Failed to allocate memroy\n"); + break; + case LUA_ERRFILE: + printf("Could not find file: %s\n","../data/init.lua"); + break; } + //errfunc,initfile() + printf("Loaded file\n"); + lua_pcall(state,0,0,-2); + //int iErr = luaL_dofile(state,"init.lua"); + //if(iErr != 0){ + //printf("Failed to open lua file:%s/init.lua\n",path); + //lua_error(state); + //} //Load some bullet physics stuff driver = device->getVideoDriver(); @@ -171,10 +184,9 @@ int main(int argc, char *argv[]){ printf("Everything registered, about to start running device!\n"); - lua_getglobal(L,"GAME"); - lua_pushcfunction(L,setbackgroundcolor); - lua_setfield(L,-2,"setbackgroundcolor"); - lua_pop(L,1); + lua_getglobal(state,"GAME");//{game} + lua_pop(state,1);// + printf("About to check if device run\n"); printf("Device is %p\n",device); while(device->run()){ @@ -197,7 +209,23 @@ int main(int argc, char *argv[]){ } smgr->drawAll(); + lua_getglobal(state,"GAME"); + lua_getfield(state,-1,"drawPostScene"); + if(!lua_isnil(state,-1)){ + lua_call(state,0,0); + lua_pop(state,1); + }else{ + lua_pop(state,2); + } guienv->drawAll(); + lua_getglobal(state,"GAME"); + lua_getfield(state,-1,"drawPostGui"); + if(!lua_isnil(state,-1)){ + lua_call(state,0,0); + lua_pop(state,1); + }else{ + lua_pop(state,2); + } driver->endScene(); }else{ device->yield(); |
