QTfrontend/SDLs.cpp
author nemo
Thu, 15 Oct 2009 19:24:14 +0000
changeset 2464 851b4e47ed2b
parent 2443 fececcbc2189
child 2494 1e10a47cabea
permissions -rw-r--r--
oops. shotgun reload
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
555
0376fdcc6322 Get possible screen resolutions from SDL library
unc0rr
parents:
diff changeset
     1
/*
1066
1f1b3686a2b0 Update copyright headers a bit
unc0rr
parents: 555
diff changeset
     2
 * Hedgewars, a free turn based strategy game
555
0376fdcc6322 Get possible screen resolutions from SDL library
unc0rr
parents:
diff changeset
     3
 * Copyright (c) 2007 Andrey Korotaev <unC0Rr@gmail.com>
0376fdcc6322 Get possible screen resolutions from SDL library
unc0rr
parents:
diff changeset
     4
 *
0376fdcc6322 Get possible screen resolutions from SDL library
unc0rr
parents:
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
0376fdcc6322 Get possible screen resolutions from SDL library
unc0rr
parents:
diff changeset
     6
 * it under the terms of the GNU General Public License as published by
0376fdcc6322 Get possible screen resolutions from SDL library
unc0rr
parents:
diff changeset
     7
 * the Free Software Foundation; version 2 of the License
0376fdcc6322 Get possible screen resolutions from SDL library
unc0rr
parents:
diff changeset
     8
 *
0376fdcc6322 Get possible screen resolutions from SDL library
unc0rr
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
0376fdcc6322 Get possible screen resolutions from SDL library
unc0rr
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
0376fdcc6322 Get possible screen resolutions from SDL library
unc0rr
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0376fdcc6322 Get possible screen resolutions from SDL library
unc0rr
parents:
diff changeset
    12
 * GNU General Public License for more details.
0376fdcc6322 Get possible screen resolutions from SDL library
unc0rr
parents:
diff changeset
    13
 *
0376fdcc6322 Get possible screen resolutions from SDL library
unc0rr
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License
0376fdcc6322 Get possible screen resolutions from SDL library
unc0rr
parents:
diff changeset
    15
 * along with this program; if not, write to the Free Software
0376fdcc6322 Get possible screen resolutions from SDL library
unc0rr
parents:
diff changeset
    16
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
0376fdcc6322 Get possible screen resolutions from SDL library
unc0rr
parents:
diff changeset
    17
 */
0376fdcc6322 Get possible screen resolutions from SDL library
unc0rr
parents:
diff changeset
    18
0376fdcc6322 Get possible screen resolutions from SDL library
unc0rr
parents:
diff changeset
    19
#include "SDLs.h"
0376fdcc6322 Get possible screen resolutions from SDL library
unc0rr
parents:
diff changeset
    20
0376fdcc6322 Get possible screen resolutions from SDL library
unc0rr
parents:
diff changeset
    21
#include "SDL.h"
1223
41d7283934c1 Hackish way to play music in frontend... to be fixed
unc0rr
parents: 1191
diff changeset
    22
#include "hwconsts.h"
555
0376fdcc6322 Get possible screen resolutions from SDL library
unc0rr
parents:
diff changeset
    23
2428
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2418
diff changeset
    24
#include <QApplication>
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2418
diff changeset
    25
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2418
diff changeset
    26
extern char sdlkeys[1024][2][128];
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2418
diff changeset
    27
extern char xb360buttons[][128];
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2418
diff changeset
    28
extern char xb360dpad[128];
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2418
diff changeset
    29
extern char xbox360axes[][128];
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2418
diff changeset
    30
2443
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2428
diff changeset
    31
#ifdef _WIN32
2402
edd12b259e7c revert to manual startup of frontend's OpenAL session (keeping voices' bug fixed)
koda
parents: 2399
diff changeset
    32
bool hardware;
2443
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2428
diff changeset
    33
#endif
2418
538a777f90c4 fix build and partially moves messages to errlib
koda
parents: 2402
diff changeset
    34
extern char *programname;
2402
edd12b259e7c revert to manual startup of frontend's OpenAL session (keeping voices' bug fixed)
koda
parents: 2399
diff changeset
    35
2428
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2418
diff changeset
    36
SDLInteraction::SDLInteraction()
555
0376fdcc6322 Get possible screen resolutions from SDL library
unc0rr
parents:
diff changeset
    37
{
2191
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents: 2050
diff changeset
    38
	music = -1;
2443
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2428
diff changeset
    39
#ifdef _WIN32
2428
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2418
diff changeset
    40
	hardware = false;
2443
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2428
diff changeset
    41
#endif
2428
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2418
diff changeset
    42
	SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK);
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2418
diff changeset
    43
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2418
diff changeset
    44
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2418
diff changeset
    45
	if(SDL_NumJoysticks())
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2418
diff changeset
    46
		addGameControllerKeys();
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2418
diff changeset
    47
	SDL_QuitSubSystem(SDL_INIT_JOYSTICK);
555
0376fdcc6322 Get possible screen resolutions from SDL library
unc0rr
parents:
diff changeset
    48
}
0376fdcc6322 Get possible screen resolutions from SDL library
unc0rr
parents:
diff changeset
    49
0376fdcc6322 Get possible screen resolutions from SDL library
unc0rr
parents:
diff changeset
    50
SDLInteraction::~SDLInteraction()
0376fdcc6322 Get possible screen resolutions from SDL library
unc0rr
parents:
diff changeset
    51
{
1224
0b9fbee5ceda - Add icons for each theme
unc0rr
parents: 1223
diff changeset
    52
	SDL_Quit();
2443
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2428
diff changeset
    53
	oalb_close();
555
0376fdcc6322 Get possible screen resolutions from SDL library
unc0rr
parents:
diff changeset
    54
}
0376fdcc6322 Get possible screen resolutions from SDL library
unc0rr
parents:
diff changeset
    55
2443
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2428
diff changeset
    56
#ifdef _WIN32
2428
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2418
diff changeset
    57
void SDLInteraction::setHardwareSound(bool hardware_snd)
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2418
diff changeset
    58
{
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2418
diff changeset
    59
	hardware = hardware_snd;
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2418
diff changeset
    60
}
2443
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2428
diff changeset
    61
#endif
2428
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2418
diff changeset
    62
555
0376fdcc6322 Get possible screen resolutions from SDL library
unc0rr
parents:
diff changeset
    63
QStringList SDLInteraction::getResolutions() const
0376fdcc6322 Get possible screen resolutions from SDL library
unc0rr
parents:
diff changeset
    64
{
0376fdcc6322 Get possible screen resolutions from SDL library
unc0rr
parents:
diff changeset
    65
	QStringList result;
0376fdcc6322 Get possible screen resolutions from SDL library
unc0rr
parents:
diff changeset
    66
0376fdcc6322 Get possible screen resolutions from SDL library
unc0rr
parents:
diff changeset
    67
	SDL_Rect **modes;
0376fdcc6322 Get possible screen resolutions from SDL library
unc0rr
parents:
diff changeset
    68
1191
5539aa59f703 With this change, SDL will probably report more screen resolutions on dual-monitor configurations
unc0rr
parents: 1066
diff changeset
    69
	modes = SDL_ListModes(NULL, SDL_FULLSCREEN);
555
0376fdcc6322 Get possible screen resolutions from SDL library
unc0rr
parents:
diff changeset
    70
0376fdcc6322 Get possible screen resolutions from SDL library
unc0rr
parents:
diff changeset
    71
	if((modes == (SDL_Rect **)0) || (modes == (SDL_Rect **)-1))
0376fdcc6322 Get possible screen resolutions from SDL library
unc0rr
parents:
diff changeset
    72
	{
0376fdcc6322 Get possible screen resolutions from SDL library
unc0rr
parents:
diff changeset
    73
		result << "640x480";
0376fdcc6322 Get possible screen resolutions from SDL library
unc0rr
parents:
diff changeset
    74
	} else
0376fdcc6322 Get possible screen resolutions from SDL library
unc0rr
parents:
diff changeset
    75
	{
0376fdcc6322 Get possible screen resolutions from SDL library
unc0rr
parents:
diff changeset
    76
		for(int i = 0; modes[i]; ++i)
2443
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2428
diff changeset
    77
			if ((modes[i]->w >= 640) && (modes[i]->h >= 480) && (modes[i]->h <= 1200))
555
0376fdcc6322 Get possible screen resolutions from SDL library
unc0rr
parents:
diff changeset
    78
				result << QString("%1x%2").arg(modes[i]->w).arg(modes[i]->h);
0376fdcc6322 Get possible screen resolutions from SDL library
unc0rr
parents:
diff changeset
    79
	}
0376fdcc6322 Get possible screen resolutions from SDL library
unc0rr
parents:
diff changeset
    80
0376fdcc6322 Get possible screen resolutions from SDL library
unc0rr
parents:
diff changeset
    81
	return result;
0376fdcc6322 Get possible screen resolutions from SDL library
unc0rr
parents:
diff changeset
    82
}
2191
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents: 2050
diff changeset
    83
2428
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2418
diff changeset
    84
void SDLInteraction::addGameControllerKeys() const
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2418
diff changeset
    85
{
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2418
diff changeset
    86
	QStringList result;
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2418
diff changeset
    87
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2418
diff changeset
    88
	int i = 0;
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2418
diff changeset
    89
	while(i < 1024 && sdlkeys[i][1][0] != '\0')
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2418
diff changeset
    90
		i++;
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2418
diff changeset
    91
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2418
diff changeset
    92
	// Iterate through all game controllers
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2418
diff changeset
    93
	for(int jid = 0; jid < SDL_NumJoysticks(); jid++)
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2418
diff changeset
    94
	{
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2418
diff changeset
    95
		SDL_Joystick* joy = SDL_JoystickOpen(jid);
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2418
diff changeset
    96
		
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2418
diff changeset
    97
		// Retrieve the game controller's name and strip "Controller (...)" that's added by some drivers (English only)
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2418
diff changeset
    98
		QString joyname = QString(SDL_JoystickName(jid)).replace(QRegExp("^Controller \\((.*)\\)$"), "\\1");
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2418
diff changeset
    99
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2418
diff changeset
   100
		// Connected Xbox 360 controller? Use specific button names then
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2418
diff changeset
   101
		// Might be interesting to add 'named' buttons for the most often used gamepads
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2418
diff changeset
   102
		bool isxb = joyname.contains("Xbox 360");
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2418
diff changeset
   103
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2418
diff changeset
   104
		// This part of the string won't change for multiple keys/hats, so keep it
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2418
diff changeset
   105
		QString prefix = QString("%1 (%2): ").arg(joyname).arg(jid + 1);
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2418
diff changeset
   106
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2418
diff changeset
   107
		// Register entries for missing axes not assigned to sticks of this joystick/gamepad
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2418
diff changeset
   108
		for(int aid = 0; aid < SDL_JoystickNumAxes(joy) && i < 1021; aid++)
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2418
diff changeset
   109
		{
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2418
diff changeset
   110
			// Axis 2 on xbox 360 is left/right trigger but those are used as buttons anyway so skip it
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2418
diff changeset
   111
			if(aid == 2 && isxb)
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2418
diff changeset
   112
				continue;
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2418
diff changeset
   113
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2418
diff changeset
   114
			// Again store the part of the string not changing for multiple uses
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2418
diff changeset
   115
			QString axis = prefix + QApplication::translate("binds (keys)", "Axis") + QString(" %1 ").arg(aid + 1);
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2418
diff changeset
   116
			
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2418
diff changeset
   117
			// Entry for "Axis Up"
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2418
diff changeset
   118
			sprintf(sdlkeys[i][0], "j%da%du", jid, aid);
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2418
diff changeset
   119
			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());
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2418
diff changeset
   120
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2418
diff changeset
   121
			// Entry for "Axis Down"
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2418
diff changeset
   122
			sprintf(sdlkeys[i][0], "j%da%dd", jid, aid);
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2418
diff changeset
   123
			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());
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2418
diff changeset
   124
		}
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2418
diff changeset
   125
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2418
diff changeset
   126
		// Register entries for all coolie hats of this joystick/gamepad
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2418
diff changeset
   127
		for(int hid = 0; hid < SDL_JoystickNumHats(joy) && i < 1019; hid++)
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2418
diff changeset
   128
		{
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2418
diff changeset
   129
			// Again store the part of the string not changing for multiple uses
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2418
diff changeset
   130
			QString hat = prefix + (isxb ? (QApplication::translate("binds (keys)", xb360dpad) + QString(" ")) : QApplication::translate("binds (keys)", "Hat") + QString(" %1 ").arg(hid + 1));
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2418
diff changeset
   131
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2418
diff changeset
   132
			// Entry for "Hat Up"
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2418
diff changeset
   133
			sprintf(sdlkeys[i][0], "j%dh%du", jid, hid);			
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2418
diff changeset
   134
			sprintf(sdlkeys[i++][1], "%s", (hat + QApplication::translate("binds (keys)", "(Up)")).toStdString().c_str());
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2418
diff changeset
   135
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2418
diff changeset
   136
			// Entry for "Hat Down"
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2418
diff changeset
   137
			sprintf(sdlkeys[i][0], "j%dh%dd", jid, hid);			
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2418
diff changeset
   138
			sprintf(sdlkeys[i++][1], "%s", (hat + QApplication::translate("binds (keys)", "(Down)")).toStdString().c_str());
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2418
diff changeset
   139
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2418
diff changeset
   140
			// Entry for "Hat Left"
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2418
diff changeset
   141
			sprintf(sdlkeys[i][0], "j%dh%dl", jid, hid);			
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2418
diff changeset
   142
			sprintf(sdlkeys[i++][1], "%s", (hat + QApplication::translate("binds (keys)", "(Left)")).toStdString().c_str());
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2418
diff changeset
   143
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2418
diff changeset
   144
			// Entry for "Hat Right"
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2418
diff changeset
   145
			sprintf(sdlkeys[i][0], "j%dh%dr", jid, hid);			
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2418
diff changeset
   146
			sprintf(sdlkeys[i++][1], "%s", (hat + QApplication::translate("binds (keys)", "(Right)")).toStdString().c_str());
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2418
diff changeset
   147
		}
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2418
diff changeset
   148
		
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2418
diff changeset
   149
		// Register entries for all buttons of this joystick/gamepad
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2418
diff changeset
   150
		for(int bid = 0; bid < SDL_JoystickNumButtons(joy) && i < 1022; bid++)
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2418
diff changeset
   151
		{
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2418
diff changeset
   152
			// Buttons
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2418
diff changeset
   153
			sprintf(sdlkeys[i][0], "j%db%d", jid, bid);			
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2418
diff changeset
   154
			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());
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2418
diff changeset
   155
		}
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2418
diff changeset
   156
		// Close the game controller as we no longer need it
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2418
diff changeset
   157
		SDL_JoystickClose(joy);
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2418
diff changeset
   158
	}
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2418
diff changeset
   159
	
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2418
diff changeset
   160
	// Terminate the list
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2418
diff changeset
   161
	sdlkeys[i][0][0] = '\0';
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2418
diff changeset
   162
	sdlkeys[i][1][0] = '\0';
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2418
diff changeset
   163
}
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2418
diff changeset
   164
2399
ddde0ac1472b fix a bug that prevented from hearing team voicepacks if frontend started with music disabled
koda
parents: 2392
diff changeset
   165
void SDLInteraction::StartMusic()
1223
41d7283934c1 Hackish way to play music in frontend... to be fixed
unc0rr
parents: 1191
diff changeset
   166
{
2402
edd12b259e7c revert to manual startup of frontend's OpenAL session (keeping voices' bug fixed)
koda
parents: 2399
diff changeset
   167
	OpenAL_Init();
2191
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents: 2050
diff changeset
   168
	if (music < 0) {
2443
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2428
diff changeset
   169
		music = oalb_loadfile(QString(datadir->absolutePath() + "/Music/main theme.ogg").toLocal8Bit().constData());
2392
a55dbef5cf31 Smaxx's patch fixing openal sound issues with poor card drivers
koda
parents: 2294
diff changeset
   170
	
2210
1cb7118a77dd initial bugfix for volume setup
koda
parents: 2192
diff changeset
   171
	}
2443
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2428
diff changeset
   172
	oalb_playsound(music, 1);
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2428
diff changeset
   173
	oalb_setvolume(music, 60);
1223
41d7283934c1 Hackish way to play music in frontend... to be fixed
unc0rr
parents: 1191
diff changeset
   174
}
41d7283934c1 Hackish way to play music in frontend... to be fixed
unc0rr
parents: 1191
diff changeset
   175
41d7283934c1 Hackish way to play music in frontend... to be fixed
unc0rr
parents: 1191
diff changeset
   176
void SDLInteraction::StopMusic()
41d7283934c1 Hackish way to play music in frontend... to be fixed
unc0rr
parents: 1191
diff changeset
   177
{
2443
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2428
diff changeset
   178
//	if (music >= 0) openal_fadeout(music, 40);
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2428
diff changeset
   179
	oalb_stopsound(music);
1223
41d7283934c1 Hackish way to play music in frontend... to be fixed
unc0rr
parents: 1191
diff changeset
   180
}
2402
edd12b259e7c revert to manual startup of frontend's OpenAL session (keeping voices' bug fixed)
koda
parents: 2399
diff changeset
   181
edd12b259e7c revert to manual startup of frontend's OpenAL session (keeping voices' bug fixed)
koda
parents: 2399
diff changeset
   182
//we need thjs wrapper because of some issues with windows drivers
edd12b259e7c revert to manual startup of frontend's OpenAL session (keeping voices' bug fixed)
koda
parents: 2399
diff changeset
   183
//beware that this cause a slight delay when playing the first sound
edd12b259e7c revert to manual startup of frontend's OpenAL session (keeping voices' bug fixed)
koda
parents: 2399
diff changeset
   184
void OpenAL_Init()
edd12b259e7c revert to manual startup of frontend's OpenAL session (keeping voices' bug fixed)
koda
parents: 2399
diff changeset
   185
{
2443
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2428
diff changeset
   186
	if (!oalb_ready())
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2428
diff changeset
   187
#ifdef _WIN32
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2428
diff changeset
   188
        	oalb_init(programname, hardware ? 1 : 0);
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2428
diff changeset
   189
#else
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2428
diff changeset
   190
		oalb_init(programname, 0);
fececcbc2189 Smaxx patch for fixing all sound related issues on any system
koda
parents: 2428
diff changeset
   191
#endif
2402
edd12b259e7c revert to manual startup of frontend's OpenAL session (keeping voices' bug fixed)
koda
parents: 2399
diff changeset
   192
}
edd12b259e7c revert to manual startup of frontend's OpenAL session (keeping voices' bug fixed)
koda
parents: 2399
diff changeset
   193