More bug fixes for error handling if we have early program launch errors.
This commit is contained in:
parent
1fbff088e4
commit
221b099c67
|
@ -40,7 +40,6 @@ string debugLogFile = "";
|
||||||
class ExceptionHandler: public PlatformExceptionHandler{
|
class ExceptionHandler: public PlatformExceptionHandler{
|
||||||
public:
|
public:
|
||||||
virtual void handle(){
|
virtual void handle(){
|
||||||
|
|
||||||
string msg = "#1 An error ocurred and Glest will close.\nPlease report this bug to "+mailString+", attaching the generated "+getCrashDumpFileName()+" file.";
|
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());
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"%s\n",msg.c_str());
|
||||||
|
|
||||||
|
@ -54,7 +53,6 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
static void handleRuntimeError(const char *msg) {
|
static void handleRuntimeError(const char *msg) {
|
||||||
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"%s\n",msg);
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"%s\n",msg);
|
||||||
|
|
||||||
Program *program = Program::getInstance();
|
Program *program = Program::getInstance();
|
||||||
|
@ -65,7 +63,6 @@ public:
|
||||||
else {
|
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.");
|
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);
|
restoreVideoMode(true);
|
||||||
//SystemFlags::Close();
|
//SystemFlags::Close();
|
||||||
exit(0);
|
exit(0);
|
||||||
|
|
|
@ -91,6 +91,19 @@ void Program::ShowMessageProgramState::mouseDownLeft(int x, int y) {
|
||||||
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
//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) {
|
void Program::ShowMessageProgramState::mouseMove(int x, int y, const MouseState &mouseState) {
|
||||||
mouseX = x;
|
mouseX = x;
|
||||||
mouseY = y;
|
mouseY = y;
|
||||||
|
@ -193,6 +206,8 @@ void Program::keyPress(char c){
|
||||||
|
|
||||||
void Program::loop(){
|
void Program::loop(){
|
||||||
|
|
||||||
|
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
//render
|
//render
|
||||||
programState->render();
|
programState->render();
|
||||||
|
|
||||||
|
@ -201,6 +216,8 @@ void Program::loop(){
|
||||||
programState->updateCamera();
|
programState->updateCamera();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
//update world
|
//update world
|
||||||
while(updateTimer.isTime()){
|
while(updateTimer.isTime()){
|
||||||
GraphicComponent::update();
|
GraphicComponent::update();
|
||||||
|
@ -209,10 +226,14 @@ void Program::loop(){
|
||||||
NetworkManager::getInstance().update();
|
NetworkManager::getInstance().update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
//fps timer
|
//fps timer
|
||||||
while(fpsTimer.isTime()){
|
while(fpsTimer.isTime()){
|
||||||
programState->tick();
|
programState->tick();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Program::resize(SizeState sizeState){
|
void Program::resize(SizeState sizeState){
|
||||||
|
@ -360,7 +381,7 @@ void Program::restoreDisplaySettings(){
|
||||||
}
|
}
|
||||||
|
|
||||||
void Program::showMessage(const char *msg) {
|
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;
|
ProgramState *originalState = NULL;
|
||||||
if(this->programState) {
|
if(this->programState) {
|
||||||
|
@ -368,7 +389,7 @@ void Program::showMessage(const char *msg) {
|
||||||
originalState = this->programState;
|
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);
|
showCursor(true);
|
||||||
|
|
||||||
|
@ -379,18 +400,18 @@ void Program::showMessage(const char *msg) {
|
||||||
this->programState = NULL;
|
this->programState = NULL;
|
||||||
setState(showMsg);
|
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) {
|
while(Window::handleEvent() && showMsg->wantExit() == false) {
|
||||||
loop();
|
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;
|
delete this->programState;
|
||||||
this->programState = NULL;
|
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"));
|
showCursor(Config::getInstance().getBool("Windowed"));
|
||||||
|
|
||||||
|
@ -398,16 +419,16 @@ void Program::showMessage(const char *msg) {
|
||||||
init(this->window,false);
|
init(this->window,false);
|
||||||
//setState(originalState);
|
//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;
|
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;
|
this->programState= originalState;
|
||||||
//programState->load();
|
//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();
|
//programState->init();
|
||||||
|
|
||||||
|
|
|
@ -85,6 +85,7 @@ private:
|
||||||
virtual void render();
|
virtual void render();
|
||||||
virtual void mouseDownLeft(int x, int y);
|
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 void update();
|
||||||
virtual bool wantExit() { return userWantsExit; }
|
virtual bool wantExit() { return userWantsExit; }
|
||||||
};
|
};
|
||||||
|
|
141
source/glest_game/sound/sound_renderer.cpp
Normal file
141
source/glest_game/sound/sound_renderer.cpp
Normal file
|
@ -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(d<audibleDist){
|
||||||
|
float vol= (1.f-d/audibleDist)*fxVolume;
|
||||||
|
float correctedVol= log10(log10(vol*9+1)*9+1);
|
||||||
|
staticSound->setVolume(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
|
|
@ -51,17 +51,21 @@ bool Window::handleEvent() {
|
||||||
SDL_Event event;
|
SDL_Event event;
|
||||||
while(SDL_PollEvent(&event)) {
|
while(SDL_PollEvent(&event)) {
|
||||||
try {
|
try {
|
||||||
//printf("[%d]\n",event.type);
|
//printf("START [%d]\n",event.type);
|
||||||
|
|
||||||
switch(event.type) {
|
switch(event.type) {
|
||||||
case SDL_QUIT:
|
case SDL_QUIT:
|
||||||
return false;
|
return false;
|
||||||
case SDL_MOUSEBUTTONDOWN:
|
case SDL_MOUSEBUTTONDOWN:
|
||||||
|
if(global_window) {
|
||||||
global_window->handleMouseDown(event);
|
global_window->handleMouseDown(event);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case SDL_MOUSEBUTTONUP: {
|
case SDL_MOUSEBUTTONUP: {
|
||||||
|
if(global_window) {
|
||||||
global_window->eventMouseUp(event.button.x,
|
global_window->eventMouseUp(event.button.x,
|
||||||
event.button.y,getMouseButton(event.button.button));
|
event.button.y,getMouseButton(event.button.button));
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case SDL_MOUSEMOTION: {
|
case SDL_MOUSEMOTION: {
|
||||||
|
@ -69,7 +73,10 @@ bool Window::handleEvent() {
|
||||||
ms.leftMouse = (event.motion.state & SDL_BUTTON_LMASK) != 0;
|
ms.leftMouse = (event.motion.state & SDL_BUTTON_LMASK) != 0;
|
||||||
ms.rightMouse = (event.motion.state & SDL_BUTTON_RMASK) != 0;
|
ms.rightMouse = (event.motion.state & SDL_BUTTON_RMASK) != 0;
|
||||||
ms.centerMouse = (event.motion.state & SDL_BUTTON_MMASK) != 0;
|
ms.centerMouse = (event.motion.state & SDL_BUTTON_MMASK) != 0;
|
||||||
|
|
||||||
|
if(global_window) {
|
||||||
global_window->eventMouseMove(event.motion.x, event.motion.y, &ms);
|
global_window->eventMouseMove(event.motion.x, event.motion.y, &ms);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case SDL_KEYDOWN:
|
case SDL_KEYDOWN:
|
||||||
|
@ -78,11 +85,15 @@ bool Window::handleEvent() {
|
||||||
&& (event.key.keysym.mod & (KMOD_LALT | KMOD_RALT))) {
|
&& (event.key.keysym.mod & (KMOD_LALT | KMOD_RALT))) {
|
||||||
toggleFullscreen();
|
toggleFullscreen();
|
||||||
}
|
}
|
||||||
|
if(global_window) {
|
||||||
global_window->eventKeyDown(getKey(event.key.keysym));
|
global_window->eventKeyDown(getKey(event.key.keysym));
|
||||||
global_window->eventKeyPress(static_cast<char>(event.key.keysym.unicode));
|
global_window->eventKeyPress(static_cast<char>(event.key.keysym.unicode));
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case SDL_KEYUP:
|
case SDL_KEYUP:
|
||||||
|
if(global_window) {
|
||||||
global_window->eventKeyUp(getKey(event.key.keysym));
|
global_window->eventKeyUp(getKey(event.key.keysym));
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} catch(std::exception& e) {
|
} catch(std::exception& e) {
|
||||||
|
@ -90,6 +101,8 @@ bool Window::handleEvent() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//printf("END [%d]\n",event.type);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user