aboutsummaryrefslogtreecommitdiff
path: root/src/server/main.cpp
diff options
context:
space:
mode:
authorAlexander <alex@cogarr.net>2019-02-10 18:10:14 -0500
committerAlexander <alex@cogarr.net>2019-02-10 18:10:14 -0500
commit5478f357b62062ffccfecb4c7b5fc607f0e7a518 (patch)
treec850f7137cd350962c3911ce11f94da55f41d0d0 /src/server/main.cpp
parent6326eba6d844d079edf51b44bab8b9f9c21a8fb7 (diff)
downloadbrokengine-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/server/main.cpp')
-rw-r--r--src/server/main.cpp77
1 files changed, 60 insertions, 17 deletions
diff --git a/src/server/main.cpp b/src/server/main.cpp
index 2464899..b326e5f 100644
--- a/src/server/main.cpp
+++ b/src/server/main.cpp
@@ -23,9 +23,14 @@ extern "C" {
#include <shared/phys/physcommon.hpp>
#include <shared/util/hashmap.hpp>
+#include <server/lua_api/load_game.hpp>
+#include <server/lua_api/load_io.hpp>
+
using namespace std;
using namespace chrono;
+bool game_active = true;
+
void dropRigidBody(btRigidBody* rb){
}
@@ -40,43 +45,81 @@ void gameloop(){
//printf("done net\n");
}
-int main (){
+int main (int argc, char *argv[]){
printf("Brok[en]gine Server\n");
-
- putenv("LUA_PATH=../data/?.lua");
+ game_active = true;
+ char *path;
+ if(argc == 2){
+ path = argv[1];
+ }else{
+ path = (char*)"../data";
+ }
+ size_t envstrsize = snprintf(NULL,0,"LUA_PATH=%s/?.lua",path);
+ char envstr[envstrsize];
+ sprintf(envstr,"LUA_PATH=%s/?.lua",path);
+ putenv(envstr);
+ //printf("Put lua path\n");
L = luaL_newstate();
-
- lua_newtable(L);//{}
- lua_setglobal(L,"GAME");//
+ //printf("Created lua state\n");
+ //lua_newtable(L);//{}
+ //lua_setglobal(L,"GAME");//
+ load_gamefuncs(L);
+ printf("Created global table\n");
phys_genesis();
+ printf("Started phys\n");
luaL_openlibs(L);
+ printf("Opened standard libs\n");
loadLLibs(L);
+ printf("Opened aux libs\n");
loadNetLibs(L);
+ printf("Opened net libs\n");
load_physfuncs(L);
- int iErr = luaL_dofile(L,"../data/init.lua");
- if(iErr != 0){
- printf("Failed to open lua file:../data/init.lua\n");
- lua_error(L);
+ printf("Opened phys libs\n");
+ load_iofuncs(L);
+ printf("About to push error func\n");
+ pusherrorfunc(L);//errfunc
+ printf("pushed error func\n");
+ size_t init_file_path_len = snprintf(NULL,0,"%s/init.lua",path);
+ char init_file_path[init_file_path_len];
+ sprintf(init_file_path,"%s/init.lua",path);
+ switch(luaL_loadfile(L,init_file_path)){
+ case 0:
+ break; //no error
+ case LUA_ERRSYNTAX:
+ printf("Syntax error, failed to load: %s\n%s",init_file_path,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",init_file_path);
+ break;
}
+ //errfunc,initfile()
+ printf("Loaded file\n");
+ lua_pcall(L,0,0,-2);
do{
- printf("Start of server gameloop\n");
+ //printf("Start of server gameloop\n");
gameloop();
- printf("Gameloop\n");
- std::this_thread::yield();
- printf("Thread yeild\n");
+ //printf("Gameloop\n");
+ //std::this_thread::yield();
+ std::this_thread::sleep_for(std::chrono::milliseconds(100));
+ //printf("Thread yeild\n");
lua_getglobal(L,"GAME");//{}
lua_getfield(L,-1,"tick");//{},function_tick()
- printf("Found game tick\n");
if(!lua_isnil(L,-1)){
+ //printf("Found game tick\n");
lua_call(L,0,0);
lua_pop(L,1);
}else{
+ //printf("Did not find tick function\n");
lua_pop(L,2);
}
- printf("End of server gameloop\n");
- }while(true);
+ //printf("End of server gameloop\n");
+ }while(game_active);
phys_shutdown();
+ printf("Goodbye\n");
return 0;
}