From 632a759ee66ed90798ca63ed2f1ca9e4e31772d7 Mon Sep 17 00:00:00 2001 From: Deve Date: Sat, 6 May 2017 22:38:05 +0200 Subject: [PATCH] Allow to choose device type using environmental variable --- lib/irrlicht/source/Irrlicht/Irrlicht.cpp | 106 ++++++++++++++++++---- 1 file changed, 87 insertions(+), 19 deletions(-) diff --git a/lib/irrlicht/source/Irrlicht/Irrlicht.cpp b/lib/irrlicht/source/Irrlicht/Irrlicht.cpp index 4c6a1746e..9418cc6f3 100644 --- a/lib/irrlicht/source/Irrlicht/Irrlicht.cpp +++ b/lib/irrlicht/source/Irrlicht/Irrlicht.cpp @@ -51,6 +51,8 @@ #include #endif +#include + namespace irr { //! stub for calling createDeviceEx @@ -72,63 +74,129 @@ namespace irr return createDeviceEx(p); } + + static void overrideDeviceType(E_DEVICE_TYPE& device_type) + { + const char* irr_device_type = getenv("IRR_DEVICE_TYPE"); + + if (irr_device_type == NULL) + return; + +#ifdef _IRR_COMPILE_WITH_WINDOWS_DEVICE_ + if (strcmp(irr_device_type, "win32") == 0) + { + device_type = EIDT_WIN32; + } +#endif +#ifdef _IRR_COMPILE_WITH_OSX_DEVICE_ + if (strcmp(irr_device_type, "osx") == 0) + { + device_type = EIDT_OSX; + } +#endif +#ifdef _IRR_COMPILE_WITH_WINDOWS_CE_DEVICE_ + if (strcmp(irr_device_type, "wince") == 0) + { + device_type = EIDT_WINCE; + } +#endif +#ifdef _IRR_COMPILE_WITH_WAYLAND + if (strcmp(irr_device_type, "wayland") == 0) + { + device_type = EIDT_WAYLAND; + } +#endif +#ifdef _IRR_COMPILE_WITH_X11_DEVICE_ + if (strcmp(irr_device_type, "x11") == 0) + { + device_type = EIDT_X11; + } +#endif +#ifdef _IRR_COMPILE_WITH_SDL_DEVICE_ + if (strcmp(irr_device_type, "sdl") == 0) + { + device_type = EIDT_SDL; + } +#endif +#ifdef _IRR_COMPILE_WITH_FB_DEVICE_ + if (strcmp(irr_device_type, "framebuffer") == 0) + { + device_type = EIDT_FRAMEBUFFER; + } +#endif +#ifdef _IRR_COMPILE_WITH_ANDROID_DEVICE_ + if (strcmp(irr_device_type, "android") == 0) + { + device_type = EIDT_ANDROID; + } +#endif +#ifdef _IRR_COMPILE_WITH_CONSOLE_DEVICE_ + if (strcmp(irr_device_type, "console") == 0) + { + device_type = EIDT_CONSOLE; + } +#endif + } extern "C" IRRLICHT_API IrrlichtDevice* IRRCALLCONV createDeviceEx(const SIrrlichtCreationParameters& params) { IrrlichtDevice* dev = 0; + + SIrrlichtCreationParameters creation_params = params; + overrideDeviceType(creation_params.DeviceType); #ifdef _IRR_COMPILE_WITH_WINDOWS_DEVICE_ - if (params.DeviceType == EIDT_WIN32 || (!dev && params.DeviceType == EIDT_BEST)) - dev = new CIrrDeviceWin32(params); + if (creation_params.DeviceType == EIDT_WIN32 || (!dev && creation_params.DeviceType == EIDT_BEST)) + dev = new CIrrDeviceWin32(creation_params); #endif #ifdef _IRR_COMPILE_WITH_OSX_DEVICE_ - if (params.DeviceType == EIDT_OSX || (!dev && params.DeviceType == EIDT_BEST)) - dev = new CIrrDeviceMacOSX(params); + if (creation_params.DeviceType == EIDT_OSX || (!dev && creation_params.DeviceType == EIDT_BEST)) + dev = new CIrrDeviceMacOSX(creation_params); #endif #ifdef _IRR_COMPILE_WITH_WINDOWS_CE_DEVICE_ - if (params.DeviceType == EIDT_WINCE || (!dev && params.DeviceType == EIDT_BEST)) - dev = new CIrrDeviceWinCE(params); + if (creation_params.DeviceType == EIDT_WINCE || (!dev && creation_params.DeviceType == EIDT_BEST)) + dev = new CIrrDeviceWinCE(creation_params); #endif #ifdef _IRR_COMPILE_WITH_WAYLAND - if (params.DeviceType == EIDT_WAYLAND || (!dev && params.DeviceType == EIDT_BEST)) + if (creation_params.DeviceType == EIDT_WAYLAND || (!dev && creation_params.DeviceType == EIDT_BEST)) { if (CIrrDeviceWayland::isWaylandDeviceWorking()) { - dev = new CIrrDeviceWayland(params); + dev = new CIrrDeviceWayland(creation_params); } } #endif #ifdef _IRR_COMPILE_WITH_X11_DEVICE_ - if (params.DeviceType == EIDT_X11 || (!dev && params.DeviceType == EIDT_BEST)) - dev = new CIrrDeviceLinux(params); + if (creation_params.DeviceType == EIDT_X11 || (!dev && creation_params.DeviceType == EIDT_BEST)) + dev = new CIrrDeviceLinux(creation_params); #endif #ifdef _IRR_COMPILE_WITH_SDL_DEVICE_ - if (params.DeviceType == EIDT_SDL || (!dev && params.DeviceType == EIDT_BEST)) - dev = new CIrrDeviceSDL(params); + if (creation_params.DeviceType == EIDT_SDL || (!dev && creation_params.DeviceType == EIDT_BEST)) + dev = new CIrrDeviceSDL(creation_params); #endif #ifdef _IRR_COMPILE_WITH_FB_DEVICE_ - if (params.DeviceType == EIDT_FRAMEBUFFER || (!dev && params.DeviceType == EIDT_BEST)) - dev = new CIrrDeviceFB(params); + if (creation_params.DeviceType == EIDT_FRAMEBUFFER || (!dev && creation_params.DeviceType == EIDT_BEST)) + dev = new CIrrDeviceFB(creation_params); #endif #ifdef _IRR_COMPILE_WITH_ANDROID_DEVICE_ - if (params.DeviceType == EIDT_ANDROID || (!dev && params.DeviceType == EIDT_BEST)) - dev = new CIrrDeviceAndroid(params); + if (creation_params.DeviceType == EIDT_ANDROID || (!dev && creation_params.DeviceType == EIDT_BEST)) + dev = new CIrrDeviceAndroid(creation_params); #endif #ifdef _IRR_COMPILE_WITH_CONSOLE_DEVICE_ - if (params.DeviceType == EIDT_CONSOLE || (!dev && params.DeviceType == EIDT_BEST)) - dev = new CIrrDeviceConsole(params); + if (creation_params.DeviceType == EIDT_CONSOLE || (!dev && creation_params.DeviceType == EIDT_BEST)) + dev = new CIrrDeviceConsole(creation_params); #endif - if (dev && !dev->getVideoDriver() && params.DriverType != video::EDT_NULL) + if (dev && !dev->getVideoDriver() && creation_params.DriverType != video::EDT_NULL) { dev->closeDevice(); // destroy window dev->run(); // consume quit message