From cb7bd8ff04de6c54c346abc1af1bcb195709690d Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Sat, 9 Jun 2012 05:02:01 +0000 Subject: [PATCH] - added menu option and commandline parameter to disable video playback --- source/glest_game/main/main.cpp | 8 +++++ source/glest_game/menu/menu_state_options.cpp | 24 +++++++++++-- source/glest_game/menu/menu_state_options.h | 3 ++ .../include/platform/sdl/platform_main.h | 10 +++++- .../sources/graphics/video_player.cpp | 36 +++++++++++-------- 5 files changed, 62 insertions(+), 19 deletions(-) diff --git a/source/glest_game/main/main.cpp b/source/glest_game/main/main.cpp index 4f90a9a4..18517c87 100644 --- a/source/glest_game/main/main.cpp +++ b/source/glest_game/main/main.cpp @@ -3437,6 +3437,14 @@ int glestMain(int argc, char** argv) { } } + + if(hasCommandArgument(argc, argv,GAME_ARGS[GAME_ARG_DISABLE_VIDEOS]) == true) { + VideoPlayer::setDisabled(true); + } + else if(config.getBool("EnableVideos","true") == false) { + VideoPlayer::setDisabled(true); + } + // Set some statics based on ini entries SystemFlags::ENABLE_THREADED_LOGGING = config.getBool("ThreadedLogging","true"); FontGl::setDefault_fontType(config.getString("DefaultFont",FontGl::getDefault_fontType().c_str())); diff --git a/source/glest_game/menu/menu_state_options.cpp b/source/glest_game/menu/menu_state_options.cpp index 9b8e1f05..dee16902 100644 --- a/source/glest_game/menu/menu_state_options.cpp +++ b/source/glest_game/menu/menu_state_options.cpp @@ -304,6 +304,13 @@ MenuStateOptions::MenuStateOptions(Program *program, MainMenu *mainMenu): checkBoxRainEffect.setValue(config.getBool("RainEffect","true")); currentLine-=lineOffset; + labelVideos.registerGraphicComponent(containerName,"labelVideos"); + labelVideos.init(currentLabelStart ,currentLine); + labelVideos.setText(lang.get("EnableVideos")); + + checkBoxVideos.registerGraphicComponent(containerName,"checkBoxVideos"); + checkBoxVideos.init(currentColumnStart ,currentLine ); + checkBoxVideos.setValue(config.getBool("EnableVideos","true")); // end @@ -648,6 +655,8 @@ void MenuStateOptions::reloadUI() { labelRainEffect.setText(lang.get("RainEffect")); + labelVideos.setText(lang.get("EnableVideos")); + labelMiscSection.setFont(CoreData::getInstance().getMenuFontVeryBig()); labelMiscSection.setFont3D(CoreData::getInstance().getMenuFontVeryBig3D()); labelMiscSection.setText(lang.get("Misc")); @@ -875,9 +884,11 @@ void MenuStateOptions::mouseClick(int x, int y, MouseButton mouseButton){ checkBoxDisableScreenshotConsoleText.mouseClick(x, y); checkBoxMouseMoveScrollsWorld.mouseClick(x, y); - checkBoxVisibleHud.mouseClick(x, y); - checkBoxRainEffect.mouseClick(x,y); - checkBoxRainEffectMenu.mouseClick(x,y); + checkBoxVisibleHud.mouseClick(x, y); + checkBoxRainEffect.mouseClick(x,y); + checkBoxRainEffectMenu.mouseClick(x,y); + + checkBoxVideos.mouseClick(x,y); } } @@ -920,6 +931,8 @@ void MenuStateOptions::mouseMove(int x, int y, const MouseState *ms){ checkBoxVisibleHud.mouseMove(x, y); checkBoxRainEffect.mouseMove(x, y); checkBoxRainEffectMenu.mouseMove(x, y); + + checkBoxVideos.mouseMove(x, y); } bool MenuStateOptions::isInSpecialKeyCaptureEvent() { @@ -1073,6 +1086,9 @@ void MenuStateOptions::render(){ renderer.renderLabel(&labelShadowTextureSize); renderer.renderListBox(&listBoxShadowTextureSize); + + renderer.renderLabel(&labelVideos); + renderer.renderCheckBox(&checkBoxVideos); } renderer.renderConsole(&console,false,true); @@ -1135,6 +1151,8 @@ void MenuStateOptions::saveConfig(){ config.setBool("RainEffect", checkBoxRainEffect.getValue()); config.setBool("RainEffectMenu", checkBoxRainEffectMenu.getValue()); + config.setBool("EnableVideos", checkBoxVideos.getValue()); + string currentResolution=config.getString("ScreenWidth")+"x"+config.getString("ScreenHeight"); string selectedResolution=listBoxScreenModes.getSelectedItem(); if(currentResolution!=selectedResolution){ diff --git a/source/glest_game/menu/menu_state_options.h b/source/glest_game/menu/menu_state_options.h index 32437f5e..6e04bc1e 100644 --- a/source/glest_game/menu/menu_state_options.h +++ b/source/glest_game/menu/menu_state_options.h @@ -131,6 +131,9 @@ private: GraphicLabel labelShadowTextureSize; GraphicListBox listBoxShadowTextureSize; + GraphicLabel labelVideos; + GraphicCheckBox checkBoxVideos; + map languageList; public: diff --git a/source/shared_lib/include/platform/sdl/platform_main.h b/source/shared_lib/include/platform/sdl/platform_main.h index 93c092f3..c964f2e0 100644 --- a/source/shared_lib/include/platform/sdl/platform_main.h +++ b/source/shared_lib/include/platform/sdl/platform_main.h @@ -81,6 +81,9 @@ const char *GAME_ARGS[] = { "--use-font", "--font-basesize", + + "--disable-videos", + "--verbose" }; @@ -146,6 +149,9 @@ enum GAME_ARG_TYPE { GAME_ARG_USE_FONT, GAME_ARG_FONT_BASESIZE, + + GAME_ARG_DISABLE_VIDEOS, + GAME_ARG_VERBOSE_MODE, GAME_ARG_END @@ -424,10 +430,12 @@ void printParameterHelp(const char *argv0, bool foundInvalidArgs) { printf("\n \t\texample:"); printf("\n %s %s=$APPLICATIONDATAPATH/data/core/fonts/Vera.ttf",extractFileFromDirectoryPath(argv0).c_str(),GAME_ARGS[GAME_ARG_USE_FONT]); - printf("\n%s=x\t\t\toverride the font base size.",GAME_ARGS[GAME_ARG_FONT_BASESIZE]); + printf("\n%s=x\t\toverride the font base size.",GAME_ARGS[GAME_ARG_FONT_BASESIZE]); printf("\n \t\tWhere x is the numeric base font size to use."); printf("\n \t\texample: %s %s=5",extractFileFromDirectoryPath(argv0).c_str(),GAME_ARGS[GAME_ARG_FONT_BASESIZE]); + printf("\n%s\t\tdisables video playback.",GAME_ARGS[GAME_ARG_DISABLE_VIDEOS]); + printf("\n%s\t\t\tdisplays verbose information in the console.",GAME_ARGS[GAME_ARG_VERBOSE_MODE]); printf("\n\n"); diff --git a/source/shared_lib/sources/graphics/video_player.cpp b/source/shared_lib/sources/graphics/video_player.cpp index 70abf63c..bb41a6a1 100644 --- a/source/shared_lib/sources/graphics/video_player.cpp +++ b/source/shared_lib/sources/graphics/video_player.cpp @@ -451,6 +451,10 @@ VideoPlayer::~VideoPlayer() { } bool VideoPlayer::hasBackEndVideoPlayer() { + if(VideoPlayer::disabled == true) { + return false; + } + #ifdef HAS_LIBVLC return true; #endif @@ -981,7 +985,7 @@ bool VideoPlayer::initPlayer() { void VideoPlayer::closePlayer() { #ifdef HAS_LIBVLC - if(ctxPtr->libvlc != NULL) { + if(ctxPtr != NULL && ctxPtr->libvlc != NULL) { // // Stop stream and clean up libVLC // @@ -1004,21 +1008,23 @@ void VideoPlayer::closePlayer() { // // Close window and clean up libSDL // - if(ctxPtr->mutex != NULL) { - SDL_DestroyMutex(ctxPtr->mutex); - } - if(ctxPtr->surf != NULL) { - SDL_FreeSurface(ctxPtr->surf); - } - if(ctxPtr->empty != NULL) { - SDL_FreeSurface(ctxPtr->empty); - } + if(ctxPtr != NULL) { + if(ctxPtr->mutex != NULL) { + SDL_DestroyMutex(ctxPtr->mutex); + } + if(ctxPtr->surf != NULL) { + SDL_FreeSurface(ctxPtr->surf); + } + if(ctxPtr->empty != NULL) { + SDL_FreeSurface(ctxPtr->empty); + } - glDeleteTextures(1, &ctxPtr->textureId); + glDeleteTextures(1, &ctxPtr->textureId); - if(ctxPtr->needToQuit == true) { - SDL_Event quit_event = {SDL_QUIT}; - SDL_PushEvent(&quit_event); + if(ctxPtr->needToQuit == true) { + SDL_Event quit_event = {SDL_QUIT}; + SDL_PushEvent(&quit_event); + } } } @@ -1285,7 +1291,7 @@ bool VideoPlayer::isPlaying() const { (ctxPtr->error == false || ctxPtr->stopped == false) && finished == false && stop == false); - if(ctxPtr->verboseEnabled) printf("isPlaying isPlaying = %d,error = %d, stopped = %d, end_of_media = %d\n",ctxPtr->isPlaying,ctxPtr->error,ctxPtr->stopped,ctxPtr->end_of_media); + if(ctxPtr != NULL && ctxPtr->verboseEnabled) printf("isPlaying isPlaying = %d,error = %d, stopped = %d, end_of_media = %d\n",ctxPtr->isPlaying,ctxPtr->error,ctxPtr->stopped,ctxPtr->end_of_media); return result; }