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.
This commit is contained in:
@@ -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
|
||||
|
||||
/**
|
||||
|
@@ -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;
|
||||
|
Reference in New Issue
Block a user