main_mac.mm 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #include "AtomSampleViewerApplication.h"
  9. #include <AzGameFramework/Application/GameApplication.h>
  10. #include "MacO3DEApplication.h"
  11. #include <mach-o/dyld.h>
  12. #include <libgen.h>
  13. int main(int argc, char** argv)
  14. {
  15. /*
  16. * AtomSampleViewer executable is not getting it's current working directory set correctly on Mac.
  17. * When launched from the Finder it's set to the active users folder.
  18. * When launched in the terminal it's set to the terminal's working directory.
  19. *
  20. * Fix is to get the path to the executable and set the current working directory to match it.
  21. */
  22. char path[1024];
  23. uint32_t size = sizeof(path);
  24. int result = _NSGetExecutablePath(path, &size);
  25. AZ_Assert(result == 0, "Mac path buffer too small; need size %u\n", size);
  26. char* dir = dirname(path);
  27. chdir(dir);
  28. // Ensure the process is a foreground application. Must be done before creating the application.
  29. ProcessSerialNumber processSerialNumber = { 0, kCurrentProcess };
  30. TransformProcessType(&processSerialNumber, kProcessTransformToForegroundApplication);
  31. // Create a custom AppKit application, and a custom AppKit application delegate.
  32. @autoreleasepool
  33. {
  34. [MacO3DEApplication sharedApplication];
  35. [NSApp setDelegate: [[MacO3DEApplicationDelegate alloc] init]];
  36. // Register some default application behaviours
  37. [[NSUserDefaults standardUserDefaults] registerDefaults:
  38. [[NSDictionary alloc] initWithObjectsAndKeys:
  39. [NSNumber numberWithBool: FALSE], @"AppleMomentumScrollSupported",
  40. [NSNumber numberWithBool: FALSE], @"ApplePressAndHoldEnabled",
  41. nil]];
  42. // Launch the AppKit application and release the memory pool.
  43. [NSApp finishLaunching];
  44. }
  45. // Launch the Open 3D Engine application.
  46. return AtomSampleViewer::RunGameCommon(argc, argv);
  47. }