summaryrefslogtreecommitdiff
path: root/src/os/macosx
diff options
context:
space:
mode:
authorMichael Lutz <michi@icosahedron.de>2020-12-26 16:07:47 +0100
committerMichael Lutz <michi@icosahedron.de>2021-01-03 13:25:32 +0100
commit9ccef816f90e9a7e3042cd89141ba3c0956d7bb9 (patch)
tree906ca656f585147070658dc14211b31c0689a83e /src/os/macosx
parentab7da117e066983d076f540b9722e1b79cf01d98 (diff)
downloadopenttd-9ccef816f90e9a7e3042cd89141ba3c0956d7bb9.tar.xz
Codechange: [OSX] Re-arrange the OSX video driver code by combining all drawing code and moving the window/event handling to a different file.
This is just a code move/rename, not a functionality change.
Diffstat (limited to 'src/os/macosx')
-rw-r--r--src/os/macosx/macos.mm45
1 files changed, 45 insertions, 0 deletions
diff --git a/src/os/macosx/macos.mm b/src/os/macosx/macos.mm
index 19e1d4b76..8ecd3a88e 100644
--- a/src/os/macosx/macos.mm
+++ b/src/os/macosx/macos.mm
@@ -12,7 +12,9 @@
#include "../../rev.h"
#include "macos.h"
#include "../../string_func.h"
+#include "../../fileio_func.h"
#include <pthread.h>
+#include <array>
#define Rect OTTDRect
#define Point OTTDPoint
@@ -40,6 +42,10 @@ typedef struct {
#define NSOperatingSystemVersion OTTDOperatingSystemVersion
#endif
+#ifdef WITH_COCOA
+static NSAutoreleasePool *_ottd_autorelease_pool;
+#endif
+
/**
* Get the version of the MacOS we are running under. Code adopted
* from http://www.cocoadev.com/index.pl?DeterminingOSVersion
@@ -191,6 +197,45 @@ bool GetClipboardContents(char *buffer, const char *last)
return true;
}
+
+/** Set the application's bundle directory.
+ *
+ * This is needed since OS X application bundles do not have a
+ * current directory and the data files are 'somewhere' in the bundle.
+ */
+void CocoaSetApplicationBundleDir()
+{
+ extern std::array<std::string, NUM_SEARCHPATHS> _searchpaths;
+
+ char tmp[MAXPATHLEN];
+ CFAutoRelease<CFURLRef> url(CFBundleCopyResourcesDirectoryURL(CFBundleGetMainBundle()));
+ if (CFURLGetFileSystemRepresentation(url.get(), true, (unsigned char *)tmp, MAXPATHLEN)) {
+ _searchpaths[SP_APPLICATION_BUNDLE_DIR] = tmp;
+ AppendPathSeparator(_searchpaths[SP_APPLICATION_BUNDLE_DIR]);
+ } else {
+ _searchpaths[SP_APPLICATION_BUNDLE_DIR].clear();
+ }
+}
+
+/**
+ * Setup autorelease for the application pool.
+ *
+ * These are called from main() to prevent a _NSAutoreleaseNoPool error when
+ * exiting before the cocoa video driver has been loaded
+ */
+void CocoaSetupAutoreleasePool()
+{
+ _ottd_autorelease_pool = [ [ NSAutoreleasePool alloc ] init ];
+}
+
+/**
+ * Autorelease the application pool.
+ */
+void CocoaReleaseAutoreleasePool()
+{
+ [ _ottd_autorelease_pool release ];
+}
+
#endif
/**