From 221b099c67862d84cf08ce6ffd5aa8161339a6a6 Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Tue, 23 Mar 2010 08:46:20 +0000 Subject: [PATCH] More bug fixes for error handling if we have early program launch errors. --- source/glest_game/main/main.cpp | 3 - source/glest_game/main/program.cpp | 37 ++++- source/glest_game/main/program.h | 3 +- source/glest_game/sound/sound_renderer.cpp | 141 ++++++++++++++++++ .../sources/platform/sdl/window.cpp | 27 +++- 5 files changed, 192 insertions(+), 19 deletions(-) create mode 100644 source/glest_game/sound/sound_renderer.cpp diff --git a/source/glest_game/main/main.cpp b/source/glest_game/main/main.cpp index 3e13013b..31679018 100644 --- a/source/glest_game/main/main.cpp +++ b/source/glest_game/main/main.cpp @@ -40,7 +40,6 @@ string debugLogFile = ""; class ExceptionHandler: public PlatformExceptionHandler{ public: virtual void handle(){ - string msg = "#1 An error ocurred and Glest will close.\nPlease report this bug to "+mailString+", attaching the generated "+getCrashDumpFileName()+" file."; SystemFlags::OutputDebug(SystemFlags::debugSystem,"%s\n",msg.c_str()); @@ -54,7 +53,6 @@ public: } static void handleRuntimeError(const char *msg) { - SystemFlags::OutputDebug(SystemFlags::debugSystem,"%s\n",msg); Program *program = Program::getInstance(); @@ -65,7 +63,6 @@ public: else { message("#2 An error ocurred and Glest will close.\nError msg = [" + (msg != NULL ? string(msg) : string("?")) + "]\n\nPlease report this bug to "+mailString+", attaching the generated "+getCrashDumpFileName()+" file."); } - restoreVideoMode(true); //SystemFlags::Close(); exit(0); diff --git a/source/glest_game/main/program.cpp b/source/glest_game/main/program.cpp index 3b831b19..5356e605 100644 --- a/source/glest_game/main/program.cpp +++ b/source/glest_game/main/program.cpp @@ -91,6 +91,19 @@ void Program::ShowMessageProgramState::mouseDownLeft(int x, int y) { //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__); } +void Program::ShowMessageProgramState::keyPress(char c){ + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d] c = [%d]\n",__FILE__,__FUNCTION__,__LINE__,c); + + // if user pressed return we exit + if(c == 13) { + program->exit(); + userWantsExit = true; + } + else { + //msgBox.keyPress(c); + } +} + void Program::ShowMessageProgramState::mouseMove(int x, int y, const MouseState &mouseState) { mouseX = x; mouseY = y; @@ -193,6 +206,8 @@ void Program::keyPress(char c){ void Program::loop(){ + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__); + //render programState->render(); @@ -201,6 +216,8 @@ void Program::loop(){ programState->updateCamera(); } + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__); + //update world while(updateTimer.isTime()){ GraphicComponent::update(); @@ -209,10 +226,14 @@ void Program::loop(){ NetworkManager::getInstance().update(); } + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__); + //fps timer while(fpsTimer.isTime()){ programState->tick(); } + + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__); } void Program::resize(SizeState sizeState){ @@ -360,7 +381,7 @@ void Program::restoreDisplaySettings(){ } void Program::showMessage(const char *msg) { - //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__); ProgramState *originalState = NULL; if(this->programState) { @@ -368,7 +389,7 @@ void Program::showMessage(const char *msg) { originalState = this->programState; } - //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__); showCursor(true); @@ -379,18 +400,18 @@ void Program::showMessage(const char *msg) { this->programState = NULL; setState(showMsg); - //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__); while(Window::handleEvent() && showMsg->wantExit() == false) { loop(); } - //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 this->programState; this->programState = NULL; - //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__); showCursor(Config::getInstance().getBool("Windowed")); @@ -398,16 +419,16 @@ void Program::showMessage(const char *msg) { init(this->window,false); //setState(originalState); - //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] START\n",__FILE__,__FUNCTION__); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] START\n",__FILE__,__FUNCTION__); delete this->programState; - //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] %d\n",__FILE__,__FUNCTION__,__LINE__); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] %d\n",__FILE__,__FUNCTION__,__LINE__); this->programState= originalState; //programState->load(); - //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] %d\n",__FILE__,__FUNCTION__,__LINE__); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] %d\n",__FILE__,__FUNCTION__,__LINE__); //programState->init(); diff --git a/source/glest_game/main/program.h b/source/glest_game/main/program.h index 4b64487a..9437746a 100644 --- a/source/glest_game/main/program.h +++ b/source/glest_game/main/program.h @@ -84,7 +84,8 @@ private: virtual void render(); virtual void mouseDownLeft(int x, int y); - virtual void mouseMove(int x, int y, const MouseState &mouseState); + virtual void mouseMove(int x, int y, const MouseState &mouseState); + virtual void keyPress(char c); virtual void update(); virtual bool wantExit() { return userWantsExit; } }; diff --git a/source/glest_game/sound/sound_renderer.cpp b/source/glest_game/sound/sound_renderer.cpp new file mode 100644 index 00000000..8312aac3 --- /dev/null +++ b/source/glest_game/sound/sound_renderer.cpp @@ -0,0 +1,141 @@ +// ============================================================== +// This file is part of Glest (www.glest.org) +// +// Copyright (C) 2001-2008 Martiņo Figueroa +// +// You can redistribute this code and/or modify it under +// the terms of the GNU General Public License as published +// by the Free Software Foundation; either version 2 of the +// License, or (at your option) any later version +// ============================================================== + +#include "sound_renderer.h" + +#include "core_data.h" +#include "config.h" +#include "sound_interface.h" +#include "factory_repository.h" +#include "leak_dumper.h" + +using namespace Shared::Graphics; +using namespace Shared::Sound; + +namespace Glest{ namespace Game{ + +const int SoundRenderer::ambientFade= 6000; +const float SoundRenderer::audibleDist= 50.f; + +// ===================================================== +// class SoundRenderer +// ===================================================== + +SoundRenderer::SoundRenderer(){ + soundPlayer = NULL; + loadConfig(); +} + +void SoundRenderer::init(Window *window){ + SoundInterface &si= SoundInterface::getInstance(); + FactoryRepository &fr= FactoryRepository::getInstance(); + Config &config= Config::getInstance(); + + si.setFactory(fr.getSoundFactory(config.getString("FactorySound"))); + soundPlayer= si.newSoundPlayer(); + + SoundPlayerParams soundPlayerParams; + soundPlayerParams.staticBufferCount= config.getInt("SoundStaticBuffers"); + soundPlayerParams.strBufferCount= config.getInt("SoundStreamingBuffers"); + soundPlayer->init(&soundPlayerParams); +} + +SoundRenderer::~SoundRenderer(){ + delete soundPlayer; + soundPlayer = NULL; +} + +SoundRenderer &SoundRenderer::getInstance(){ + static SoundRenderer soundRenderer; + return soundRenderer; +} + +void SoundRenderer::update(){ + if(soundPlayer != NULL) { + soundPlayer->updateStreams(); + } +} + +// ======================= Music ============================ + +void SoundRenderer::playMusic(StrSound *strSound){ + strSound->setVolume(musicVolume); + strSound->restart(); + if(soundPlayer != NULL) { + soundPlayer->play(strSound); + } +} + +void SoundRenderer::stopMusic(StrSound *strSound){ + if(soundPlayer != NULL) { + soundPlayer->stop(strSound); + } +} + +// ======================= Fx ============================ + +void SoundRenderer::playFx(StaticSound *staticSound, Vec3f soundPos, Vec3f camPos){ + if(staticSound!=NULL){ + float d= soundPos.dist(camPos); + + if(dsetVolume(correctedVol); + + if(soundPlayer != NULL) { + soundPlayer->play(staticSound); + } + } + } +} + +void SoundRenderer::playFx(StaticSound *staticSound){ + if(staticSound!=NULL){ + staticSound->setVolume(fxVolume); + if(soundPlayer != NULL) { + soundPlayer->play(staticSound); + } + } +} + +// ======================= Ambient ============================ + +void SoundRenderer::playAmbient(StrSound *strSound){ + strSound->setVolume(ambientVolume); + if(soundPlayer != NULL) { + soundPlayer->play(strSound, ambientFade); + } +} + +void SoundRenderer::stopAmbient(StrSound *strSound){ + if(soundPlayer != NULL) { + soundPlayer->stop(strSound, ambientFade); + } +} + +// ======================= Misc ============================ + +void SoundRenderer::stopAllSounds(){ + if(soundPlayer != NULL) { + soundPlayer->stopAllSounds(); + } +} + +void SoundRenderer::loadConfig(){ + Config &config= Config::getInstance(); + + fxVolume= config.getInt("SoundVolumeFx")/100.f; + musicVolume= config.getInt("SoundVolumeMusic")/100.f; + ambientVolume= config.getInt("SoundVolumeAmbient")/100.f; +} + +}}//end namespace diff --git a/source/shared_lib/sources/platform/sdl/window.cpp b/source/shared_lib/sources/platform/sdl/window.cpp index 7f9e7c87..abf95dfd 100644 --- a/source/shared_lib/sources/platform/sdl/window.cpp +++ b/source/shared_lib/sources/platform/sdl/window.cpp @@ -51,17 +51,21 @@ bool Window::handleEvent() { SDL_Event event; while(SDL_PollEvent(&event)) { try { - //printf("[%d]\n",event.type); + //printf("START [%d]\n",event.type); switch(event.type) { case SDL_QUIT: return false; case SDL_MOUSEBUTTONDOWN: - global_window->handleMouseDown(event); + if(global_window) { + global_window->handleMouseDown(event); + } break; case SDL_MOUSEBUTTONUP: { - global_window->eventMouseUp(event.button.x, + if(global_window) { + global_window->eventMouseUp(event.button.x, event.button.y,getMouseButton(event.button.button)); + } break; } case SDL_MOUSEMOTION: { @@ -69,7 +73,10 @@ bool Window::handleEvent() { ms.leftMouse = (event.motion.state & SDL_BUTTON_LMASK) != 0; ms.rightMouse = (event.motion.state & SDL_BUTTON_RMASK) != 0; ms.centerMouse = (event.motion.state & SDL_BUTTON_MMASK) != 0; - global_window->eventMouseMove(event.motion.x, event.motion.y, &ms); + + if(global_window) { + global_window->eventMouseMove(event.motion.x, event.motion.y, &ms); + } break; } case SDL_KEYDOWN: @@ -78,11 +85,15 @@ bool Window::handleEvent() { && (event.key.keysym.mod & (KMOD_LALT | KMOD_RALT))) { toggleFullscreen(); } - global_window->eventKeyDown(getKey(event.key.keysym)); - global_window->eventKeyPress(static_cast(event.key.keysym.unicode)); + if(global_window) { + global_window->eventKeyDown(getKey(event.key.keysym)); + global_window->eventKeyPress(static_cast(event.key.keysym.unicode)); + } break; case SDL_KEYUP: - global_window->eventKeyUp(getKey(event.key.keysym)); + if(global_window) { + global_window->eventKeyUp(getKey(event.key.keysym)); + } break; } } catch(std::exception& e) { @@ -90,6 +101,8 @@ bool Window::handleEvent() { } } + //printf("END [%d]\n",event.type); + return true; }