From 8fd436b6128ed27e3feea48be43ce6471e0377d2 Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Tue, 22 May 2012 06:17:56 +0000 Subject: [PATCH] - added new lua method to play video's in scenarios: playStaticVideo --- source/glest_game/game/commander.cpp | 4 +- source/glest_game/game/game.cpp | 165 ++++++++++++++++++ source/glest_game/game/game.h | 17 ++ source/glest_game/game/script_manager.cpp | 62 +++++++ source/glest_game/game/script_manager.h | 10 ++ source/glest_game/world/world.cpp | 16 ++ source/glest_game/world/world.h | 5 + .../sources/graphics/video_player.cpp | 4 + 8 files changed, 281 insertions(+), 2 deletions(-) diff --git a/source/glest_game/game/commander.cpp b/source/glest_game/game/commander.cpp index bc944d19..ad783db1 100644 --- a/source/glest_game/game/commander.cpp +++ b/source/glest_game/game/commander.cpp @@ -470,12 +470,12 @@ void Commander::trySwitchTeamVote(const Faction* faction, SwitchTeamVote *vote) } void Commander::tryPauseGame() const { - NetworkCommand command(this->world,nctPauseResume, true); + NetworkCommand command(this->world,nctPauseResume, 1); pushNetworkCommand(&command); } void Commander::tryResumeGame() const { - NetworkCommand command(this->world,nctPauseResume, false); + NetworkCommand command(this->world,nctPauseResume, 0); pushNetworkCommand(&command); } diff --git a/source/glest_game/game/game.cpp b/source/glest_game/game/game.cpp index 6d69b56c..629f2cdf 100644 --- a/source/glest_game/game/game.cpp +++ b/source/glest_game/game/game.cpp @@ -24,6 +24,8 @@ #include "checksum.h" #include "auto_test.h" #include "menu_state_keysetup.h" +#include "video_player.h" + #include "leak_dumper.h" using namespace Shared::Graphics; @@ -59,6 +61,8 @@ Game::Game() : ProgramState(NULL) { originalDisplayMsgCallback = NULL; aiInterfaces.clear(); + videoPlayer = NULL; + playingStaticVideo = false; mouse2d=0; mouseX=0; @@ -212,6 +216,8 @@ Game::Game(Program *program, const GameSettings *gameSettings,bool masterserverM if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); this->masterserverMode = masterserverMode; + videoPlayer = NULL; + playingStaticVideo = false; if(this->masterserverMode == true) { printf("Starting a new game...\n"); @@ -330,6 +336,10 @@ Game::~Game() { if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] aiInterfaces.size() = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,aiInterfaces.size()); + delete videoPlayer; + videoPlayer = NULL; + playingStaticVideo = false; + // MUST DO THIS LAST!!!! Because objects above have pointers to things like // unit particles and fade them out etc and this end method deletes the original // object pointers. @@ -1337,6 +1347,13 @@ void Game::update() { //else if(role == nrClient) { else { commander.signalNetworkUpdate(this); + + if(playingStaticVideo == true) { + if(videoPlayer->isPlaying() == false) { + playingStaticVideo = false; + tryPauseToggle(false); + } + } } //call the chat manager @@ -1782,6 +1799,50 @@ int Game::getFirstUnusedTeamNumber() { return result; } +void Game::setupRenderForVideo() { + Renderer &renderer= Renderer::getInstance(); + renderer.clearBuffers(); + //3d + renderer.reset3dMenu(); + renderer.clearZBuffer(); + //2d + renderer.reset2d(); +} + +void Game::tryPauseToggle(bool pauseValue) { + bool allowAdminMenuItems = false; + NetworkManager &networkManager= NetworkManager::getInstance(); + NetworkRole role = networkManager.getNetworkRole(); + if(role == nrServer) { + allowAdminMenuItems = true; + } + else if(role == nrClient) { + ClientInterface *clientInterface = dynamic_cast(networkManager.getClientInterface()); + + if(clientInterface != NULL && + gameSettings.getMasterserver_admin() == clientInterface->getSessionKey()) { + allowAdminMenuItems = true; + } + } + + bool isNetworkGame = this->gameSettings.isNetworkGame(); + //printf("Try Pause allowAdminMenuItems = %d, pauseValue = %d\n",allowAdminMenuItems,pauseValue); + + if(allowAdminMenuItems) { + if(pauseValue == true) { + commander.tryPauseGame(); + } + else { + if(isNetworkGame == false) { + setPaused(pauseValue, true); + } + else { + commander.tryResumeGame(); + } + } + } +} + void Game::mouseDownLeft(int x, int y) { if(this->masterserverMode == true) { return; @@ -3115,6 +3176,8 @@ void Game::render2d() { } } + renderVideoPlayer(); + renderer.renderPopupMenu(&popupMenu); renderer.renderPopupMenu(&popupMenuSwitchTeams); @@ -3612,6 +3675,108 @@ void Game::addNetworkCommandToReplayList(NetworkCommand* networkCommand, int wor } } +void Game::renderVideoPlayer() { + if(videoPlayer != NULL) { + if(videoPlayer->isPlaying() == true) { + videoPlayer->playFrame(false); + } + else { + delete videoPlayer; + videoPlayer = NULL; + } + } +} + +void Game::playStaticVideo(const string &playVideo) { + if(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == false && + Shared::Graphics::VideoPlayer::hasBackEndVideoPlayer() == true) { + + //togglePauseGame(true,true); + tryPauseToggle(true); + setupRenderForVideo(); + + +// 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(playVideo.c_str(), +// screen, +// 0,0, +// screen->w, +// screen->h, +// screen->format->BitsPerPixel, +// vlcPluginsPath, +// SystemFlags::VERBOSE_MODE_ENABLED); +// player.PlayVideo(); + //} + //tryPauseToggle(false); + + playStreamingVideo(playVideo); + playingStaticVideo = true; + } +} +void Game::playStreamingVideo(const string &playVideo) { + if(videoPlayer == NULL) { + if(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == false && + Shared::Graphics::VideoPlayer::hasBackEndVideoPlayer() == true) { + Context *c= GraphicsInterface::getInstance().getCurrentContext(); + SDL_Surface *screen = static_cast(c)->getPlatformContextGlPtr()->getScreen(); + + 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); + } + } + else { + if(videoPlayer->isPlaying() == false) { + delete videoPlayer; + videoPlayer = NULL; + + if(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == false && + Shared::Graphics::VideoPlayer::hasBackEndVideoPlayer() == true) { + Context *c= GraphicsInterface::getInstance().getCurrentContext(); + SDL_Surface *screen = static_cast(c)->getPlatformContextGlPtr()->getScreen(); + + 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); + } + } + } + + if(videoPlayer != NULL) { + videoPlayer->initPlayer(); + } +} +void Game::stopStreamingVideo(const string &playVideo) { + if(videoPlayer != NULL) { + videoPlayer->StopVideo(); + } +} + +void Game::stopAllVideo() { + if(videoPlayer != NULL) { + videoPlayer->StopVideo(); + } +} + + void Game::saveGame(){ string file = this->saveGame(GameConstants::saveGameFilePattern); char szBuf[8096]=""; diff --git a/source/glest_game/game/game.h b/source/glest_game/game/game.h index e5f00f8b..bccd24c0 100644 --- a/source/glest_game/game/game.h +++ b/source/glest_game/game/game.h @@ -34,6 +34,10 @@ using std::vector; using namespace Shared::Platform; using namespace Shared::PlatformCommon; +namespace Shared { namespace Graphics { + class VideoPlayer; +}} + namespace Glest{ namespace Game{ class GraphicMessageBox; @@ -160,6 +164,10 @@ private: int lastworldFrameCountForReplay; std::vector > replayCommandList; + std::vector streamingVideos; + Shared::Graphics::VideoPlayer *videoPlayer; + bool playingStaticVideo; + public: Game(); Game(Program *program, const GameSettings *gameSettings, bool masterserverMode); @@ -188,6 +196,8 @@ public: bool getPaused(); void setPaused(bool value, bool forceAllowPauseStateChange=false); + void tryPauseToggle(bool pause); + void setupRenderForVideo(); void saveGame(); const int getTotalRenderFps() const {return totalRenderFps;} @@ -241,6 +251,11 @@ public: void endGame(); + void playStaticVideo(const string &playVideo); + void playStreamingVideo(const string &playVideo); + void stopStreamingVideo(const string &playVideo); + void stopAllVideo(); + string saveGame(string name); static void loadGame(string name,Program *programPtr,bool isMasterserverMode); @@ -279,6 +294,8 @@ private: void setupPopupMenus(bool checkClientAdminOverrideOnly); string getDebugStats(std::map &factionDebugInfo); + + void renderVideoPlayer(); }; }}//end namespace diff --git a/source/glest_game/game/script_manager.cpp b/source/glest_game/game/script_manager.cpp index 1bf00c25..5d051c14 100644 --- a/source/glest_game/game/script_manager.cpp +++ b/source/glest_game/game/script_manager.cpp @@ -257,11 +257,18 @@ void ScriptManager::init(World* world, GameCamera *gameCamera, const XmlNode *ro luaScript.registerFunction(giveKills, "giveKills"); luaScript.registerFunction(morphToUnit, "morphToUnit"); luaScript.registerFunction(moveToUnit, "moveToUnit"); + luaScript.registerFunction(playStaticSound, "playStaticSound"); luaScript.registerFunction(playStreamingSound, "playStreamingSound"); luaScript.registerFunction(stopStreamingSound, "stopStreamingSound"); luaScript.registerFunction(stopAllSound, "stopAllSound"); luaScript.registerFunction(togglePauseGame, "togglePauseGame"); + + luaScript.registerFunction(playStaticVideo, "playStaticVideo"); + //luaScript.registerFunction(playStreamingVideo, "playStreamingVideo"); + //luaScript.registerFunction(stopStreamingVideo, "stopStreamingVideo"); + luaScript.registerFunction(stopAllVideo, "stopAllVideo"); + luaScript.registerFunction(giveResource, "giveResource"); luaScript.registerFunction(givePositionCommand, "givePositionCommand"); luaScript.registerFunction(giveProductionCommand, "giveProductionCommand"); @@ -879,6 +886,29 @@ void ScriptManager::stopAllSound() { world->stopAllSound(); } +void ScriptManager::playStaticVideo(const string &playVideo) { + if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d] playVideo [%s]\n",__FILE__,__FUNCTION__,__LINE__,playVideo.c_str()); + ScriptManager_STREFLOP_Wrapper streflopWrapper; + world->playStaticVideo(playVideo); +} +void ScriptManager::playStreamingVideo(const string &playVideo) { + if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d] playVideo [%s]\n",__FILE__,__FUNCTION__,__LINE__,playVideo.c_str()); + ScriptManager_STREFLOP_Wrapper streflopWrapper; + world->playStreamingVideo(playVideo); +} + +void ScriptManager::stopStreamingVideo(const string &playVideo) { + if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d] playVideo [%s]\n",__FILE__,__FUNCTION__,__LINE__,playVideo.c_str()); + ScriptManager_STREFLOP_Wrapper streflopWrapper; + world->stopStreamingVideo(playVideo); +} + +void ScriptManager::stopAllVideo() { + if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + ScriptManager_STREFLOP_Wrapper streflopWrapper; + world->stopAllVideo(); +} + void ScriptManager::togglePauseGame(int pauseStatus) { if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d] pauseStatus = %d\n",__FILE__,__FUNCTION__,__LINE__,pauseStatus); ScriptManager_STREFLOP_Wrapper streflopWrapper; @@ -1548,6 +1578,38 @@ int ScriptManager::stopAllSound(LuaHandle* luaHandle) { return luaArguments.getReturnCount(); } + + +int ScriptManager::playStaticVideo(LuaHandle* luaHandle) { + LuaArguments luaArguments(luaHandle); + if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d] sound [%s]\n",__FILE__,__FUNCTION__,__LINE__,luaArguments.getString(-1).c_str()); + thisScriptManager->playStaticVideo(luaArguments.getString(-1)); + return luaArguments.getReturnCount(); +} + +int ScriptManager::playStreamingVideo(LuaHandle* luaHandle) { + LuaArguments luaArguments(luaHandle); + if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d] sound [%s]\n",__FILE__,__FUNCTION__,__LINE__,luaArguments.getString(-1).c_str()); + thisScriptManager->playStreamingVideo(luaArguments.getString(-1)); + return luaArguments.getReturnCount(); +} + +int ScriptManager::stopStreamingVideo(LuaHandle* luaHandle) { + LuaArguments luaArguments(luaHandle); + if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d] sound [%s]\n",__FILE__,__FUNCTION__,__LINE__,luaArguments.getString(-1).c_str()); + thisScriptManager->stopStreamingVideo(luaArguments.getString(-1)); + return luaArguments.getReturnCount(); +} + +int ScriptManager::stopAllVideo(LuaHandle* luaHandle) { + LuaArguments luaArguments(luaHandle); + if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + thisScriptManager->stopAllVideo(); + return luaArguments.getReturnCount(); +} + + + int ScriptManager::togglePauseGame(LuaHandle* luaHandle) { LuaArguments luaArguments(luaHandle); if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d] value = %d\n",__FILE__,__FUNCTION__,__LINE__,luaArguments.getInt(-1)); diff --git a/source/glest_game/game/script_manager.h b/source/glest_game/game/script_manager.h index b17f12fd..9c3df3bf 100644 --- a/source/glest_game/game/script_manager.h +++ b/source/glest_game/game/script_manager.h @@ -256,6 +256,11 @@ private: void stopAllSound(); void togglePauseGame(int pauseStatus); + void playStaticVideo(const string &playVideo); + void playStreamingVideo(const string &playVideo); + void stopStreamingVideo(const string &playVideo); + void stopAllVideo(); + void giveResource(const string &resourceName, int factionIndex, int amount); void givePositionCommand(int unitId, const string &producedName, const Vec2i &pos); void giveProductionCommand(int unitId, const string &producedName); @@ -361,6 +366,11 @@ private: static int stopAllSound(LuaHandle* luaHandle); static int togglePauseGame(LuaHandle* luaHandle); + static int playStaticVideo(LuaHandle* luaHandle); + static int playStreamingVideo(LuaHandle* luaHandle); + static int stopStreamingVideo(LuaHandle* luaHandle); + static int stopAllVideo(LuaHandle* luaHandle); + static int giveResource(LuaHandle* luaHandle); static int givePositionCommand(LuaHandle* luaHandle); static int giveProductionCommand(LuaHandle* luaHandle); diff --git a/source/glest_game/world/world.cpp b/source/glest_game/world/world.cpp index 82738ed7..135c96da 100644 --- a/source/glest_game/world/world.cpp +++ b/source/glest_game/world/world.cpp @@ -2033,6 +2033,22 @@ int World::getNextCommandGroupId() { return ++nextCommandGroupId; } +void World::playStaticVideo(const string &playVideo) { + this->game->playStaticVideo(playVideo); +} + +void World::playStreamingVideo(const string &playVideo) { + this->game->playStreamingVideo(playVideo); +} + +void World::stopStreamingVideo(const string &playVideo) { + this->game->stopStreamingVideo(playVideo); +} + +void World::stopAllVideo() { + this->game->stopAllVideo(); +} + void World::removeResourceTargetFromCache(const Vec2i &pos) { for(int i= 0; i < factions.size(); ++i) { factions[i]->removeResourceTargetFromCache(pos); diff --git a/source/glest_game/world/world.h b/source/glest_game/world/world.h index 1c9db8fe..9b6bc439 100644 --- a/source/glest_game/world/world.h +++ b/source/glest_game/world/world.h @@ -280,6 +280,11 @@ public: inline UnitUpdater * getUnitUpdater() { return &unitUpdater; } + void playStaticVideo(const string &playVideo); + void playStreamingVideo(const string &playVideo); + void stopStreamingVideo(const string &playVideo); + void stopAllVideo(); + void removeResourceTargetFromCache(const Vec2i &pos); string getExploredCellsLookupItemCacheStats(); diff --git a/source/shared_lib/sources/graphics/video_player.cpp b/source/shared_lib/sources/graphics/video_player.cpp index fb535b2b..2e2865ae 100644 --- a/source/shared_lib/sources/graphics/video_player.cpp +++ b/source/shared_lib/sources/graphics/video_player.cpp @@ -1339,7 +1339,11 @@ bool VideoPlayer::playFrame(bool swapBuffers) { #else const double HEIGHT_MULTIPLIER = 0.80; const double WIDTH_MULTIPLIER = 0.60; +// const double HEIGHT_MULTIPLIER = 1.0; +// const double WIDTH_MULTIPLIER = 1.0; + #endif + glBegin(GL_TRIANGLE_STRIP); glTexCoord2i(0, 1); glVertex2i(ctxPtr->x, ctxPtr->y + ctxPtr->height * HEIGHT_MULTIPLIER);