#include #include extern "C" { #include #include #include } #include #include #include #include "initdevice.hpp" #include "menuhandeler.hpp" #include "lua_api/load_gui.hpp" #include "lua_api/load_game.hpp" #include "lua_api/load_core.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); } lua_State* L; void loadIrrLibs(lua_State* L, IrrlichtDevice* device){ printf("Loading guifuncs...\n"); load_guifuncs(L,device); load_gamefuncs(L,device); load_corefuncs(L,device); } int main(int argc, char *argv[]){ //Create a new lua state, this gets shared everywhere lua_State *state = luaL_newstate(); L = state; //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(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); device->drop(); return 0; }