mirror of
https://github.com/ZDoom/gzdoom.git
synced 2024-11-26 14:01:45 +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
|
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
|
namespace
|
||||||
{
|
{
|
||||||
|
|
||||||
TArray<FString> s_argv;
|
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",
|
printf(GAMENAME" %s - %s - Cocoa version\nCompiled on %s\n\n",
|
||||||
GetVersionString(), GetGitTime(), __DATE__);
|
GetVersionString(), GetGitTime(), __DATE__);
|
||||||
|
@ -178,7 +165,15 @@ int OriginalMain(int argc, char** argv)
|
||||||
vid_defheight = static_cast<int>(screenSize.height);
|
vid_defheight = static_cast<int>(screenSize.height);
|
||||||
vid_vsync = true;
|
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
|
} // unnamed namespace
|
||||||
|
@ -203,6 +198,10 @@ int OriginalMain(int argc, char** argv)
|
||||||
|
|
||||||
- (void)processEvents:(NSTimer*)timer;
|
- (void)processEvents:(NSTimer*)timer;
|
||||||
|
|
||||||
|
- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender;
|
||||||
|
|
||||||
|
- (void)sendExitEvent:(id)sender;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|
||||||
|
@ -276,7 +275,7 @@ extern bool AppActive;
|
||||||
|
|
||||||
argv[argc] = nullptr;
|
argv[argc] = nullptr;
|
||||||
|
|
||||||
exit(OriginalMain(argc, &argv[0]));
|
exit(DoMain(argc, &argv[0]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -341,6 +340,17 @@ extern bool AppActive;
|
||||||
[pool release];
|
[pool release];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender
|
||||||
|
{
|
||||||
|
[self sendExitEvent:sender];
|
||||||
|
return NSTerminateLater;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)sendExitEvent:(id)sender
|
||||||
|
{
|
||||||
|
throw CExitEvent(0);
|
||||||
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|
||||||
|
@ -370,7 +380,7 @@ NSMenuItem* CreateApplicationMenu()
|
||||||
keyEquivalent:@""];
|
keyEquivalent:@""];
|
||||||
[menu addItem:[NSMenuItem separatorItem]];
|
[menu addItem:[NSMenuItem separatorItem]];
|
||||||
[menu addItemWithTitle:[@"Quit " stringByAppendingString:@GAMENAME]
|
[menu addItemWithTitle:[@"Quit " stringByAppendingString:@GAMENAME]
|
||||||
action:@selector(terminate:)
|
action:@selector(sendExitEvent:)
|
||||||
keyEquivalent:@"q"];
|
keyEquivalent:@"q"];
|
||||||
|
|
||||||
NSMenuItem* menuItem = [NSMenuItem new];
|
NSMenuItem* menuItem = [NSMenuItem new];
|
||||||
|
|
|
@ -64,8 +64,8 @@
|
||||||
- (void)exitAppOnClose
|
- (void)exitAppOnClose
|
||||||
{
|
{
|
||||||
NSButton* closeButton = [self standardWindowButton:NSWindowCloseButton];
|
NSButton* closeButton = [self standardWindowButton:NSWindowCloseButton];
|
||||||
[closeButton setAction:@selector(terminate:)];
|
[closeButton setAction:@selector(sendExitEvent:)];
|
||||||
[closeButton setTarget:NSApp];
|
[closeButton setTarget:NSApp.delegate];
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
@ -172,7 +172,7 @@ void FConsoleWindow::ShowFatalError(const char* const message)
|
||||||
[quitButton setTitle:@"Quit"];
|
[quitButton setTitle:@"Quit"];
|
||||||
[quitButton setKeyEquivalent:@"\r"];
|
[quitButton setKeyEquivalent:@"\r"];
|
||||||
[quitButton setTarget:NSApp];
|
[quitButton setTarget:NSApp];
|
||||||
[quitButton setAction:@selector(terminate:)];
|
[quitButton setAction:@selector(stopModal)];
|
||||||
|
|
||||||
NSView* quitPanel = [[NSView alloc] initWithFrame:NSMakeRect(0.0f, 0.0f, textViewWidth, 32.0f)];
|
NSView* quitPanel = [[NSView alloc] initWithFrame:NSMakeRect(0.0f, 0.0f, textViewWidth, 32.0f)];
|
||||||
[quitPanel setAutoresizingMask:NSViewWidthSizable];
|
[quitPanel setAutoresizingMask:NSViewWidthSizable];
|
||||||
|
@ -461,8 +461,8 @@ void FConsoleWindow::NetInit(const char* const message, const int playerCount)
|
||||||
[m_netAbortButton setBezelStyle:NSRoundedBezelStyle];
|
[m_netAbortButton setBezelStyle:NSRoundedBezelStyle];
|
||||||
[m_netAbortButton setTitle:@"Cancel"];
|
[m_netAbortButton setTitle:@"Cancel"];
|
||||||
[m_netAbortButton setKeyEquivalent:@"\r"];
|
[m_netAbortButton setKeyEquivalent:@"\r"];
|
||||||
[m_netAbortButton setTarget:NSApp];
|
[m_netAbortButton setTarget:NSApp.delegate];
|
||||||
[m_netAbortButton setAction:@selector(terminate:)];
|
[m_netAbortButton setAction:@selector(sendExitEvent:)];
|
||||||
|
|
||||||
// Panel for controls above
|
// Panel for controls above
|
||||||
m_netView = [[NSView alloc] initWithFrame:NSMakeRect(0.0f, 0.0f, 512.0f, NET_VIEW_HEIGHT)];
|
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_argv.h"
|
||||||
#include "m_misc.h"
|
#include "m_misc.h"
|
||||||
#include "gameconfigfile.h"
|
#include "gameconfigfile.h"
|
||||||
|
#include "doomerrors.h"
|
||||||
|
|
||||||
#include <Cocoa/Cocoa.h>
|
#include <Cocoa/Cocoa.h>
|
||||||
#include <wordexp.h>
|
#include <wordexp.h>
|
||||||
|
@ -360,7 +361,7 @@ static NSArray* GetKnownExtensions()
|
||||||
|
|
||||||
if ( @selector(terminate:) == [menuItem action] )
|
if ( @selector(terminate:) == [menuItem action] )
|
||||||
{
|
{
|
||||||
exit(0);
|
throw CExitEvent(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue