aboutsummaryrefslogtreecommitdiff
path: root/src/client/initdevice.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/initdevice.cpp
downloadbrokengine-d2b36e6c65ec8126c0ebc96adb7e011e78a5eacc.tar.gz
brokengine-d2b36e6c65ec8126c0ebc96adb7e011e78a5eacc.tar.bz2
brokengine-d2b36e6c65ec8126c0ebc96adb7e011e78a5eacc.zip
Initial commit
Diffstat (limited to 'src/client/initdevice.cpp')
-rw-r--r--src/client/initdevice.cpp189
1 files changed, 189 insertions, 0 deletions
diff --git a/src/client/initdevice.cpp b/src/client/initdevice.cpp
new file mode 100644
index 0000000..814dd67
--- /dev/null
+++ b/src/client/initdevice.cpp
@@ -0,0 +1,189 @@
+
+extern "C" {
+ #include <lua.h>
+ #include <lauxlib.h>
+ #include <lualib.h>
+}
+#include <irrlicht.h>
+
+#include "initdevice.hpp"
+
+using namespace irr;
+using namespace core;
+using namespace scene;
+using namespace video;
+using namespace io;
+using namespace gui;
+
+struct settings{
+ u8 aa;
+ u8 bits;
+ E_DEVICE_TYPE dtype;
+ u32 adapter;
+ bool doublebuffer;
+ bool multithread;
+ E_DRIVER_TYPE driver;
+ bool fullscreen;
+ bool stencilbuffer;
+ bool stereobuffer;
+ bool performancetimers;
+ bool vsync;
+ dimension2d<u32> windowsize;
+ u8 zbuffer;
+};
+
+void parseSetting(const char* settingname, lua_State* L, settings* set){
+ if(strcmp(settingname,"Anti Alias") == 0){
+ if(lua_isnumber(L,-1)){
+ set->aa = lua_tonumber(L,-1);
+ }else{
+ printf("Setting \"Anti Alias\" must be a number.\n");
+ }
+ }else if(strcmp(settingname,"Bits Per Pixel") == 0){
+ if(lua_isnumber(L,-1)){
+ set->bits = lua_tonumber(L,-1);
+ }else{
+ printf("Setting \"Bits Per Pixel\" must be a number.\n");
+ }
+ }else if(strcmp(settingname,"Device Type") == 0){
+ if(lua_isstring(L,-1)){
+ const char* dtn = lua_tostring(L,-1);
+ if(strcmp(dtn,"WIN32") == 0){
+ set->dtype = irr::EIDT_WIN32;
+ }else if(strcmp(dtn,"WINCE") == 0){
+ set->dtype = irr::EIDT_WINCE;
+ }else if(strcmp(dtn,"OSX") == 0){
+ set->dtype = irr::EIDT_OSX;
+ }else if(strcmp(dtn,"X11") == 0){
+ set->dtype = irr::EIDT_X11;
+ }else if(strcmp(dtn,"SDL") == 0){
+ set->dtype = irr::EIDT_SDL;
+ }else if(strcmp(dtn,"CONSOLE") == 0){
+ set->dtype = irr::EIDT_CONSOLE;
+ }else if(strcmp(dtn,"BEST") == 0){
+ set->dtype = irr::EIDT_BEST;
+ }
+ }else{
+ printf("Setting \"Device Type\" must be a string\n");
+ }
+ }else if(strcmp(settingname,"Display Adapter") == 0){
+ if(lua_isnumber(L,-1)){
+ set->adapter = lua_tonumber(L,-1);
+ }else{
+ printf("Setting \"Display Adapter\" must be a number\n");
+ }
+ }else if(strcmp(settingname,"Double Buffer") == 0){
+ if(lua_isboolean(L,-1)){
+ set->doublebuffer = lua_toboolean(L,-1) == 1;
+ }else{
+ printf("Setting \"Double Buffer\" must be a boolean\n");
+ }
+ }else if(strcmp(settingname,"Multithreaded") == 0){
+ if(lua_isboolean(L,-1)){
+ set->multithread = lua_toboolean(L,-1) == 1;
+ }else{
+ printf("Setting \"Multithreaded\" must be a boolean\n");
+ }
+ }else if(strcmp(settingname,"Driver Type") == 0){
+ if(lua_isstring(L,-1)){
+ const char* dts = lua_tostring(L,-1);
+ if(strcmp(dts,"NULL") == 0){
+ set->driver = EDT_NULL;
+ }else if(strcmp(dts,"SOFTWARE") == 0){
+ set->driver = EDT_SOFTWARE;
+ }else if(strcmp(dts,"BURNINGS") == 0){
+ set->driver = EDT_BURNINGSVIDEO;
+ }else if(strcmp(dts,"D3D8") == 0){
+ set->driver = EDT_DIRECT3D8;
+ }else if(strcmp(dts,"D3D9") == 0){
+ set->driver = EDT_DIRECT3D9;
+ }else if(strcmp(dts,"OPENGL") == 0){
+ set->driver = EDT_OPENGL;
+ }
+ }else{
+ printf("Setting \"Driver Type\" must be a string\n");
+ }
+ }else if(strcmp(settingname,"Fullscreen") == 0){
+ if(lua_isboolean(L,-1)){
+ set->fullscreen = lua_toboolean(L,-1) == 1;
+ }else{
+ printf("Setting \"Fullscreen\" must be a boolean\n");
+ }
+ }else if(strcmp(settingname,"Stencil Buffer") == 0){
+ if(lua_isboolean(L,-1)){
+ set->stencilbuffer = lua_toboolean(L,-1) == 1;
+ }else{
+ printf("Setting \"Stencil Buffer\" must be a boolean\n");
+ }
+ }else if(strcmp(settingname,"Stereo Buffer") == 0){
+ if(lua_isboolean(L,-1)){
+ set->stereobuffer = lua_toboolean(L,-1) == 1;
+ }else{
+ printf("Setting \"Stereo Buffer\" must be a boolean\n");
+ }
+ }else if(strcmp(settingname,"VSync") == 0){
+ if(lua_isboolean(L,-1)){
+ set->vsync = lua_toboolean(L,-1) == 1;
+ }else{
+ printf("Setting \"VSync\" must be a boolean\n");
+ }
+ }else if(strcmp(settingname,"Window Width") == 0){
+ if(lua_isnumber(L,-1)){
+ set->windowsize.Width = lua_tonumber(L,-1);
+ }else{
+ printf("Setting \"Window Width\" must be a number");
+ }
+ }else if(strcmp(settingname,"Window Height") == 0){
+ if(lua_isnumber(L,-1)){
+ set->windowsize.Height = lua_tonumber(L,-1);
+ }else{
+ printf("Setting \"Window Height\" must be a number");
+ }
+ }
+}
+
+void settingsFromTable(lua_State *L, SIrrlichtCreationParameters* p){
+ lua_pushnil(L);
+ settings* set = (settings*)malloc(sizeof(settings));
+ while(lua_next(L,-2) != 0){
+ printf("%s - %s\n",
+ lua_typename(L, lua_type(L, -2)),
+ lua_typename(L, lua_type(L, -1)));
+ if(lua_isstring(L,-2)){
+ const char* setstr = lua_tostring(L,-2);
+ printf("\tFound setting %s\n",setstr);
+ parseSetting(setstr,L,set);
+ }else{
+ printf("\tFound a non-string setting key! Key is a %s\n",luaL_typename(L,-1));
+ }
+ lua_pop(L,1);
+ }
+ p->AntiAlias = set->aa;
+ p->Bits = set->bits;
+ p->DeviceType = set->dtype;
+ p->DisplayAdapter = set->adapter;
+ p->DriverMultithreaded = set->multithread;
+ p->DriverType = set->driver;
+ p->Fullscreen = set->fullscreen;
+ p->Stencilbuffer = set->stencilbuffer;
+ p->Vsync = set->vsync;
+ p->WindowSize = set->windowsize;
+ p->ZBufferBits = set->zbuffer;
+ free(set);
+ printf("Settings loaded");
+}
+
+IrrlichtDevice* spawnIrrDevice(lua_State* L){
+ printf("Attempting to load settings...\n");
+ int iErr = luaL_dofile(L,"../data/deviceinit.lua");
+ SIrrlichtCreationParameters p = SIrrlichtCreationParameters();
+ settingsFromTable(L,&p);
+ if(iErr != 0){
+ printf("Failed to open lua file:/data/deviceinit.lua\n");
+ }
+ IrrlichtDevice* dev = createDeviceEx(p);
+ if(!dev)
+ exit(1);
+ dev->setWindowCaption(L"Borkengin");
+ return dev;
+}