Index: src/.clang-format ================================================================== --- src/.clang-format +++ src/.clang-format @@ -13,5 +13,7 @@ nullable, nonnull, null_resettable, null_unspecified, assign, retain, strong, copy, weak, unsafe_unretained, atomic, nonatomic, getter, setter ] +IndentPPDirectives: AfterHash +PPIndentWidth: 1 Index: src/Cube.mm ================================================================== --- src/Cube.mm +++ src/Cube.mm @@ -3,21 +3,21 @@ #include "cube.h" 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); writecfg(); cleangl(); @@ -29,20 +29,20 @@ void quit() // normal exit { writeservercfg(); - [OFApplication.sharedApplication terminateWithStatus: 0]; + [OFApplication.sharedApplication terminateWithStatus:0]; } void 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 * alloc(int s) // for some big chunks... most other allocs use the memory pool { @@ -96,88 +96,73 @@ } VARF(gamespeed, 10, 100, 1000, if (multiplayer()) gamespeed = 100); VARP(minmillis, 0, 5, 1000); -int islittleendian = 1; int framesinmap = 0; -- (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; +- (void)applicationDidFinishLaunching:(OFNotification *)notification +{ + 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"); - }; - -#ifdef _DEBUG - par = SDL_INIT_NOPARACHUTE; - fs = 0; -#endif + 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]; + } + } + + 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"); log("net"); if (enet_initialize() < 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); log("video: sdl"); @@ -184,11 +169,12 @@ if (SDL_InitSubSystem(SDL_INIT_VIDEO) < 0) fatal("Unable to initialize SDL Video"); 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"); SDL_WM_SetCaption("cube engine", NULL); SDL_WM_GrabInput(SDL_GRAB_ON); Index: src/console.mm ================================================================== --- src/console.mm +++ src/console.mm @@ -138,12 +138,12 @@ COMMAND(saycommand, ARG_VARI); COMMAND(mapmsg, ARG_1STR); #ifndef _WIN32 -#include -#include +# include +# include #endif void pasteconsole() { Index: src/cube.h ================================================================== --- src/cube.h +++ src/cube.h @@ -2,11 +2,11 @@ #import #include "tools.h" -@interface Cube: OFObject +@interface Cube : OFObject @end enum // block types, order matters! { SOLID = 0, // entirely solid cube [only specifies wtex] @@ -444,16 +444,16 @@ void var_##name() { body; } #define ATOI(s) strtol(s, NULL, 0) // supports hexadecimal numbers #ifdef WIN32 -#define WIN32_LEAN_AND_MEAN -#include "windows.h" -#define _WINDOWS -#define ZLIB_DLL +# define WIN32_LEAN_AND_MEAN +# include "windows.h" +# define _WINDOWS +# define ZLIB_DLL #else -#include +# include #endif #include #include Index: src/protos.h ================================================================== --- src/protos.h +++ src/protos.h @@ -212,27 +212,27 @@ float x, float y, float z, float yaw, float pitch, bool teammate, float scale, float speed, int snap = 0, int basetime = 0); extern mapmodelinfo *getmminfo(int i); // server -extern void initserver(bool dedicated, int uprate, char *sdesc, char *ip, - char *master, char *passwd, int maxcl); +extern void initserver(bool dedicated, int uprate, const char *sdesc, + const char *ip, const char *master, OFString *passwd, int maxcl); extern void cleanupserver(); extern void localconnect(); extern void localdisconnect(); extern void localclienttoserver(struct _ENetPacket *); extern void serverslice(int seconds, unsigned int timeout); extern void putint(uchar *&p, int n); 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 restoreserverstate(vector &ents); extern uchar *retrieveservers(uchar *buf, int buflen); extern char msgsizelookup(int msg); extern void serverms(int mode, int numplayers, int minremain, char *smapname, 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 ENetPacket *recvmap(int n); // weapon extern void selectgun(int a = -1, int b = -1, int c = -1); Index: src/rendergl.mm ================================================================== --- src/rendergl.mm +++ src/rendergl.mm @@ -1,15 +1,15 @@ // rendergl.cpp: core opengl rendering stuff #include "cube.h" #ifdef DARWIN -#define GL_COMBINE_EXT GL_COMBINE_ARB -#define GL_COMBINE_RGB_EXT GL_COMBINE_RGB_ARB -#define GL_SOURCE0_RBG_EXT GL_SOURCE0_RGB_ARB -#define GL_SOURCE1_RBG_EXT GL_SOURCE1_RGB_ARB -#define GL_RGB_SCALE_EXT GL_RGB_SCALE_ARB +# define GL_COMBINE_EXT GL_COMBINE_ARB +# define GL_COMBINE_RGB_EXT GL_COMBINE_RGB_ARB +# define GL_SOURCE0_RBG_EXT GL_SOURCE0_RGB_ARB +# define GL_SOURCE1_RBG_EXT GL_SOURCE1_RGB_ARB +# define GL_RGB_SCALE_EXT GL_RGB_SCALE_ARB #endif extern int curvert; bool hasoverbright = false; Index: src/savegamedemo.mm ================================================================== --- src/savegamedemo.mm +++ src/savegamedemo.mm @@ -1,11 +1,15 @@ // loading and saving of savegames & demos, dumps the spawn state of all // mapents, the full state of all dynents (monsters + player) #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; bool demorecording = false; bool demoplayback = false; bool demoloading = false; Index: src/server.mm ================================================================== --- src/server.mm +++ src/server.mm @@ -44,11 +44,11 @@ }; int interm = 0, minremain = 0, mapend = 0; bool mapreload = false; -char *serverpassword = ""; +static OFString *serverpassword = @""; bool isdedicated; ENetHost *serverhost = NULL; int bsend = 0, brec = 0, laststatus = 0, lastsec = 0; @@ -306,11 +306,11 @@ uchar *p = start + 2; putint(p, SV_INITS2C); putint(p, n); putint(p, PROTOCOL_VERSION); putint(p, smapname[0]); - sendstring(serverpassword, p); + sendstring(serverpassword.UTF8String, p); putint(p, clients.length() > maxclients); if (smapname[0]) { putint(p, SV_MAPCHANGE); sendstring(smapname, p); putint(p, mode); @@ -507,12 +507,12 @@ strcpy_s(c.hostname, "local"); send_welcome(&c - &clients[0]); }; void -initserver(bool dedicated, int uprate, char *sdesc, char *ip, char *master, - char *passwd, int maxcl) +initserver(bool dedicated, int uprate, const char *sdesc, const char *ip, + const char *master, OFString *passwd, int maxcl) { serverpassword = passwd; maxclients = maxcl; servermsinit(master ? master : "wouter.fov120.com/cube/masterserver/", sdesc, dedicated); Index: src/serverms.mm ================================================================== --- src/serverms.mm +++ src/serverms.mm @@ -145,11 +145,11 @@ enet_socket_send(pongsock, &addr, &buf, 1); }; }; void -servermsinit(const char *master, char *sdesc, bool listen) +servermsinit(const char *master, const char *sdesc, bool listen) { const char *mid = strstr(master, "/"); if (!mid) mid = master; strcpy_s(masterpath, mid); Index: src/serverutil.mm ================================================================== --- src/serverutil.mm +++ src/serverutil.mm @@ -41,11 +41,11 @@ } else return c; }; void -sendstring(char *t, uchar *&p) +sendstring(const char *t, uchar *&p) { while (*t) putint(p, *t++); putint(p, 0); }; @@ -182,9 +182,9 @@ }; }; if (enet_initialize() < 0) fatal("Unable to initialise network module"); - initserver(true, uprate, sdesc, ip, master, passwd, maxcl); + initserver(true, uprate, sdesc, ip, master, @(passwd), maxcl); return 0; -}; +} #endif Index: src/sound.mm ================================================================== --- src/sound.mm +++ src/sound.mm @@ -19,17 +19,17 @@ vec loc; bool inuse; } soundlocs[MAXCHAN]; #ifdef USE_MIXER -#include "SDL_mixer.h" -#define MAXVOL MIX_MAX_VOLUME +# include "SDL_mixer.h" +# define MAXVOL MIX_MAX_VOLUME Mix_Music *mod = NULL; void *stream = NULL; #else -#include "fmod.h" -#define MAXVOL 255 +# include "fmod.h" +# define MAXVOL 255 FMUSIC_MODULE *mod = NULL; FSOUND_STREAM *stream = NULL; #endif void Index: src/tools.h ================================================================== --- src/tools.h +++ src/tools.h @@ -2,33 +2,33 @@ #ifndef _TOOLS_H #define _TOOLS_H #ifdef __GNUC__ -#define gamma __gamma +# define gamma __gamma #endif #include #ifdef __GNUC__ -#undef gamma +# undef gamma #endif #include #include #include #include #include #include #ifdef __GNUC__ -#include +# include #else -#include +# include #endif #ifdef NULL -#undef NULL +# undef NULL #endif #define NULL 0 typedef unsigned char uchar; typedef unsigned short ushort; @@ -47,17 +47,17 @@ #define loopj(m) loop(j, m) #define loopk(m) loop(k, m) #define loopl(m) loop(l, m) #ifdef WIN32 -#pragma warning(3 : 4189) +# pragma warning(3 : 4189) // #pragma comment(linker,"/OPT:NOWIN98") -#define PATHDIV '\\' +# define PATHDIV '\\' #else -#define __cdecl -#define _vsnprintf vsnprintf -#define PATHDIV '/' +# define __cdecl +# define _vsnprintf vsnprintf +# define PATHDIV '/' #endif // easy safe strings #define _MAXDEFSTR 260 @@ -128,11 +128,11 @@ __asm fld a __asm fsub fhalf __asm fistp retval // perf regalloc? return retval; }; #else -#define fast_f2nat(val) ((int)(val)) +# define fast_f2nat(val) ((int)(val)) #endif extern char *path(char *s); extern char *loadfile(char *fn, int *size); extern void endianswap(void *, int, int);