Migrate to OFOptionsParser

FossilOrigin-Name: f642e9dfbf67a6be7bf37d9df2cf3b037537a29c74387f49b0a0e82d6816d616
This commit is contained in:
Jonathan Schleifer 2025-03-02 14:42:43 +00:00
parent 1e8d1cfbef
commit 866e81fcde
12 changed files with 101 additions and 109 deletions

View file

@ -5,17 +5,17 @@
OF_APPLICATION_DELEGATE(Cube)
@implementation Cube
- (void)showMessage: (OFString *)msg
- (void)showMessage:(OFString *)msg
{
#ifdef _WIN32
MessageBoxW(NULL, msg.UTF16String, L"cube fatal error",
MB_OK | MB_SYSTEMMODAL);
MessageBoxW(
NULL, msg.UTF16String, L"cube fatal error", MB_OK | MB_SYSTEMMODAL);
#else
[OFStdOut writeString: msg];
[OFStdOut writeString:msg];
#endif
}
- (void)applicationWillTerminate: (OFNotification *)notification
- (void)applicationWillTerminate:(OFNotification *)notification
{
stop();
disconnect(true);
@ -31,7 +31,7 @@ void
quit() // normal exit
{
writeservercfg();
[OFApplication.sharedApplication terminateWithStatus: 0];
[OFApplication.sharedApplication terminateWithStatus:0];
}
void
@ -39,8 +39,8 @@ fatal(char *s, char *o) // failure exit
{
sprintf_sd(msg)("%s%s (%s)\n", s, o, SDL_GetError());
OFApplication *app = OFApplication.sharedApplication;
[(Cube *)app.delegate showMessage: @(msg)];
[app terminateWithStatus: 1];
[(Cube *)app.delegate showMessage:@(msg)];
[app terminateWithStatus:1];
}
void *
@ -98,73 +98,57 @@ keyrepeat(bool on)
VARF(gamespeed, 10, 100, 1000, if (multiplayer()) gamespeed = 100);
VARP(minmillis, 0, 5, 1000);
int islittleendian = 1;
int framesinmap = 0;
- (void)applicationDidFinishLaunching: (OFNotification *)notification
- (void)applicationDidFinishLaunching:(OFNotification *)notification
{
bool dedicated = false;
int fs = SDL_FULLSCREEN, par = 0, uprate = 0, maxcl = 4;
char *sdesc = "", *ip = "", *master = NULL, *passwd = "";
islittleendian = *((char *)&islittleendian);
int argc, *argcPtr;
char **argv, ***argvPtr;
[OFApplication.sharedApplication getArgumentCount: &argcPtr
andArgumentValues: &argvPtr];
argc = *argcPtr;
argv = *argvPtr;
bool dedicated, windowed;
int par = 0, uprate = 0, maxcl = 4;
OFString *__autoreleasing sdesc, *__autoreleasing ip;
OFString *__autoreleasing master, *__autoreleasing passwd;
processInitQueue();
#define log(s) conoutf(@"init: %s", s)
log("sdl");
for (int i = 1; i < argc; i++) {
char *a = &argv[i][2];
if (argv[i][0] == '-')
switch (argv[i][1]) {
case 'd':
dedicated = true;
break;
case 't':
fs = 0;
break;
case 'w':
scr_w = atoi(a);
break;
case 'h':
scr_h = atoi(a);
break;
case 'u':
uprate = atoi(a);
break;
case 'n':
sdesc = a;
break;
case 'i':
ip = a;
break;
case 'm':
master = a;
break;
case 'p':
passwd = a;
break;
case 'c':
maxcl = atoi(a);
break;
default:
conoutf(@"unknown commandline option");
}
else
conoutf(@"unknown commandline argument");
};
const OFOptionsParserOption options[] = {
{'d', nil, 0, &dedicated, NULL}, {'t', nil, 0, &windowed, NULL},
{'w', nil, 1, NULL, NULL}, {'h', nil, 1, NULL, NULL},
{'u', nil, 1, NULL, NULL}, {'n', nil, 1, NULL, &sdesc},
{'i', nil, 1, NULL, &ip}, {'m', nil, 1, NULL, &master},
{'p', nil, 1, NULL, &passwd}, {'c', nil, 1, NULL, NULL}};
OFOptionsParser *optionsParser =
[OFOptionsParser parserWithOptions:options];
OFUnichar option;
while ((option = [optionsParser nextOption]) != '\0') {
switch (option) {
case 'w':
scr_w = optionsParser.argument.longLongValue;
break;
case 'h':
scr_h = optionsParser.argument.longLongValue;
break;
case 'u':
uprate = optionsParser.argument.longLongValue;
break;
case 'c':
maxcl = optionsParser.argument.longLongValue;
break;
case ':':
case '=':
case '?':
conoutf(@"unknown commandline option");
[OFApplication terminateWithStatus:1];
}
}
#ifdef _DEBUG
par = SDL_INIT_NOPARACHUTE;
fs = 0;
#endif
if (sdesc == nil)
sdesc = @"";
if (ip == nil)
ip = @"";
if (passwd == nil)
passwd = @"";
if (SDL_Init(SDL_INIT_TIMER | SDL_INIT_VIDEO | par) < 0)
fatal("Unable to initialize SDL");
@ -174,8 +158,9 @@ int framesinmap = 0;
fatal("Unable to initialise network module");
initclient();
initserver(dedicated, uprate, sdesc, ip, master, passwd,
maxcl); // never returns if dedicated
// never returns if dedicated
initserver(dedicated, uprate, sdesc.UTF8String, ip.UTF8String,
master.UTF8String, passwd, maxcl);
log("world");
empty_world(7, true);
@ -186,7 +171,8 @@ int framesinmap = 0;
log("video: mode");
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
if (SDL_SetVideoMode(scr_w, scr_h, 0, SDL_OPENGL | fs) == NULL)
if (SDL_SetVideoMode(scr_w, scr_h, 0,
SDL_OPENGL | (!windowed ? SDL_FULLSCREEN : 0)) == NULL)
fatal("Unable to create OpenGL screen");
log("video: misc");