summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoregladil <egladil@openttd.org>2007-11-25 14:43:16 +0000
committeregladil <egladil@openttd.org>2007-11-25 14:43:16 +0000
commit35159d5db3b9e739f640d04616f0ee131e65c70b (patch)
tree8ee1ef0bc994c64d37a179e595db5424e0af4375
parentb24392dfddb6710584927efba2ba6d4cc971aad6 (diff)
downloadopenttd-35159d5db3b9e739f640d04616f0ee131e65c70b.tar.xz
(svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
-rw-r--r--src/music/qtmidi.cpp3
-rw-r--r--src/os/macosx/macos.h40
-rw-r--r--src/os/macosx/macos.mm80
-rw-r--r--src/sound/cocoa_s.cpp3
-rw-r--r--src/video/cocoa/cocoa_v.mm15
-rw-r--r--src/video/cocoa/event.mm3
-rw-r--r--src/video/cocoa/fullscreen.mm1
-rw-r--r--src/video/cocoa/wnd_quartz.mm7
-rw-r--r--src/video/cocoa/wnd_quickdraw.mm6
9 files changed, 153 insertions, 5 deletions
diff --git a/src/music/qtmidi.cpp b/src/music/qtmidi.cpp
index 88a1b49dd..2e4892285 100644
--- a/src/music/qtmidi.cpp
+++ b/src/music/qtmidi.cpp
@@ -19,6 +19,9 @@
*/
+#define MAC_OS_X_VERSION_MIN_REQUIRED MAC_OS_X_VERSION_10_3
+#include <AvailabilityMacros.h>
+
/*
* OpenTTD includes.
*/
diff --git a/src/os/macosx/macos.h b/src/os/macosx/macos.h
index b8a6cd511..dc2637acc 100644
--- a/src/os/macosx/macos.h
+++ b/src/os/macosx/macos.h
@@ -27,4 +27,44 @@ void ShowMacErrorDialog(const char *error);
(__builtin_expect(!(e), 0) ? ShowMacAssertDialog ( __func__, __FILE__, __LINE__, #e ): (void)0 )
#endif
+
+
+/**
+ * Get the major version of Mac OS we are running under. Useful for things like the cocoa driver.
+ * @return major version of the os. This would be 10 in the case of 10.4.11.
+ */
+long GetMacOSVersionMajor();
+
+/**
+ * Get the minor version of Mac OS we are running under. Useful for things like the cocoa driver.
+ * @return minor version of the os. This would be 4 in the case of 10.4.11.
+ */
+long GetMacOSVersionMinor();
+
+/**
+ * Get the bugfix version of Mac OS we are running under. Useful for things like the cocoa driver.
+ * @return bugfix version of the os. This would be 11 in the case of 10.4.11.
+ */
+long GetMacOSVersionBugfix();
+
+/**
+ * Check if we are at least running on the specified version of Mac OS.
+ * @param major major version of the os. This would be 10 in the case of 10.4.11.
+ * @param minor minor version of the os. This would be 4 in the case of 10.4.11.
+ * @param bugfix bugfix version of the os. This would be 11 in the case of 10.4.11.
+ * @return true if the running os is at least what we asked, false otherwise.
+ */
+static inline bool MacOSVersionIsAtLeast(long major, long minor, long bugfix)
+{
+ long maj = GetMacOSVersionMajor();
+ long min = GetMacOSVersionMinor();
+ long bf = GetMacOSVersionBugfix();
+
+ if (maj < major) return false;
+ if (maj == major && min < minor) return false;
+ if (maj == major && min == minor && bf < bugfix) return false;
+
+ return true;
+}
+
#endif /* MACOS_H */
diff --git a/src/os/macosx/macos.mm b/src/os/macosx/macos.mm
index 22bf8a987..def108059 100644
--- a/src/os/macosx/macos.mm
+++ b/src/os/macosx/macos.mm
@@ -1,5 +1,8 @@
/* $Id$ */
+#define MAC_OS_X_VERSION_MIN_REQUIRED MAC_OS_X_VERSION_10_3
+#include <AvailabilityMacros.h>
+
#include <AppKit/AppKit.h>
#include <mach/mach.h>
@@ -168,6 +171,81 @@ const char *GetCurrentLocale(const char *)
NSArray* languages = [defs objectForKey:@"AppleLanguages"];
NSString* preferredLang = [languages objectAtIndex:0];
/* preferredLang is either 2 or 5 characters long ("xx" or "xx_YY"). */
- [ preferredLang getCString:retbuf maxLength:32 encoding:NSASCIIStringEncoding ];
+ if (MacOSVersionIsAtLeast(10, 4, 0)) {
+ [ preferredLang getCString:retbuf maxLength:32 encoding:NSASCIIStringEncoding ];
+ } else {
+ [ preferredLang getCString:retbuf maxLength:32 ];
+ }
return retbuf;
}
+
+
+/*
+ * This will only give an accurate result for versions before OS X 10.8 since it uses bcd encoding
+ * for the minor and bugfix version numbers and a scheme of representing all numbers from 9 and up
+ * with 9. This means we can't tell OS X 10.9 from 10.9 or 10.11. Please use GetMacOSVersionMajor()
+ * and GetMacOSVersionMinor() instead.
+ */
+static long GetMacOSVersion()
+{
+ static long sysVersion = -1;
+
+ if (sysVersion != -1) return sysVersion;
+
+ if (Gestalt(gestaltSystemVersion, &sysVersion) != noErr) sysVersion = -1;
+ return sysVersion;
+}
+
+long GetMacOSVersionMajor()
+{
+ static long sysVersion = -1;
+
+ if (sysVersion != -1) return sysVersion;
+
+ sysVersion = GetMacOSVersion();
+ if (sysVersion == -1) return -1;
+
+ if (sysVersion >= 0x1040) {
+ if (Gestalt(gestaltSystemVersionMajor, &sysVersion) != noErr) sysVersion = -1;
+ } else {
+ sysVersion = GB(sysVersion, 12, 4) * 10 + GB(sysVersion, 8, 4);
+ }
+
+ return sysVersion;
+}
+
+long GetMacOSVersionMinor()
+{
+ static long sysVersion = -1;
+
+ if (sysVersion != -1) return sysVersion;
+
+ sysVersion = GetMacOSVersion();
+ if (sysVersion == -1) return -1;
+
+ if (sysVersion >= 0x1040) {
+ if (Gestalt(gestaltSystemVersionMinor, &sysVersion) != noErr) sysVersion = -1;
+ } else {
+ sysVersion = GB(sysVersion, 4, 4);
+ }
+
+ return sysVersion;
+}
+
+long GetMacOSVersionBugfix()
+{
+ static long sysVersion = -1;
+
+ if (sysVersion != -1) return sysVersion;
+
+ sysVersion = GetMacOSVersion();
+ if (sysVersion == -1) return -1;
+
+ if (sysVersion >= 0x1040) {
+ if (Gestalt(gestaltSystemVersionBugFix, &sysVersion) != noErr) sysVersion = -1;
+ } else {
+ sysVersion = GB(sysVersion, 0, 4);
+ }
+
+ return sysVersion;
+}
diff --git a/src/sound/cocoa_s.cpp b/src/sound/cocoa_s.cpp
index 890761ebc..27812d9e9 100644
--- a/src/sound/cocoa_s.cpp
+++ b/src/sound/cocoa_s.cpp
@@ -8,6 +8,9 @@
#ifdef WITH_COCOA
+#define MAC_OS_X_VERSION_MIN_REQUIRED MAC_OS_X_VERSION_10_3
+#include <AvailabilityMacros.h>
+
#include <AudioUnit/AudioUnit.h>
/* Name conflict */
diff --git a/src/video/cocoa/cocoa_v.mm b/src/video/cocoa/cocoa_v.mm
index 9aad12012..24a7a4086 100644
--- a/src/video/cocoa/cocoa_v.mm
+++ b/src/video/cocoa/cocoa_v.mm
@@ -8,6 +8,7 @@
#ifdef WITH_COCOA
+#define MAC_OS_X_VERSION_MIN_REQUIRED MAC_OS_X_VERSION_10_3
#include <AvailabilityMacros.h>
#import <Cocoa/Cocoa.h>
@@ -229,13 +230,17 @@ void QZ_GameSizeChanged()
static CocoaSubdriver *QZ_CreateWindowSubdriver(int width, int height, int bpp)
{
- long sysVersion;
+ CocoaSubdriver *ret;
- if (Gestalt(gestaltSystemVersion, &sysVersion) == noErr && sysVersion >= 0x1040) {
- return QZ_CreateWindowQuartzSubdriver(width, height, bpp);
+ if (MacOSVersionIsAtLeast(10, 4, 0)) {
+ ret = QZ_CreateWindowQuartzSubdriver(width, height, bpp);
+ if (ret != NULL) return ret;
}
- return QZ_CreateWindowQuickdrawSubdriver(width, height, bpp);
+ ret = QZ_CreateWindowQuickdrawSubdriver(width, height, bpp);
+ if (ret != NULL) return ret;
+
+ return NULL;
}
@@ -282,6 +287,8 @@ const char *VideoDriver_Cocoa::Start(const char * const *parm)
{
int width, height, bpp;
+ if (!MacOSVersionIsAtLeast(10, 3, 0)) return "The Cocoa video driver requires Mac OS X 10.3 or later.";
+
if (_cocoa_video_started) return "Already started";
_cocoa_video_started = true;
diff --git a/src/video/cocoa/event.mm b/src/video/cocoa/event.mm
index 18002b439..76e148e9a 100644
--- a/src/video/cocoa/event.mm
+++ b/src/video/cocoa/event.mm
@@ -8,6 +8,9 @@
#ifdef WITH_COCOA
+#define MAC_OS_X_VERSION_MIN_REQUIRED MAC_OS_X_VERSION_10_3
+#include <AvailabilityMacros.h>
+
#import <Cocoa/Cocoa.h>
#import <sys/time.h> /* gettimeofday */
#import <sys/param.h> /* for MAXPATHLEN */
diff --git a/src/video/cocoa/fullscreen.mm b/src/video/cocoa/fullscreen.mm
index a6d2a3387..f7612f6c9 100644
--- a/src/video/cocoa/fullscreen.mm
+++ b/src/video/cocoa/fullscreen.mm
@@ -8,6 +8,7 @@
#ifdef WITH_COCOA
+#define MAC_OS_X_VERSION_MIN_REQUIRED MAC_OS_X_VERSION_10_3
#include <AvailabilityMacros.h>
#import <Cocoa/Cocoa.h>
diff --git a/src/video/cocoa/wnd_quartz.mm b/src/video/cocoa/wnd_quartz.mm
index 847bdc4b5..9df8525f3 100644
--- a/src/video/cocoa/wnd_quartz.mm
+++ b/src/video/cocoa/wnd_quartz.mm
@@ -8,6 +8,7 @@
#ifdef WITH_COCOA
+#define MAC_OS_X_VERSION_MIN_REQUIRED MAC_OS_X_VERSION_10_4
#include <AvailabilityMacros.h>
#import <Cocoa/Cocoa.h>
@@ -685,6 +686,7 @@ CGPoint WindowQuartzSubdriver::PrivateLocalToCG(NSPoint* p)
p->y = window_height - p->y;
*p = [ qzview convertPoint:*p toView: nil ];
+
*p = [ window convertBaseToScreen:*p ];
p->y = device_height - p->y;
@@ -779,6 +781,11 @@ CocoaSubdriver *QZ_CreateWindowQuartzSubdriver(int width, int height, int bpp)
{
WindowQuartzSubdriver *ret;
+ if (!MacOSVersionIsAtLeast(10, 4, 0)) {
+ DEBUG(driver, 0, "The cocoa quartz subdriver requires Mac OS X 10.4 or later.");
+ return NULL;
+ }
+
if (bpp != 8 && bpp != 32) {
DEBUG(driver, 0, "The cocoa quartz subdriver only supports 8 and 32 bpp.");
return NULL;
diff --git a/src/video/cocoa/wnd_quickdraw.mm b/src/video/cocoa/wnd_quickdraw.mm
index 92bcdd4ee..9a19c7a3d 100644
--- a/src/video/cocoa/wnd_quickdraw.mm
+++ b/src/video/cocoa/wnd_quickdraw.mm
@@ -8,6 +8,8 @@
#ifdef WITH_COCOA
+#define MAC_OS_X_VERSION_MIN_REQUIRED MAC_OS_X_VERSION_10_3
+#define MAC_OS_X_VERSION_MAX_ALLOWED MAC_OS_X_VERSION_10_3
#include <AvailabilityMacros.h>
#import <Cocoa/Cocoa.h>
@@ -796,6 +798,10 @@ CocoaSubdriver *QZ_CreateWindowQuickdrawSubdriver(int width, int height, int bpp
{
WindowQuickdrawSubdriver *ret;
+ if (MacOSVersionIsAtLeast(10, 4, 0)) {
+ DEBUG(driver, 0, "The cocoa quickdraw subdriver is not recommended for Mac OS X 10.4 or later.");
+ }
+
if (bpp != 8 && bpp != 32) {
DEBUG(driver, 0, "The cocoa quickdraw subdriver only supports 8 and 32 bpp.");
return NULL;