author | unc0rr |
Thu, 10 May 2012 00:58:05 +0400 | |
changeset 7034 | e3639ce1d4f8 |
parent 6952 | 7f70f37bbf08 |
child 8117 | 329d9756b57c |
permissions | -rw-r--r-- |
555 | 1 |
/* |
1066 | 2 |
* Hedgewars, a free turn based strategy game |
6952 | 3 |
* Copyright (c) 2004-2012 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 02111-1307, USA |
|
17 |
*/ |
|
18 |
||
6168 | 19 |
/** |
6170 | 20 |
* @file |
6168 | 21 |
* @brief SDLInteraction class implementation |
22 |
*/ |
|
555 | 23 |
|
24 |
#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
|
25 |
#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
|
26 |
|
5252 | 27 |
#include "HWApplication.h" |
2428 | 28 |
|
6165
6fe3e922246e
moving and renaming SDLs.*, making it a singleton; cleaning up class responsibilties wrt SDLInteraction; some comments
sheepluva
parents:
6164
diff
changeset
|
29 |
#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
|
30 |
|
2428 | 31 |
extern char sdlkeys[1024][2][128]; |
32 |
extern char xb360buttons[][128]; |
|
33 |
extern char xb360dpad[128]; |
|
34 |
extern char xbox360axes[][128]; |
|
35 |
||
6165
6fe3e922246e
moving and renaming SDLs.*, making it a singleton; cleaning up class responsibilties wrt SDLInteraction; some comments
sheepluva
parents:
6164
diff
changeset
|
36 |
|
6fe3e922246e
moving and renaming SDLs.*, making it a singleton; cleaning up class responsibilties wrt SDLInteraction; some comments
sheepluva
parents:
6164
diff
changeset
|
37 |
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
|
38 |
{ |
6fe3e922246e
moving and renaming SDLs.*, making it a singleton; cleaning up class responsibilties wrt SDLInteraction; some comments
sheepluva
parents:
6164
diff
changeset
|
39 |
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
|
40 |
return instance; |
6fe3e922246e
moving and renaming SDLs.*, making it a singleton; cleaning up class responsibilties wrt SDLInteraction; some comments
sheepluva
parents:
6164
diff
changeset
|
41 |
} |
6fe3e922246e
moving and renaming SDLs.*, making it a singleton; cleaning up class responsibilties wrt SDLInteraction; some comments
sheepluva
parents:
6164
diff
changeset
|
42 |
|
6fe3e922246e
moving and renaming SDLs.*, making it a singleton; cleaning up class responsibilties wrt SDLInteraction; some comments
sheepluva
parents:
6164
diff
changeset
|
43 |
|
2428 | 44 |
SDLInteraction::SDLInteraction() |
555 | 45 |
{ |
5085 | 46 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2531
diff
changeset
|
47 |
SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK); |
3697 | 48 |
|
6166 | 49 |
m_audioInitialized = false; |
50 |
m_music = NULL; |
|
51 |
m_musicTrack = ""; |
|
52 |
m_isPlayingMusic = false; |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2531
diff
changeset
|
53 |
if(SDL_NumJoysticks()) |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2531
diff
changeset
|
54 |
addGameControllerKeys(); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2531
diff
changeset
|
55 |
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
|
56 |
|
6167 | 57 |
m_soundMap = new QMap<QString,Mix_Chunk*>(); |
555 | 58 |
} |
59 |
||
6166 | 60 |
|
555 | 61 |
SDLInteraction::~SDLInteraction() |
62 |
{ |
|
6165
6fe3e922246e
moving and renaming SDLs.*, making it a singleton; cleaning up class responsibilties wrt SDLInteraction; some comments
sheepluva
parents:
6164
diff
changeset
|
63 |
stopMusic(); |
6166 | 64 |
if (m_audioInitialized) |
65 |
{ |
|
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6585
diff
changeset
|
66 |
if (m_music != NULL) |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6585
diff
changeset
|
67 |
{ |
6524 | 68 |
Mix_HaltMusic(); |
6166 | 69 |
Mix_FreeMusic(m_music); |
6524 | 70 |
} |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2531
diff
changeset
|
71 |
Mix_CloseAudio(); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2531
diff
changeset
|
72 |
} |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2531
diff
changeset
|
73 |
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
|
74 |
|
6167 | 75 |
delete m_soundMap; |
555 | 76 |
} |
77 |
||
6166 | 78 |
|
555 | 79 |
QStringList SDLInteraction::getResolutions() const |
80 |
{ |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2531
diff
changeset
|
81 |
QStringList result; |
555 | 82 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2531
diff
changeset
|
83 |
SDL_Rect **modes; |
555 | 84 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2531
diff
changeset
|
85 |
modes = SDL_ListModes(NULL, SDL_FULLSCREEN); |
555 | 86 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2531
diff
changeset
|
87 |
if((modes == (SDL_Rect **)0) || (modes == (SDL_Rect **)-1)) |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2531
diff
changeset
|
88 |
{ |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2531
diff
changeset
|
89 |
result << "640x480"; |
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6585
diff
changeset
|
90 |
} |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6585
diff
changeset
|
91 |
else |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2531
diff
changeset
|
92 |
{ |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2531
diff
changeset
|
93 |
for(int i = 0; modes[i]; ++i) |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2531
diff
changeset
|
94 |
if ((modes[i]->w >= 640) && (modes[i]->h >= 480)) |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2531
diff
changeset
|
95 |
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
|
96 |
} |
555 | 97 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2531
diff
changeset
|
98 |
return result; |
555 | 99 |
} |
2191 | 100 |
|
6166 | 101 |
|
2428 | 102 |
void SDLInteraction::addGameControllerKeys() const |
103 |
{ |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2531
diff
changeset
|
104 |
QStringList result; |
2428 | 105 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2531
diff
changeset
|
106 |
int i = 0; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2531
diff
changeset
|
107 |
while(i < 1024 && sdlkeys[i][1][0] != '\0') |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2531
diff
changeset
|
108 |
i++; |
2428 | 109 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2531
diff
changeset
|
110 |
// Iterate through all game controllers |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2531
diff
changeset
|
111 |
for(int jid = 0; jid < SDL_NumJoysticks(); jid++) |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2531
diff
changeset
|
112 |
{ |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2531
diff
changeset
|
113 |
SDL_Joystick* joy = SDL_JoystickOpen(jid); |
3697 | 114 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2531
diff
changeset
|
115 |
// 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
|
116 |
QString joyname = QString(SDL_JoystickName(jid)).replace(QRegExp("^Controller \\((.*)\\)$"), "\\1"); |
2428 | 117 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2531
diff
changeset
|
118 |
// Connected Xbox 360 controller? Use specific button names then |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2531
diff
changeset
|
119 |
// 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
|
120 |
bool isxb = joyname.contains("Xbox 360"); |
2428 | 121 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2531
diff
changeset
|
122 |
// 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
|
123 |
QString prefix = QString("%1 (%2): ").arg(joyname).arg(jid + 1); |
2428 | 124 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2531
diff
changeset
|
125 |
// 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
|
126 |
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
|
127 |
{ |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2531
diff
changeset
|
128 |
// Again store the part of the string not changing for multiple uses |
5252 | 129 |
QString axis = prefix + HWApplication::translate("binds (keys)", "Axis") + QString(" %1 ").arg(aid + 1); |
3697 | 130 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2531
diff
changeset
|
131 |
// Entry for "Axis Up" |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2531
diff
changeset
|
132 |
sprintf(sdlkeys[i][0], "j%da%du", jid, aid); |
5747 | 133 |
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 | 134 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2531
diff
changeset
|
135 |
// Entry for "Axis Down" |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2531
diff
changeset
|
136 |
sprintf(sdlkeys[i][0], "j%da%dd", jid, aid); |
5747 | 137 |
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
|
138 |
} |
2428 | 139 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2531
diff
changeset
|
140 |
// 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
|
141 |
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
|
142 |
{ |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2531
diff
changeset
|
143 |
// Again store the part of the string not changing for multiple uses |
5252 | 144 |
QString hat = prefix + (isxb ? (HWApplication::translate("binds (keys)", xb360dpad) + QString(" ")) : HWApplication::translate("binds (keys)", "Hat") + QString(" %1 ").arg(hid + 1)); |
2428 | 145 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2531
diff
changeset
|
146 |
// Entry for "Hat Up" |
3697 | 147 |
sprintf(sdlkeys[i][0], "j%dh%du", jid, hid); |
5747 | 148 |
sprintf(sdlkeys[i++][1], "%s", (hat + HWApplication::translate("binds (keys)", "(Up)")).toUtf8().constData()); |
2428 | 149 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2531
diff
changeset
|
150 |
// Entry for "Hat Down" |
3697 | 151 |
sprintf(sdlkeys[i][0], "j%dh%dd", jid, hid); |
5747 | 152 |
sprintf(sdlkeys[i++][1], "%s", (hat + HWApplication::translate("binds (keys)", "(Down)")).toUtf8().constData()); |
2428 | 153 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2531
diff
changeset
|
154 |
// Entry for "Hat Left" |
3697 | 155 |
sprintf(sdlkeys[i][0], "j%dh%dl", jid, hid); |
5747 | 156 |
sprintf(sdlkeys[i++][1], "%s", (hat + HWApplication::translate("binds (keys)", "(Left)")).toUtf8().constData()); |
2428 | 157 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2531
diff
changeset
|
158 |
// Entry for "Hat Right" |
3697 | 159 |
sprintf(sdlkeys[i][0], "j%dh%dr", jid, hid); |
5747 | 160 |
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
|
161 |
} |
3697 | 162 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2531
diff
changeset
|
163 |
// Register entries for all buttons of this joystick/gamepad |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2531
diff
changeset
|
164 |
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
|
165 |
{ |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2531
diff
changeset
|
166 |
// Buttons |
3697 | 167 |
sprintf(sdlkeys[i][0], "j%db%d", jid, bid); |
5747 | 168 |
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
|
169 |
} |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2531
diff
changeset
|
170 |
// 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
|
171 |
SDL_JoystickClose(joy); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2531
diff
changeset
|
172 |
} |
3697 | 173 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2531
diff
changeset
|
174 |
// Terminate the list |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2531
diff
changeset
|
175 |
sdlkeys[i][0][0] = '\0'; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2531
diff
changeset
|
176 |
sdlkeys[i][1][0] = '\0'; |
2428 | 177 |
} |
178 |
||
6166 | 179 |
|
180 |
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
|
181 |
{ |
6166 | 182 |
// don't init again |
183 |
if (m_audioInitialized) |
|
184 |
return; |
|
185 |
||
186 |
SDL_Init(SDL_INIT_AUDIO); |
|
187 |
Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 1024); |
|
188 |
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
|
189 |
} |
51d3f4b6293a
revert audio to use SDL_mixer -- also frontend uses it, so it needs sdlmixer sources
koda
parents:
2494
diff
changeset
|
190 |
|
6166 | 191 |
|
6165
6fe3e922246e
moving and renaming SDLs.*, making it a singleton; cleaning up class responsibilties wrt SDLInteraction; some comments
sheepluva
parents:
6164
diff
changeset
|
192 |
void SDLInteraction::playSoundFile(const QString & soundFile) |
1223
41d7283934c1
Hackish way to play music in frontend... to be fixed
unc0rr
parents:
1191
diff
changeset
|
193 |
{ |
6166 | 194 |
SDLAudioInit(); |
6167 | 195 |
if (!m_soundMap->contains(soundFile)) |
196 |
m_soundMap->insert(soundFile, Mix_LoadWAV(soundFile.toLocal8Bit().constData())); |
|
6165
6fe3e922246e
moving and renaming SDLs.*, making it a singleton; cleaning up class responsibilties wrt SDLInteraction; some comments
sheepluva
parents:
6164
diff
changeset
|
197 |
|
6585 | 198 |
//FIXME: this is a hack, but works as long as we have few concurrent playing sounds |
199 |
if (Mix_Playing(lastchannel) == false) |
|
200 |
lastchannel = Mix_PlayChannel(-1, m_soundMap->value(soundFile), 0); |
|
6165
6fe3e922246e
moving and renaming SDLs.*, making it a singleton; cleaning up class responsibilties wrt SDLInteraction; some comments
sheepluva
parents:
6164
diff
changeset
|
201 |
} |
6fe3e922246e
moving and renaming SDLs.*, making it a singleton; cleaning up class responsibilties wrt SDLInteraction; some comments
sheepluva
parents:
6164
diff
changeset
|
202 |
|
6166 | 203 |
void SDLInteraction::setMusicTrack(const QString & musicFile) |
204 |
{ |
|
205 |
bool wasPlayingMusic = m_isPlayingMusic; |
|
206 |
||
207 |
stopMusic(); |
|
208 |
||
209 |
if (m_music != NULL) |
|
210 |
{ |
|
211 |
Mix_FreeMusic(m_music); |
|
212 |
m_music = NULL; |
|
213 |
} |
|
214 |
||
215 |
m_musicTrack = musicFile; |
|
216 |
||
217 |
if (wasPlayingMusic) |
|
218 |
startMusic(); |
|
219 |
} |
|
220 |
||
221 |
||
6165
6fe3e922246e
moving and renaming SDLs.*, making it a singleton; cleaning up class responsibilties wrt SDLInteraction; some comments
sheepluva
parents:
6164
diff
changeset
|
222 |
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
|
223 |
{ |
6166 | 224 |
if (m_isPlayingMusic) |
225 |
return; |
|
226 |
||
227 |
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
|
228 |
|
6166 | 229 |
if (m_musicTrack.isEmpty()) |
230 |
return; |
|
3697 | 231 |
|
6166 | 232 |
SDLAudioInit(); |
233 |
||
234 |
if (m_music == NULL) |
|
235 |
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
|
236 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2531
diff
changeset
|
237 |
Mix_VolumeMusic(MIX_MAX_VOLUME - 28); |
6166 | 238 |
Mix_FadeInMusic(m_music, -1, 1750); |
1223
41d7283934c1
Hackish way to play music in frontend... to be fixed
unc0rr
parents:
1191
diff
changeset
|
239 |
} |
41d7283934c1
Hackish way to play music in frontend... to be fixed
unc0rr
parents:
1191
diff
changeset
|
240 |
|
6166 | 241 |
|
6165
6fe3e922246e
moving and renaming SDLs.*, making it a singleton; cleaning up class responsibilties wrt SDLInteraction; some comments
sheepluva
parents:
6164
diff
changeset
|
242 |
void SDLInteraction::stopMusic() |
1223
41d7283934c1
Hackish way to play music in frontend... to be fixed
unc0rr
parents:
1191
diff
changeset
|
243 |
{ |
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6585
diff
changeset
|
244 |
if (m_isPlayingMusic && (m_music != NULL)) |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6585
diff
changeset
|
245 |
{ |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2531
diff
changeset
|
246 |
// fade out music to finish 0,5 seconds from now |
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6585
diff
changeset
|
247 |
while(!Mix_FadeOutMusic(1000) && Mix_PlayingMusic()) |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6585
diff
changeset
|
248 |
{ |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2531
diff
changeset
|
249 |
SDL_Delay(100); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2531
diff
changeset
|
250 |
} |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2531
diff
changeset
|
251 |
} |
6166 | 252 |
|
253 |
m_isPlayingMusic = false; |
|
1223
41d7283934c1
Hackish way to play music in frontend... to be fixed
unc0rr
parents:
1191
diff
changeset
|
254 |
} |
2402
edd12b259e7c
revert to manual startup of frontend's OpenAL session (keeping voices' bug fixed)
koda
parents:
2399
diff
changeset
|
255 |