- added new lua method to play video's in scenarios:

playStaticVideo
This commit is contained in:
Mark Vejvoda 2012-05-22 06:17:56 +00:00
parent 8ba7fd0fa0
commit 8fd436b612
8 changed files with 281 additions and 2 deletions

View File

@ -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);
}

View File

@ -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<ClientInterface *>(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<ContextGl*>(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<ContextGl*>(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<ContextGl*>(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]="";

View File

@ -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<std::pair<int,NetworkCommand> > replayCommandList;
std::vector<string> 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<int,string> &factionDebugInfo);
void renderVideoPlayer();
};
}}//end namespace

View File

@ -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));

View File

@ -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);

View File

@ -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);

View File

@ -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();

View File

@ -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);