aboutsummaryrefslogtreecommitdiff
path: root/src/client/main.cpp
diff options
context:
space:
mode:
authorAlexander Pickering <alexandermpickering@gmail.com>2016-11-01 00:28:16 -0400
committerAlexander Pickering <alexandermpickering@gmail.com>2016-11-01 00:28:16 -0400
commitd2b36e6c65ec8126c0ebc96adb7e011e78a5eacc (patch)
tree9e005502ea2c125c90b5011f573f381f84ade0ef /src/client/main.cpp
downloadbrokengine-d2b36e6c65ec8126c0ebc96adb7e011e78a5eacc.tar.gz
brokengine-d2b36e6c65ec8126c0ebc96adb7e011e78a5eacc.tar.bz2
brokengine-d2b36e6c65ec8126c0ebc96adb7e011e78a5eacc.zip
Initial commit
Diffstat (limited to 'src/client/main.cpp')
-rw-r--r--src/client/main.cpp93
1 files changed, 93 insertions, 0 deletions
diff --git a/src/client/main.cpp b/src/client/main.cpp
new file mode 100644
index 0000000..4e284c5
--- /dev/null
+++ b/src/client/main.cpp
@@ -0,0 +1,93 @@
+#include <stdio.h>
+#include <stdlib.h>
+extern "C" {
+ #include <lua.h>
+ #include <lauxlib.h>
+ #include <lualib.h>
+}
+#include <irrlicht.h>
+
+#include <btBulletDynamicsCommon.h>
+#include <cstdlib>
+
+#include "initdevice.hpp"
+#include "menuhandeler.hpp"
+#include "lua_api/load_gui.hpp"
+#include "lua_api/load_game.hpp"
+#include "callbackhandeler.hpp"
+
+using namespace irr;
+using namespace core;
+using namespace scene;
+using namespace video;
+using namespace io;
+using namespace gui;
+
+void loadLLibs(lua_State* L){
+ luaopen_base(L);
+ luaopen_table(L);
+ luaopen_io(L);
+ luaopen_string(L);
+ luaopen_math(L);
+}
+
+void loadIrrLibs(lua_State* L, IrrlichtDevice* device){
+ printf("Loading guifuncs...\n");
+ load_guifuncs(L,device);
+ load_gamefuncs(L,device);
+}
+
+int main(int argc, char *argv[]){
+ //Create a new lua state, this gets shared everywhere
+ lua_State *state = luaL_newstate();
+ //Load the lua libraries
+ loadLLibs(state);
+ //Defined in initdevice.cpp, creates the irrlicht device
+ IrrlichtDevice *device = spawnIrrDevice(state);
+ if (!device)
+ return 1;
+ //Loads libraries for interfaceing with irrlicht
+ loadIrrLibs(state,device);
+ printf("Loadded irr libs...\n");
+ //Sets the global event handeler
+ GlobalEventReceiver ger = GlobalEventReceiver(device);
+ device->setEventReceiver(&ger);
+ int iErr = luaL_dofile(state,"../data/guitest.lua");
+ if(iErr != 0){
+ lua_error(state);
+ printf("Failed to open lua file:../data/guitest.lua\n");
+ }
+
+
+
+ device->setWindowCaption(L"Bork[en]gine Demo");
+
+ //Load some menu
+ loadMenu("Some menu",device);
+
+ IVideoDriver* driver = device->getVideoDriver();
+ ISceneManager* smgr = device->getSceneManager();
+ IGUIEnvironment* guienv = device->getGUIEnvironment();
+
+ guienv->addStaticText(L"Hello World! This is the Irrlicht Software renderer!",
+ rect<s32>(10,10,260,22), true);
+
+ smgr->addCameraSceneNode(0, vector3df(0,30,-40), vector3df(0,5,0));
+
+ printf("Everything registered, about to start running device!\n");
+
+ while(device->run()){
+ driver->beginScene(true, true, SColor(255,100,101,140));
+
+ smgr->drawAll();
+ guienv->drawAll();
+
+ driver->endScene();
+ lua_getglobal(state,"GAME");
+ lua_getfield(state,-1,"tick");
+ if(!lua_isnil(state,-1))
+ lua_call(state,0,0);
+ }
+ lua_close(state);
+ return 0;
+}