Changeset - r223:ad6d67641576
[Not reviewed]
master
0 8 0
darkvater - 20 years ago 2004-09-12 22:03:14
darkvater@openttd.org
(svn r224) -Fix: Music now finally works on WinXP. DirectMusic is now default for an OS >= WinNT4 (WinNT4, Win2k, WinXP), and MIDI driver for lower OS's (Win95, Win98, WinME, etc).
8 files changed with 61 insertions and 19 deletions:
0 comments (0 inline, 0 general)
console.c
Show inline comments
 
@@ -730,7 +730,7 @@ void IConsoleCmdHook(const byte * name, 
 

	
 
bool IConsoleCmdHookHandle(_iconsole_cmd * hook_cmd, byte type)
 
{
 
	bool (*proc)(_iconsole_cmd * hook_cmd);
 
	bool (*proc)(_iconsole_cmd * hook_cmd) = NULL;
 
	switch (type) {
 
	case ICONSOLE_HOOK_AFTER_EXEC:
 
		proc = hook_cmd->hook_after_exec;
 
@@ -741,11 +741,9 @@ bool IConsoleCmdHookHandle(_iconsole_cmd
 
	case ICONSOLE_HOOK_ACCESS:
 
		proc = hook_cmd->hook_access;
 
		break;
 
	default:
 
		proc = NULL;
 
		break;
 
	default: return true;
 
	}
 
	if (proc == NULL) return true;
 

	
 
	return proc(hook_cmd);
 
}
 

	
functions.h
Show inline comments
 
@@ -275,6 +275,7 @@ void CheckSwitchToEuro();
 
void LoadFromConfig();
 
void SaveToConfig();
 
int ttd_main(int argc, char* argv[]);
 
byte GetOSVersion();
 

	
 
void DeterminePaths();
 
char * CDECL str_fmt(const char *str, ...);
hal.h
Show inline comments
 
@@ -38,7 +38,7 @@ typedef struct {
 
	const char *name;
 
	const char *longname;
 
	const void *drv;
 
	uint flags;
 
	uint32 flags;
 
} DriverDesc;
 

	
 
enum {
ttd.c
Show inline comments
 
@@ -52,6 +52,7 @@ extern void HalGameLoop();
 
uint32 _pixels_redrawn;
 
bool _dbg_screen_rect;
 
bool disable_computer;
 
static byte _os_version = 0;
 

	
 
void CDECL error(const char *s, ...) {
 
	va_list va;
 
@@ -192,7 +193,7 @@ static const DriverDesc *ChooseDefaultDr
 
	const DriverDesc *best = NULL;
 
	int best_pri = -1;
 
	do {
 
		if ((int)(dd->flags&DF_PRIORITY_MASK) > best_pri) {
 
		if ((int)(dd->flags&DF_PRIORITY_MASK) > best_pri && _os_version >= (byte)dd->flags) {
 
			best_pri = dd->flags&DF_PRIORITY_MASK;
 
			best = dd;
 
		}
 
@@ -571,6 +572,7 @@ int ttd_main(int argc, char* argv[])
 

	
 
	// Sample catalogue
 
	DEBUG(misc, 1) ("Loading sound effects...");
 
	_os_version = GetOSVersion();
 
	MxInitialize(11025, "sample.cat");
 

	
 
	// This must be done early, since functions use the InvalidateWindow* calls
unix.c
Show inline comments
 
@@ -353,6 +353,13 @@ const DriverDesc _music_driver_descs[] =
 
	{     NULL,	NULL,										NULL,										0}
 
};
 

	
 
/* GetOSVersion returns the minimal required version of OS to be able to use that driver.
 
	 Not needed for *nix. */
 
byte GetOSVersion()
 
{
 
	return 1; // any arbitrary number bigger then 0
 
}
 

	
 
bool FileExists(const char *filename)
 
{
 
	return access(filename, 0) == 0;
w32dm.c
Show inline comments
 
@@ -64,8 +64,8 @@ static char * DMusicMidiStart(char **par
 
{
 
	if (InitDirectMusic() == true)
 
		return(0);
 
	else
 
		return("Unable to initialize DirectMusic");
 

	
 
  return("Unable to initialize DirectMusic");
 
}
 

	
 
static void DMusicMidiStop()
 
@@ -113,4 +113,4 @@ static void DMusicMidiSetVolume(byte vol
 
	SetVolume(vol);
 
}
 

	
 
#endif
 
#endif /* WIN32_ENABLE_DIRECTMUSIC_SUPPORT */
w32dm2.cpp
Show inline comments
 
@@ -302,4 +302,4 @@ void SetVolume(long vol)
 
}
 
#endif
 

	
 
#endif // WIN32_ENABLE_DIRECTMUSIC_SUPPORT
 
#endif /* WIN32_ENABLE_DIRECTMUSIC_SUPPORT */
win32.c
Show inline comments
 
@@ -1775,33 +1775,67 @@ void FiosDelete(const char *name)
 
	DeleteFile(path);
 
}
 

	
 
#define Windows_2000		5
 
#define Windows_NT3_51	4
 

	
 
/* flags show the minimum required OS to use a given feature. Currently
 
	 only dwMajorVersion is used
 
														MajorVersion	MinorVersion
 
		Windows Server 2003					5							 2
 
		Windows XP									5							 1
 
		Windows 2000								5							 0
 
		Windows NT 4.0							4							 0
 
		Windows Me									4							90
 
		Windows 98									4							10
 
		Windows 95									4							 0
 
		Windows NT 3.51							3							51
 
*/
 

	
 
const DriverDesc _video_driver_descs[] = {
 
	{"null", "Null Video Driver",				&_null_video_driver,	0},
 
	{"null", "Null Video Driver",				&_null_video_driver,		0},
 
#if defined(WITH_SDL)
 
	{"sdl", "SDL Video Driver",					&_sdl_video_driver,	1},
 
	{"sdl", "SDL Video Driver",					&_sdl_video_driver,			1},
 
#endif
 
	{"win32", "Win32 GDI Video Driver",	&_win32_video_driver,	2},
 
	{"win32", "Win32 GDI Video Driver",	&_win32_video_driver,		Windows_NT3_51},
 
	{NULL}
 
};
 

	
 
const DriverDesc _sound_driver_descs[] = {
 
	{"null", "Null Sound Driver",			&_null_sound_driver,	0},
 
#if defined(WITH_SDL)
 
	{"sdl", "SDL Sound Driver",				&_sdl_sound_driver,	1},
 
	{"sdl", "SDL Sound Driver",				&_sdl_sound_driver,		1},
 
#endif
 
	{"win32", "Win32 WaveOut Driver",	&_win32_sound_driver,	2},
 
	{"win32", "Win32 WaveOut Driver",	&_win32_sound_driver,	Windows_NT3_51},
 
	{NULL}
 
};
 

	
 
const DriverDesc _music_driver_descs[] = {
 
	{"null", "Null Music Driver",		&_null_music_driver,	0},
 
	{"null", "Null Music Driver",		&_null_music_driver,				0},
 
#ifdef WIN32_ENABLE_DIRECTMUSIC_SUPPORT
 
	{"dmusic", "DirectMusic MIDI Driver",	&_dmusic_midi_driver,	1},
 
	{"dmusic", "DirectMusic MIDI Driver",	&_dmusic_midi_driver,	Windows_2000},
 
#endif
 
	{"win32", "Win32 MIDI Driver",	&_win32_music_driver,	2},
 
	// Win32 MIDI driver has higher priority then DMusic, so this one is chosen
 
	{"win32", "Win32 MIDI Driver",	&_win32_music_driver,				Windows_NT3_51},
 
	{NULL}
 
};
 

	
 
byte GetOSVersion()
 
{
 
	OSVERSIONINFO osvi;
 

	
 
	ZeroMemory(&osvi, sizeof(OSVERSIONINFO));
 
	osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
 

	
 
	if (GetVersionEx(&osvi)) {
 
		DEBUG(misc, 2) ("Windows Version is %d", osvi.dwMajorVersion);
 
		return (byte)osvi.dwMajorVersion;
 
	}
 

	
 
	// GetVersionEx failed, but we can safely assume at least Win95/WinNT3.51 is used
 
	DEBUG(misc, 0) ("Windows version retrieval failed, defaulting to level 4");
 
	return Windows_NT3_51;
 
}
 

	
 
bool FileExists(const char *filename)
 
{
 
	HANDLE hand = CreateFile(filename, 0, 0, NULL, OPEN_EXISTING, 0, NULL);
0 comments (0 inline, 0 general)