aboutsummaryrefslogtreecommitdiff
path: root/src/server/main.cpp
blob: 246489978c2873d94d08dc314275c2a9e966e9c3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include <stdio.h>
#include <stdlib.h>
extern "C" {
  #include <lua.h>
  #include <lauxlib.h>
  #include <lualib.h>
}

//C++ things
#include <vector>
#include <thread>
#include <list>

#include <string.h> // for strstr()

#include <btBulletDynamicsCommon.h>
#include <cstdlib>

#include <shared/lua_api/common.hpp>
#include <shared/lua_api/load_net.hpp>
#include <shared/lua_api/load_phys.hpp>
#include <shared/phys/physcommon.hpp>
#include <shared/util/hashmap.hpp>

using namespace std;
using namespace chrono;

void dropRigidBody(btRigidBody* rb){
}

void dropChar(btKinematicCharacterController *a){
}

lua_State* L;
void gameloop(){
	gameloop_phys(NULL);
	//printf("done physics\n");
	gameloop_net(L);
	//printf("done net\n");
}

int main (){
	printf("Brok[en]gine Server\n");

	putenv("LUA_PATH=../data/?.lua");
	L = luaL_newstate();

	lua_newtable(L);//{}
	lua_setglobal(L,"GAME");//

	phys_genesis();
	luaL_openlibs(L);
	loadLLibs(L);
	loadNetLibs(L);
	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);
	}
	do{
		printf("Start of server gameloop\n");
		gameloop();
		printf("Gameloop\n");
		std::this_thread::yield();
		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)){
			lua_call(L,0,0);
			lua_pop(L,1);
		}else{
			lua_pop(L,2);
		}
		printf("End of server gameloop\n");
	}while(true);
	phys_shutdown();

	return 0;
}