- bugfix so that openal 1.13 works properly with megaglest

- added some code so we can show error messages when no menu item is active
This commit is contained in:
Mark Vejvoda 2011-04-09 01:22:39 +00:00
parent 6b63089612
commit 2bab37fdc0
5 changed files with 119 additions and 36 deletions

View File

@ -423,10 +423,16 @@ public:
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
//abort();
if(program && gameInitialized == true) {
//printf("\nprogram->getState() [%p]\n",program->getState());
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
if(program->getState() != NULL) {
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
program->showMessage(errMsg.c_str());
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
for(;program->isMessageShowing();) {
//program->getState()->render();
Window::handleEvent();
@ -434,13 +440,16 @@ public:
}
}
else {
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
program->showMessage(errMsg.c_str());
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
for(;program->isMessageShowing();) {
//program->renderProgramMsgBox();
Window::handleEvent();
program->loop();
}
}
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
}
else {
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);

View File

@ -47,6 +47,25 @@ const int SOUND_THREAD_UPDATE_MILLISECONDS = 25;
// class Program::CrashProgramState
// =====================================================
void ProgramState::render() {
Renderer &renderer= Renderer::getInstance();
renderer.clearBuffers();
renderer.reset2d();
renderer.renderMessageBox(program->getMsgBox());
renderer.renderMouse2d(mouseX, mouseY, mouse2dAnim);
renderer.swapBuffers();
}
void ProgramState::update() {
mouse2dAnim = (mouse2dAnim +1) % Renderer::maxMouse2dAnim;
}
void ProgramState::mouseMove(int x, int y, const MouseState *mouseState) {
mouseX = x;
mouseY = y;
program->getMsgBox()->mouseMove(x, y);
}
Program::ShowMessageProgramState::ShowMessageProgramState(Program *program, const char *msg) :
ProgramState(program) {
userWantsExit = false;
@ -256,6 +275,7 @@ void Program::loopWorker() {
}
ProgramState *prevState = this->programState;
assert(programState != NULL);
programState->render();
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d programState->render took msecs: %lld ==============> MAIN LOOP RENDERING\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis());
@ -284,9 +304,10 @@ void Program::loopWorker() {
if(prevState == this->programState) {
if(soundThreadManager == NULL || soundThreadManager->isThreadExecutionLagging()) {
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d] ERROR / WARNING soundThreadManager->isThreadExecutionLagging is TRUE\n",__FILE__,__FUNCTION__,__LINE__);
SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s %d] ERROR / WARNING soundThreadManager->isThreadExecutionLagging is TRUE\n",__FILE__,__FUNCTION__,__LINE__);
if(soundThreadManager != NULL) {
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d] ERROR / WARNING soundThreadManager->isThreadExecutionLagging is TRUE\n",__FILE__,__FUNCTION__,__LINE__);
SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s %d] ERROR / WARNING soundThreadManager->isThreadExecutionLagging is TRUE\n",__FILE__,__FUNCTION__,__LINE__);
}
SoundRenderer::getInstance().update();
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chronoUpdateLoop.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] SoundRenderer::getInstance().update() took msecs: %lld, updateCount = %d\n",__FILE__,__FUNCTION__,__LINE__,chronoUpdateLoop.getMillis(),updateCount);
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chronoUpdateLoop.getMillis() > 0) chronoUpdateLoop.start();
@ -398,6 +419,7 @@ void Program::setState(ProgramState *programState, bool cleanupOldState)
updateCameraTimer.init(GameConstants::cameraFps, maxTimes);
this->programState= programState;
assert(programState != NULL);
programState->load();
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);

View File

@ -47,6 +47,10 @@ class ProgramState{
protected:
Program *program;
int mouseX;
int mouseY;
int mouse2dAnim;
int startX;
int startY;
bool forceMouseRender;
@ -55,11 +59,16 @@ public:
ProgramState(Program *program) {
this->program= program;
this->forceMouseRender = false;
this->mouseX = 0;
this->mouseY = 0;
this->mouse2dAnim = 0;
}
virtual ~ProgramState(){};
virtual void render()=0;
virtual void update(){};
//virtual void render()=0;
virtual void render();
virtual void update();
virtual void updateCamera(){};
virtual void tick(){};
virtual void init(){};
@ -75,7 +84,7 @@ public:
virtual void mouseDoubleClickRight(int x, int y){}
virtual void mouseDoubleClickCenter(int x, int y){}
virtual void eventMouseWheel(int x, int y, int zDelta){}
virtual void mouseMove(int x, int y, const MouseState *mouseState) {};
virtual void mouseMove(int x, int y, const MouseState *mouseState);
virtual void keyDown(char key){};
virtual void keyUp(char key){};
virtual void keyPress(char c){};
@ -137,6 +146,7 @@ public:
static Program *getInstance() {return singleton;}
GraphicMessageBox * getMsgBox() { return &msgBox; }
void initNormal(WindowGl *window);
void initServer(WindowGl *window,bool autostart=false,bool openNetworkSlots=false);
void initClient(WindowGl *window, const Ip &serverIp);

View File

@ -112,8 +112,8 @@ private:
StaticSoundSource* findStaticSoundSource();
StreamSoundSource* findStreamSoundSource();
void checkAlcError(const char* message);
static void checkAlError(const char* message);
void checkAlcError(string message);
static void checkAlError(string message);
ALCdevice* device;
ALCcontext* context;

View File

@ -14,6 +14,7 @@
#include "platform_util.h"
#include "util.h"
#include "conversion.h"
#include "leak_dumper.h"
namespace Shared{ namespace Sound{ namespace OpenAL{
@ -38,40 +39,66 @@ SoundSource::~SoundSource()
bool SoundSource::playing()
{
ALint state = AL_PLAYING;
ALint state = AL_STOPPED;
alGetSourcei(source, AL_SOURCE_STATE, &state);
return state != AL_STOPPED;
return(state == AL_PLAYING || state == AL_PAUSED);
}
void SoundSource::unQueueBuffers() {
int processed;
alGetSourcei(source, AL_BUFFERS_PROCESSED, &processed);
SoundPlayerOpenAL::checkAlError("Problem unqueuing buffers (alGetSourcei AL_BUFFERS_PROCESSED) in audio source: ");
SoundPlayerOpenAL::checkAlError("Problem unqueuing buffers START OF METHOD: ");
int queued;
ALint queued=0;
alGetSourcei(source, AL_BUFFERS_QUEUED, &queued);
SoundPlayerOpenAL::checkAlError("Problem unqueuing buffers (alGetSourcei AL_BUFFERS_QUEUED) in audio source: ");
SoundPlayerOpenAL::checkAlError(string(__FILE__) + string(" ") + string(__FUNCTION__) + string(" ") + intToStr(__LINE__));
ALint processed=0;
alGetSourcei(source, AL_BUFFERS_PROCESSED, &processed);
SoundPlayerOpenAL::checkAlError(string(__FILE__) + string(" ") + string(__FUNCTION__) + string(" ") + intToStr(__LINE__));
while(processed--) {
ALuint buffer=0;
alSourceUnqueueBuffers(source, 1, &buffer);
SoundPlayerOpenAL::checkAlError(string(__FILE__) + string(" ") + string(__FUNCTION__) + string(" ") + intToStr(__LINE__));
}
// ALint queued=0;
// alGetSourcei(source, AL_BUFFERS_QUEUED, &queued);
// while(queued--) {
// ALuint buffer=0;
// alSourceUnqueueBuffers(source, 1, &buffer);
// SoundPlayerOpenAL::checkAlError("Problem unqueuing buffers (alSourceUnqueueBuffers) in audio source: ");
// }
//
// SoundPlayerOpenAL::checkAlError("Problem unqueuing buffers (alGetSourcei AL_BUFFERS_QUEUED) in audio source: ");
//if(processed < queued) {
while(queued--) {
ALuint buffer;
alSourceUnqueueBuffers(source, 1, &buffer);
SoundPlayerOpenAL::checkAlError("Problem unqueuing buffers (alSourceUnqueueBuffers) in audio source: ");
}
//}
}
void SoundSource::stop()
{
void SoundSource::stop() {
alSourceStop(source);
SoundPlayerOpenAL::checkAlError("Problem stopping audio source (alSourceStop): ");
SoundPlayerOpenAL::checkAlError(string(__FILE__) + string(" ") + string(__FUNCTION__) + string(" ") + intToStr(__LINE__));
unQueueBuffers();
alSourcei(source, AL_BUFFER, AL_NONE);
SoundPlayerOpenAL::checkAlError(string(__FILE__) + string(" ") + string(__FUNCTION__) + string(" ") + intToStr(__LINE__));
SoundPlayerOpenAL::checkAlError("Problem stopping audio source: ");
//unQueueBuffers();
alSourceRewind(source); // stops the source
SoundPlayerOpenAL::checkAlError(string(__FILE__) + string(" ") + string(__FUNCTION__) + string(" ") + intToStr(__LINE__));
while(playing() == true) {
//alSourceStop(source);
//SoundPlayerOpenAL::checkAlError(string(__FILE__) + string(" ") + string(__FUNCTION__) + string(" ") + intToStr(__LINE__));
ALint state = AL_STOPPED;
alGetSourcei(source, AL_SOURCE_STATE, &state);
SoundPlayerOpenAL::checkAlError(string(__FILE__) + string(" ") + string(__FUNCTION__) + string(" ") + intToStr(__LINE__));
sleep(1);
printf("$$$ WAITING FOR OPENAL TO STOP state = %d!\n",state);
}
//unQueueBuffers();
//SoundPlayerOpenAL::checkAlError(string(__FILE__) + string(" ") + string(__FUNCTION__) + string(" ") + intToStr(__LINE__));
}
ALenum SoundSource::getFormat(Sound* sound)
@ -134,20 +161,22 @@ void StaticSoundSource::play(StaticSound* sound) {
static_cast<ALsizei> (sound->getInfo()->getSize()),
static_cast<ALsizei> (sound->getInfo()->getSamplesPerSecond()));
SoundPlayerOpenAL::checkAlError("Couldn't fill audio buffer: ");
SoundPlayerOpenAL::checkAlError(string(__FILE__) + string(" ") + string(__FUNCTION__) + string(" ") + intToStr(__LINE__));
alSourcei(source, AL_BUFFER, buffer);
SoundPlayerOpenAL::checkAlError(string(__FILE__) + string(" ") + string(__FUNCTION__) + string(" ") + intToStr(__LINE__));
alSourcef(source, AL_GAIN, sound->getVolume());
SoundPlayerOpenAL::checkAlError(string(__FILE__) + string(" ") + string(__FUNCTION__) + string(" ") + intToStr(__LINE__));
alSourcePlay(source);
SoundPlayerOpenAL::checkAlError("Couldn't start audio source: ");
SoundPlayerOpenAL::checkAlError(string(__FILE__) + string(" ") + string(__FUNCTION__) + string(" ") + intToStr(__LINE__));
}
StreamSoundSource::StreamSoundSource()
{
sound = 0;
alGenBuffers(STREAMFRAGMENTS, buffers);
SoundPlayerOpenAL::checkAlError("Couldn't allocate audio buffers: ");
SoundPlayerOpenAL::checkAlError(string(__FILE__) + string(" ") + string(__FUNCTION__) + string(" ") + intToStr(__LINE__));
}
StreamSoundSource::~StreamSoundSource()
@ -186,14 +215,18 @@ void StreamSoundSource::play(StrSound* sound, int64 fadeon)
}
if(fadeon > 0) {
alSourcef(source, AL_GAIN, 0);
SoundPlayerOpenAL::checkAlError(string(__FILE__) + string(" ") + string(__FUNCTION__) + string(" ") + intToStr(__LINE__));
fadeState = FadingOn;
fade = fadeon;
chrono.start();
} else {
fadeState = NoFading;
alSourcef(source, AL_GAIN, sound->getVolume());
SoundPlayerOpenAL::checkAlError(string(__FILE__) + string(" ") + string(__FUNCTION__) + string(" ") + intToStr(__LINE__));
}
alSourcePlay(source);
SoundPlayerOpenAL::checkAlError(string(__FILE__) + string(" ") + string(__FUNCTION__) + string(" ") + intToStr(__LINE__));
}
void StreamSoundSource::update()
@ -204,16 +237,18 @@ void StreamSoundSource::update()
if(fadeState == NoFading){
alSourcef(source, AL_GAIN, sound->getVolume());
SoundPlayerOpenAL::checkAlError(string(__FILE__) + string(" ") + string(__FUNCTION__) + string(" ") + intToStr(__LINE__));
}
ALint processed = 0;
alGetSourcei(source, AL_BUFFERS_PROCESSED, &processed);
SoundPlayerOpenAL::checkAlError(string(__FILE__) + string(" ") + string(__FUNCTION__) + string(" ") + intToStr(__LINE__));
while(processed > 0) {
processed--;
ALuint buffer;
alSourceUnqueueBuffers(source, 1, &buffer);
SoundPlayerOpenAL::checkAlError("Couldn't unqueue audio buffer: ");
SoundPlayerOpenAL::checkAlError(string(__FILE__) + string(" ") + string(__FUNCTION__) + string(" ") + intToStr(__LINE__));
if(!fillBufferAndQueue(buffer))
break;
@ -225,7 +260,7 @@ void StreamSoundSource::update()
std::cerr << "Restarting audio source because of buffer underrun.\n";
alSourcePlay(source);
SoundPlayerOpenAL::checkAlError("Couldn't restart audio source: ");
SoundPlayerOpenAL::checkAlError(string(__FILE__) + string(" ") + string(__FUNCTION__) + string(" ") + intToStr(__LINE__));
}
// handle fading
@ -233,10 +268,13 @@ void StreamSoundSource::update()
case FadingOn:
if(chrono.getMillis() > fade) {
alSourcef(source, AL_GAIN, sound->getVolume());
SoundPlayerOpenAL::checkAlError(string(__FILE__) + string(" ") + string(__FUNCTION__) + string(" ") + intToStr(__LINE__));
fadeState = NoFading;
} else {
alSourcef(source, AL_GAIN, sound->getVolume() *
static_cast<float> (chrono.getMillis())/fade);
SoundPlayerOpenAL::checkAlError(string(__FILE__) + string(" ") + string(__FUNCTION__) + string(" ") + intToStr(__LINE__));
}
break;
case FadingOff:
@ -245,6 +283,7 @@ void StreamSoundSource::update()
} else {
alSourcef(source, AL_GAIN, sound->getVolume() *
(1.0f - static_cast<float>(chrono.getMillis())/fade));
SoundPlayerOpenAL::checkAlError(string(__FILE__) + string(" ") + string(__FUNCTION__) + string(" ") + intToStr(__LINE__));
}
break;
default:
@ -387,6 +426,7 @@ void SoundPlayerOpenAL::end() {
if(SystemFlags::getSystemSettingType(SystemFlags::debugSound).enabled) SystemFlags::OutputDebug(SystemFlags::debugSound,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
alcMakeContextCurrent( NULL );
SoundPlayerOpenAL::checkAlcError(string(__FILE__) + string(" ") + string(__FUNCTION__) + string(" ") + intToStr(__LINE__));
if(SystemFlags::getSystemSettingType(SystemFlags::debugSound).enabled) SystemFlags::OutputDebug(SystemFlags::debugSound,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
@ -558,20 +598,22 @@ StreamSoundSource* SoundPlayerOpenAL::findStreamSoundSource() {
return source;
}
void SoundPlayerOpenAL::checkAlcError(const char* message) {
void SoundPlayerOpenAL::checkAlcError(string message) {
int err = alcGetError(device);
if(err != ALC_NO_ERROR) {
std::stringstream msg;
msg << message << alcGetString(device, err);
msg << message.c_str() << alcGetString(device, err);
printf("openalc error [%s]\n",message.c_str());
throw std::runtime_error(msg.str());
}
}
void SoundPlayerOpenAL::checkAlError(const char* message) {
void SoundPlayerOpenAL::checkAlError(string message) {
int err = alGetError();
if(err != AL_NO_ERROR) {
std::stringstream msg;
msg << message << alGetString(err);
msg << message.c_str() << alGetString(err);
printf("openal error [%s]\n",message.c_str());
throw std::runtime_error(msg.str());
}
}