QTfrontend/util/SDLInteraction.cpp
changeset 8326 023a71940f26
parent 8117 329d9756b57c
child 9080 9b42757d7e71
equal deleted inserted replaced
8325:ecd51650d5d8 8326:023a71940f26
    23 
    23 
    24 #include "SDL.h"
    24 #include "SDL.h"
    25 #include "SDL_mixer.h"
    25 #include "SDL_mixer.h"
    26 
    26 
    27 #include "HWApplication.h"
    27 #include "HWApplication.h"
       
    28 #include "hwform.h" /* you know, we could just put a config singleton lookup function in gameuiconfig or something... */
       
    29 #include "gameuiconfig.h"
    28 
    30 
    29 #include "SDLInteraction.h"
    31 #include "SDLInteraction.h"
    30 
    32 
    31 #include "physfsrwops.h"
    33 #include "physfsrwops.h"
    32 
    34 
   184     // don't init again
   186     // don't init again
   185     if (m_audioInitialized)
   187     if (m_audioInitialized)
   186         return;
   188         return;
   187 
   189 
   188     SDL_Init(SDL_INIT_AUDIO);
   190     SDL_Init(SDL_INIT_AUDIO);
   189     Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 1024);
   191     if(!Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 1024)) /* should we keep trying, or just turn off permanently? */
   190     m_audioInitialized = true;
   192         m_audioInitialized = true;
   191 }
   193 }
   192 
   194 
   193 
   195 
   194 void SDLInteraction::playSoundFile(const QString & soundFile)
   196 void SDLInteraction::playSoundFile(const QString & soundFile)
   195 {
   197 {
       
   198     if (!HWForm::config || !HWForm::config->isFrontendSoundEnabled()) return;
   196     SDLAudioInit();
   199     SDLAudioInit();
       
   200     if (!m_audioInitialized) return;
   197     if (!m_soundMap->contains(soundFile))
   201     if (!m_soundMap->contains(soundFile))
   198         m_soundMap->insert(soundFile, Mix_LoadWAV_RW(PHYSFSRWOPS_openRead(soundFile.toLocal8Bit().constData()), 1));
   202         m_soundMap->insert(soundFile, Mix_LoadWAV_RW(PHYSFSRWOPS_openRead(soundFile.toLocal8Bit().constData()), 1));
   199 
   203 
   200     //FIXME: this is a hack, but works as long as we have few concurrent playing sounds
   204     //FIXME: this is a hack, but works as long as we have few concurrent playing sounds
   201     if (Mix_Playing(lastchannel) == false)
   205     if (Mix_Playing(lastchannel) == false)
   230 
   234 
   231     if (m_musicTrack.isEmpty())
   235     if (m_musicTrack.isEmpty())
   232         return;
   236         return;
   233 
   237 
   234     SDLAudioInit();
   238     SDLAudioInit();
       
   239     if (!m_audioInitialized) return;
   235 
   240 
   236     if (m_music == NULL)
   241     if (m_music == NULL)
   237         m_music = Mix_LoadMUS_RW(PHYSFSRWOPS_openRead(m_musicTrack.toLocal8Bit().constData()));
   242         m_music = Mix_LoadMUS_RW(PHYSFSRWOPS_openRead(m_musicTrack.toLocal8Bit().constData()));
   238 
   243 
   239     Mix_VolumeMusic(MIX_MAX_VOLUME - 28);
   244     Mix_VolumeMusic(MIX_MAX_VOLUME - 28);