summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordarkvater <darkvater@openttd.org>2004-09-12 22:03:14 +0000
committerdarkvater <darkvater@openttd.org>2004-09-12 22:03:14 +0000
commit989ed101bc9ff659736354f42ac22dfd23809e92 (patch)
tree059fa9da5c30ef18e3f8d338d639a6d1f3d67e0d
parente295e46e3eccd58626ce2b02aab24b96c025636b (diff)
downloadopenttd-989ed101bc9ff659736354f42ac22dfd23809e92.tar.xz
(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).
-rw-r--r--console.c8
-rw-r--r--functions.h1
-rw-r--r--hal.h2
-rw-r--r--ttd.c4
-rw-r--r--unix.c7
-rw-r--r--w32dm.c6
-rw-r--r--w32dm2.cpp2
-rw-r--r--win32.c50
8 files changed, 61 insertions, 19 deletions
diff --git a/console.c b/console.c
index 8c9b7a025..227120bb1 100644
--- a/console.c
+++ b/console.c
@@ -730,7 +730,7 @@ void IConsoleCmdHook(const byte * name, byte type, void * proc)
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 * hook_cmd, byte type)
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);
}
diff --git a/functions.h b/functions.h
index 6f24b05c9..ab9ec0b4e 100644
--- a/functions.h
+++ b/functions.h
@@ -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, ...);
diff --git a/hal.h b/hal.h
index 8eff9e662..63e7562b8 100644
--- a/hal.h
+++ b/hal.h
@@ -38,7 +38,7 @@ typedef struct {
const char *name;
const char *longname;
const void *drv;
- uint flags;
+ uint32 flags;
} DriverDesc;
enum {
diff --git a/ttd.c b/ttd.c
index c7d792307..2e760e188 100644
--- a/ttd.c
+++ b/ttd.c
@@ -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 *ChooseDefaultDriver(const DriverDesc *dd)
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
diff --git a/unix.c b/unix.c
index 932a4a56c..06aa7b9da 100644
--- a/unix.c
+++ b/unix.c
@@ -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;
diff --git a/w32dm.c b/w32dm.c
index f8aebca20..665e1eb71 100644
--- a/w32dm.c
+++ b/w32dm.c
@@ -64,8 +64,8 @@ static char * DMusicMidiStart(char **parm)
{
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 */
diff --git a/w32dm2.cpp b/w32dm2.cpp
index b32182bcd..ac42fd5a6 100644
--- a/w32dm2.cpp
+++ b/w32dm2.cpp
@@ -302,4 +302,4 @@ void SetVolume(long vol)
}
#endif
-#endif // WIN32_ENABLE_DIRECTMUSIC_SUPPORT
+#endif /* WIN32_ENABLE_DIRECTMUSIC_SUPPORT */
diff --git a/win32.c b/win32.c
index bee14f853..6519a47e4 100644
--- a/win32.c
+++ b/win32.c
@@ -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);