diff options
author | Michael Lutz <michi@icosahedron.de> | 2020-12-26 16:07:47 +0100 |
---|---|---|
committer | Michael Lutz <michi@icosahedron.de> | 2021-01-03 13:25:32 +0100 |
commit | 9ccef816f90e9a7e3042cd89141ba3c0956d7bb9 (patch) | |
tree | 906ca656f585147070658dc14211b31c0689a83e /src/os | |
parent | ab7da117e066983d076f540b9722e1b79cf01d98 (diff) | |
download | openttd-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')
-rw-r--r-- | src/os/macosx/macos.mm | 45 | ||||
-rw-r--r-- | src/os/unix/unix.cpp | 8 |
2 files changed, 49 insertions, 4 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 /** diff --git a/src/os/unix/unix.cpp b/src/os/unix/unix.cpp index 2bcd6151a..4b94539b0 100644 --- a/src/os/unix/unix.cpp +++ b/src/os/unix/unix.cpp @@ -235,8 +235,8 @@ void ShowOSErrorBox(const char *buf, bool system) #endif #ifdef WITH_COCOA -void cocoaSetupAutoreleasePool(); -void cocoaReleaseAutoreleasePool(); +void CocoaSetupAutoreleasePool(); +void CocoaReleaseAutoreleasePool(); #endif int CDECL main(int argc, char *argv[]) @@ -245,7 +245,7 @@ int CDECL main(int argc, char *argv[]) for (int i = 0; i < argc; i++) ValidateString(argv[i]); #ifdef WITH_COCOA - cocoaSetupAutoreleasePool(); + CocoaSetupAutoreleasePool(); /* This is passed if we are launched by double-clicking */ if (argc >= 2 && strncmp(argv[1], "-psn", 4) == 0) { argv[1] = nullptr; @@ -261,7 +261,7 @@ int CDECL main(int argc, char *argv[]) int ret = openttd_main(argc, argv); #ifdef WITH_COCOA - cocoaReleaseAutoreleasePool(); + CocoaReleaseAutoreleasePool(); #endif return ret; |