author | Zorg <zorgiepoo@gmail.com> |
Sun, 03 Apr 2011 00:13:38 -0400 | |
changeset 5083 | b0b560f561b5 |
parent 4976 | 088d40d8aba2 |
child 5085 | e8944ed92b61 |
permissions | -rw-r--r-- |
555 | 1 |
/* |
1066 | 2 |
* Hedgewars, a free turn based strategy game |
4976 | 3 |
* Copyright (c) 2007-2011 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 |
||
19 |
#include "SDLs.h" |
|
20 |
||
21 |
#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
|
22 |
#include "SDL_mixer.h" |
1223
41d7283934c1
Hackish way to play music in frontend... to be fixed
unc0rr
parents:
1191
diff
changeset
|
23 |
#include "hwconsts.h" |
555 | 24 |
|
2428 | 25 |
#include <QApplication> |
26 |
||
5083
b0b560f561b5
Fixed messages complaining about no autorelease pool being set up with objects leaking on the Mac. I simply initialized an autorelease pool in the couple of places that needed it.
Zorg <zorgiepoo@gmail.com>
parents:
4976
diff
changeset
|
27 |
#ifdef __APPLE__ |
b0b560f561b5
Fixed messages complaining about no autorelease pool being set up with objects leaking on the Mac. I simply initialized an autorelease pool in the couple of places that needed it.
Zorg <zorgiepoo@gmail.com>
parents:
4976
diff
changeset
|
28 |
#include "CocoaInitializer.h" |
b0b560f561b5
Fixed messages complaining about no autorelease pool being set up with objects leaking on the Mac. I simply initialized an autorelease pool in the couple of places that needed it.
Zorg <zorgiepoo@gmail.com>
parents:
4976
diff
changeset
|
29 |
#endif |
b0b560f561b5
Fixed messages complaining about no autorelease pool being set up with objects leaking on the Mac. I simply initialized an autorelease pool in the couple of places that needed it.
Zorg <zorgiepoo@gmail.com>
parents:
4976
diff
changeset
|
30 |
|
2515
51d3f4b6293a
revert audio to use SDL_mixer -- also frontend uses it, so it needs sdlmixer sources
koda
parents:
2494
diff
changeset
|
31 |
|
2428 | 32 |
extern char sdlkeys[1024][2][128]; |
33 |
extern char xb360buttons[][128]; |
|
34 |
extern char xb360dpad[128]; |
|
35 |
extern char xbox360axes[][128]; |
|
36 |
||
2402
edd12b259e7c
revert to manual startup of frontend's OpenAL session (keeping voices' bug fixed)
koda
parents:
2399
diff
changeset
|
37 |
|
2428 | 38 |
SDLInteraction::SDLInteraction() |
555 | 39 |
{ |
5083
b0b560f561b5
Fixed messages complaining about no autorelease pool being set up with objects leaking on the Mac. I simply initialized an autorelease pool in the couple of places that needed it.
Zorg <zorgiepoo@gmail.com>
parents:
4976
diff
changeset
|
40 |
#ifdef __APPLE__ |
b0b560f561b5
Fixed messages complaining about no autorelease pool being set up with objects leaking on the Mac. I simply initialized an autorelease pool in the couple of places that needed it.
Zorg <zorgiepoo@gmail.com>
parents:
4976
diff
changeset
|
41 |
// SDL_Init needs a NSAutoreleasePool set up |
b0b560f561b5
Fixed messages complaining about no autorelease pool being set up with objects leaking on the Mac. I simply initialized an autorelease pool in the couple of places that needed it.
Zorg <zorgiepoo@gmail.com>
parents:
4976
diff
changeset
|
42 |
CocoaInitializer initializer; |
b0b560f561b5
Fixed messages complaining about no autorelease pool being set up with objects leaking on the Mac. I simply initialized an autorelease pool in the couple of places that needed it.
Zorg <zorgiepoo@gmail.com>
parents:
4976
diff
changeset
|
43 |
#endif |
b0b560f561b5
Fixed messages complaining about no autorelease pool being set up with objects leaking on the Mac. I simply initialized an autorelease pool in the couple of places that needed it.
Zorg <zorgiepoo@gmail.com>
parents:
4976
diff
changeset
|
44 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2531
diff
changeset
|
45 |
SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK); |
3697 | 46 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2531
diff
changeset
|
47 |
musicInitialized = 0; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2531
diff
changeset
|
48 |
music = NULL; |
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); |
555 | 52 |
} |
53 |
||
54 |
SDLInteraction::~SDLInteraction() |
|
55 |
{ |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2531
diff
changeset
|
56 |
if (musicInitialized == 1) { |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2531
diff
changeset
|
57 |
if (music != NULL) |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2531
diff
changeset
|
58 |
Mix_FreeMusic(music); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2531
diff
changeset
|
59 |
Mix_CloseAudio(); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2531
diff
changeset
|
60 |
} |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2531
diff
changeset
|
61 |
SDL_Quit(); |
555 | 62 |
} |
63 |
||
64 |
QStringList SDLInteraction::getResolutions() const |
|
65 |
{ |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2531
diff
changeset
|
66 |
QStringList result; |
555 | 67 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2531
diff
changeset
|
68 |
SDL_Rect **modes; |
555 | 69 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2531
diff
changeset
|
70 |
modes = SDL_ListModes(NULL, SDL_FULLSCREEN); |
555 | 71 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2531
diff
changeset
|
72 |
if((modes == (SDL_Rect **)0) || (modes == (SDL_Rect **)-1)) |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2531
diff
changeset
|
73 |
{ |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2531
diff
changeset
|
74 |
result << "640x480"; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2531
diff
changeset
|
75 |
} else |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2531
diff
changeset
|
76 |
{ |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2531
diff
changeset
|
77 |
for(int i = 0; modes[i]; ++i) |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2531
diff
changeset
|
78 |
if ((modes[i]->w >= 640) && (modes[i]->h >= 480)) |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2531
diff
changeset
|
79 |
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
|
80 |
} |
555 | 81 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2531
diff
changeset
|
82 |
return result; |
555 | 83 |
} |
2191 | 84 |
|
2428 | 85 |
void SDLInteraction::addGameControllerKeys() const |
86 |
{ |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2531
diff
changeset
|
87 |
QStringList result; |
2428 | 88 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2531
diff
changeset
|
89 |
int i = 0; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2531
diff
changeset
|
90 |
while(i < 1024 && sdlkeys[i][1][0] != '\0') |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2531
diff
changeset
|
91 |
i++; |
2428 | 92 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2531
diff
changeset
|
93 |
// Iterate through all game controllers |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2531
diff
changeset
|
94 |
for(int jid = 0; jid < SDL_NumJoysticks(); jid++) |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2531
diff
changeset
|
95 |
{ |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2531
diff
changeset
|
96 |
SDL_Joystick* joy = SDL_JoystickOpen(jid); |
3697 | 97 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2531
diff
changeset
|
98 |
// 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
|
99 |
QString joyname = QString(SDL_JoystickName(jid)).replace(QRegExp("^Controller \\((.*)\\)$"), "\\1"); |
2428 | 100 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2531
diff
changeset
|
101 |
// Connected Xbox 360 controller? Use specific button names then |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2531
diff
changeset
|
102 |
// 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
|
103 |
bool isxb = joyname.contains("Xbox 360"); |
2428 | 104 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2531
diff
changeset
|
105 |
// 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
|
106 |
QString prefix = QString("%1 (%2): ").arg(joyname).arg(jid + 1); |
2428 | 107 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2531
diff
changeset
|
108 |
// 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
|
109 |
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
|
110 |
{ |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2531
diff
changeset
|
111 |
// Again store the part of the string not changing for multiple uses |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2531
diff
changeset
|
112 |
QString axis = prefix + QApplication::translate("binds (keys)", "Axis") + QString(" %1 ").arg(aid + 1); |
3697 | 113 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2531
diff
changeset
|
114 |
// Entry for "Axis Up" |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2531
diff
changeset
|
115 |
sprintf(sdlkeys[i][0], "j%da%du", jid, aid); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2531
diff
changeset
|
116 |
sprintf(sdlkeys[i++][1], "%s", ((isxb && aid < 5) ? (prefix + QApplication::translate("binds (keys)", xbox360axes[aid * 2])) : axis + QApplication::translate("binds (keys)", "(Up)")).toStdString().c_str()); |
2428 | 117 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2531
diff
changeset
|
118 |
// Entry for "Axis Down" |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2531
diff
changeset
|
119 |
sprintf(sdlkeys[i][0], "j%da%dd", jid, aid); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2531
diff
changeset
|
120 |
sprintf(sdlkeys[i++][1], "%s", ((isxb && aid < 5) ? (prefix + QApplication::translate("binds (keys)", xbox360axes[aid * 2 + 1])) : axis + QApplication::translate("binds (keys)", "(Down)")).toStdString().c_str()); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2531
diff
changeset
|
121 |
} |
2428 | 122 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2531
diff
changeset
|
123 |
// 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
|
124 |
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
|
125 |
{ |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2531
diff
changeset
|
126 |
// Again store the part of the string not changing for multiple uses |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2531
diff
changeset
|
127 |
QString hat = prefix + (isxb ? (QApplication::translate("binds (keys)", xb360dpad) + QString(" ")) : QApplication::translate("binds (keys)", "Hat") + QString(" %1 ").arg(hid + 1)); |
2428 | 128 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2531
diff
changeset
|
129 |
// Entry for "Hat Up" |
3697 | 130 |
sprintf(sdlkeys[i][0], "j%dh%du", jid, hid); |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2531
diff
changeset
|
131 |
sprintf(sdlkeys[i++][1], "%s", (hat + QApplication::translate("binds (keys)", "(Up)")).toStdString().c_str()); |
2428 | 132 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2531
diff
changeset
|
133 |
// Entry for "Hat Down" |
3697 | 134 |
sprintf(sdlkeys[i][0], "j%dh%dd", jid, hid); |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2531
diff
changeset
|
135 |
sprintf(sdlkeys[i++][1], "%s", (hat + QApplication::translate("binds (keys)", "(Down)")).toStdString().c_str()); |
2428 | 136 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2531
diff
changeset
|
137 |
// Entry for "Hat Left" |
3697 | 138 |
sprintf(sdlkeys[i][0], "j%dh%dl", jid, hid); |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2531
diff
changeset
|
139 |
sprintf(sdlkeys[i++][1], "%s", (hat + QApplication::translate("binds (keys)", "(Left)")).toStdString().c_str()); |
2428 | 140 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2531
diff
changeset
|
141 |
// Entry for "Hat Right" |
3697 | 142 |
sprintf(sdlkeys[i][0], "j%dh%dr", jid, hid); |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2531
diff
changeset
|
143 |
sprintf(sdlkeys[i++][1], "%s", (hat + QApplication::translate("binds (keys)", "(Right)")).toStdString().c_str()); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2531
diff
changeset
|
144 |
} |
3697 | 145 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2531
diff
changeset
|
146 |
// Register entries for all buttons of this joystick/gamepad |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2531
diff
changeset
|
147 |
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
|
148 |
{ |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2531
diff
changeset
|
149 |
// Buttons |
3697 | 150 |
sprintf(sdlkeys[i][0], "j%db%d", jid, bid); |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2531
diff
changeset
|
151 |
sprintf(sdlkeys[i++][1], "%s", (prefix + ((isxb && bid < 10) ? (QApplication::translate("binds (keys)", xb360buttons[bid]) + QString(" ")) : QApplication::translate("binds (keys)", "Button") + QString(" %1").arg(bid + 1))).toStdString().c_str()); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2531
diff
changeset
|
152 |
} |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2531
diff
changeset
|
153 |
// 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
|
154 |
SDL_JoystickClose(joy); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2531
diff
changeset
|
155 |
} |
3697 | 156 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2531
diff
changeset
|
157 |
// Terminate the list |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2531
diff
changeset
|
158 |
sdlkeys[i][0][0] = '\0'; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2531
diff
changeset
|
159 |
sdlkeys[i][1][0] = '\0'; |
2428 | 160 |
} |
161 |
||
2515
51d3f4b6293a
revert audio to use SDL_mixer -- also frontend uses it, so it needs sdlmixer sources
koda
parents:
2494
diff
changeset
|
162 |
void SDLInteraction::SDLMusicInit() |
51d3f4b6293a
revert audio to use SDL_mixer -- also frontend uses it, so it needs sdlmixer sources
koda
parents:
2494
diff
changeset
|
163 |
{ |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2531
diff
changeset
|
164 |
if (musicInitialized == 0) { |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2531
diff
changeset
|
165 |
SDL_Init(SDL_INIT_AUDIO); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2531
diff
changeset
|
166 |
Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 1024); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2531
diff
changeset
|
167 |
musicInitialized = 1; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2531
diff
changeset
|
168 |
} |
2515
51d3f4b6293a
revert audio to use SDL_mixer -- also frontend uses it, so it needs sdlmixer sources
koda
parents:
2494
diff
changeset
|
169 |
} |
51d3f4b6293a
revert audio to use SDL_mixer -- also frontend uses it, so it needs sdlmixer sources
koda
parents:
2494
diff
changeset
|
170 |
|
51d3f4b6293a
revert audio to use SDL_mixer -- also frontend uses it, so it needs sdlmixer sources
koda
parents:
2494
diff
changeset
|
171 |
|
2399
ddde0ac1472b
fix a bug that prevented from hearing team voicepacks if frontend started with music disabled
koda
parents:
2392
diff
changeset
|
172 |
void SDLInteraction::StartMusic() |
1223
41d7283934c1
Hackish way to play music in frontend... to be fixed
unc0rr
parents:
1191
diff
changeset
|
173 |
{ |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2531
diff
changeset
|
174 |
SDLMusicInit(); |
2515
51d3f4b6293a
revert audio to use SDL_mixer -- also frontend uses it, so it needs sdlmixer sources
koda
parents:
2494
diff
changeset
|
175 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2531
diff
changeset
|
176 |
if (music == NULL) { |
4594
5645462cc78f
removing all " " in filenames under share and replacing "_" with " " in missions
Henek
parents:
3697
diff
changeset
|
177 |
music = Mix_LoadMUS((datadir->absolutePath() + "/Music/main_theme.ogg").toLocal8Bit().constData()); |
3697 | 178 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2531
diff
changeset
|
179 |
} |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2531
diff
changeset
|
180 |
Mix_VolumeMusic(MIX_MAX_VOLUME - 28); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2531
diff
changeset
|
181 |
Mix_FadeInMusic(music, -1, 1750); |
1223
41d7283934c1
Hackish way to play music in frontend... to be fixed
unc0rr
parents:
1191
diff
changeset
|
182 |
} |
41d7283934c1
Hackish way to play music in frontend... to be fixed
unc0rr
parents:
1191
diff
changeset
|
183 |
|
41d7283934c1
Hackish way to play music in frontend... to be fixed
unc0rr
parents:
1191
diff
changeset
|
184 |
void SDLInteraction::StopMusic() |
41d7283934c1
Hackish way to play music in frontend... to be fixed
unc0rr
parents:
1191
diff
changeset
|
185 |
{ |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2531
diff
changeset
|
186 |
if (music != NULL) { |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2531
diff
changeset
|
187 |
// 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
|
188 |
while(!Mix_FadeOutMusic(1000) && Mix_PlayingMusic()) { |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2531
diff
changeset
|
189 |
SDL_Delay(100); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2531
diff
changeset
|
190 |
} |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2531
diff
changeset
|
191 |
} |
1223
41d7283934c1
Hackish way to play music in frontend... to be fixed
unc0rr
parents:
1191
diff
changeset
|
192 |
} |
2402
edd12b259e7c
revert to manual startup of frontend's OpenAL session (keeping voices' bug fixed)
koda
parents:
2399
diff
changeset
|
193 |