now fade out of music when starting game and fade out of music when ending game

This commit is contained in:
Mark Vejvoda 2011-10-21 19:52:55 +00:00
parent c6d4e898a0
commit 14736ddfb7
11 changed files with 94 additions and 17 deletions

View File

@ -46,6 +46,8 @@ const float PHOTO_MODE_MAXHEIGHT = 500.0;
const int CREATE_NEW_TEAM = -100; const int CREATE_NEW_TEAM = -100;
const int CANCEL_SWITCH_TEAM = -1; const int CANCEL_SWITCH_TEAM = -1;
const int fadeMusicMilliseconds = 3500;
Game::Game() : ProgramState(NULL) { Game::Game() : ProgramState(NULL) {
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
@ -192,6 +194,67 @@ 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",__FILE__,__FUNCTION__,__LINE__); if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
} }
void Game::endGame() {
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
Object::setStateCallback(NULL);
thisGamePtr = NULL;
if(originalDisplayMsgCallback != NULL) {
NetworkInterface::setDisplayMessageFunction(originalDisplayMsgCallback);
}
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
Logger &logger= Logger::getInstance();
Renderer &renderer= Renderer::getInstance();
logger.loadLoadingScreen("");
logger.setState(Lang::getInstance().get("Deleting"));
//logger.add("Game", true);
logger.add("Game", false);
logger.hideProgress();
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
// Cannot Fade because sound files will be deleted below
SoundRenderer::getInstance().stopAllSounds(fadeMusicMilliseconds);
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
// deleteValues(aiInterfaces.begin(), aiInterfaces.end());
// aiInterfaces.clear();
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
// gui.end(); //selection must be cleared before deleting units
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
// world.end(); //must die before selection because of referencers
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] aiInterfaces.size() = %d\n",__FILE__,__FUNCTION__,__LINE__,aiInterfaces.size());
// 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.
renderer.endGame();
GameConstants::updateFps = original_updateFps;
GameConstants::cameraFps = original_cameraFps;
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
Unit::setGame(NULL);
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] ==== END GAME ==== getCurrentPixelByteCount() = %llu\n",__FILE__,__FUNCTION__,__LINE__,(long long unsigned int)renderer.getCurrentPixelByteCount());
if(SystemFlags::getSystemSettingType(SystemFlags::debugWorldSynch).enabled) SystemFlags::OutputDebug(SystemFlags::debugWorldSynch,"==== END GAME ====\n");
//this->program->reInitGl();
//renderer.reinitAll();
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
}
Game::~Game() { Game::~Game() {
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
@ -215,6 +278,7 @@ Game::~Game() {
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
// Cannot Fade because sound files will be deleted below
SoundRenderer::getInstance().stopAllSounds(); SoundRenderer::getInstance().stopAllSounds();
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
@ -591,7 +655,7 @@ void Game::load(int loadTypes) {
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] loadTypes = %d, gameSettings = [%s]\n",__FILE__,__FUNCTION__,__LINE__,loadTypes,this->gameSettings.toString().c_str()); if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] loadTypes = %d, gameSettings = [%s]\n",__FILE__,__FUNCTION__,__LINE__,loadTypes,this->gameSettings.toString().c_str());
SoundRenderer &soundRenderer= SoundRenderer::getInstance(); SoundRenderer &soundRenderer= SoundRenderer::getInstance();
soundRenderer.stopAllSounds(); soundRenderer.stopAllSounds(fadeMusicMilliseconds);
Config &config = Config::getInstance(); Config &config = Config::getInstance();
Logger &logger= Logger::getInstance(); Logger &logger= Logger::getInstance();
@ -894,7 +958,7 @@ void Game::init(bool initForPreviewOnly) {
//sounds //sounds
SoundRenderer &soundRenderer= SoundRenderer::getInstance(); SoundRenderer &soundRenderer= SoundRenderer::getInstance();
soundRenderer.stopAllSounds(); soundRenderer.stopAllSounds(fadeMusicMilliseconds);
soundRenderer= SoundRenderer::getInstance(); soundRenderer= SoundRenderer::getInstance();
Tileset *tileset= world.getTileset(); Tileset *tileset= world.getTileset();
@ -1208,7 +1272,7 @@ void Game::update() {
//sounds //sounds
SoundRenderer &soundRenderer= SoundRenderer::getInstance(); SoundRenderer &soundRenderer= SoundRenderer::getInstance();
soundRenderer.stopAllSounds(); soundRenderer.stopAllSounds(fadeMusicMilliseconds);
soundRenderer= SoundRenderer::getInstance(); soundRenderer= SoundRenderer::getInstance();
Tileset *tileset= world.getTileset(); Tileset *tileset= world.getTileset();
@ -2435,11 +2499,16 @@ Stats Game::quitGame() {
void Game::exitGameState(Program *program, Stats &endStats) { void Game::exitGameState(Program *program, Stats &endStats) {
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
ProgramState *newState = new BattleEnd(program, &endStats); Game *game = dynamic_cast<Game *>(program->getState());
if(game) {
game->endGame();
}
ProgramState *newState = new BattleEnd(program, &endStats, game);
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
program->setState(newState); program->setState(newState, false);
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
} }

View File

@ -218,6 +218,8 @@ public:
virtual vector<Texture2D *> processTech(string techName); virtual vector<Texture2D *> processTech(string techName);
virtual void consoleAddLine(string line); virtual void consoleAddLine(string line);
void endGame();
private: private:
//render //render
void render3d(); void render3d();

View File

@ -34,8 +34,10 @@ namespace Glest{ namespace Game{
// class BattleEnd // class BattleEnd
// ===================================================== // =====================================================
BattleEnd::BattleEnd(Program *program, const Stats *stats): ProgramState(program) { BattleEnd::BattleEnd(Program *program, const Stats *stats,ProgramState *originState): ProgramState(program) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d] stats = %p\n",__FILE__,__FUNCTION__,__LINE__,stats); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d] stats = %p\n",__FILE__,__FUNCTION__,__LINE__,stats);
this->originState = originState;
if(stats != NULL) { if(stats != NULL) {
this->stats= *stats; this->stats= *stats;
} }
@ -61,6 +63,9 @@ BattleEnd::BattleEnd(Program *program, const Stats *stats): ProgramState(program
BattleEnd::~BattleEnd() { BattleEnd::~BattleEnd() {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
delete originState;
originState = NULL;
SoundRenderer::getInstance().playMusic(CoreData::getInstance().getMenuMusic()); SoundRenderer::getInstance().playMusic(CoreData::getInstance().getMenuMusic());
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);

View File

@ -34,11 +34,12 @@ private:
int mouse2d; int mouse2d;
GraphicMessageBox mainMessageBox; GraphicMessageBox mainMessageBox;
Texture2D *renderToTexture; Texture2D *renderToTexture;
ProgramState *originState;
void showMessageBox(const string &text, const string &header, bool toggle); void showMessageBox(const string &text, const string &header, bool toggle);
public: public:
BattleEnd(Program *program, const Stats *stats); BattleEnd(Program *program, const Stats *stats, ProgramState *originState);
~BattleEnd(); ~BattleEnd();
virtual void update(); virtual void update();

View File

@ -240,14 +240,14 @@ void SoundRenderer::stopAmbient(StrSound *strSound) {
// ======================= Misc ============================ // ======================= Misc ============================
void SoundRenderer::stopAllSounds() { void SoundRenderer::stopAllSounds(int64 fadeOff) {
if(soundPlayer != NULL) { if(soundPlayer != NULL) {
MutexSafeWrapper safeMutex(NULL,string(__FILE__) + "_" + intToStr(__LINE__)); MutexSafeWrapper safeMutex(NULL,string(__FILE__) + "_" + intToStr(__LINE__));
if(runThreadSafe == true) { if(runThreadSafe == true) {
safeMutex.setMutex(&mutex); safeMutex.setMutex(&mutex);
} }
soundPlayer->stopAllSounds(); soundPlayer->stopAllSounds(fadeOff);
} }
} }

View File

@ -77,7 +77,7 @@ public:
void stopAmbient(StrSound *strSound); void stopAmbient(StrSound *strSound);
//misc //misc
void stopAllSounds(); void stopAllSounds(int64 fadeOff=0);
void loadConfig(); void loadConfig();
bool wasInitOk() const; bool wasInitOk() const;

View File

@ -117,7 +117,7 @@ public:
virtual void play(StaticSound *staticSound); virtual void play(StaticSound *staticSound);
virtual void play(StrSound *strSound, int64 fadeOn=0); virtual void play(StrSound *strSound, int64 fadeOn=0);
virtual void stop(StrSound *strSound, int64 fadeOff=0); virtual void stop(StrSound *strSound, int64 fadeOff=0);
virtual void stopAllSounds(); virtual void stopAllSounds(int64 fadeOff=0);
virtual void updateStreams(); //updates str buffers if needed virtual void updateStreams(); //updates str buffers if needed
private: private:

View File

@ -100,7 +100,7 @@ public:
virtual void play(StaticSound *staticSound); virtual void play(StaticSound *staticSound);
virtual void play(StrSound *strSound, int64 fadeOn=0); virtual void play(StrSound *strSound, int64 fadeOn=0);
virtual void stop(StrSound *strSound, int64 fadeOff=0); virtual void stop(StrSound *strSound, int64 fadeOff=0);
virtual void stopAllSounds(); virtual void stopAllSounds(int64 fadeOff=0);
virtual void updateStreams(); //updates str buffers if needed virtual void updateStreams(); //updates str buffers if needed
private: private:

View File

@ -54,7 +54,7 @@ public:
virtual void play(StaticSound *staticSound)= 0; virtual void play(StaticSound *staticSound)= 0;
virtual void play(StrSound *strSound, int64 fadeOn=0)= 0; //delay and fade in miliseconds virtual void play(StrSound *strSound, int64 fadeOn=0)= 0; //delay and fade in miliseconds
virtual void stop(StrSound *strSound, int64 fadeOff=0)= 0; virtual void stop(StrSound *strSound, int64 fadeOff=0)= 0;
virtual void stopAllSounds()= 0; virtual void stopAllSounds(int64 fadeOff=0)= 0;
virtual void updateStreams()= 0; virtual void updateStreams()= 0;
virtual bool wasInitOk() const { return initOk; } virtual bool wasInitOk() const { return initOk; }
}; };

View File

@ -427,12 +427,12 @@ void SoundPlayerDs8::stop(StrSound *strSound, int64 fadeOff){
} }
} }
void SoundPlayerDs8::stopAllSounds(){ void SoundPlayerDs8::stopAllSounds(int64 fadeOff){
if(initOk == false) return; if(initOk == false) return;
for(unsigned int i=0; i<params.strBufferCount; ++i){ for(unsigned int i=0; i<params.strBufferCount; ++i){
if(!strSoundBuffers[i].isFree()){ if(!strSoundBuffers[i].isFree()){
strSoundBuffers[i].stop(0); strSoundBuffers[i].stop(fadeOff);
strSoundBuffers[i].end(); strSoundBuffers[i].end();
} }
} }

View File

@ -505,7 +505,7 @@ void SoundPlayerOpenAL::stop(StrSound* strSound, int64 fadeOff) {
} }
} }
void SoundPlayerOpenAL::stopAllSounds() { void SoundPlayerOpenAL::stopAllSounds(int64 fadeOff) {
if(initOk == false) return; if(initOk == false) return;
for(StaticSoundSources::iterator i = staticSources.begin(); for(StaticSoundSources::iterator i = staticSources.begin();
@ -516,7 +516,7 @@ void SoundPlayerOpenAL::stopAllSounds() {
for(StreamSoundSources::iterator i = streamSources.begin(); for(StreamSoundSources::iterator i = streamSources.begin();
i != streamSources.end(); ++i) { i != streamSources.end(); ++i) {
StreamSoundSource* source = *i; StreamSoundSource* source = *i;
source->stop(); source->stop(fadeOff);
} }
} }