From 40c1a39c40682ebed5f007a77155f7f4b1f80157 Mon Sep 17 00:00:00 2001 From: Phil Marell Date: Sun, 11 Jul 2021 16:57:22 +1000 Subject: [PATCH 01/19] Add .DS_Store to .gitignore --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 390e353..cc91ea2 100644 --- a/.gitignore +++ b/.gitignore @@ -50,6 +50,8 @@ SDL2-2.0.12/sdl2.pc SDL2-2.0.12/sdl2-config install_manifest.txt +## macOS +.DS_Store ## Xcode projects AerofoilMac/xcuserdata/ From ccceec8b3c1b689f5bc2038c80e5fca1103d76de Mon Sep 17 00:00:00 2001 From: Phil Marell Date: Sat, 24 Jul 2021 16:00:33 +1000 Subject: [PATCH 02/19] Xcode 13 automatic change --- AerofoilMac/AerofoilMac.xcodeproj/project.pbxproj | 2 -- 1 file changed, 2 deletions(-) diff --git a/AerofoilMac/AerofoilMac.xcodeproj/project.pbxproj b/AerofoilMac/AerofoilMac.xcodeproj/project.pbxproj index 0416bf5..06361b3 100644 --- a/AerofoilMac/AerofoilMac.xcodeproj/project.pbxproj +++ b/AerofoilMac/AerofoilMac.xcodeproj/project.pbxproj @@ -2348,7 +2348,6 @@ "@executable_path/../Frameworks", ); MARKETING_VERSION = 1.1.0; - OTHER_LDFLAGS = ""; PRODUCT_BUNDLE_IDENTIFIER = com.madthijs.AerofoilMac; PRODUCT_NAME = "$(TARGET_NAME)"; }; @@ -2382,7 +2381,6 @@ "@executable_path/../Frameworks", ); MARKETING_VERSION = 1.1.0; - OTHER_LDFLAGS = ""; PRODUCT_BUNDLE_IDENTIFIER = com.madthijs.AerofoilMac; PRODUCT_NAME = "$(TARGET_NAME)"; }; From e02919f1fc8ebe04b5be8b27720d9b1ba4de9781 Mon Sep 17 00:00:00 2001 From: Phil Marell Date: Sat, 24 Jul 2021 16:00:01 +1000 Subject: [PATCH 03/19] Use tabs in Xcode project --- AerofoilMac/AerofoilMac.xcodeproj/project.pbxproj | 1 + 1 file changed, 1 insertion(+) diff --git a/AerofoilMac/AerofoilMac.xcodeproj/project.pbxproj b/AerofoilMac/AerofoilMac.xcodeproj/project.pbxproj index 06361b3..670fb22 100644 --- a/AerofoilMac/AerofoilMac.xcodeproj/project.pbxproj +++ b/AerofoilMac/AerofoilMac.xcodeproj/project.pbxproj @@ -1042,6 +1042,7 @@ 5C54D687262D8AC400AB55E0 /* Resources */, ); sourceTree = ""; + usesTabs = 1; }; 5C54D0972629B42100AB55E0 /* Products */ = { isa = PBXGroup; From ab6c447a2f2cdeb0413abae8953aa6330bf31077 Mon Sep 17 00:00:00 2001 From: Phil Marell Date: Sat, 24 Jul 2021 16:12:53 +1000 Subject: [PATCH 04/19] Compile on Xcode 13 --- GpApp/HouseIO.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/GpApp/HouseIO.cpp b/GpApp/HouseIO.cpp index 4d93dc0..775d4f3 100644 --- a/GpApp/HouseIO.cpp +++ b/GpApp/HouseIO.cpp @@ -3257,7 +3257,11 @@ static ExportHouseResult_t TryExportIcon(GpVector &resData, const THand for (uint8_t i = 0; i < 16; i++) { uint32_t error = 0; - const int16_t deltas[3] = { palette[i].r - color.r, palette[i].g - color.g, palette[i].b - color.b }; + const int16_t deltas[3] = { + static_cast(palette[i].r - color.r), + static_cast(palette[i].g - color.g), + static_cast(palette[i].b - color.b) + }; for (int ch = 0; ch < 3; ch++) error += static_cast(deltas[ch] * deltas[ch]); From b83fd1b28f8f498fab819490aba37b96d96ebfef Mon Sep 17 00:00:00 2001 From: Phil Marell Date: Sat, 24 Jul 2021 16:23:58 +1000 Subject: [PATCH 05/19] =?UTF-8?q?Move=20=E2=80=9Cend=20game=E2=80=9D=20log?= =?UTF-8?q?ic=20into=20common=20function?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- GpApp/Input.cpp | 63 ++++++++++++++++++++----------------------------- 1 file changed, 26 insertions(+), 37 deletions(-) diff --git a/GpApp/Input.cpp b/GpApp/Input.cpp index b5e81ce..86fb22d 100644 --- a/GpApp/Input.cpp +++ b/GpApp/Input.cpp @@ -42,6 +42,7 @@ void DoPause (void); void DoTouchScreenMenu (void); void DoBatteryEngaged (gliderPtr); void DoHeliumEngaged (gliderPtr); +void DoEndGame (void); void QuerySaveGame (Boolean &save, Boolean &cancel); @@ -72,27 +73,10 @@ void LogDemoKey (char keyIs) void DoCommandKey (void) { const KeyDownStates *theKeys = PortabilityLayer::InputManager::GetInstance()->GetKeys(); - + if (theKeys->IsSet(PL_KEY_ASCII('Q'))) { - Boolean wantCancel = false; - playing = false; - paused = false; - if ((!twoPlayerGame) && (!demoGoing)) - { - Boolean wantSave = false; - QuerySaveGame(wantSave, wantCancel); - - if (wantSave) - { - // New save game. - if (!SaveGame2()) - wantCancel = true; - } - } - - if (wantCancel) - playing = true; + DoEndGame(); } else if ((theKeys->IsSet(PL_KEY_ASCII('S'))) && (!twoPlayerGame)) { @@ -337,24 +321,7 @@ void DoTouchScreenMenu(void) switch (highlightedItem) { case TouchScreenMenuItems::kQuit: - { - Boolean wantCancel = false; - playing = false; - paused = false; - if ((!twoPlayerGame) && (!demoGoing)) - { - Boolean wantSave = false; - QuerySaveGame(wantSave, wantCancel); - if (wantSave) - { - if (!SaveGame2()) // New save game. - wantCancel = true; - } - } - - if (wantCancel) - playing = true; - } + DoEndGame(); break; case TouchScreenMenuItems::kSave: assert(!twoPlayerGame); @@ -813,6 +780,28 @@ void GetInput (gliderPtr thisGlider) } } +void DoEndGame() { + Boolean wantCancel = false; + playing = false; + paused = false; + quitting = false; + if ((!twoPlayerGame) && (!demoGoing)) + { + Boolean wantSave = false; + QuerySaveGame(wantSave, wantCancel); + if (wantSave) + { + if (!SaveGame2()) // New save game. + wantCancel = true; + } + } + + if (wantCancel) + { + playing = true; + } +} + //-------------------------------------------------------------- QuerySaveGame void QuerySaveGame (Boolean &save, Boolean &cancel) From a32b33ef1bcc91553340a25991763f950938b6c3 Mon Sep 17 00:00:00 2001 From: Phil Marell Date: Sat, 24 Jul 2021 16:24:56 +1000 Subject: [PATCH 06/19] =?UTF-8?q?Ask=20to=20save=20game=20if=20user=20?= =?UTF-8?q?=E2=80=9Cexternally=E2=80=9D=20quits=20while=20in-game?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit An “external quit” being defined as one where the portability handler receives a request to quit the app, such as closing the window, or on macOS using the Quit menu item. This can prevent the user losing their progress after having finished with a game. --- GpApp/Play.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/GpApp/Play.cpp b/GpApp/Play.cpp index 1715dc0..9e2923f 100644 --- a/GpApp/Play.cpp +++ b/GpApp/Play.cpp @@ -46,7 +46,7 @@ void HandleRoomVisitation (void); void SetObjectsToDefaults (void); void InitTelephone (void); void HandleTelephone (void); - +void DoEndGame (void); phoneType thePhone, theChimes; Rect glidSrcRect, justRoomsRect; @@ -717,7 +717,11 @@ void PlayGame (void) HandleDynamicScoreboard(); } } - + + if (quitting) { + DoEndGame(); + } + if (gameOver) { countDown--; From c3eb23af4b63224712e63e19b524aa83d7b5150a Mon Sep 17 00:00:00 2001 From: Phil Marell Date: Sun, 11 Jul 2021 16:41:06 +1000 Subject: [PATCH 07/19] Handle external quits while in editor This mitigates against potential data loss after having finished editing a house. --- GpApp/Events.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/GpApp/Events.cpp b/GpApp/Events.cpp index b6f109c..27e54e8 100644 --- a/GpApp/Events.cpp +++ b/GpApp/Events.cpp @@ -28,7 +28,7 @@ void HandleOSEvent (EventRecord *); void HandleHighLevelEvent (EventRecord *); void HandleIdleTask (void); void IncrementMode (void); - +void DoEndGame (void); long lastUp, incrementModeTime; @@ -398,6 +398,17 @@ void HandleIdleTask (void) HandleSplashResolutionChange(); } } + +#ifndef COMPILEDEMO + if (quitting) { + if (theMode == kEditMode) { + if (!QuerySaveChanges()) { + quitting = false; + } + } + } +#endif + TickMainMenuUI(); } From e098370249382e9ccc3c4e9d4fe73a295fc5de74 Mon Sep 17 00:00:00 2001 From: Phil Marell Date: Sat, 24 Jul 2021 16:27:34 +1000 Subject: [PATCH 08/19] Use Command key instead of Control as modifier on macOS This provides an experience closer to the original classic Mac version. This is supported by the earlier changes to gracefully quit the game. --- AerofoilSDL/GpDisplayDriver_SDL_GL2.cpp | 8 ++++++++ GpCommon/GpVOSEvent.h | 4 ++-- PortabilityLayer/MenuManager.cpp | 10 +++++++++- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/AerofoilSDL/GpDisplayDriver_SDL_GL2.cpp b/AerofoilSDL/GpDisplayDriver_SDL_GL2.cpp index f323d86..01da78b 100644 --- a/AerofoilSDL/GpDisplayDriver_SDL_GL2.cpp +++ b/AerofoilSDL/GpDisplayDriver_SDL_GL2.cpp @@ -1637,11 +1637,19 @@ static bool IdentifyVKey(const SDL_KeyboardEvent *keyEvt, GpKeyIDSubset_t &outSu return false; } break; +#ifdef __MACOS__ + case SDLK_LGUI: +#else case SDLK_LCTRL: +#endif outSubset = GpKeyIDSubsets::kSpecial; outKey.m_specialKey = GpKeySpecials::kLeftCtrl; break; +#ifdef __MACOS__ + case SDLK_RGUI: +#else case SDLK_RCTRL: +#endif outSubset = GpKeyIDSubsets::kSpecial; outKey.m_specialKey = GpKeySpecials::kRightCtrl; break; diff --git a/GpCommon/GpVOSEvent.h b/GpCommon/GpVOSEvent.h index 4389d32..08c8305 100644 --- a/GpCommon/GpVOSEvent.h +++ b/GpCommon/GpVOSEvent.h @@ -97,8 +97,8 @@ namespace GpKeySpecials kEnter, kLeftShift, kRightShift, - kLeftCtrl, - kRightCtrl, + kLeftCtrl, // Maps to Command modifier on macOS. + kRightCtrl, // kLeftAlt, kRightAlt, kNumLock, diff --git a/PortabilityLayer/MenuManager.cpp b/PortabilityLayer/MenuManager.cpp index e55e6f7..f73b8ff 100644 --- a/PortabilityLayer/MenuManager.cpp +++ b/PortabilityLayer/MenuManager.cpp @@ -1405,14 +1405,22 @@ namespace PortabilityLayer size_t MenuManagerImpl::FormatHintText(uint8_t *buffer, uint8_t key) { +#ifdef __MACOS__ + buffer[0] = 'C'; + buffer[1] = 'm'; + buffer[2] = 'd'; + buffer[3] = '+'; + buffer[4] = key; + return 5; +#else buffer[0] = 'C'; buffer[1] = 't'; buffer[2] = 'r'; buffer[3] = 'l'; buffer[4] = '+'; buffer[5] = key; - return 6; +#endif } MenuManagerImpl *MenuManagerImpl::GetInstance() From f16ffa0c4c50f412d8c66c44ef8f497a3ff0518e Mon Sep 17 00:00:00 2001 From: Phil Marell Date: Wed, 28 Jul 2021 19:44:03 +1000 Subject: [PATCH 09/19] Replace Main.storyboard with custom MainMenu.xib The new xib file contains the default main menu created by Xcode, but removes the command-H shortcut from the Hide menu item, so that the in-game High Scores item takes effect instead. Also SDL only supports custom nib files, not storyboards. --- .../AerofoilMac.xcodeproj/project.pbxproj | 14 +- .../AerofoilMac/Base.lproj/Main.storyboard | 717 ------------------ .../AerofoilMac/Base.lproj/MainMenu.xib | 105 +++ AerofoilMac/AerofoilMac/Info.plist | 4 +- 4 files changed, 114 insertions(+), 726 deletions(-) delete mode 100644 AerofoilMac/AerofoilMac/Base.lproj/Main.storyboard create mode 100644 AerofoilMac/AerofoilMac/Base.lproj/MainMenu.xib diff --git a/AerofoilMac/AerofoilMac.xcodeproj/project.pbxproj b/AerofoilMac/AerofoilMac.xcodeproj/project.pbxproj index 670fb22..b1396e2 100644 --- a/AerofoilMac/AerofoilMac.xcodeproj/project.pbxproj +++ b/AerofoilMac/AerofoilMac.xcodeproj/project.pbxproj @@ -7,8 +7,8 @@ objects = { /* Begin PBXBuildFile section */ + 4A04C5AC269AD58E009F5CA3 /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 4A04C59D269AD58E009F5CA3 /* MainMenu.xib */; }; 5C54D0A02629B42400AB55E0 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 5C54D09F2629B42400AB55E0 /* Assets.xcassets */; }; - 5C54D0A32629B42400AB55E0 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 5C54D0A12629B42400AB55E0 /* Main.storyboard */; }; 5C54D0BE2629B72000AB55E0 /* stb_image_write.h in Headers */ = {isa = PBXBuildFile; fileRef = 5C54D0BC2629B72000AB55E0 /* stb_image_write.h */; }; 5C54D0BF2629B72000AB55E0 /* stb_image_write.c in Sources */ = {isa = PBXBuildFile; fileRef = 5C54D0BD2629B72000AB55E0 /* stb_image_write.c */; }; 5C54D26D2629B86700AB55E0 /* adler32.c in Sources */ = {isa = PBXBuildFile; fileRef = 5C54D25E2629B86600AB55E0 /* adler32.c */; }; @@ -589,9 +589,9 @@ /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ + 4A04C59E269AD58E009F5CA3 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/MainMenu.xib; sourceTree = ""; }; 5C54D0962629B42100AB55E0 /* Aerofoil.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Aerofoil.app; sourceTree = BUILT_PRODUCTS_DIR; }; 5C54D09F2629B42400AB55E0 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; - 5C54D0A22629B42400AB55E0 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 5C54D0A42629B42400AB55E0 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 5C54D0A72629B42400AB55E0 /* AerofoilMac.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = AerofoilMac.entitlements; sourceTree = ""; }; 5C54D0B32629B5C600AB55E0 /* libAerofoilShared.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libAerofoilShared.a; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -1068,7 +1068,7 @@ 5C54D655262D84A800AB55E0 /* GpSystemServices_X.cpp */, 5C54D658262D84A900AB55E0 /* GpSystemServices_X.h */, 5C54D0A42629B42400AB55E0 /* Info.plist */, - 5C54D0A12629B42400AB55E0 /* Main.storyboard */, + 4A04C59D269AD58E009F5CA3 /* MainMenu.xib */, ); path = AerofoilMac; sourceTree = ""; @@ -1981,7 +1981,7 @@ buildActionMask = 2147483647; files = ( 5C54D0A02629B42400AB55E0 /* Assets.xcassets in Resources */, - 5C54D0A32629B42400AB55E0 /* Main.storyboard in Resources */, + 4A04C5AC269AD58E009F5CA3 /* MainMenu.xib in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -2200,12 +2200,12 @@ /* End PBXTargetDependency section */ /* Begin PBXVariantGroup section */ - 5C54D0A12629B42400AB55E0 /* Main.storyboard */ = { + 4A04C59D269AD58E009F5CA3 /* MainMenu.xib */ = { isa = PBXVariantGroup; children = ( - 5C54D0A22629B42400AB55E0 /* Base */, + 4A04C59E269AD58E009F5CA3 /* Base */, ); - name = Main.storyboard; + name = MainMenu.xib; sourceTree = ""; }; /* End PBXVariantGroup section */ diff --git a/AerofoilMac/AerofoilMac/Base.lproj/Main.storyboard b/AerofoilMac/AerofoilMac/Base.lproj/Main.storyboard deleted file mode 100644 index bffcdff..0000000 --- a/AerofoilMac/AerofoilMac/Base.lproj/Main.storyboard +++ /dev/null @@ -1,717 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Default - - - - - - - Left to Right - - - - - - - Right to Left - - - - - - - - - - - Default - - - - - - - Left to Right - - - - - - - Right to Left - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/AerofoilMac/AerofoilMac/Base.lproj/MainMenu.xib b/AerofoilMac/AerofoilMac/Base.lproj/MainMenu.xib new file mode 100644 index 0000000..aeb7bab --- /dev/null +++ b/AerofoilMac/AerofoilMac/Base.lproj/MainMenu.xib @@ -0,0 +1,105 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/AerofoilMac/AerofoilMac/Info.plist b/AerofoilMac/AerofoilMac/Info.plist index af98330..cb3c356 100644 --- a/AerofoilMac/AerofoilMac/Info.plist +++ b/AerofoilMac/AerofoilMac/Info.plist @@ -24,8 +24,8 @@ public.app-category.arcade-games LSMinimumSystemVersion $(MACOSX_DEPLOYMENT_TARGET) - NSMainStoryboardFile - Main + NSMainNibFile + MainMenu NSPrincipalClass NSApplication From 00488c6feada914288dfb3fada912200e5f3c7f3 Mon Sep 17 00:00:00 2001 From: Phil Marell Date: Sat, 24 Jul 2021 16:32:58 +1000 Subject: [PATCH 10/19] Override Cocoa app lifecycle defined by SDL --- .../AerofoilMac.xcodeproj/project.pbxproj | 18 ++++++++ AerofoilMac/AerofoilMac/AerofoilAppDelegate.h | 9 ++++ .../AerofoilMac/AerofoilAppDelegate.mm | 44 +++++++++++++++++++ AerofoilMac/AerofoilMac/AerofoilApplication.h | 9 ++++ AerofoilMac/AerofoilMac/AerofoilApplication.m | 13 ++++++ AerofoilMac/AerofoilMac/MacInit.h | 6 +++ AerofoilMac/AerofoilMac/MacInit.mm | 22 ++++++++++ AerofoilX/GpMain_SDL_X.cpp | 5 +++ 8 files changed, 126 insertions(+) create mode 100644 AerofoilMac/AerofoilMac/AerofoilAppDelegate.h create mode 100644 AerofoilMac/AerofoilMac/AerofoilAppDelegate.mm create mode 100644 AerofoilMac/AerofoilMac/AerofoilApplication.h create mode 100644 AerofoilMac/AerofoilMac/AerofoilApplication.m create mode 100644 AerofoilMac/AerofoilMac/MacInit.h create mode 100644 AerofoilMac/AerofoilMac/MacInit.mm diff --git a/AerofoilMac/AerofoilMac.xcodeproj/project.pbxproj b/AerofoilMac/AerofoilMac.xcodeproj/project.pbxproj index b1396e2..1bc23b9 100644 --- a/AerofoilMac/AerofoilMac.xcodeproj/project.pbxproj +++ b/AerofoilMac/AerofoilMac.xcodeproj/project.pbxproj @@ -8,6 +8,9 @@ /* Begin PBXBuildFile section */ 4A04C5AC269AD58E009F5CA3 /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 4A04C59D269AD58E009F5CA3 /* MainMenu.xib */; }; + 4A04C5AF269AD600009F5CA3 /* AerofoilAppDelegate.mm in Sources */ = {isa = PBXBuildFile; fileRef = 4A04C5AE269AD600009F5CA3 /* AerofoilAppDelegate.mm */; }; + 4A04C5B6269AE945009F5CA3 /* AerofoilApplication.m in Sources */ = {isa = PBXBuildFile; fileRef = 4A04C5B5269AE945009F5CA3 /* AerofoilApplication.m */; }; + 4A04C5B7269AE96B009F5CA3 /* MacInit.mm in Sources */ = {isa = PBXBuildFile; fileRef = 4A04C5B0269AE243009F5CA3 /* MacInit.mm */; }; 5C54D0A02629B42400AB55E0 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 5C54D09F2629B42400AB55E0 /* Assets.xcassets */; }; 5C54D0BE2629B72000AB55E0 /* stb_image_write.h in Headers */ = {isa = PBXBuildFile; fileRef = 5C54D0BC2629B72000AB55E0 /* stb_image_write.h */; }; 5C54D0BF2629B72000AB55E0 /* stb_image_write.c in Sources */ = {isa = PBXBuildFile; fileRef = 5C54D0BD2629B72000AB55E0 /* stb_image_write.c */; }; @@ -590,6 +593,12 @@ /* Begin PBXFileReference section */ 4A04C59E269AD58E009F5CA3 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/MainMenu.xib; sourceTree = ""; }; + 4A04C5AD269AD600009F5CA3 /* AerofoilAppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AerofoilAppDelegate.h; sourceTree = ""; }; + 4A04C5AE269AD600009F5CA3 /* AerofoilAppDelegate.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = AerofoilAppDelegate.mm; sourceTree = ""; usesTabs = 1; }; + 4A04C5B0269AE243009F5CA3 /* MacInit.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = MacInit.mm; sourceTree = ""; }; + 4A04C5B2269AE368009F5CA3 /* MacInit.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MacInit.h; sourceTree = ""; }; + 4A04C5B4269AE945009F5CA3 /* AerofoilApplication.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AerofoilApplication.h; sourceTree = ""; }; + 4A04C5B5269AE945009F5CA3 /* AerofoilApplication.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AerofoilApplication.m; sourceTree = ""; }; 5C54D0962629B42100AB55E0 /* Aerofoil.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Aerofoil.app; sourceTree = BUILT_PRODUCTS_DIR; }; 5C54D09F2629B42400AB55E0 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 5C54D0A42629B42400AB55E0 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; @@ -1065,10 +1074,16 @@ 5C54D656262D84A800AB55E0 /* GpLogDriver_X.cpp */, 5C54D659262D84A900AB55E0 /* GpLogDriver_X.h */, 5C54D654262D84A800AB55E0 /* GpMain_SDL_X.cpp */, + 4A04C5B0269AE243009F5CA3 /* MacInit.mm */, + 4A04C5B2269AE368009F5CA3 /* MacInit.h */, 5C54D655262D84A800AB55E0 /* GpSystemServices_X.cpp */, 5C54D658262D84A900AB55E0 /* GpSystemServices_X.h */, 5C54D0A42629B42400AB55E0 /* Info.plist */, 4A04C59D269AD58E009F5CA3 /* MainMenu.xib */, + 4A04C5B4269AE945009F5CA3 /* AerofoilApplication.h */, + 4A04C5B5269AE945009F5CA3 /* AerofoilApplication.m */, + 4A04C5AD269AD600009F5CA3 /* AerofoilAppDelegate.h */, + 4A04C5AE269AD600009F5CA3 /* AerofoilAppDelegate.mm */, ); path = AerofoilMac; sourceTree = ""; @@ -1997,8 +2012,10 @@ 5C54D67A262D889D00AB55E0 /* DrawQuad32P.cpp in Sources */, 5C54D67B262D889D00AB55E0 /* CopyQuadP.cpp in Sources */, 5C54D669262D886900AB55E0 /* GpThreadEvent_Cpp11.cpp in Sources */, + 4A04C5B6269AE945009F5CA3 /* AerofoilApplication.m in Sources */, 5C54D65B262D84A900AB55E0 /* GpMain_SDL_X.cpp in Sources */, 5C54D67C262D889E00AB55E0 /* DrawQuadPaletteP.cpp in Sources */, + 4A04C5B7269AE96B009F5CA3 /* MacInit.mm in Sources */, 5C54D679262D889D00AB55E0 /* GpDisplayDriver_SDL_GL2.cpp in Sources */, 5C54D67F262D889E00AB55E0 /* GpAudioDriver_SDL2.cpp in Sources */, 5C54D668262D886900AB55E0 /* GpSystemServices_POSIX.cpp in Sources */, @@ -2006,6 +2023,7 @@ 5C54D65C262D84A900AB55E0 /* GpSystemServices_X.cpp in Sources */, 5C54D67D262D889E00AB55E0 /* ScaleQuadP.cpp in Sources */, 5C54D678262D889D00AB55E0 /* GpInputDriver_SDL_Gamepad.cpp in Sources */, + 4A04C5AF269AD600009F5CA3 /* AerofoilAppDelegate.mm in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/AerofoilMac/AerofoilMac/AerofoilAppDelegate.h b/AerofoilMac/AerofoilMac/AerofoilAppDelegate.h new file mode 100644 index 0000000..48808e4 --- /dev/null +++ b/AerofoilMac/AerofoilMac/AerofoilAppDelegate.h @@ -0,0 +1,9 @@ +#import + +NS_ASSUME_NONNULL_BEGIN + +@interface AerofoilAppDelegate : NSObject + +@end + +NS_ASSUME_NONNULL_END diff --git a/AerofoilMac/AerofoilMac/AerofoilAppDelegate.mm b/AerofoilMac/AerofoilMac/AerofoilAppDelegate.mm new file mode 100644 index 0000000..153ad53 --- /dev/null +++ b/AerofoilMac/AerofoilMac/AerofoilAppDelegate.mm @@ -0,0 +1,44 @@ +#import "AerofoilAppDelegate.h" +#import "About.h" +#include "WindowManager.h" +#include "GliderDefines.h" // kPlayMode + +extern short theMode; +void DoSettingsMain(void); + +@interface AerofoilAppDelegate () + +@property (weak) IBOutlet NSMenuItem *aboutAerofoilMenuItem; +@property (weak) IBOutlet NSMenuItem *aboutGliderPROMenuItem; +@property (weak) IBOutlet NSMenuItem *preferencesMenuItem; + +@end + +@implementation AerofoilAppDelegate + +- (IBAction)showAboutAerofoil:(id)sender { + DoAboutFramework(); +} +- (IBAction)showAboutGliderPRO:(id)sender { + DoAbout(); +} +- (IBAction)showPreferences:(id)sender { + DoSettingsMain(); +} + +- (BOOL)validateMenuItem:(NSMenuItem *)menuItem { + if (menuItem == _aboutAerofoilMenuItem || menuItem == _aboutGliderPROMenuItem) { + return ![self menuItemsDisabled]; + } else if (menuItem == _preferencesMenuItem) { + return ![self menuItemsDisabled]; + } else { + return NO; + } +} + +- (BOOL)menuItemsDisabled { + PortabilityLayer::WindowManager* wm = PortabilityLayer::WindowManager::GetInstance(); + return theMode == kPlayMode || wm->IsExclusiveWindowVisible(); +} + +@end diff --git a/AerofoilMac/AerofoilMac/AerofoilApplication.h b/AerofoilMac/AerofoilMac/AerofoilApplication.h new file mode 100644 index 0000000..537b2ec --- /dev/null +++ b/AerofoilMac/AerofoilMac/AerofoilApplication.h @@ -0,0 +1,9 @@ +#import + +NS_ASSUME_NONNULL_BEGIN + +@interface AerofoilApplication : NSApplication + +@end + +NS_ASSUME_NONNULL_END diff --git a/AerofoilMac/AerofoilMac/AerofoilApplication.m b/AerofoilMac/AerofoilMac/AerofoilApplication.m new file mode 100644 index 0000000..b5477d1 --- /dev/null +++ b/AerofoilMac/AerofoilMac/AerofoilApplication.m @@ -0,0 +1,13 @@ +#import "AerofoilApplication.h" +#include "SDL.h" + +extern int SDL_SendQuit(void); + +@implementation AerofoilApplication + +- (void)terminate:(id)sender { + // TODO: Use Aerofoil method instead of private SDL method + SDL_SendQuit(); +} + +@end diff --git a/AerofoilMac/AerofoilMac/MacInit.h b/AerofoilMac/AerofoilMac/MacInit.h new file mode 100644 index 0000000..9f26d23 --- /dev/null +++ b/AerofoilMac/AerofoilMac/MacInit.h @@ -0,0 +1,6 @@ +#ifndef MacInit_h +#define MacInit_h + +int MacInit(void); + +#endif /* MacInit_h */ diff --git a/AerofoilMac/AerofoilMac/MacInit.mm b/AerofoilMac/AerofoilMac/MacInit.mm new file mode 100644 index 0000000..d77408f --- /dev/null +++ b/AerofoilMac/AerofoilMac/MacInit.mm @@ -0,0 +1,22 @@ +#import +#import "AerofoilApplication.h" +#import "AerofoilAppDelegate.h" +#import "MacInit.h" +#include "SDL.h" + +int MacInit(void) { + // Instantiate NSApp and its delegate first, so SDL chooses those over its own implementation. + [AerofoilApplication sharedApplication]; + [[NSBundle mainBundle] loadNibNamed:@"MainMenu" owner:NSApp topLevelObjects:nil]; + + if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_GAMECONTROLLER) < 0) + return -1; + + // Gracefully activate app. + // + // (SDL forcefully does this via [NSApp activateIgnoringOtherApps:YES], + // which isn't consistent with normal Mac apps). + [NSApp finishLaunching]; + + return 0; +} diff --git a/AerofoilX/GpMain_SDL_X.cpp b/AerofoilX/GpMain_SDL_X.cpp index f5d5880..74c9bcb 100644 --- a/AerofoilX/GpMain_SDL_X.cpp +++ b/AerofoilX/GpMain_SDL_X.cpp @@ -20,6 +20,7 @@ #include "IGpVOSEventQueue.h" #include +#include "MacInit.h" GpXGlobals g_gpXGlobals; @@ -40,7 +41,11 @@ SDLMAIN_DECLSPEC int SDL_main(int argc, char *argv[]) enableLogging = true; } +#ifndef __MACOS__ if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_GAMECONTROLLER) < 0) +#else + if (MacInit()) +#endif return -1; GpFileSystem_X::GetInstance()->Init(); From 90943d945b32d5a606e2f4f39e6f5e18f6f33c51 Mon Sep 17 00:00:00 2001 From: Phil Marell Date: Sat, 24 Jul 2021 16:30:17 +1000 Subject: [PATCH 11/19] =?UTF-8?q?Expose=20certain=20methods=20to=20be=20us?= =?UTF-8?q?ed=C2=A0for=20Mac=20menu=20items?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- GpApp/About.h | 2 +- PortabilityLayer/WindowManager.cpp | 5 +++++ PortabilityLayer/WindowManager.h | 1 + 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/GpApp/About.h b/GpApp/About.h index a90709e..03387d1 100644 --- a/GpApp/About.h +++ b/GpApp/About.h @@ -6,5 +6,5 @@ void DoAbout (void); - +void DoAboutFramework (void); diff --git a/PortabilityLayer/WindowManager.cpp b/PortabilityLayer/WindowManager.cpp index 2b7f512..cadde4e 100644 --- a/PortabilityLayer/WindowManager.cpp +++ b/PortabilityLayer/WindowManager.cpp @@ -186,6 +186,7 @@ namespace PortabilityLayer void SetWindowTitle(Window *window, const PLPasStr &title) override; Rect2i GetWindowFullRect(Window *window) const override; bool GetWindowChromeInteractionZone(Window *window, const Vec2i &point, RegionID_t &outRegion) const override; + bool IsExclusiveWindowVisible() override; void SwapExclusiveWindow(Window *& windowRef) override; void FlickerWindowIn(Window *window, int32_t velocity) GP_ASYNCIFY_PARANOID_OVERRIDE; @@ -1322,6 +1323,10 @@ namespace PortabilityLayer return static_cast(window)->GetChromeInteractionZone(point, outRegion); } + bool WindowManagerImpl::IsExclusiveWindowVisible() { + return m_exclusiveWindow != nullptr; + } + void WindowManagerImpl::SwapExclusiveWindow(Window *& windowRef) { const bool hadExclusiveWindow = (m_exclusiveWindow != nullptr); diff --git a/PortabilityLayer/WindowManager.h b/PortabilityLayer/WindowManager.h index a17483e..613350a 100644 --- a/PortabilityLayer/WindowManager.h +++ b/PortabilityLayer/WindowManager.h @@ -38,6 +38,7 @@ namespace PortabilityLayer virtual void SetWindowTitle(Window *window, const PLPasStr &title) = 0; virtual Rect2i GetWindowFullRect(Window *window) const = 0; virtual bool GetWindowChromeInteractionZone(Window *window, const Vec2i &point, RegionID_t &outRegion) const = 0; + virtual bool IsExclusiveWindowVisible() = 0; virtual void SwapExclusiveWindow(Window *& windowRef) = 0; GP_ASYNCIFY_PARANOID_VIRTUAL void FlickerWindowIn(Window *window, int32_t velocity) GP_ASYNCIFY_PARANOID_PURE; From 0e3534d902ffec28780eec1d5ca6a15fbcf5cbe7 Mon Sep 17 00:00:00 2001 From: Phil Marell Date: Sat, 24 Jul 2021 16:00:26 +1000 Subject: [PATCH 12/19] Wire objects/actions in nib --- .../AerofoilMac/Base.lproj/MainMenu.xib | 29 ++++++++++++++++--- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/AerofoilMac/AerofoilMac/Base.lproj/MainMenu.xib b/AerofoilMac/AerofoilMac/Base.lproj/MainMenu.xib index aeb7bab..9eaf59c 100644 --- a/AerofoilMac/AerofoilMac/Base.lproj/MainMenu.xib +++ b/AerofoilMac/AerofoilMac/Base.lproj/MainMenu.xib @@ -5,9 +5,13 @@ - + + + + + - + @@ -17,11 +21,21 @@ - + + + + + + + - + + + + + @@ -101,5 +115,12 @@ + + + + + + + From f36a8da95fe3d608e3bd34559499faffbf47a7f9 Mon Sep 17 00:00:00 2001 From: Phil Marell Date: Wed, 28 Jul 2021 20:14:34 +1000 Subject: [PATCH 13/19] Allow native menu to unhighlight --- AerofoilMac/AerofoilMac/AerofoilAppDelegate.mm | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/AerofoilMac/AerofoilMac/AerofoilAppDelegate.mm b/AerofoilMac/AerofoilMac/AerofoilAppDelegate.mm index 153ad53..cb115d3 100644 --- a/AerofoilMac/AerofoilMac/AerofoilAppDelegate.mm +++ b/AerofoilMac/AerofoilMac/AerofoilAppDelegate.mm @@ -17,13 +17,19 @@ void DoSettingsMain(void); @implementation AerofoilAppDelegate - (IBAction)showAboutAerofoil:(id)sender { - DoAboutFramework(); + [self performAsynchronously:DoAboutFramework]; } - (IBAction)showAboutGliderPRO:(id)sender { - DoAbout(); + [self performAsynchronously:DoAbout]; } - (IBAction)showPreferences:(id)sender { - DoSettingsMain(); + [self performAsynchronously:DoSettingsMain]; +} + +- (void)performAsynchronously:(void(*)())function { + dispatch_async(dispatch_get_main_queue(), ^{ + function(); + }); } - (BOOL)validateMenuItem:(NSMenuItem *)menuItem { From 42ec9e36468eec2bb843811e12833281eaed8fd5 Mon Sep 17 00:00:00 2001 From: Phil Marell Date: Thu, 5 Aug 2021 18:46:36 +1000 Subject: [PATCH 14/19] Use #pragma once --- AerofoilMac/AerofoilMac/MacInit.h | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/AerofoilMac/AerofoilMac/MacInit.h b/AerofoilMac/AerofoilMac/MacInit.h index 9f26d23..de81670 100644 --- a/AerofoilMac/AerofoilMac/MacInit.h +++ b/AerofoilMac/AerofoilMac/MacInit.h @@ -1,6 +1,3 @@ -#ifndef MacInit_h -#define MacInit_h +#pragma once int MacInit(void); - -#endif /* MacInit_h */ From 5ab966ea98a08bba504754baf45dd02a5d2086f1 Mon Sep 17 00:00:00 2001 From: Phil Marell Date: Sun, 8 Aug 2021 12:27:10 +1000 Subject: [PATCH 15/19] Fix build errors --- AerofoilMac/AerofoilMac.xcodeproj/project.pbxproj | 11 ++++++++++- PortabilityLayer/RenderedFont.h | 1 + 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/AerofoilMac/AerofoilMac.xcodeproj/project.pbxproj b/AerofoilMac/AerofoilMac.xcodeproj/project.pbxproj index 1bc23b9..945e707 100644 --- a/AerofoilMac/AerofoilMac.xcodeproj/project.pbxproj +++ b/AerofoilMac/AerofoilMac.xcodeproj/project.pbxproj @@ -11,6 +11,8 @@ 4A04C5AF269AD600009F5CA3 /* AerofoilAppDelegate.mm in Sources */ = {isa = PBXBuildFile; fileRef = 4A04C5AE269AD600009F5CA3 /* AerofoilAppDelegate.mm */; }; 4A04C5B6269AE945009F5CA3 /* AerofoilApplication.m in Sources */ = {isa = PBXBuildFile; fileRef = 4A04C5B5269AE945009F5CA3 /* AerofoilApplication.m */; }; 4A04C5B7269AE96B009F5CA3 /* MacInit.mm in Sources */ = {isa = PBXBuildFile; fileRef = 4A04C5B0269AE243009F5CA3 /* MacInit.mm */; }; + 4A2818FE26BBDD35005A36C0 /* CompositeRenderedFont.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4A2818EF26BBDD35005A36C0 /* CompositeRenderedFont.cpp */; }; + 4A2818FF26BBDD35005A36C0 /* CompositeRenderedFont.h in Headers */ = {isa = PBXBuildFile; fileRef = 4A2818FD26BBDD35005A36C0 /* CompositeRenderedFont.h */; }; 5C54D0A02629B42400AB55E0 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 5C54D09F2629B42400AB55E0 /* Assets.xcassets */; }; 5C54D0BE2629B72000AB55E0 /* stb_image_write.h in Headers */ = {isa = PBXBuildFile; fileRef = 5C54D0BC2629B72000AB55E0 /* stb_image_write.h */; }; 5C54D0BF2629B72000AB55E0 /* stb_image_write.c in Sources */ = {isa = PBXBuildFile; fileRef = 5C54D0BD2629B72000AB55E0 /* stb_image_write.c */; }; @@ -598,7 +600,10 @@ 4A04C5B0269AE243009F5CA3 /* MacInit.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = MacInit.mm; sourceTree = ""; }; 4A04C5B2269AE368009F5CA3 /* MacInit.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MacInit.h; sourceTree = ""; }; 4A04C5B4269AE945009F5CA3 /* AerofoilApplication.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AerofoilApplication.h; sourceTree = ""; }; - 4A04C5B5269AE945009F5CA3 /* AerofoilApplication.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AerofoilApplication.m; sourceTree = ""; }; + 4A04C5B5269AE945009F5CA3 /* AerofoilApplication.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = AerofoilApplication.mm; sourceTree = ""; }; + 4A2818EF26BBDD35005A36C0 /* CompositeRenderedFont.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CompositeRenderedFont.cpp; sourceTree = ""; }; + 4A2818FD26BBDD35005A36C0 /* CompositeRenderedFont.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CompositeRenderedFont.h; sourceTree = ""; }; + 4AA1EB4D26BF9399001D8CC6 /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = System/Library/Frameworks/Cocoa.framework; sourceTree = SDKROOT; }; 5C54D0962629B42100AB55E0 /* Aerofoil.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Aerofoil.app; sourceTree = BUILT_PRODUCTS_DIR; }; 5C54D09F2629B42400AB55E0 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 5C54D0A42629B42400AB55E0 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; @@ -1166,6 +1171,8 @@ 5C54D2B12629BC6800AB55E0 /* CFileStream.cpp */, 5C54D2AE2629BC6800AB55E0 /* CFileStream.h */, 5C54D2B52629BC6800AB55E0 /* CombinedTimestamp.h */, + 4A2818EF26BBDD35005A36C0 /* CompositeRenderedFont.cpp */, + 4A2818FD26BBDD35005A36C0 /* CompositeRenderedFont.h */, 5C54D2FC2629BC6800AB55E0 /* DataTypes.h */, 5C54D2D62629BC6800AB55E0 /* DeflateCodec.cpp */, 5C54D2EB2629BC6800AB55E0 /* DeflateCodec.h */, @@ -1630,6 +1637,7 @@ isa = PBXHeadersBuildPhase; buildActionMask = 2147483647; files = ( + 4A2818FF26BBDD35005A36C0 /* CompositeRenderedFont.h in Headers */, 5C54D44B2629BC6D00AB55E0 /* FontFamilyID.h in Headers */, 5CB787212639D1D800D8FDB6 /* GpAllocator_C.h in Headers */, 5C54D38C2629BC6A00AB55E0 /* EllipsePlotter.h in Headers */, @@ -2202,6 +2210,7 @@ 5C54D4282629BC6C00AB55E0 /* RandomNumberGenerator.cpp in Sources */, 5C54D550262B3C2E00AB55E0 /* DynamicMaps.cpp in Sources */, 5C54D4502629BC6D00AB55E0 /* PLButtonWidget.cpp in Sources */, + 4A2818FE26BBDD35005A36C0 /* CompositeRenderedFont.cpp in Sources */, 5C54D568262B3C2E00AB55E0 /* Scoreboard.cpp in Sources */, 5C54D596262B3C2F00AB55E0 /* Link.cpp in Sources */, ); diff --git a/PortabilityLayer/RenderedFont.h b/PortabilityLayer/RenderedFont.h index 3eca5c1..3aadd9d 100644 --- a/PortabilityLayer/RenderedFont.h +++ b/PortabilityLayer/RenderedFont.h @@ -1,6 +1,7 @@ #pragma once #include +#include class PLPasStr; struct GpRenderedFontMetrics; From 9f5699a61e01aec2980c712b2f338401dcecf6ba Mon Sep 17 00:00:00 2001 From: Phil Marell Date: Sun, 8 Aug 2021 12:27:29 +1000 Subject: [PATCH 16/19] Return correct value for macOS --- AerofoilX/GpSystemServices_X.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/AerofoilX/GpSystemServices_X.cpp b/AerofoilX/GpSystemServices_X.cpp index d8439dd..32e0f8f 100644 --- a/AerofoilX/GpSystemServices_X.cpp +++ b/AerofoilX/GpSystemServices_X.cpp @@ -107,7 +107,11 @@ bool GpSystemServices_X::HasNativeFileManager() const GpOperatingSystem_t GpSystemServices_X::GetOperatingSystem() const { +#ifdef __MACOS__ + return GpOperatingSystems::kMacOS; +#else return GpOperatingSystems::kLinux; +#endif } GpOperatingSystemFlavor_t GpSystemServices_X::GetOperatingSystemFlavor() const From 7ba11df286e3811658dd9a761323383f2eacfdfc Mon Sep 17 00:00:00 2001 From: Phil Marell Date: Sun, 8 Aug 2021 16:57:24 +1000 Subject: [PATCH 17/19] Add quit event to queue without using private SDL method --- AerofoilMac/AerofoilMac.xcodeproj/project.pbxproj | 13 ++++++++----- ...AerofoilApplication.m => AerofoilApplication.mm} | 8 ++++---- 2 files changed, 12 insertions(+), 9 deletions(-) rename AerofoilMac/AerofoilMac/{AerofoilApplication.m => AerofoilApplication.mm} (53%) diff --git a/AerofoilMac/AerofoilMac.xcodeproj/project.pbxproj b/AerofoilMac/AerofoilMac.xcodeproj/project.pbxproj index 945e707..df9ab65 100644 --- a/AerofoilMac/AerofoilMac.xcodeproj/project.pbxproj +++ b/AerofoilMac/AerofoilMac.xcodeproj/project.pbxproj @@ -9,10 +9,11 @@ /* Begin PBXBuildFile section */ 4A04C5AC269AD58E009F5CA3 /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 4A04C59D269AD58E009F5CA3 /* MainMenu.xib */; }; 4A04C5AF269AD600009F5CA3 /* AerofoilAppDelegate.mm in Sources */ = {isa = PBXBuildFile; fileRef = 4A04C5AE269AD600009F5CA3 /* AerofoilAppDelegate.mm */; }; - 4A04C5B6269AE945009F5CA3 /* AerofoilApplication.m in Sources */ = {isa = PBXBuildFile; fileRef = 4A04C5B5269AE945009F5CA3 /* AerofoilApplication.m */; }; + 4A04C5B6269AE945009F5CA3 /* AerofoilApplication.mm in Sources */ = {isa = PBXBuildFile; fileRef = 4A04C5B5269AE945009F5CA3 /* AerofoilApplication.mm */; }; 4A04C5B7269AE96B009F5CA3 /* MacInit.mm in Sources */ = {isa = PBXBuildFile; fileRef = 4A04C5B0269AE243009F5CA3 /* MacInit.mm */; }; 4A2818FE26BBDD35005A36C0 /* CompositeRenderedFont.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4A2818EF26BBDD35005A36C0 /* CompositeRenderedFont.cpp */; }; 4A2818FF26BBDD35005A36C0 /* CompositeRenderedFont.h in Headers */ = {isa = PBXBuildFile; fileRef = 4A2818FD26BBDD35005A36C0 /* CompositeRenderedFont.h */; }; + 4AA1EB5C26BF9556001D8CC6 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4AA1EB4D26BF9399001D8CC6 /* Cocoa.framework */; }; 5C54D0A02629B42400AB55E0 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 5C54D09F2629B42400AB55E0 /* Assets.xcassets */; }; 5C54D0BE2629B72000AB55E0 /* stb_image_write.h in Headers */ = {isa = PBXBuildFile; fileRef = 5C54D0BC2629B72000AB55E0 /* stb_image_write.h */; }; 5C54D0BF2629B72000AB55E0 /* stb_image_write.c in Sources */ = {isa = PBXBuildFile; fileRef = 5C54D0BD2629B72000AB55E0 /* stb_image_write.c */; }; @@ -600,9 +601,9 @@ 4A04C5B0269AE243009F5CA3 /* MacInit.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = MacInit.mm; sourceTree = ""; }; 4A04C5B2269AE368009F5CA3 /* MacInit.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MacInit.h; sourceTree = ""; }; 4A04C5B4269AE945009F5CA3 /* AerofoilApplication.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AerofoilApplication.h; sourceTree = ""; }; + 4A2818EF26BBDD35005A36C0 /* CompositeRenderedFont.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CompositeRenderedFont.cpp; path = CompositeRenderedFont.cpp; sourceTree = ""; }; + 4A2818FD26BBDD35005A36C0 /* CompositeRenderedFont.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CompositeRenderedFont.h; path = CompositeRenderedFont.h; sourceTree = ""; }; 4A04C5B5269AE945009F5CA3 /* AerofoilApplication.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = AerofoilApplication.mm; sourceTree = ""; }; - 4A2818EF26BBDD35005A36C0 /* CompositeRenderedFont.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CompositeRenderedFont.cpp; sourceTree = ""; }; - 4A2818FD26BBDD35005A36C0 /* CompositeRenderedFont.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CompositeRenderedFont.h; sourceTree = ""; }; 4AA1EB4D26BF9399001D8CC6 /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = System/Library/Frameworks/Cocoa.framework; sourceTree = SDKROOT; }; 5C54D0962629B42100AB55E0 /* Aerofoil.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Aerofoil.app; sourceTree = BUILT_PRODUCTS_DIR; }; 5C54D09F2629B42400AB55E0 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; @@ -1033,6 +1034,7 @@ files = ( 5C54D636262D7E4800AB55E0 /* SDL2.framework in Frameworks */, 5C54D635262D7E4100AB55E0 /* libAerofoilShared.a in Frameworks */, + 4AA1EB5C26BF9556001D8CC6 /* Cocoa.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -1086,7 +1088,7 @@ 5C54D0A42629B42400AB55E0 /* Info.plist */, 4A04C59D269AD58E009F5CA3 /* MainMenu.xib */, 4A04C5B4269AE945009F5CA3 /* AerofoilApplication.h */, - 4A04C5B5269AE945009F5CA3 /* AerofoilApplication.m */, + 4A04C5B5269AE945009F5CA3 /* AerofoilApplication.mm */, 4A04C5AD269AD600009F5CA3 /* AerofoilAppDelegate.h */, 4A04C5AE269AD600009F5CA3 /* AerofoilAppDelegate.mm */, ); @@ -1513,6 +1515,7 @@ 5C54D5D5262D746E00AB55E0 /* Frameworks */ = { isa = PBXGroup; children = ( + 4AA1EB4D26BF9399001D8CC6 /* Cocoa.framework */, 5C54D5D6262D759500AB55E0 /* SDL.xcodeproj */, ); name = Frameworks; @@ -2020,7 +2023,7 @@ 5C54D67A262D889D00AB55E0 /* DrawQuad32P.cpp in Sources */, 5C54D67B262D889D00AB55E0 /* CopyQuadP.cpp in Sources */, 5C54D669262D886900AB55E0 /* GpThreadEvent_Cpp11.cpp in Sources */, - 4A04C5B6269AE945009F5CA3 /* AerofoilApplication.m in Sources */, + 4A04C5B6269AE945009F5CA3 /* AerofoilApplication.mm in Sources */, 5C54D65B262D84A900AB55E0 /* GpMain_SDL_X.cpp in Sources */, 5C54D67C262D889E00AB55E0 /* DrawQuadPaletteP.cpp in Sources */, 4A04C5B7269AE96B009F5CA3 /* MacInit.mm in Sources */, diff --git a/AerofoilMac/AerofoilMac/AerofoilApplication.m b/AerofoilMac/AerofoilMac/AerofoilApplication.mm similarity index 53% rename from AerofoilMac/AerofoilMac/AerofoilApplication.m rename to AerofoilMac/AerofoilMac/AerofoilApplication.mm index b5477d1..7ec1389 100644 --- a/AerofoilMac/AerofoilMac/AerofoilApplication.m +++ b/AerofoilMac/AerofoilMac/AerofoilApplication.mm @@ -1,13 +1,13 @@ #import "AerofoilApplication.h" #include "SDL.h" -extern int SDL_SendQuit(void); - @implementation AerofoilApplication - (void)terminate:(id)sender { - // TODO: Use Aerofoil method instead of private SDL method - SDL_SendQuit(); + SDL_Event event; + event.quit.type = SDL_QUIT; + event.quit.timestamp = SDL_GetTicks(); + SDL_PushEvent(&event); } @end From 744b06796d278b6ef473e12a88e4d32ff70d1ee1 Mon Sep 17 00:00:00 2001 From: Phil Marell Date: Sun, 8 Aug 2021 16:43:46 +1000 Subject: [PATCH 18/19] Remove no longer true comment --- GpCommon/GpVOSEvent.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/GpCommon/GpVOSEvent.h b/GpCommon/GpVOSEvent.h index 53ce2f4..80f30a5 100644 --- a/GpCommon/GpVOSEvent.h +++ b/GpCommon/GpVOSEvent.h @@ -97,8 +97,8 @@ namespace GpKeySpecials kEnter, kLeftShift, kRightShift, - kLeftCtrl, // Maps to Command modifier on macOS. - kRightCtrl, // + kLeftCtrl, + kRightCtrl, kLeftAlt, kRightAlt, kLeftCommand, From 5b5fb1578045d3eeadea3e180dce8a3514d9f96d Mon Sep 17 00:00:00 2001 From: Phil Marell Date: Sun, 8 Aug 2021 16:59:27 +1000 Subject: [PATCH 19/19] Send events through queue instead of calling game methods directly --- AerofoilMac/AerofoilMac/AerofoilAppDelegate.mm | 15 ++++----------- AerofoilMac/AerofoilMac/AerofoilApplication.h | 3 +++ AerofoilMac/AerofoilMac/AerofoilApplication.mm | 15 +++++++++++++++ GpApp/Events.cpp | 15 +++++++++++++++ GpCommon/GpVOSEvent.h | 13 +++++++++++++ PortabilityLayer/PLSysCalls.cpp | 4 ++++ 6 files changed, 54 insertions(+), 11 deletions(-) diff --git a/AerofoilMac/AerofoilMac/AerofoilAppDelegate.mm b/AerofoilMac/AerofoilMac/AerofoilAppDelegate.mm index cb115d3..6ddf4f8 100644 --- a/AerofoilMac/AerofoilMac/AerofoilAppDelegate.mm +++ b/AerofoilMac/AerofoilMac/AerofoilAppDelegate.mm @@ -1,10 +1,9 @@ #import "AerofoilAppDelegate.h" -#import "About.h" +#import "AerofoilApplication.h" #include "WindowManager.h" #include "GliderDefines.h" // kPlayMode extern short theMode; -void DoSettingsMain(void); @interface AerofoilAppDelegate () @@ -17,19 +16,13 @@ void DoSettingsMain(void); @implementation AerofoilAppDelegate - (IBAction)showAboutAerofoil:(id)sender { - [self performAsynchronously:DoAboutFramework]; + [NSApp sendMenuItemEvent:GpMenuItemSelectionEvents::kAboutAerofoil]; } - (IBAction)showAboutGliderPRO:(id)sender { - [self performAsynchronously:DoAbout]; + [NSApp sendMenuItemEvent:GpMenuItemSelectionEvents::kAboutGliderPRO]; } - (IBAction)showPreferences:(id)sender { - [self performAsynchronously:DoSettingsMain]; -} - -- (void)performAsynchronously:(void(*)())function { - dispatch_async(dispatch_get_main_queue(), ^{ - function(); - }); + [NSApp sendMenuItemEvent:GpMenuItemSelectionEvents::kPreferences]; } - (BOOL)validateMenuItem:(NSMenuItem *)menuItem { diff --git a/AerofoilMac/AerofoilMac/AerofoilApplication.h b/AerofoilMac/AerofoilMac/AerofoilApplication.h index 537b2ec..79e4cd5 100644 --- a/AerofoilMac/AerofoilMac/AerofoilApplication.h +++ b/AerofoilMac/AerofoilMac/AerofoilApplication.h @@ -1,9 +1,12 @@ #import +#include "GpVOSEvent.h" NS_ASSUME_NONNULL_BEGIN @interface AerofoilApplication : NSApplication +- (void)sendMenuItemEvent:(GpMenuItemSelectionEvent_t)itemEvent; + @end NS_ASSUME_NONNULL_END diff --git a/AerofoilMac/AerofoilMac/AerofoilApplication.mm b/AerofoilMac/AerofoilMac/AerofoilApplication.mm index 7ec1389..616b3c4 100644 --- a/AerofoilMac/AerofoilMac/AerofoilApplication.mm +++ b/AerofoilMac/AerofoilMac/AerofoilApplication.mm @@ -1,4 +1,6 @@ #import "AerofoilApplication.h" +#include "IGpVOSEventQueue.h" +#include "GpAppInterface.h" #include "SDL.h" @implementation AerofoilApplication @@ -10,4 +12,17 @@ SDL_PushEvent(&event); } +- (void)sendMenuItemEvent:(GpMenuItemSelectionEvent_t)itemEvent { + GpVOSEvent event; + event.m_eventType = GpVOSEventTypes::kMenuItemSelected; + event.m_event.m_menuItemSelectionEvent = itemEvent; + [self sendVOSEvent:event]; +} + +- (void)sendVOSEvent:(GpVOSEvent)event { + IGpVOSEventQueue* queue = GpAppInterface_Get()->PL_GetDriverCollection()->GetDriver(); + if (GpVOSEvent *evt = queue->QueueEvent()) + *evt = event; +} + @end diff --git a/GpApp/Events.cpp b/GpApp/Events.cpp index 67199bc..0f83b74 100644 --- a/GpApp/Events.cpp +++ b/GpApp/Events.cpp @@ -466,6 +466,21 @@ void HandleEvent (void) break; } } + else if (theEvent.m_vosEvent.m_eventType == GpVOSEventType_t::kMenuItemSelected) + { + switch (theEvent.m_vosEvent.m_event.m_menuItemSelectionEvent) + { + case GpMenuItemSelectionEvents::kAboutGliderPRO: + DoAbout(); + break; + case GpMenuItemSelectionEvents::kAboutAerofoil: + DoAboutFramework(); + break; + case GpMenuItemSelectionEvents::kPreferences: + DoSettingsMain(); + break; + } + } } else HandleIdleTask(); diff --git a/GpCommon/GpVOSEvent.h b/GpCommon/GpVOSEvent.h index 80f30a5..cca994c 100644 --- a/GpCommon/GpVOSEvent.h +++ b/GpCommon/GpVOSEvent.h @@ -270,6 +270,17 @@ struct GpVideoResolutionChangedEvent uint32_t m_newHeight; }; +namespace GpMenuItemSelectionEvents +{ + enum GpMenuItemSelectionEvent { + kAboutGliderPRO, + kAboutAerofoil, + kPreferences + }; +} + +typedef GpMenuItemSelectionEvents::GpMenuItemSelectionEvent GpMenuItemSelectionEvent_t; + namespace GpVOSEventTypes { enum GpVOSEventType @@ -279,6 +290,7 @@ namespace GpVOSEventTypes kTouchInput, kGamepadInput, kVideoResolutionChanged, + kMenuItemSelected, kQuit }; } @@ -294,6 +306,7 @@ struct GpVOSEvent GpTouchInputEvent m_touchInputEvent; GpGamepadInputEvent m_gamepadInputEvent; GpVideoResolutionChangedEvent m_resolutionChangedEvent; + GpMenuItemSelectionEvent_t m_menuItemSelectionEvent; }; EventUnion m_event; diff --git a/PortabilityLayer/PLSysCalls.cpp b/PortabilityLayer/PLSysCalls.cpp index 536ea34..e79454c 100644 --- a/PortabilityLayer/PLSysCalls.cpp +++ b/PortabilityLayer/PLSysCalls.cpp @@ -169,6 +169,10 @@ static void TranslateVOSEvent(const GpVOSEvent *vosEvent, uint32_t timestamp, Po appHandler->OnQuit(); break; + case GpVOSEventTypes::kMenuItemSelected: + if (TimeTaggedVOSEvent *evt = queue->Enqueue()) + *evt = TimeTaggedVOSEvent::Create(*vosEvent, timestamp); + break; } }