From f8841f96f279fe4c479779364f3f06914cf8bc02 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Fri, 31 Oct 2014 20:05:06 +0100 Subject: Added -headless For automated stuff on devices without GPU --- src/app/app.cpp | 76 ++++++++++++++++++++++++++++++++++++--------------------- src/app/app.h | 6 ++--- 2 files changed, 51 insertions(+), 31 deletions(-) (limited to 'src/app') diff --git a/src/app/app.cpp b/src/app/app.cpp index 513fc27..93fb554 100644 --- a/src/app/app.cpp +++ b/src/app/app.cpp @@ -31,6 +31,7 @@ #include "common/resources/resourcemanager.h" #include "graphics/engine/modelmanager.h" +#include "graphics/core/nulldevice.h" #include "graphics/opengl/gldevice.h" #include "object/robotmain.h" @@ -168,6 +169,7 @@ CApplication::CApplication() m_runSceneRank = 0; m_sceneTest = false; + m_headless = false; m_resolutionOverride = false; m_language = LANGUAGE_ENV; @@ -228,7 +230,8 @@ ParseArgsStatus CApplication::ParseArguments(int argc, char *argv[]) OPT_SAVEDIR, OPT_MOD, OPT_VBO, - OPT_RESOLUTION + OPT_RESOLUTION, + OPT_HEADLESS }; option options[] = @@ -245,6 +248,7 @@ ParseArgsStatus CApplication::ParseArguments(int argc, char *argv[]) { "mod", required_argument, nullptr, OPT_MOD }, { "vbo", required_argument, nullptr, OPT_VBO }, { "resolution", required_argument, nullptr, OPT_RESOLUTION }, + { "headless", no_argument, nullptr, OPT_HEADLESS }, { nullptr, 0, nullptr, 0} }; @@ -287,6 +291,7 @@ ParseArgsStatus CApplication::ParseArguments(int argc, char *argv[]) GetLogger()->Message(" -mod path load datadir mod from given path\n"); GetLogger()->Message(" -vbo mode set OpenGL VBO mode (one of: auto, enable, disable)\n"); GetLogger()->Message(" -resolution WxH set resolution\n"); + GetLogger()->Message(" -headless headless mode - disables graphics, sound and user interaction\n"); return PARSE_ARGS_HELP; } case OPT_DEBUG: @@ -402,6 +407,11 @@ ParseArgsStatus CApplication::ParseArguments(int argc, char *argv[]) m_resolutionOverride = true; break; } + case OPT_HEADLESS: + { + m_headless = true; + break; + } default: assert(false); // should never get here } @@ -460,7 +470,11 @@ bool CApplication::Create() //Create the sound instance. #ifdef OPENAL_SOUND - m_sound = static_cast(new ALSound()); + if(!m_headless) { + m_sound = static_cast(new ALSound()); + } else { + m_sound = new CSoundInterface(); + } #else GetLogger()->Info("No sound support.\n"); m_sound = new CSoundInterface(); @@ -505,35 +519,37 @@ bool CApplication::Create() return false; } - // load settings from profile - int iValue; - if ( GetProfile().GetIntProperty("Setup", "Resolution", iValue) && !m_resolutionOverride ) - { - std::vector modes; - GetVideoResolutionList(modes, true, true); - if (static_cast(iValue) < modes.size()) - m_deviceConfig.size = modes.at(iValue); - } + if(!m_headless) { + // load settings from profile + int iValue; + if ( GetProfile().GetIntProperty("Setup", "Resolution", iValue) && !m_resolutionOverride ) + { + std::vector modes; + GetVideoResolutionList(modes, true, true); + if (static_cast(iValue) < modes.size()) + m_deviceConfig.size = modes.at(iValue); + } - if ( GetProfile().GetIntProperty("Setup", "Fullscreen", iValue) && !m_resolutionOverride ) - { - m_deviceConfig.fullScreen = (iValue == 1); - } + if ( GetProfile().GetIntProperty("Setup", "Fullscreen", iValue) && !m_resolutionOverride ) + { + m_deviceConfig.fullScreen = (iValue == 1); + } - if (! CreateVideoSurface()) - return false; // dialog is in function + if (! CreateVideoSurface()) + return false; // dialog is in function - if (m_private->surface == nullptr) - { - m_errorMessage = std::string("SDL error while setting video mode:\n") + - std::string(SDL_GetError()); - GetLogger()->Error(m_errorMessage.c_str()); - m_exitCode = 4; - return false; + if (m_private->surface == nullptr) + { + m_errorMessage = std::string("SDL error while setting video mode:\n") + + std::string(SDL_GetError()); + GetLogger()->Error(m_errorMessage.c_str()); + m_exitCode = 4; + return false; + } + + SDL_WM_SetCaption(m_windowTitle.c_str(), m_windowTitle.c_str()); } - SDL_WM_SetCaption(m_windowTitle.c_str(), m_windowTitle.c_str()); - // Enable translating key codes of key press events to unicode chars SDL_EnableUNICODE(1); SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); @@ -541,8 +557,12 @@ bool CApplication::Create() // Don't generate joystick events SDL_JoystickEventState(SDL_IGNORE); - // The video is ready, we can create and initalize the graphics device - m_device = new Gfx::CGLDevice(m_deviceConfig); + if(!m_headless) { + // The video is ready, we can create and initalize the graphics device + m_device = new Gfx::CGLDevice(m_deviceConfig); + } else { + m_device = new Gfx::CNullDevice(); + } if (! m_device->Create() ) { m_errorMessage = std::string("Error in CDevice::Create()\n") + standardInfoMessage; diff --git a/src/app/app.h b/src/app/app.h index d933374..52ed77a 100644 --- a/src/app/app.h +++ b/src/app/app.h @@ -500,11 +500,11 @@ protected: //! Low cpu mode bool m_lowCPU; - - //! Show prototype levels - bool m_protoMode; //! Screen resoultion overriden by commandline bool m_resolutionOverride; + + //! Headles mode + bool m_headless; }; -- cgit v1.2.3-1-g7c22