From 1ffa019bb5e1835d58b7503e8c3097d0ea6b74fd Mon Sep 17 00:00:00 2001 From: rubidium Date: Wed, 13 Nov 2013 22:03:26 +0000 Subject: [PATCH] (svn r25992) [1.3] -Backport from trunk: - Fix: The wrong vehicle would be taken in a shared order vehicle list window when the ID >= 65536, causing assertions triggering later on [FS#5800] (r25965) - Fix: [OSX] Compilation under OSX 10.9 [FS#5797] (r25962, r25951, r25950, r25913) - Fix: [NewGRF] A powered rail type implies it is compatible as well, but some NewGRF did not state that causing the path reservation code to bail out in some cases because there was no compatible path [FS#5779] (r25961) --- src/newgrf.cpp | 2 +- src/os/macosx/osx_stdafx.h | 2 +- src/vehicle_gui.cpp | 2 +- src/video/cocoa/cocoa_v.mm | 83 +++++++++++++++++++++++++++++++++-- src/video/cocoa/fullscreen.mm | 77 ++------------------------------ 5 files changed, 86 insertions(+), 80 deletions(-) diff --git a/src/newgrf.cpp b/src/newgrf.cpp index e426100cf0..d18283f53a 100644 --- a/src/newgrf.cpp +++ b/src/newgrf.cpp @@ -3965,8 +3965,8 @@ static ChangeInfoResult RailTypeChangeInfo(uint id, int numinfo, int prop, ByteR RailType rt = GetRailTypeByLabel(BSWAP32(label), false); if (rt != INVALID_RAILTYPE) { switch (prop) { + case 0x0F: SetBit(rti->powered_railtypes, rt); // Powered implies compatible. case 0x0E: SetBit(rti->compatible_railtypes, rt); break; - case 0x0F: SetBit(rti->powered_railtypes, rt); break; case 0x18: SetBit(rti->introduction_required_railtypes, rt); break; case 0x19: SetBit(rti->introduces_railtypes, rt); break; } diff --git a/src/os/macosx/osx_stdafx.h b/src/os/macosx/osx_stdafx.h index 5adbde1792..87cff83723 100644 --- a/src/os/macosx/osx_stdafx.h +++ b/src/os/macosx/osx_stdafx.h @@ -53,7 +53,7 @@ /* Some gcc versions include assert.h via this header. As this would interfere * with our own assert redefinition, include this header first. */ -#if defined(__GNUC__) && (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3)) +#if !defined(__clang__) && defined(__GNUC__) && (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3)) # include #endif diff --git a/src/vehicle_gui.cpp b/src/vehicle_gui.cpp index 72b8ef1305..6b93731866 100644 --- a/src/vehicle_gui.cpp +++ b/src/vehicle_gui.cpp @@ -1618,7 +1618,7 @@ static WindowDesc _vehicle_list_desc( _nested_vehicle_list, lengthof(_nested_vehicle_list) ); -static void ShowVehicleListWindowLocal(CompanyID company, VehicleListType vlt, VehicleType vehicle_type, uint16 unique_number) +static void ShowVehicleListWindowLocal(CompanyID company, VehicleListType vlt, VehicleType vehicle_type, uint32 unique_number) { if (!Company::IsValidID(company) && company != OWNER_NONE) return; diff --git a/src/video/cocoa/cocoa_v.mm b/src/video/cocoa/cocoa_v.mm index 8e7b7824ec..6c8981cca8 100644 --- a/src/video/cocoa/cocoa_v.mm +++ b/src/video/cocoa/cocoa_v.mm @@ -223,6 +223,80 @@ static void setupApplication() [ NSApp setDelegate:_ottd_main ]; } + +static int CDECL ModeSorter(const OTTD_Point *p1, const OTTD_Point *p2) +{ + if (p1->x < p2->x) return -1; + if (p1->x > p2->x) return +1; + if (p1->y < p2->y) return -1; + if (p1->y > p2->y) return +1; + return 0; +} + +uint QZ_ListModes(OTTD_Point *modes, uint max_modes, CGDirectDisplayID display_id, int device_depth) +{ + CFArrayRef mode_list = CGDisplayAvailableModes(display_id); + CFIndex num_modes = CFArrayGetCount(mode_list); + + /* Build list of modes with the requested bpp */ + uint count = 0; + for (CFIndex i = 0; i < num_modes && count < max_modes; i++) { + int intvalue, bpp; + uint16 width, height; + + CFDictionaryRef onemode = (const __CFDictionary*)CFArrayGetValueAtIndex(mode_list, i); + CFNumberRef number = (const __CFNumber*)CFDictionaryGetValue(onemode, kCGDisplayBitsPerPixel); + CFNumberGetValue(number, kCFNumberSInt32Type, &bpp); + + if (bpp != device_depth) continue; + + number = (const __CFNumber*)CFDictionaryGetValue(onemode, kCGDisplayWidth); + CFNumberGetValue(number, kCFNumberSInt32Type, &intvalue); + width = (uint16)intvalue; + + number = (const __CFNumber*)CFDictionaryGetValue(onemode, kCGDisplayHeight); + CFNumberGetValue(number, kCFNumberSInt32Type, &intvalue); + height = (uint16)intvalue; + + /* Check if mode is already in the list */ + bool hasMode = false; + for (uint i = 0; i < count; i++) { + if (modes[i].x == width && modes[i].y == height) { + hasMode = true; + break; + } + } + + if (hasMode) continue; + + /* Add mode to the list */ + modes[count].x = width; + modes[count].y = height; + count++; + } + + /* Sort list smallest to largest */ + QSortT(modes, count, &ModeSorter); + + return count; +} + +/** Small function to test if the main display can display 8 bpp in fullscreen */ +bool QZ_CanDisplay8bpp() +{ + /* 8bpp modes are deprecated starting in 10.5. CoreGraphics will return them + * as available in the display list, but many features (e.g. palette animation) + * will be broken. */ + if (MacOSVersionIsAtLeast(10, 5, 0)) return false; + + OTTD_Point p; + + /* We want to know if 8 bpp is possible in fullscreen and not anything about + * resolutions. Because of this we want to fill a list of 1 resolution of 8 bpp + * on display 0 (main) and return if we found one. */ + return QZ_ListModes(&p, 1, 0, 8); +} + /** * Update the video modus. * @@ -319,9 +393,12 @@ static CocoaSubdriver *QZ_CreateSubdriver(int width, int height, int bpp, bool f /* OSX 10.7 allows to toggle fullscreen mode differently */ if (MacOSVersionIsAtLeast(10, 7, 0)) { ret = QZ_CreateWindowSubdriver(width, height, bpp); - } else { + } +#if (MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_9) + else { ret = fullscreen ? QZ_CreateFullscreenSubdriver(width, height, bpp) : QZ_CreateWindowSubdriver(width, height, bpp); } +#endif /* (MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_9) */ if (ret != NULL) { /* We cannot set any fullscreen mode on OSX 10.7 when not compiled against SDK 10.7 */ @@ -338,7 +415,7 @@ static CocoaSubdriver *QZ_CreateSubdriver(int width, int height, int bpp, bool f ret = QZ_CreateWindowSubdriver(640, 480, bpp); if (ret != NULL) return ret; -#ifdef _DEBUG +#if defined(_DEBUG) && (MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_9) /* This Fullscreen mode crashes on OSX 10.7 */ if (!MacOSVersionIsAtLeast(10, 7, 0)) { /* Try fullscreen too when in debug mode */ @@ -346,7 +423,7 @@ static CocoaSubdriver *QZ_CreateSubdriver(int width, int height, int bpp, bool f ret = QZ_CreateFullscreenSubdriver(640, 480, bpp); if (ret != NULL) return ret; } -#endif +#endif /* defined(_DEBUG) && (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_9) */ return NULL; } diff --git a/src/video/cocoa/fullscreen.mm b/src/video/cocoa/fullscreen.mm index 86de2cdc90..8de36f8525 100644 --- a/src/video/cocoa/fullscreen.mm +++ b/src/video/cocoa/fullscreen.mm @@ -17,6 +17,8 @@ #include "../../stdafx.h" +#if (MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_9) + #define Rect OTTDRect #define Point OTTDPoint #import @@ -74,80 +76,6 @@ struct OTTD_QuartzGammaTable { } @end - -static int CDECL ModeSorter(const OTTD_Point *p1, const OTTD_Point *p2) -{ - if (p1->x < p2->x) return -1; - if (p1->x > p2->x) return +1; - if (p1->y < p2->y) return -1; - if (p1->y > p2->y) return +1; - return 0; -} - -uint QZ_ListModes(OTTD_Point *modes, uint max_modes, CGDirectDisplayID display_id, int device_depth) -{ - CFArrayRef mode_list = CGDisplayAvailableModes(display_id); - CFIndex num_modes = CFArrayGetCount(mode_list); - - /* Build list of modes with the requested bpp */ - uint count = 0; - for (CFIndex i = 0; i < num_modes && count < max_modes; i++) { - int intvalue, bpp; - uint16 width, height; - - CFDictionaryRef onemode = (const __CFDictionary*)CFArrayGetValueAtIndex(mode_list, i); - CFNumberRef number = (const __CFNumber*)CFDictionaryGetValue(onemode, kCGDisplayBitsPerPixel); - CFNumberGetValue(number, kCFNumberSInt32Type, &bpp); - - if (bpp != device_depth) continue; - - number = (const __CFNumber*)CFDictionaryGetValue(onemode, kCGDisplayWidth); - CFNumberGetValue(number, kCFNumberSInt32Type, &intvalue); - width = (uint16)intvalue; - - number = (const __CFNumber*)CFDictionaryGetValue(onemode, kCGDisplayHeight); - CFNumberGetValue(number, kCFNumberSInt32Type, &intvalue); - height = (uint16)intvalue; - - /* Check if mode is already in the list */ - bool hasMode = false; - for (uint i = 0; i < count; i++) { - if (modes[i].x == width && modes[i].y == height) { - hasMode = true; - break; - } - } - - if (hasMode) continue; - - /* Add mode to the list */ - modes[count].x = width; - modes[count].y = height; - count++; - } - - /* Sort list smallest to largest */ - QSortT(modes, count, &ModeSorter); - - return count; -} - -/** Small function to test if the main display can display 8 bpp in fullscreen */ -bool QZ_CanDisplay8bpp() -{ - /* 8bpp modes are deprecated starting in 10.5. CoreGraphics will return them - * as available in the display list, but many features (e.g. palette animation) - * will be broken. */ - if (MacOSVersionIsAtLeast(10, 5, 0)) return false; - - OTTD_Point p; - - /* We want to know if 8 bpp is possible in fullscreen and not anything about - * resolutions. Because of this we want to fill a list of 1 resolution of 8 bpp - * on display 0 (main) and return if we found one. */ - return QZ_ListModes(&p, 1, 0, 8); -} - class FullscreenSubdriver: public CocoaSubdriver { CGDirectDisplayID display_id; ///< 0 == main display (only support single display) CFDictionaryRef cur_mode; ///< current mode of the display @@ -592,4 +520,5 @@ CocoaSubdriver *QZ_CreateFullscreenSubdriver(int width, int height, int bpp) return ret; } +#endif /* (MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_9) */ #endif /* WITH_COCOA */