diff --git a/source/glest_game/game/game.cpp b/source/glest_game/game/game.cpp index 629f2cdf..2ad037a4 100644 --- a/source/glest_game/game/game.cpp +++ b/source/glest_game/game/game.cpp @@ -1801,12 +1801,13 @@ int Game::getFirstUnusedTeamNumber() { void Game::setupRenderForVideo() { Renderer &renderer= Renderer::getInstance(); - renderer.clearBuffers(); + //renderer.clearBuffers(); //3d - renderer.reset3dMenu(); - renderer.clearZBuffer(); + //renderer.reset3dMenu(); + //renderer.clearZBuffer(); //2d - renderer.reset2d(); + //renderer.reset2d(); + renderer.setupRenderForVideo(); } void Game::tryPauseToggle(bool pauseValue) { @@ -3726,7 +3727,9 @@ void Game::playStreamingVideo(const string &playVideo) { string vlcPluginsPath = Config::getInstance().getString("VideoPlayerPluginsPath",""); - videoPlayer = new Shared::Graphics::VideoPlayer(playVideo.c_str(), + videoPlayer = new Shared::Graphics::VideoPlayer( + &Renderer::getInstance(), + playVideo.c_str(), screen, 0,0, screen->w, @@ -3748,14 +3751,16 @@ void Game::playStreamingVideo(const string &playVideo) { string vlcPluginsPath = Config::getInstance().getString("VideoPlayerPluginsPath",""); - videoPlayer = new Shared::Graphics::VideoPlayer(playVideo.c_str(), - screen, - 0,0, - screen->w, - screen->h, - screen->format->BitsPerPixel, - vlcPluginsPath, - SystemFlags::VERBOSE_MODE_ENABLED); + videoPlayer = new Shared::Graphics::VideoPlayer( + &Renderer::getInstance(), + playVideo.c_str(), + screen, + 0,0, + screen->w, + screen->h, + screen->format->BitsPerPixel, + vlcPluginsPath, + SystemFlags::VERBOSE_MODE_ENABLED); } } } diff --git a/source/glest_game/graphics/renderer.cpp b/source/glest_game/graphics/renderer.cpp index 25a43440..f372f187 100644 --- a/source/glest_game/graphics/renderer.cpp +++ b/source/glest_game/graphics/renderer.cpp @@ -8533,4 +8533,47 @@ void Renderer::renderPopupMenu(PopupMenu *menu) { } +void Renderer::setupRenderForVideo() { + clearBuffers(); + //3d + reset3dMenu(); + clearZBuffer(); + //2d + reset2d(); + glClearColor(0.f, 0.f, 0.f, 1.f); +} + +void Renderer::renderVideoLoading(int progressPercent) { + //printf("Rendering progress progressPercent = %d\n",progressPercent); + setupRenderForVideo(); + + Lang &lang= Lang::getInstance(); + string textToRender = lang.get("PleaseWait"); + const Metrics &metrics= Metrics::getInstance(); + + if(CoreData::getInstance().getMenuFontBig3D() != NULL) { + + int renderX = 0; + int renderY = 0; + int w= metrics.getVirtualW(); + renderX = (w / 2) - (CoreData::getInstance().getMenuFontBig3D()->getMetrics()->getTextWidth(textToRender) / 2); + int h= metrics.getVirtualH(); + renderY = (h / 2) + (CoreData::getInstance().getMenuFontBig3D()->getMetrics()->getHeight(textToRender) / 2); + + renderText3D( + textToRender, + CoreData::getInstance().getMenuFontBig3D(), + Vec3f(1.f, 1.f, 0.f), + renderX, renderY, false); + } + else { + renderText( + textToRender, + CoreData::getInstance().getMenuFontBig(), + Vec3f(1.f, 1.f, 0.f), (metrics.getScreenW() / 2), + (metrics.getScreenH() / 2), true); + } + swapBuffers(); +} + }}//end namespace diff --git a/source/glest_game/graphics/renderer.h b/source/glest_game/graphics/renderer.h index c496deb7..2861e7a4 100644 --- a/source/glest_game/graphics/renderer.h +++ b/source/glest_game/graphics/renderer.h @@ -37,6 +37,7 @@ #include "graphics_interface.h" #include "base_renderer.h" #include "simple_threads.h" +#include "video_player.h" #ifdef DEBUG_RENDERING_ENABLED # define IF_DEBUG_EDITION(x) x @@ -179,7 +180,8 @@ public: class Renderer : public RendererInterface, public BaseRenderer, // This is for screen saver thread - public SimpleTaskCallbackInterface { + public SimpleTaskCallbackInterface, + public VideoLoadingCallbackInterface { public: //progress bar static const int maxProgressBar; @@ -591,6 +593,9 @@ public: void setProgram(Program *program) { this->program = program; } + void setupRenderForVideo(); + virtual void renderVideoLoading(int progressPercent); + private: //private misc float computeSunAngle(float time); diff --git a/source/glest_game/main/intro.cpp b/source/glest_game/main/intro.cpp index 9dfa7aed..22bd7eae 100644 --- a/source/glest_game/main/intro.cpp +++ b/source/glest_game/main/intro.cpp @@ -498,19 +498,27 @@ Intro::Intro(Program *program): CoreData::getInstance().hasIntroVideoFilename() == true) { string introVideoFile = CoreData::getInstance().getIntroVideoFilename(); //if(fileExists(introVideoFile)) { + + renderer.clearBuffers(); + renderer.reset3dMenu(); + renderer.clearZBuffer(); + renderer.reset2d(); + Context *c= GraphicsInterface::getInstance().getCurrentContext(); SDL_Surface *screen = static_cast(c)->getPlatformContextGlPtr()->getScreen(); string vlcPluginsPath = Config::getInstance().getString("VideoPlayerPluginsPath",""); //printf("screen->w = %d screen->h = %d screen->format->BitsPerPixel = %d\n",screen->w,screen->h,screen->format->BitsPerPixel); - Shared::Graphics::VideoPlayer player(introVideoFile.c_str(), - screen, - -1,-1, - screen->w, - screen->h, - screen->format->BitsPerPixel, - vlcPluginsPath, - SystemFlags::VERBOSE_MODE_ENABLED); + Shared::Graphics::VideoPlayer player( + &Renderer::getInstance(), + introVideoFile.c_str(), + screen, + 0,0, + screen->w, + screen->h, + screen->format->BitsPerPixel, + vlcPluginsPath, + SystemFlags::VERBOSE_MODE_ENABLED); player.PlayVideo(); exitAfterIntroVideo = true; return; diff --git a/source/glest_game/menu/main_menu.cpp b/source/glest_game/menu/main_menu.cpp index 806d0032..922e3877 100644 --- a/source/glest_game/menu/main_menu.cpp +++ b/source/glest_game/menu/main_menu.cpp @@ -105,14 +105,16 @@ void MainMenu::init() { string vlcPluginsPath = Config::getInstance().getString("VideoPlayerPluginsPath",""); //printf("screen->w = %d screen->h = %d screen->format->BitsPerPixel = %d\n",screen->w,screen->h,screen->format->BitsPerPixel); - menuBackgroundVideo = new VideoPlayer(introVideoFile.c_str(), - screen, - 0,0, - screen->w, - screen->h, - screen->format->BitsPerPixel, - vlcPluginsPath, - SystemFlags::VERBOSE_MODE_ENABLED); + menuBackgroundVideo = new VideoPlayer( + &Renderer::getInstance(), + introVideoFile.c_str(), + screen, + 0,0, + screen->w, + screen->h, + screen->format->BitsPerPixel, + vlcPluginsPath, + SystemFlags::VERBOSE_MODE_ENABLED); menuBackgroundVideo->initPlayer(); //} } diff --git a/source/shared_lib/include/graphics/video_player.h b/source/shared_lib/include/graphics/video_player.h index 2f0f2a1e..8f80eaf1 100644 --- a/source/shared_lib/include/graphics/video_player.h +++ b/source/shared_lib/include/graphics/video_player.h @@ -20,6 +20,12 @@ using namespace std; namespace Shared{ namespace Graphics{ +class VideoLoadingCallbackInterface { +public: + /** a value from 1 to 100 representing % done */ + virtual void renderVideoLoading(int progressPercent) = 0; +}; + class VideoPlayer { protected: @@ -38,12 +44,13 @@ protected: bool stop; bool finished; + VideoLoadingCallbackInterface *loadingCB; ctx *ctxPtr; void init(); public: - VideoPlayer(string filename, SDL_Surface *surface, int x, int y, + VideoPlayer(VideoLoadingCallbackInterface *loadingCB, string filename, SDL_Surface *surface, int x, int y, int width, int height, int colorBits, string pluginsPath,bool verboseEnabled=false); virtual ~VideoPlayer(); diff --git a/source/shared_lib/sources/graphics/video_player.cpp b/source/shared_lib/sources/graphics/video_player.cpp index 2e2865ae..f718d272 100644 --- a/source/shared_lib/sources/graphics/video_player.cpp +++ b/source/shared_lib/sources/graphics/video_player.cpp @@ -70,6 +70,7 @@ std::string getRegKey(const std::string& location, const std::string& name){ class ctx { public: ctx() { + loadingCB = NULL; empty = NULL; textureId = 0; // Texture ID surf = NULL; @@ -99,6 +100,7 @@ public: #endif } + Shared::Graphics::VideoLoadingCallbackInterface *loadingCB; SDL_Surface *empty; GLuint textureId; // Texture ID SDL_Surface *surf; @@ -399,9 +401,10 @@ void callbacks( const libvlc_event_t* event, void* data ) { #endif -VideoPlayer::VideoPlayer(string filename, SDL_Surface *surface, +VideoPlayer::VideoPlayer(VideoLoadingCallbackInterface *loadingCB, string filename, SDL_Surface *surface, int x, int y,int width, int height,int colorBits,string pluginsPath, bool verboseEnabled) : ctxPtr(NULL) { + this->loadingCB = loadingCB; this->filename = filename; this->surface = surface; this->x = x; @@ -421,6 +424,7 @@ VideoPlayer::VideoPlayer(string filename, SDL_Surface *surface, void VideoPlayer::init() { ctxPtr = new ctx(); + ctxPtr->loadingCB = loadingCB; ctxPtr->x = x; ctxPtr->y = y; ctxPtr->width = width; @@ -605,7 +609,7 @@ bool VideoPlayer::initPlayer() { */ const string HTTP_PREFIX = "http"; - const double MAX_VIDEO_START_MILLISECONDS = 20; + const double MAX_VIDEO_START_MILLISECONDS = 20.0; if(ctxPtr->libvlc != NULL) { #if defined(LIBVLC_VERSION_PRE_2) && defined(LIBVLC_VERSION_PRE_1_1_13) @@ -906,7 +910,11 @@ bool VideoPlayer::initPlayer() { if(ctxPtr->started == true) { break; } - SDL_Delay(10); + if(this->loadingCB != NULL) { + int progress = ((difftime(time(NULL),waitStart) / MAX_VIDEO_START_MILLISECONDS) * 100.0); + this->loadingCB->renderVideoLoading(progress); + } + SDL_Delay(1); } //SDL_Delay(5000);