# HG changeset patch # User darkvater # Date 1095026594 0 # Node ID 0e5cc5a65df66fd840d4e41f6a9d8dec34abc33c # Parent b884560013977bc791f19ea0b53315386ea5ac31 (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). diff -r b88456001397 -r 0e5cc5a65df6 console.c --- a/console.c Sun Sep 12 21:49:38 2004 +0000 +++ b/console.c Sun Sep 12 22:03:14 2004 +0000 @@ -730,7 +730,7 @@ 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 @@ 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 -r b88456001397 -r 0e5cc5a65df6 functions.h --- a/functions.h Sun Sep 12 21:49:38 2004 +0000 +++ b/functions.h Sun Sep 12 22:03:14 2004 +0000 @@ -275,6 +275,7 @@ void LoadFromConfig(); void SaveToConfig(); int ttd_main(int argc, char* argv[]); +byte GetOSVersion(); void DeterminePaths(); char * CDECL str_fmt(const char *str, ...); diff -r b88456001397 -r 0e5cc5a65df6 hal.h --- a/hal.h Sun Sep 12 21:49:38 2004 +0000 +++ b/hal.h Sun Sep 12 22:03:14 2004 +0000 @@ -38,7 +38,7 @@ const char *name; const char *longname; const void *drv; - uint flags; + uint32 flags; } DriverDesc; enum { diff -r b88456001397 -r 0e5cc5a65df6 ttd.c --- a/ttd.c Sun Sep 12 21:49:38 2004 +0000 +++ b/ttd.c Sun Sep 12 22:03:14 2004 +0000 @@ -52,6 +52,7 @@ 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 @@ 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 @@ // 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 -r b88456001397 -r 0e5cc5a65df6 unix.c --- a/unix.c Sun Sep 12 21:49:38 2004 +0000 +++ b/unix.c Sun Sep 12 22:03:14 2004 +0000 @@ -353,6 +353,13 @@ { 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 -r b88456001397 -r 0e5cc5a65df6 w32dm.c --- a/w32dm.c Sun Sep 12 21:49:38 2004 +0000 +++ b/w32dm.c Sun Sep 12 22:03:14 2004 +0000 @@ -64,8 +64,8 @@ { if (InitDirectMusic() == true) return(0); - else - return("Unable to initialize DirectMusic"); + + return("Unable to initialize DirectMusic"); } static void DMusicMidiStop() @@ -113,4 +113,4 @@ SetVolume(vol); } -#endif +#endif /* WIN32_ENABLE_DIRECTMUSIC_SUPPORT */ diff -r b88456001397 -r 0e5cc5a65df6 w32dm2.cpp --- a/w32dm2.cpp Sun Sep 12 21:49:38 2004 +0000 +++ b/w32dm2.cpp Sun Sep 12 22:03:14 2004 +0000 @@ -302,4 +302,4 @@ } #endif -#endif // WIN32_ENABLE_DIRECTMUSIC_SUPPORT +#endif /* WIN32_ENABLE_DIRECTMUSIC_SUPPORT */ diff -r b88456001397 -r 0e5cc5a65df6 win32.c --- a/win32.c Sun Sep 12 21:49:38 2004 +0000 +++ b/win32.c Sun Sep 12 22:03:14 2004 +0000 @@ -1775,33 +1775,67 @@ 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);