diff --git a/src/.clang-format b/src/.clang-format index dcb3031..2270666 100644 --- a/src/.clang-format +++ b/src/.clang-format @@ -15,3 +15,5 @@ ObjCPropertyAttributeOrder: [ atomic, nonatomic, getter, setter ] +IndentPPDirectives: AfterHash +PPIndentWidth: 1 diff --git a/src/Cube.mm b/src/Cube.mm index 71291a1..11b784d 100644 --- a/src/Cube.mm +++ b/src/Cube.mm @@ -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"); diff --git a/src/console.mm b/src/console.mm index 21a9b5f..0eac8d4 100644 --- a/src/console.mm +++ b/src/console.mm @@ -140,8 +140,8 @@ COMMAND(saycommand, ARG_VARI); COMMAND(mapmsg, ARG_1STR); #ifndef _WIN32 -#include -#include +# include +# include #endif void diff --git a/src/cube.h b/src/cube.h index 696afd7..ce82bb9 100644 --- a/src/cube.h +++ b/src/cube.h @@ -4,7 +4,7 @@ #include "tools.h" -@interface Cube: OFObject +@interface Cube : OFObject @end 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 #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 diff --git a/src/protos.h b/src/protos.h index 090c708..1d80a0b 100644 --- a/src/protos.h +++ b/src/protos.h @@ -214,8 +214,8 @@ extern void rendermodel(char *mdl, int frame, int range, int tex, float rad, 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(); @@ -223,14 +223,14 @@ 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); diff --git a/src/rendergl.mm b/src/rendergl.mm index 6e0e97f..17b8a4b 100644 --- a/src/rendergl.mm +++ b/src/rendergl.mm @@ -3,11 +3,11 @@ #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; diff --git a/src/savegamedemo.mm b/src/savegamedemo.mm index 123ed28..28df06f 100644 --- a/src/savegamedemo.mm +++ b/src/savegamedemo.mm @@ -3,7 +3,11 @@ #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; diff --git a/src/server.mm b/src/server.mm index 1f270e6..1ae6b2f 100644 --- a/src/server.mm +++ b/src/server.mm @@ -46,7 +46,7 @@ restoreserverstate( int interm = 0, minremain = 0, mapend = 0; bool mapreload = false; -char *serverpassword = ""; +static OFString *serverpassword = @""; bool isdedicated; ENetHost *serverhost = NULL; @@ -308,7 +308,7 @@ send_welcome(int n) 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); @@ -509,8 +509,8 @@ localconnect() }; 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; diff --git a/src/serverms.mm b/src/serverms.mm index 32d18d9..188e11b 100644 --- a/src/serverms.mm +++ b/src/serverms.mm @@ -147,7 +147,7 @@ serverms(int mode, int numplayers, int minremain, char *smapname, int seconds, }; 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) diff --git a/src/serverutil.mm b/src/serverutil.mm index fc8477b..0957a7f 100644 --- a/src/serverutil.mm +++ b/src/serverutil.mm @@ -43,7 +43,7 @@ getint(uchar *&p) }; void -sendstring(char *t, uchar *&p) +sendstring(const char *t, uchar *&p) { while (*t) putint(p, *t++); @@ -184,7 +184,7 @@ main(int argc, char *argv[]) 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 diff --git a/src/sound.mm b/src/sound.mm index a3e6739..fd5627a 100644 --- a/src/sound.mm +++ b/src/sound.mm @@ -21,13 +21,13 @@ struct soundloc { } 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 diff --git a/src/tools.h b/src/tools.h index b19c5f4..66a50ca 100644 --- a/src/tools.h +++ b/src/tools.h @@ -4,13 +4,13 @@ #define _TOOLS_H #ifdef __GNUC__ -#define gamma __gamma +# define gamma __gamma #endif #include #ifdef __GNUC__ -#undef gamma +# undef gamma #endif #include @@ -20,13 +20,13 @@ #include #include #ifdef __GNUC__ -#include +# include #else -#include +# include #endif #ifdef NULL -#undef NULL +# undef NULL #endif #define NULL 0 @@ -49,13 +49,13 @@ typedef unsigned int uint; #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 @@ -130,7 +130,7 @@ fast_f2nat(float a) return retval; }; #else -#define fast_f2nat(val) ((int)(val)) +# define fast_f2nat(val) ((int)(val)) #endif extern char *path(char *s);