diff options
author | darkvater <darkvater@openttd.org> | 2004-09-12 22:03:14 +0000 |
---|---|---|
committer | darkvater <darkvater@openttd.org> | 2004-09-12 22:03:14 +0000 |
commit | 989ed101bc9ff659736354f42ac22dfd23809e92 (patch) | |
tree | 059fa9da5c30ef18e3f8d338d639a6d1f3d67e0d | |
parent | e295e46e3eccd58626ce2b02aab24b96c025636b (diff) | |
download | openttd-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.c | 8 | ||||
-rw-r--r-- | functions.h | 1 | ||||
-rw-r--r-- | hal.h | 2 | ||||
-rw-r--r-- | ttd.c | 4 | ||||
-rw-r--r-- | unix.c | 7 | ||||
-rw-r--r-- | w32dm.c | 6 | ||||
-rw-r--r-- | w32dm2.cpp | 2 | ||||
-rw-r--r-- | win32.c | 50 |
8 files changed, 61 insertions, 19 deletions
@@ -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, ...); @@ -38,7 +38,7 @@ typedef struct { const char *name; const char *longname; const void *drv; - uint flags; + uint32 flags; } DriverDesc; enum { @@ -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 @@ -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; @@ -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 */ @@ -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); |