author  sheepluva 
Fri, 21 Oct 2011 08:03:42 +0200  
changeset 6166  701c5b8fac56 
parent 6165  6fe3e922246e 
child 6167  728cabee2c9f 
permissions  rwrr 
555  1 
/* 
1066  2 
* Hedgewars, a free turn based strategy game 
4976  3 
* Copyright (c) 20072011 Andrey Korotaev <unC0Rr@gmail.com> 
555  4 
* 
5 
* This program is free software; you can redistribute it and/or modify 

6 
* it under the terms of the GNU General Public License as published by 

7 
* the Free Software Foundation; version 2 of the License 

8 
* 

9 
* This program is distributed in the hope that it will be useful, 

10 
* but WITHOUT ANY WARRANTY; without even the implied warranty of 

11 
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 

12 
* GNU General Public License for more details. 

13 
* 

14 
* You should have received a copy of the GNU General Public License 

15 
* along with this program; if not, write to the Free Software 

16 
* Foundation, Inc., 59 Temple Place  Suite 330, Boston, MA 021111307, USA 

17 
*/ 

18 

19 

20 
#include "SDL.h" 

2515
51d3f4b6293a
revert audio to use SDL_mixer  also frontend uses it, so it needs sdlmixer sources
koda
parents:
2494
diff
changeset

21 
#include "SDL_mixer.h" 
6164
62aa418ed214
change SDL.h/SDL.cpp to use HWDataManager instead of poking around on the harddrive  also I added doc/comments to the class
sheepluva
parents:
5747
diff
changeset

22 

5252  23 
#include "HWApplication.h" 
2428  24 

6165
6fe3e922246e
moving and renaming SDLs.*, making it a singleton; cleaning up class responsibilties wrt SDLInteraction; some comments
sheepluva
parents:
6164
diff
changeset

25 
#include "SDLInteraction.h" 
2515
51d3f4b6293a
revert audio to use SDL_mixer  also frontend uses it, so it needs sdlmixer sources
koda
parents:
2494
diff
changeset

26 

2428  27 
extern char sdlkeys[1024][2][128]; 
28 
extern char xb360buttons[][128]; 

29 
extern char xb360dpad[128]; 

30 
extern char xbox360axes[][128]; 

31 

6165
6fe3e922246e
moving and renaming SDLs.*, making it a singleton; cleaning up class responsibilties wrt SDLInteraction; some comments
sheepluva
parents:
6164
diff
changeset

32 

6fe3e922246e
moving and renaming SDLs.*, making it a singleton; cleaning up class responsibilties wrt SDLInteraction; some comments
sheepluva
parents:
6164
diff
changeset

33 
SDLInteraction & SDLInteraction::instance() 
6fe3e922246e
moving and renaming SDLs.*, making it a singleton; cleaning up class responsibilties wrt SDLInteraction; some comments
sheepluva
parents:
6164
diff
changeset

34 
{ 
6fe3e922246e
moving and renaming SDLs.*, making it a singleton; cleaning up class responsibilties wrt SDLInteraction; some comments
sheepluva
parents:
6164
diff
changeset

35 
static SDLInteraction instance; 
6fe3e922246e
moving and renaming SDLs.*, making it a singleton; cleaning up class responsibilties wrt SDLInteraction; some comments
sheepluva
parents:
6164
diff
changeset

36 
return instance; 
6fe3e922246e
moving and renaming SDLs.*, making it a singleton; cleaning up class responsibilties wrt SDLInteraction; some comments
sheepluva
parents:
6164
diff
changeset

37 
} 
6fe3e922246e
moving and renaming SDLs.*, making it a singleton; cleaning up class responsibilties wrt SDLInteraction; some comments
sheepluva
parents:
6164
diff
changeset

38 

6fe3e922246e
moving and renaming SDLs.*, making it a singleton; cleaning up class responsibilties wrt SDLInteraction; some comments
sheepluva
parents:
6164
diff
changeset

39 

2428  40 
SDLInteraction::SDLInteraction() 
555  41 
{ 
5085  42 

2948
3f21a9dc93d0
Replace tabs with spaces using 'expand t 4' command
unc0rr
parents:
2531
diff
changeset

43 
SDL_Init(SDL_INIT_VIDEO  SDL_INIT_JOYSTICK); 
3697  44 

6166  45 
m_audioInitialized = false; 
46 
m_music = NULL; 

47 
m_musicTrack = ""; 

48 
m_isPlayingMusic = false; 

2948
3f21a9dc93d0
Replace tabs with spaces using 'expand t 4' command
unc0rr
parents:
2531
diff
changeset

49 
if(SDL_NumJoysticks()) 
3f21a9dc93d0
Replace tabs with spaces using 'expand t 4' command
unc0rr
parents:
2531
diff
changeset

50 
addGameControllerKeys(); 
3f21a9dc93d0
Replace tabs with spaces using 'expand t 4' command
unc0rr
parents:
2531
diff
changeset

51 
SDL_QuitSubSystem(SDL_INIT_JOYSTICK); 
6165
6fe3e922246e
moving and renaming SDLs.*, making it a singleton; cleaning up class responsibilties wrt SDLInteraction; some comments
sheepluva
parents:
6164
diff
changeset

52 

6fe3e922246e
moving and renaming SDLs.*, making it a singleton; cleaning up class responsibilties wrt SDLInteraction; some comments
sheepluva
parents:
6164
diff
changeset

53 
soundMap = new QMap<QString,Mix_Chunk*>(); 
555  54 
} 
55 

6166  56 

555  57 
SDLInteraction::~SDLInteraction() 
58 
{ 

6165
6fe3e922246e
moving and renaming SDLs.*, making it a singleton; cleaning up class responsibilties wrt SDLInteraction; some comments
sheepluva
parents:
6164
diff
changeset

59 
stopMusic(); 
6166  60 
if (m_audioInitialized) 
61 
{ 

62 
if (m_music != NULL) 

63 
Mix_FreeMusic(m_music); 

2948
3f21a9dc93d0
Replace tabs with spaces using 'expand t 4' command
unc0rr
parents:
2531
diff
changeset

64 
Mix_CloseAudio(); 
3f21a9dc93d0
Replace tabs with spaces using 'expand t 4' command
unc0rr
parents:
2531
diff
changeset

65 
} 
3f21a9dc93d0
Replace tabs with spaces using 'expand t 4' command
unc0rr
parents:
2531
diff
changeset

66 
SDL_Quit(); 
6165
6fe3e922246e
moving and renaming SDLs.*, making it a singleton; cleaning up class responsibilties wrt SDLInteraction; some comments
sheepluva
parents:
6164
diff
changeset

67 

6fe3e922246e
moving and renaming SDLs.*, making it a singleton; cleaning up class responsibilties wrt SDLInteraction; some comments
sheepluva
parents:
6164
diff
changeset

68 
delete soundMap; 
555  69 
} 
70 

6166  71 

555  72 
QStringList SDLInteraction::getResolutions() const 
73 
{ 

2948
3f21a9dc93d0
Replace tabs with spaces using 'expand t 4' command
unc0rr
parents:
2531
diff
changeset

74 
QStringList result; 
555  75 

2948
3f21a9dc93d0
Replace tabs with spaces using 'expand t 4' command
unc0rr
parents:
2531
diff
changeset

76 
SDL_Rect **modes; 
555  77 

2948
3f21a9dc93d0
Replace tabs with spaces using 'expand t 4' command
unc0rr
parents:
2531
diff
changeset

78 
modes = SDL_ListModes(NULL, SDL_FULLSCREEN); 
555  79 

2948
3f21a9dc93d0
Replace tabs with spaces using 'expand t 4' command
unc0rr
parents:
2531
diff
changeset

80 
if((modes == (SDL_Rect **)0)  (modes == (SDL_Rect **)1)) 
3f21a9dc93d0
Replace tabs with spaces using 'expand t 4' command
unc0rr
parents:
2531
diff
changeset

81 
{ 
3f21a9dc93d0
Replace tabs with spaces using 'expand t 4' command
unc0rr
parents:
2531
diff
changeset

82 
result << "640x480"; 
3f21a9dc93d0
Replace tabs with spaces using 'expand t 4' command
unc0rr
parents:
2531
diff
changeset

83 
} else 
3f21a9dc93d0
Replace tabs with spaces using 'expand t 4' command
unc0rr
parents:
2531
diff
changeset

84 
{ 
3f21a9dc93d0
Replace tabs with spaces using 'expand t 4' command
unc0rr
parents:
2531
diff
changeset

85 
for(int i = 0; modes[i]; ++i) 
3f21a9dc93d0
Replace tabs with spaces using 'expand t 4' command
unc0rr
parents:
2531
diff
changeset

86 
if ((modes[i]>w >= 640) && (modes[i]>h >= 480)) 
3f21a9dc93d0
Replace tabs with spaces using 'expand t 4' command
unc0rr
parents:
2531
diff
changeset

87 
result << QString("%1x%2").arg(modes[i]>w).arg(modes[i]>h); 
3f21a9dc93d0
Replace tabs with spaces using 'expand t 4' command
unc0rr
parents:
2531
diff
changeset

88 
} 
555  89 

2948
3f21a9dc93d0
Replace tabs with spaces using 'expand t 4' command
unc0rr
parents:
2531
diff
changeset

90 
return result; 
555  91 
} 
2191  92 

6166  93 

2428  94 
void SDLInteraction::addGameControllerKeys() const 
95 
{ 

2948
3f21a9dc93d0
Replace tabs with spaces using 'expand t 4' command
unc0rr
parents:
2531
diff
changeset

96 
QStringList result; 
2428  97 

2948
3f21a9dc93d0
Replace tabs with spaces using 'expand t 4' command
unc0rr
parents:
2531
diff
changeset

98 
int i = 0; 
3f21a9dc93d0
Replace tabs with spaces using 'expand t 4' command
unc0rr
parents:
2531
diff
changeset

99 
while(i < 1024 && sdlkeys[i][1][0] != '\0') 
3f21a9dc93d0
Replace tabs with spaces using 'expand t 4' command
unc0rr
parents:
2531
diff
changeset

100 
i++; 
2428  101 

2948
3f21a9dc93d0
Replace tabs with spaces using 'expand t 4' command
unc0rr
parents:
2531
diff
changeset

102 
// Iterate through all game controllers 
3f21a9dc93d0
Replace tabs with spaces using 'expand t 4' command
unc0rr
parents:
2531
diff
changeset

103 
for(int jid = 0; jid < SDL_NumJoysticks(); jid++) 
3f21a9dc93d0
Replace tabs with spaces using 'expand t 4' command
unc0rr
parents:
2531
diff
changeset

104 
{ 
3f21a9dc93d0
Replace tabs with spaces using 'expand t 4' command
unc0rr
parents:
2531
diff
changeset

105 
SDL_Joystick* joy = SDL_JoystickOpen(jid); 
3697  106 

2948
3f21a9dc93d0
Replace tabs with spaces using 'expand t 4' command
unc0rr
parents:
2531
diff
changeset

107 
// Retrieve the game controller's name and strip "Controller (...)" that's added by some drivers (English only) 
3f21a9dc93d0
Replace tabs with spaces using 'expand t 4' command
unc0rr
parents:
2531
diff
changeset

108 
QString joyname = QString(SDL_JoystickName(jid)).replace(QRegExp("^Controller \\((.*)\\)$"), "\\1"); 
2428  109 

2948
3f21a9dc93d0
Replace tabs with spaces using 'expand t 4' command
unc0rr
parents:
2531
diff
changeset

110 
// Connected Xbox 360 controller? Use specific button names then 
3f21a9dc93d0
Replace tabs with spaces using 'expand t 4' command
unc0rr
parents:
2531
diff
changeset

111 
// Might be interesting to add 'named' buttons for the most often used gamepads 
3f21a9dc93d0
Replace tabs with spaces using 'expand t 4' command
unc0rr
parents:
2531
diff
changeset

112 
bool isxb = joyname.contains("Xbox 360"); 
2428  113 

2948
3f21a9dc93d0
Replace tabs with spaces using 'expand t 4' command
unc0rr
parents:
2531
diff
changeset

114 
// This part of the string won't change for multiple keys/hats, so keep it 
3f21a9dc93d0
Replace tabs with spaces using 'expand t 4' command
unc0rr
parents:
2531
diff
changeset

115 
QString prefix = QString("%1 (%2): ").arg(joyname).arg(jid + 1); 
2428  116 

2948
3f21a9dc93d0
Replace tabs with spaces using 'expand t 4' command
unc0rr
parents:
2531
diff
changeset

117 
// Register entries for missing axes not assigned to sticks of this joystick/gamepad 
3f21a9dc93d0
Replace tabs with spaces using 'expand t 4' command
unc0rr
parents:
2531
diff
changeset

118 
for(int aid = 0; aid < SDL_JoystickNumAxes(joy) && i < 1021; aid++) 
3f21a9dc93d0
Replace tabs with spaces using 'expand t 4' command
unc0rr
parents:
2531
diff
changeset

119 
{ 
3f21a9dc93d0
Replace tabs with spaces using 'expand t 4' command
unc0rr
parents:
2531
diff
changeset

120 
// Again store the part of the string not changing for multiple uses 
5252  121 
QString axis = prefix + HWApplication::translate("binds (keys)", "Axis") + QString(" %1 ").arg(aid + 1); 
3697  122 

2948
3f21a9dc93d0
Replace tabs with spaces using 'expand t 4' command
unc0rr
parents:
2531
diff
changeset

123 
// Entry for "Axis Up" 
3f21a9dc93d0
Replace tabs with spaces using 'expand t 4' command
unc0rr
parents:
2531
diff
changeset

124 
sprintf(sdlkeys[i][0], "j%da%du", jid, aid); 
5747  125 
sprintf(sdlkeys[i++][1], "%s", ((isxb && aid < 5) ? (prefix + HWApplication::translate("binds (keys)", xbox360axes[aid * 2])) : axis + HWApplication::translate("binds (keys)", "(Up)")).toUtf8().constData()); 
2428  126 

2948
3f21a9dc93d0
Replace tabs with spaces using 'expand t 4' command
unc0rr
parents:
2531
diff
changeset

127 
// Entry for "Axis Down" 
3f21a9dc93d0
Replace tabs with spaces using 'expand t 4' command
unc0rr
parents:
2531
diff
changeset

128 
sprintf(sdlkeys[i][0], "j%da%dd", jid, aid); 
5747  129 
sprintf(sdlkeys[i++][1], "%s", ((isxb && aid < 5) ? (prefix + HWApplication::translate("binds (keys)", xbox360axes[aid * 2 + 1])) : axis + HWApplication::translate("binds (keys)", "(Down)")).toUtf8().constData()); 
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand t 4' command
unc0rr
parents:
2531
diff
changeset

130 
} 
2428  131 

2948
3f21a9dc93d0
Replace tabs with spaces using 'expand t 4' command
unc0rr
parents:
2531
diff
changeset

132 
// Register entries for all coolie hats of this joystick/gamepad 
3f21a9dc93d0
Replace tabs with spaces using 'expand t 4' command
unc0rr
parents:
2531
diff
changeset

133 
for(int hid = 0; hid < SDL_JoystickNumHats(joy) && i < 1019; hid++) 
3f21a9dc93d0
Replace tabs with spaces using 'expand t 4' command
unc0rr
parents:
2531
diff
changeset

134 
{ 
3f21a9dc93d0
Replace tabs with spaces using 'expand t 4' command
unc0rr
parents:
2531
diff
changeset

135 
// Again store the part of the string not changing for multiple uses 
5252  136 
QString hat = prefix + (isxb ? (HWApplication::translate("binds (keys)", xb360dpad) + QString(" ")) : HWApplication::translate("binds (keys)", "Hat") + QString(" %1 ").arg(hid + 1)); 
2428  137 

2948
3f21a9dc93d0
Replace tabs with spaces using 'expand t 4' command
unc0rr
parents:
2531
diff
changeset

138 
// Entry for "Hat Up" 
3697  139 
sprintf(sdlkeys[i][0], "j%dh%du", jid, hid); 
5747  140 
sprintf(sdlkeys[i++][1], "%s", (hat + HWApplication::translate("binds (keys)", "(Up)")).toUtf8().constData()); 
2428  141 

2948
3f21a9dc93d0
Replace tabs with spaces using 'expand t 4' command
unc0rr
parents:
2531
diff
changeset

142 
// Entry for "Hat Down" 
3697  143 
sprintf(sdlkeys[i][0], "j%dh%dd", jid, hid); 
5747  144 
sprintf(sdlkeys[i++][1], "%s", (hat + HWApplication::translate("binds (keys)", "(Down)")).toUtf8().constData()); 
2428  145 

2948
3f21a9dc93d0
Replace tabs with spaces using 'expand t 4' command
unc0rr
parents:
2531
diff
changeset

146 
// Entry for "Hat Left" 
3697  147 
sprintf(sdlkeys[i][0], "j%dh%dl", jid, hid); 
5747  148 
sprintf(sdlkeys[i++][1], "%s", (hat + HWApplication::translate("binds (keys)", "(Left)")).toUtf8().constData()); 
2428  149 

2948
3f21a9dc93d0
Replace tabs with spaces using 'expand t 4' command
unc0rr
parents:
2531
diff
changeset

150 
// Entry for "Hat Right" 
3697  151 
sprintf(sdlkeys[i][0], "j%dh%dr", jid, hid); 
5747  152 
sprintf(sdlkeys[i++][1], "%s", (hat + HWApplication::translate("binds (keys)", "(Right)")).toUtf8().constData()); 
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand t 4' command
unc0rr
parents:
2531
diff
changeset

153 
} 
3697  154 

2948
3f21a9dc93d0
Replace tabs with spaces using 'expand t 4' command
unc0rr
parents:
2531
diff
changeset

155 
// Register entries for all buttons of this joystick/gamepad 
3f21a9dc93d0
Replace tabs with spaces using 'expand t 4' command
unc0rr
parents:
2531
diff
changeset

156 
for(int bid = 0; bid < SDL_JoystickNumButtons(joy) && i < 1022; bid++) 
3f21a9dc93d0
Replace tabs with spaces using 'expand t 4' command
unc0rr
parents:
2531
diff
changeset

157 
{ 
3f21a9dc93d0
Replace tabs with spaces using 'expand t 4' command
unc0rr
parents:
2531
diff
changeset

158 
// Buttons 
3697  159 
sprintf(sdlkeys[i][0], "j%db%d", jid, bid); 
5747  160 
sprintf(sdlkeys[i++][1], "%s", (prefix + ((isxb && bid < 10) ? (HWApplication::translate("binds (keys)", xb360buttons[bid]) + QString(" ")) : HWApplication::translate("binds (keys)", "Button") + QString(" %1").arg(bid + 1))).toUtf8().constData()); 
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand t 4' command
unc0rr
parents:
2531
diff
changeset

161 
} 
3f21a9dc93d0
Replace tabs with spaces using 'expand t 4' command
unc0rr
parents:
2531
diff
changeset

162 
// Close the game controller as we no longer need it 
3f21a9dc93d0
Replace tabs with spaces using 'expand t 4' command
unc0rr
parents:
2531
diff
changeset

163 
SDL_JoystickClose(joy); 
3f21a9dc93d0
Replace tabs with spaces using 'expand t 4' command
unc0rr
parents:
2531
diff
changeset

164 
} 
3697  165 

2948
3f21a9dc93d0
Replace tabs with spaces using 'expand t 4' command
unc0rr
parents:
2531
diff
changeset

166 
// Terminate the list 
3f21a9dc93d0
Replace tabs with spaces using 'expand t 4' command
unc0rr
parents:
2531
diff
changeset

167 
sdlkeys[i][0][0] = '\0'; 
3f21a9dc93d0
Replace tabs with spaces using 'expand t 4' command
unc0rr
parents:
2531
diff
changeset

168 
sdlkeys[i][1][0] = '\0'; 
2428  169 
} 
170 

6166  171 

172 
void SDLInteraction::SDLAudioInit() 

2515
51d3f4b6293a
revert audio to use SDL_mixer  also frontend uses it, so it needs sdlmixer sources
koda
parents:
2494
diff
changeset

173 
{ 
6166  174 
// don't init again 
175 
if (m_audioInitialized) 

176 
return; 

177 

178 
SDL_Init(SDL_INIT_AUDIO); 

179 
Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 1024); 

180 
m_audioInitialized = true; 

2515
51d3f4b6293a
revert audio to use SDL_mixer  also frontend uses it, so it needs sdlmixer sources
koda
parents:
2494
diff
changeset

181 
} 
51d3f4b6293a
revert audio to use SDL_mixer  also frontend uses it, so it needs sdlmixer sources
koda
parents:
2494
diff
changeset

182 

6166  183 

6165
6fe3e922246e
moving and renaming SDLs.*, making it a singleton; cleaning up class responsibilties wrt SDLInteraction; some comments
sheepluva
parents:
6164
diff
changeset

184 
void SDLInteraction::playSoundFile(const QString & soundFile) 
1223
41d7283934c1
Hackish way to play music in frontend... to be fixed
unc0rr
parents:
1191
diff
changeset

185 
{ 
6166  186 
SDLAudioInit(); 
6165
6fe3e922246e
moving and renaming SDLs.*, making it a singleton; cleaning up class responsibilties wrt SDLInteraction; some comments
sheepluva
parents:
6164
diff
changeset

187 
if (!soundMap>contains(soundFile)) 
6fe3e922246e
moving and renaming SDLs.*, making it a singleton; cleaning up class responsibilties wrt SDLInteraction; some comments
sheepluva
parents:
6164
diff
changeset

188 
soundMap>insert(soundFile, Mix_LoadWAV(soundFile.toLocal8Bit().constData())); 
6fe3e922246e
moving and renaming SDLs.*, making it a singleton; cleaning up class responsibilties wrt SDLInteraction; some comments
sheepluva
parents:
6164
diff
changeset

189 

6fe3e922246e
moving and renaming SDLs.*, making it a singleton; cleaning up class responsibilties wrt SDLInteraction; some comments
sheepluva
parents:
6164
diff
changeset

190 
Mix_PlayChannel(1, soundMap>value(soundFile), 0); 
6fe3e922246e
moving and renaming SDLs.*, making it a singleton; cleaning up class responsibilties wrt SDLInteraction; some comments
sheepluva
parents:
6164
diff
changeset

191 
} 
6fe3e922246e
moving and renaming SDLs.*, making it a singleton; cleaning up class responsibilties wrt SDLInteraction; some comments
sheepluva
parents:
6164
diff
changeset

192 

6166  193 

194 
void SDLInteraction::setMusicTrack(const QString & musicFile) 

195 
{ 

196 
bool wasPlayingMusic = m_isPlayingMusic; 

197 

198 
stopMusic(); 

199 

200 
if (m_music != NULL) 

201 
{ 

202 
Mix_FreeMusic(m_music); 

203 
m_music = NULL; 

204 
} 

205 

206 
m_musicTrack = musicFile; 

207 

208 
if (wasPlayingMusic) 

209 
startMusic(); 

210 
} 

211 

212 

6165
6fe3e922246e
moving and renaming SDLs.*, making it a singleton; cleaning up class responsibilties wrt SDLInteraction; some comments
sheepluva
parents:
6164
diff
changeset

213 
void SDLInteraction::startMusic() 
6fe3e922246e
moving and renaming SDLs.*, making it a singleton; cleaning up class responsibilties wrt SDLInteraction; some comments
sheepluva
parents:
6164
diff
changeset

214 
{ 
6166  215 
if (m_isPlayingMusic) 
216 
return; 

217 

218 
m_isPlayingMusic = true; 

2515
51d3f4b6293a
revert audio to use SDL_mixer  also frontend uses it, so it needs sdlmixer sources
koda
parents:
2494
diff
changeset

219 

6166  220 
if (m_musicTrack.isEmpty()) 
221 
return; 

3697  222 

6166  223 
SDLAudioInit(); 
224 

225 
if (m_music == NULL) 

226 
m_music = Mix_LoadMUS(m_musicTrack.toLocal8Bit().constData()); 

6164
62aa418ed214
change SDL.h/SDL.cpp to use HWDataManager instead of poking around on the harddrive  also I added doc/comments to the class
sheepluva
parents:
5747
diff
changeset

227 

2948
3f21a9dc93d0
Replace tabs with spaces using 'expand t 4' command
unc0rr
parents:
2531
diff
changeset

228 
Mix_VolumeMusic(MIX_MAX_VOLUME  28); 
6166  229 
Mix_FadeInMusic(m_music, 1, 1750); 
1223
41d7283934c1
Hackish way to play music in frontend... to be fixed
unc0rr
parents:
1191
diff
changeset

230 
} 
41d7283934c1
Hackish way to play music in frontend... to be fixed
unc0rr
parents:
1191
diff
changeset

231 

6166  232 

6165
6fe3e922246e
moving and renaming SDLs.*, making it a singleton; cleaning up class responsibilties wrt SDLInteraction; some comments
sheepluva
parents:
6164
diff
changeset

233 
void SDLInteraction::stopMusic() 
1223
41d7283934c1
Hackish way to play music in frontend... to be fixed
unc0rr
parents:
1191
diff
changeset

234 
{ 
6166  235 
if (m_isPlayingMusic && (m_music != NULL)) { 
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand t 4' command
unc0rr
parents:
2531
diff
changeset

236 
// fade out music to finish 0,5 seconds from now 
3f21a9dc93d0
Replace tabs with spaces using 'expand t 4' command
unc0rr
parents:
2531
diff
changeset

237 
while(!Mix_FadeOutMusic(1000) && Mix_PlayingMusic()) { 
3f21a9dc93d0
Replace tabs with spaces using 'expand t 4' command
unc0rr
parents:
2531
diff
changeset

238 
SDL_Delay(100); 
3f21a9dc93d0
Replace tabs with spaces using 'expand t 4' command
unc0rr
parents:
2531
diff
changeset

239 
} 
3f21a9dc93d0
Replace tabs with spaces using 'expand t 4' command
unc0rr
parents:
2531
diff
changeset

240 
} 
6166  241 

242 
m_isPlayingMusic = false; 

1223
41d7283934c1
Hackish way to play music in frontend... to be fixed
unc0rr
parents:
1191
diff
changeset

243 
} 
2402
edd12b259e7c
revert to manual startup of frontend's OpenAL session (keeping voices' bug fixed)
koda
parents:
2399
diff
changeset

244 