|
15 | 15 | #ifdef _WIN32 |
16 | 16 | #include <timeapi.h> |
17 | 17 | #endif |
| 18 | +#ifdef __APPLE__ |
| 19 | +#include <CoreFoundation/CoreFoundation.h> |
| 20 | +#endif |
18 | 21 |
|
19 | 22 | #if defined(__SSE2__) || (defined(_M_IX86_FP) && _M_IX86_FP >= 2) || \ |
20 | 23 | defined(__x86_64__) || defined(_M_X64) || defined(__x86_64) || defined(_M_AMD64) |
@@ -78,6 +81,9 @@ bool Game::Initialize() { |
78 | 81 | params.DriverType = irr::video::EDT_OPENGL; |
79 | 82 | params.WindowSize = irr::core::dimension2d<irr::u32>(gameConf.window_width, gameConf.window_height); |
80 | 83 | device = irr::createDeviceEx(params); |
| 84 | +#ifdef __APPLE__ |
| 85 | + FixMacOSBundleWorkingDirectory(); |
| 86 | +#endif |
81 | 87 | if(!device) { |
82 | 88 | ErrorLog("Failed to create Irrlicht Engine device!"); |
83 | 89 | return false; |
@@ -2330,6 +2336,24 @@ irr::core::recti Game::ResizeFit(irr::s32 x, irr::s32 y, irr::s32 x2, irr::s32 y |
2330 | 2336 | y2 = y2 * mul; |
2331 | 2337 | return irr::core::recti(x, y, x2, y2); |
2332 | 2338 | } |
| 2339 | + |
| 2340 | +void Game::FixMacOSBundleWorkingDirectory() { |
| 2341 | +#ifdef __APPLE__ |
| 2342 | + CFURLRef bundle_url = CFBundleCopyBundleURL(CFBundleGetMainBundle()); |
| 2343 | + CFURLRef bundle_base_url = CFURLCreateCopyDeletingLastPathComponent(nullptr, bundle_url); |
| 2344 | + CFStringRef bundle_ext = CFURLCopyPathExtension(bundle_url); |
| 2345 | + if(bundle_ext) { |
| 2346 | + char path[PATH_MAX]; |
| 2347 | + if(CFStringCompare(bundle_ext, CFSTR("app"), kCFCompareCaseInsensitive) == kCFCompareEqualTo |
| 2348 | + && CFURLGetFileSystemRepresentation(bundle_base_url, true, (UInt8*)path, PATH_MAX)) { |
| 2349 | + chdir(path); |
| 2350 | + } |
| 2351 | + CFRelease(bundle_ext); |
| 2352 | + } |
| 2353 | + CFRelease(bundle_url); |
| 2354 | + CFRelease(bundle_base_url); |
| 2355 | +#endif //__APPLE__ |
| 2356 | +} |
2333 | 2357 | void Game::SetWindowsIcon() { |
2334 | 2358 | #ifdef _WIN32 |
2335 | 2359 | HINSTANCE hInstance = (HINSTANCE)GetModuleHandleW(nullptr); |
|
0 commit comments