mirror of
https://github.com/ZDoom/gzdoom.git
synced 2024-11-22 12:11:25 +00:00
- updated Cocoa backend to follow single exit point workflow
This commit is contained in:
parent
bb5ca2ce39
commit
29e3222fb3
4 changed files with 34 additions and 23 deletions
|
@ -140,25 +140,12 @@ void I_DetectOS()
|
|||
FArgs* Args; // command line arguments
|
||||
|
||||
|
||||
int OriginalMainTry(int argc, char** argv)
|
||||
{
|
||||
Args = new FArgs(argc, argv);
|
||||
|
||||
NSString* exePath = [[NSBundle mainBundle] executablePath];
|
||||
progdir = [[exePath stringByDeletingLastPathComponent] UTF8String];
|
||||
progdir += "/";
|
||||
|
||||
auto ret = D_DoomMain();
|
||||
FConsoleWindow::DeleteInstance();
|
||||
return ret;
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
TArray<FString> s_argv;
|
||||
|
||||
int OriginalMain(int argc, char** argv)
|
||||
int DoMain(int argc, char** argv)
|
||||
{
|
||||
printf(GAMENAME" %s - %s - Cocoa version\nCompiled on %s\n\n",
|
||||
GetVersionString(), GetGitTime(), __DATE__);
|
||||
|
@ -178,7 +165,15 @@ int OriginalMain(int argc, char** argv)
|
|||
vid_defheight = static_cast<int>(screenSize.height);
|
||||
vid_vsync = true;
|
||||
|
||||
return OriginalMainTry(argc, argv);
|
||||
Args = new FArgs(argc, argv);
|
||||
|
||||
NSString* exePath = [[NSBundle mainBundle] executablePath];
|
||||
progdir = [[exePath stringByDeletingLastPathComponent] UTF8String];
|
||||
progdir += "/";
|
||||
|
||||
auto ret = D_DoomMain();
|
||||
FConsoleWindow::DeleteInstance();
|
||||
return ret;
|
||||
}
|
||||
|
||||
} // unnamed namespace
|
||||
|
@ -203,6 +198,10 @@ int OriginalMain(int argc, char** argv)
|
|||
|
||||
- (void)processEvents:(NSTimer*)timer;
|
||||
|
||||
- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender;
|
||||
|
||||
- (void)sendExitEvent:(id)sender;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
|
@ -276,7 +275,7 @@ extern bool AppActive;
|
|||
|
||||
argv[argc] = nullptr;
|
||||
|
||||
exit(OriginalMain(argc, &argv[0]));
|
||||
exit(DoMain(argc, &argv[0]));
|
||||
}
|
||||
|
||||
|
||||
|
@ -341,6 +340,17 @@ extern bool AppActive;
|
|||
[pool release];
|
||||
}
|
||||
|
||||
- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender
|
||||
{
|
||||
[self sendExitEvent:sender];
|
||||
return NSTerminateLater;
|
||||
}
|
||||
|
||||
- (void)sendExitEvent:(id)sender
|
||||
{
|
||||
throw CExitEvent(0);
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
|
@ -370,7 +380,7 @@ NSMenuItem* CreateApplicationMenu()
|
|||
keyEquivalent:@""];
|
||||
[menu addItem:[NSMenuItem separatorItem]];
|
||||
[menu addItemWithTitle:[@"Quit " stringByAppendingString:@GAMENAME]
|
||||
action:@selector(terminate:)
|
||||
action:@selector(sendExitEvent:)
|
||||
keyEquivalent:@"q"];
|
||||
|
||||
NSMenuItem* menuItem = [NSMenuItem new];
|
||||
|
|
|
@ -64,8 +64,8 @@
|
|||
- (void)exitAppOnClose
|
||||
{
|
||||
NSButton* closeButton = [self standardWindowButton:NSWindowCloseButton];
|
||||
[closeButton setAction:@selector(terminate:)];
|
||||
[closeButton setTarget:NSApp];
|
||||
[closeButton setAction:@selector(sendExitEvent:)];
|
||||
[closeButton setTarget:NSApp.delegate];
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
@ -172,7 +172,7 @@ void FConsoleWindow::ShowFatalError(const char* const message)
|
|||
[quitButton setTitle:@"Quit"];
|
||||
[quitButton setKeyEquivalent:@"\r"];
|
||||
[quitButton setTarget:NSApp];
|
||||
[quitButton setAction:@selector(terminate:)];
|
||||
[quitButton setAction:@selector(stopModal)];
|
||||
|
||||
NSView* quitPanel = [[NSView alloc] initWithFrame:NSMakeRect(0.0f, 0.0f, textViewWidth, 32.0f)];
|
||||
[quitPanel setAutoresizingMask:NSViewWidthSizable];
|
||||
|
@ -461,8 +461,8 @@ void FConsoleWindow::NetInit(const char* const message, const int playerCount)
|
|||
[m_netAbortButton setBezelStyle:NSRoundedBezelStyle];
|
||||
[m_netAbortButton setTitle:@"Cancel"];
|
||||
[m_netAbortButton setKeyEquivalent:@"\r"];
|
||||
[m_netAbortButton setTarget:NSApp];
|
||||
[m_netAbortButton setAction:@selector(terminate:)];
|
||||
[m_netAbortButton setTarget:NSApp.delegate];
|
||||
[m_netAbortButton setAction:@selector(sendExitEvent:)];
|
||||
|
||||
// Panel for controls above
|
||||
m_netView = [[NSView alloc] initWithFrame:NSMakeRect(0.0f, 0.0f, 512.0f, NET_VIEW_HEIGHT)];
|
||||
|
|
|
@ -40,6 +40,7 @@
|
|||
#include "m_argv.h"
|
||||
#include "m_misc.h"
|
||||
#include "gameconfigfile.h"
|
||||
#include "doomerrors.h"
|
||||
|
||||
#include <Cocoa/Cocoa.h>
|
||||
#include <wordexp.h>
|
||||
|
@ -360,7 +361,7 @@ static NSArray* GetKnownExtensions()
|
|||
|
||||
if ( @selector(terminate:) == [menuItem action] )
|
||||
{
|
||||
exit(0);
|
||||
throw CExitEvent(0);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue