Migrate to OFOptionsParser
FossilOrigin-Name: f642e9dfbf67a6be7bf37d9df2cf3b037537a29c74387f49b0a0e82d6816d616
This commit is contained in:
parent
1e8d1cfbef
commit
866e81fcde
12 changed files with 101 additions and 109 deletions
|
@ -15,3 +15,5 @@ ObjCPropertyAttributeOrder: [
|
||||||
atomic, nonatomic,
|
atomic, nonatomic,
|
||||||
getter, setter
|
getter, setter
|
||||||
]
|
]
|
||||||
|
IndentPPDirectives: AfterHash
|
||||||
|
PPIndentWidth: 1
|
||||||
|
|
102
src/Cube.mm
102
src/Cube.mm
|
@ -5,17 +5,17 @@
|
||||||
OF_APPLICATION_DELEGATE(Cube)
|
OF_APPLICATION_DELEGATE(Cube)
|
||||||
|
|
||||||
@implementation Cube
|
@implementation Cube
|
||||||
- (void)showMessage: (OFString *)msg
|
- (void)showMessage:(OFString *)msg
|
||||||
{
|
{
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
MessageBoxW(NULL, msg.UTF16String, L"cube fatal error",
|
MessageBoxW(
|
||||||
MB_OK | MB_SYSTEMMODAL);
|
NULL, msg.UTF16String, L"cube fatal error", MB_OK | MB_SYSTEMMODAL);
|
||||||
#else
|
#else
|
||||||
[OFStdOut writeString: msg];
|
[OFStdOut writeString:msg];
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)applicationWillTerminate: (OFNotification *)notification
|
- (void)applicationWillTerminate:(OFNotification *)notification
|
||||||
{
|
{
|
||||||
stop();
|
stop();
|
||||||
disconnect(true);
|
disconnect(true);
|
||||||
|
@ -31,7 +31,7 @@ void
|
||||||
quit() // normal exit
|
quit() // normal exit
|
||||||
{
|
{
|
||||||
writeservercfg();
|
writeservercfg();
|
||||||
[OFApplication.sharedApplication terminateWithStatus: 0];
|
[OFApplication.sharedApplication terminateWithStatus:0];
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -39,8 +39,8 @@ fatal(char *s, char *o) // failure exit
|
||||||
{
|
{
|
||||||
sprintf_sd(msg)("%s%s (%s)\n", s, o, SDL_GetError());
|
sprintf_sd(msg)("%s%s (%s)\n", s, o, SDL_GetError());
|
||||||
OFApplication *app = OFApplication.sharedApplication;
|
OFApplication *app = OFApplication.sharedApplication;
|
||||||
[(Cube *)app.delegate showMessage: @(msg)];
|
[(Cube *)app.delegate showMessage:@(msg)];
|
||||||
[app terminateWithStatus: 1];
|
[app terminateWithStatus:1];
|
||||||
}
|
}
|
||||||
|
|
||||||
void *
|
void *
|
||||||
|
@ -98,73 +98,57 @@ keyrepeat(bool on)
|
||||||
VARF(gamespeed, 10, 100, 1000, if (multiplayer()) gamespeed = 100);
|
VARF(gamespeed, 10, 100, 1000, if (multiplayer()) gamespeed = 100);
|
||||||
VARP(minmillis, 0, 5, 1000);
|
VARP(minmillis, 0, 5, 1000);
|
||||||
|
|
||||||
int islittleendian = 1;
|
|
||||||
int framesinmap = 0;
|
int framesinmap = 0;
|
||||||
|
|
||||||
- (void)applicationDidFinishLaunching: (OFNotification *)notification
|
- (void)applicationDidFinishLaunching:(OFNotification *)notification
|
||||||
{
|
{
|
||||||
bool dedicated = false;
|
bool dedicated, windowed;
|
||||||
int fs = SDL_FULLSCREEN, par = 0, uprate = 0, maxcl = 4;
|
int par = 0, uprate = 0, maxcl = 4;
|
||||||
char *sdesc = "", *ip = "", *master = NULL, *passwd = "";
|
OFString *__autoreleasing sdesc, *__autoreleasing ip;
|
||||||
islittleendian = *((char *)&islittleendian);
|
OFString *__autoreleasing master, *__autoreleasing passwd;
|
||||||
int argc, *argcPtr;
|
|
||||||
char **argv, ***argvPtr;
|
|
||||||
|
|
||||||
[OFApplication.sharedApplication getArgumentCount: &argcPtr
|
|
||||||
andArgumentValues: &argvPtr];
|
|
||||||
argc = *argcPtr;
|
|
||||||
argv = *argvPtr;
|
|
||||||
|
|
||||||
processInitQueue();
|
processInitQueue();
|
||||||
|
|
||||||
#define log(s) conoutf(@"init: %s", s)
|
#define log(s) conoutf(@"init: %s", s)
|
||||||
log("sdl");
|
log("sdl");
|
||||||
|
|
||||||
for (int i = 1; i < argc; i++) {
|
const OFOptionsParserOption options[] = {
|
||||||
char *a = &argv[i][2];
|
{'d', nil, 0, &dedicated, NULL}, {'t', nil, 0, &windowed, NULL},
|
||||||
if (argv[i][0] == '-')
|
{'w', nil, 1, NULL, NULL}, {'h', nil, 1, NULL, NULL},
|
||||||
switch (argv[i][1]) {
|
{'u', nil, 1, NULL, NULL}, {'n', nil, 1, NULL, &sdesc},
|
||||||
case 'd':
|
{'i', nil, 1, NULL, &ip}, {'m', nil, 1, NULL, &master},
|
||||||
dedicated = true;
|
{'p', nil, 1, NULL, &passwd}, {'c', nil, 1, NULL, NULL}};
|
||||||
break;
|
OFOptionsParser *optionsParser =
|
||||||
case 't':
|
[OFOptionsParser parserWithOptions:options];
|
||||||
fs = 0;
|
OFUnichar option;
|
||||||
break;
|
while ((option = [optionsParser nextOption]) != '\0') {
|
||||||
|
switch (option) {
|
||||||
case 'w':
|
case 'w':
|
||||||
scr_w = atoi(a);
|
scr_w = optionsParser.argument.longLongValue;
|
||||||
break;
|
break;
|
||||||
case 'h':
|
case 'h':
|
||||||
scr_h = atoi(a);
|
scr_h = optionsParser.argument.longLongValue;
|
||||||
break;
|
break;
|
||||||
case 'u':
|
case 'u':
|
||||||
uprate = atoi(a);
|
uprate = optionsParser.argument.longLongValue;
|
||||||
break;
|
|
||||||
case 'n':
|
|
||||||
sdesc = a;
|
|
||||||
break;
|
|
||||||
case 'i':
|
|
||||||
ip = a;
|
|
||||||
break;
|
|
||||||
case 'm':
|
|
||||||
master = a;
|
|
||||||
break;
|
|
||||||
case 'p':
|
|
||||||
passwd = a;
|
|
||||||
break;
|
break;
|
||||||
case 'c':
|
case 'c':
|
||||||
maxcl = atoi(a);
|
maxcl = optionsParser.argument.longLongValue;
|
||||||
break;
|
break;
|
||||||
default:
|
case ':':
|
||||||
|
case '=':
|
||||||
|
case '?':
|
||||||
conoutf(@"unknown commandline option");
|
conoutf(@"unknown commandline option");
|
||||||
|
[OFApplication terminateWithStatus:1];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
conoutf(@"unknown commandline argument");
|
|
||||||
};
|
|
||||||
|
|
||||||
#ifdef _DEBUG
|
if (sdesc == nil)
|
||||||
par = SDL_INIT_NOPARACHUTE;
|
sdesc = @"";
|
||||||
fs = 0;
|
if (ip == nil)
|
||||||
#endif
|
ip = @"";
|
||||||
|
if (passwd == nil)
|
||||||
|
passwd = @"";
|
||||||
|
|
||||||
if (SDL_Init(SDL_INIT_TIMER | SDL_INIT_VIDEO | par) < 0)
|
if (SDL_Init(SDL_INIT_TIMER | SDL_INIT_VIDEO | par) < 0)
|
||||||
fatal("Unable to initialize SDL");
|
fatal("Unable to initialize SDL");
|
||||||
|
@ -174,8 +158,9 @@ int framesinmap = 0;
|
||||||
fatal("Unable to initialise network module");
|
fatal("Unable to initialise network module");
|
||||||
|
|
||||||
initclient();
|
initclient();
|
||||||
initserver(dedicated, uprate, sdesc, ip, master, passwd,
|
// never returns if dedicated
|
||||||
maxcl); // never returns if dedicated
|
initserver(dedicated, uprate, sdesc.UTF8String, ip.UTF8String,
|
||||||
|
master.UTF8String, passwd, maxcl);
|
||||||
|
|
||||||
log("world");
|
log("world");
|
||||||
empty_world(7, true);
|
empty_world(7, true);
|
||||||
|
@ -186,7 +171,8 @@ int framesinmap = 0;
|
||||||
|
|
||||||
log("video: mode");
|
log("video: mode");
|
||||||
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
|
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");
|
fatal("Unable to create OpenGL screen");
|
||||||
|
|
||||||
log("video: misc");
|
log("video: misc");
|
||||||
|
|
|
@ -140,8 +140,8 @@ COMMAND(saycommand, ARG_VARI);
|
||||||
COMMAND(mapmsg, ARG_1STR);
|
COMMAND(mapmsg, ARG_1STR);
|
||||||
|
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
#include <SDL_syswm.h>
|
# include <SDL_syswm.h>
|
||||||
#include <X11/Xlib.h>
|
# include <X11/Xlib.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
12
src/cube.h
12
src/cube.h
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
#include "tools.h"
|
#include "tools.h"
|
||||||
|
|
||||||
@interface Cube: OFObject <OFApplicationDelegate>
|
@interface Cube : OFObject <OFApplicationDelegate>
|
||||||
@end
|
@end
|
||||||
|
|
||||||
enum // block types, order matters!
|
enum // block types, order matters!
|
||||||
|
@ -446,12 +446,12 @@ enum // function signatures for script functions, see command.cpp
|
||||||
#define ATOI(s) strtol(s, NULL, 0) // supports hexadecimal numbers
|
#define ATOI(s) strtol(s, NULL, 0) // supports hexadecimal numbers
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
#define WIN32_LEAN_AND_MEAN
|
# define WIN32_LEAN_AND_MEAN
|
||||||
#include "windows.h"
|
# include "windows.h"
|
||||||
#define _WINDOWS
|
# define _WINDOWS
|
||||||
#define ZLIB_DLL
|
# define ZLIB_DLL
|
||||||
#else
|
#else
|
||||||
#include <dlfcn.h>
|
# include <dlfcn.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
|
@ -214,8 +214,8 @@ extern void rendermodel(char *mdl, int frame, int range, int tex, float rad,
|
||||||
extern mapmodelinfo *getmminfo(int i);
|
extern mapmodelinfo *getmminfo(int i);
|
||||||
|
|
||||||
// server
|
// server
|
||||||
extern void initserver(bool dedicated, int uprate, char *sdesc, char *ip,
|
extern void initserver(bool dedicated, int uprate, const char *sdesc,
|
||||||
char *master, char *passwd, int maxcl);
|
const char *ip, const char *master, OFString *passwd, int maxcl);
|
||||||
extern void cleanupserver();
|
extern void cleanupserver();
|
||||||
extern void localconnect();
|
extern void localconnect();
|
||||||
extern void localdisconnect();
|
extern void localdisconnect();
|
||||||
|
@ -223,14 +223,14 @@ extern void localclienttoserver(struct _ENetPacket *);
|
||||||
extern void serverslice(int seconds, unsigned int timeout);
|
extern void serverslice(int seconds, unsigned int timeout);
|
||||||
extern void putint(uchar *&p, int n);
|
extern void putint(uchar *&p, int n);
|
||||||
extern int getint(uchar *&p);
|
extern int getint(uchar *&p);
|
||||||
extern void sendstring(char *t, uchar *&p);
|
extern void sendstring(const char *t, uchar *&p);
|
||||||
extern void startintermission();
|
extern void startintermission();
|
||||||
extern void restoreserverstate(vector<entity> &ents);
|
extern void restoreserverstate(vector<entity> &ents);
|
||||||
extern uchar *retrieveservers(uchar *buf, int buflen);
|
extern uchar *retrieveservers(uchar *buf, int buflen);
|
||||||
extern char msgsizelookup(int msg);
|
extern char msgsizelookup(int msg);
|
||||||
extern void serverms(int mode, int numplayers, int minremain, char *smapname,
|
extern void serverms(int mode, int numplayers, int minremain, char *smapname,
|
||||||
int seconds, bool isfull);
|
int seconds, bool isfull);
|
||||||
extern void servermsinit(const char *master, char *sdesc, bool listen);
|
extern void servermsinit(const char *master, const char *sdesc, bool listen);
|
||||||
extern void sendmaps(int n, string mapname, int mapsize, uchar *mapdata);
|
extern void sendmaps(int n, string mapname, int mapsize, uchar *mapdata);
|
||||||
extern ENetPacket *recvmap(int n);
|
extern ENetPacket *recvmap(int n);
|
||||||
|
|
||||||
|
|
|
@ -3,11 +3,11 @@
|
||||||
#include "cube.h"
|
#include "cube.h"
|
||||||
|
|
||||||
#ifdef DARWIN
|
#ifdef DARWIN
|
||||||
#define GL_COMBINE_EXT GL_COMBINE_ARB
|
# define GL_COMBINE_EXT GL_COMBINE_ARB
|
||||||
#define GL_COMBINE_RGB_EXT GL_COMBINE_RGB_ARB
|
# define GL_COMBINE_RGB_EXT GL_COMBINE_RGB_ARB
|
||||||
#define GL_SOURCE0_RBG_EXT GL_SOURCE0_RGB_ARB
|
# define GL_SOURCE0_RBG_EXT GL_SOURCE0_RGB_ARB
|
||||||
#define GL_SOURCE1_RBG_EXT GL_SOURCE1_RGB_ARB
|
# define GL_SOURCE1_RBG_EXT GL_SOURCE1_RGB_ARB
|
||||||
#define GL_RGB_SCALE_EXT GL_RGB_SCALE_ARB
|
# define GL_RGB_SCALE_EXT GL_RGB_SCALE_ARB
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
extern int curvert;
|
extern int curvert;
|
||||||
|
|
|
@ -3,7 +3,11 @@
|
||||||
|
|
||||||
#include "cube.h"
|
#include "cube.h"
|
||||||
|
|
||||||
extern int islittleendian;
|
#ifdef OF_BIG_ENDIAN
|
||||||
|
static const int islittleendian = 0;
|
||||||
|
#else
|
||||||
|
static const int islittleendian = 1;
|
||||||
|
#endif
|
||||||
|
|
||||||
gzFile f = NULL;
|
gzFile f = NULL;
|
||||||
bool demorecording = false;
|
bool demorecording = false;
|
||||||
|
|
|
@ -46,7 +46,7 @@ restoreserverstate(
|
||||||
int interm = 0, minremain = 0, mapend = 0;
|
int interm = 0, minremain = 0, mapend = 0;
|
||||||
bool mapreload = false;
|
bool mapreload = false;
|
||||||
|
|
||||||
char *serverpassword = "";
|
static OFString *serverpassword = @"";
|
||||||
|
|
||||||
bool isdedicated;
|
bool isdedicated;
|
||||||
ENetHost *serverhost = NULL;
|
ENetHost *serverhost = NULL;
|
||||||
|
@ -308,7 +308,7 @@ send_welcome(int n)
|
||||||
putint(p, n);
|
putint(p, n);
|
||||||
putint(p, PROTOCOL_VERSION);
|
putint(p, PROTOCOL_VERSION);
|
||||||
putint(p, smapname[0]);
|
putint(p, smapname[0]);
|
||||||
sendstring(serverpassword, p);
|
sendstring(serverpassword.UTF8String, p);
|
||||||
putint(p, clients.length() > maxclients);
|
putint(p, clients.length() > maxclients);
|
||||||
if (smapname[0]) {
|
if (smapname[0]) {
|
||||||
putint(p, SV_MAPCHANGE);
|
putint(p, SV_MAPCHANGE);
|
||||||
|
@ -509,8 +509,8 @@ localconnect()
|
||||||
};
|
};
|
||||||
|
|
||||||
void
|
void
|
||||||
initserver(bool dedicated, int uprate, char *sdesc, char *ip, char *master,
|
initserver(bool dedicated, int uprate, const char *sdesc, const char *ip,
|
||||||
char *passwd, int maxcl)
|
const char *master, OFString *passwd, int maxcl)
|
||||||
{
|
{
|
||||||
serverpassword = passwd;
|
serverpassword = passwd;
|
||||||
maxclients = maxcl;
|
maxclients = maxcl;
|
||||||
|
|
|
@ -147,7 +147,7 @@ serverms(int mode, int numplayers, int minremain, char *smapname, int seconds,
|
||||||
};
|
};
|
||||||
|
|
||||||
void
|
void
|
||||||
servermsinit(const char *master, char *sdesc, bool listen)
|
servermsinit(const char *master, const char *sdesc, bool listen)
|
||||||
{
|
{
|
||||||
const char *mid = strstr(master, "/");
|
const char *mid = strstr(master, "/");
|
||||||
if (!mid)
|
if (!mid)
|
||||||
|
|
|
@ -43,7 +43,7 @@ getint(uchar *&p)
|
||||||
};
|
};
|
||||||
|
|
||||||
void
|
void
|
||||||
sendstring(char *t, uchar *&p)
|
sendstring(const char *t, uchar *&p)
|
||||||
{
|
{
|
||||||
while (*t)
|
while (*t)
|
||||||
putint(p, *t++);
|
putint(p, *t++);
|
||||||
|
@ -184,7 +184,7 @@ main(int argc, char *argv[])
|
||||||
|
|
||||||
if (enet_initialize() < 0)
|
if (enet_initialize() < 0)
|
||||||
fatal("Unable to initialise network module");
|
fatal("Unable to initialise network module");
|
||||||
initserver(true, uprate, sdesc, ip, master, passwd, maxcl);
|
initserver(true, uprate, sdesc, ip, master, @(passwd), maxcl);
|
||||||
return 0;
|
return 0;
|
||||||
};
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -21,13 +21,13 @@ struct soundloc {
|
||||||
} soundlocs[MAXCHAN];
|
} soundlocs[MAXCHAN];
|
||||||
|
|
||||||
#ifdef USE_MIXER
|
#ifdef USE_MIXER
|
||||||
#include "SDL_mixer.h"
|
# include "SDL_mixer.h"
|
||||||
#define MAXVOL MIX_MAX_VOLUME
|
# define MAXVOL MIX_MAX_VOLUME
|
||||||
Mix_Music *mod = NULL;
|
Mix_Music *mod = NULL;
|
||||||
void *stream = NULL;
|
void *stream = NULL;
|
||||||
#else
|
#else
|
||||||
#include "fmod.h"
|
# include "fmod.h"
|
||||||
#define MAXVOL 255
|
# define MAXVOL 255
|
||||||
FMUSIC_MODULE *mod = NULL;
|
FMUSIC_MODULE *mod = NULL;
|
||||||
FSOUND_STREAM *stream = NULL;
|
FSOUND_STREAM *stream = NULL;
|
||||||
#endif
|
#endif
|
||||||
|
|
22
src/tools.h
22
src/tools.h
|
@ -4,13 +4,13 @@
|
||||||
#define _TOOLS_H
|
#define _TOOLS_H
|
||||||
|
|
||||||
#ifdef __GNUC__
|
#ifdef __GNUC__
|
||||||
#define gamma __gamma
|
# define gamma __gamma
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
#ifdef __GNUC__
|
#ifdef __GNUC__
|
||||||
#undef gamma
|
# undef gamma
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
@ -20,13 +20,13 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#ifdef __GNUC__
|
#ifdef __GNUC__
|
||||||
#include <new>
|
# include <new>
|
||||||
#else
|
#else
|
||||||
#include <new.h>
|
# include <new.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef NULL
|
#ifdef NULL
|
||||||
#undef NULL
|
# undef NULL
|
||||||
#endif
|
#endif
|
||||||
#define NULL 0
|
#define NULL 0
|
||||||
|
|
||||||
|
@ -49,13 +49,13 @@ typedef unsigned int uint;
|
||||||
#define loopl(m) loop(l, m)
|
#define loopl(m) loop(l, m)
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
#pragma warning(3 : 4189)
|
# pragma warning(3 : 4189)
|
||||||
// #pragma comment(linker,"/OPT:NOWIN98")
|
// #pragma comment(linker,"/OPT:NOWIN98")
|
||||||
#define PATHDIV '\\'
|
# define PATHDIV '\\'
|
||||||
#else
|
#else
|
||||||
#define __cdecl
|
# define __cdecl
|
||||||
#define _vsnprintf vsnprintf
|
# define _vsnprintf vsnprintf
|
||||||
#define PATHDIV '/'
|
# define PATHDIV '/'
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// easy safe strings
|
// easy safe strings
|
||||||
|
@ -130,7 +130,7 @@ fast_f2nat(float a)
|
||||||
return retval;
|
return retval;
|
||||||
};
|
};
|
||||||
#else
|
#else
|
||||||
#define fast_f2nat(val) ((int)(val))
|
# define fast_f2nat(val) ((int)(val))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
extern char *path(char *s);
|
extern char *path(char *s);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue