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{
|
||||
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);
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -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; }
|
||||
};
|
||||
|
|
|
@ -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;
|
||||
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<char>(event.key.keysym.unicode));
|
||||
if(global_window) {
|
||||
global_window->eventKeyDown(getKey(event.key.keysym));
|
||||
global_window->eventKeyPress(static_cast<char>(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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue