Index: src/Cube.mm ================================================================== --- src/Cube.mm +++ src/Cube.mm @@ -33,24 +33,26 @@ writeservercfg(); [OFApplication.sharedApplication terminateWithStatus:0]; } void -fatal(char *s, char *o) // failure exit +fatal(OFString *s, OFString *o) // failure exit { - sprintf_sd(msg)("%s%s (%s)\n", s, o, SDL_GetError()); + OFString *msg = + [OFString stringWithFormat:@"%@%@ (%s)\n", s, o, SDL_GetError()]; + OFApplication *app = OFApplication.sharedApplication; - [(Cube *)app.delegate showMessage:@(msg)]; + [(Cube *)app.delegate showMessage:msg]; [app terminateWithStatus:1]; } void * alloc(int s) // for some big chunks... most other allocs use the memory pool { void *b = calloc(1, s); if (!b) - fatal("out of memory!"); + fatal(@"out of memory!"); return b; } int scr_w = 640; int scr_h = 480; @@ -149,15 +151,15 @@ ip = @""; if (passwd == nil) passwd = @""; if (SDL_Init(SDL_INIT_TIMER | SDL_INIT_VIDEO | par) < 0) - fatal("Unable to initialize SDL"); + fatal(@"Unable to initialize SDL"); log("net"); if (enet_initialize() < 0) - fatal("Unable to initialise network module"); + fatal(@"Unable to initialise network module"); initclient(); // never returns if dedicated initserver(dedicated, uprate, sdesc.UTF8String, ip.UTF8String, master.UTF8String, passwd, maxcl); @@ -165,17 +167,17 @@ log("world"); empty_world(7, true); log("video: sdl"); if (SDL_InitSubSystem(SDL_INIT_VIDEO) < 0) - fatal("Unable to initialize SDL Video"); + 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 | (!windowed ? SDL_FULLSCREEN : 0)) == NULL) - fatal("Unable to create OpenGL screen"); + fatal(@"Unable to create OpenGL screen"); log("video: misc"); SDL_WM_SetCaption("cube engine", NULL); SDL_WM_GrabInput(SDL_GRAB_ON); keyrepeat(false); @@ -193,12 +195,12 @@ !installtex(8, path(newstring("data/martin/ball2.png")), xs, ys) || !installtex(9, path(newstring("data/martin/ball3.png")), xs, ys) || !installtex(4, path(newstring("data/explosion.jpg")), xs, ys) || !installtex(5, path(newstring("data/items.png")), xs, ys) || !installtex(1, path(newstring("data/crosshair.png")), xs, ys)) - fatal("could not find core textures (hint: run cube from the " - "parent of the bin directory)"); + fatal(@"could not find core textures (hint: run cube from the " + @"parent of the bin directory)"); log("sound"); initsound(); log("cfg"); Index: src/client.mm ================================================================== --- src/client.mm +++ src/client.mm @@ -190,18 +190,18 @@ addmsg(int rel, int num, int type, ...) { if (demoplayback) return; if (num != msgsizelookup(type)) { - sprintf_sd(s)("inconsistant msg size for %d (%d != %d)", type, - num, msgsizelookup(type)); - fatal(s); - }; + fatal([OFString + stringWithFormat:@"inconsistant msg size for %d (%d != %d)", + type, num, msgsizelookup(type)]); + } if (messages.length() == 100) { conoutf(@"command flood protection (type %d)", type); return; - }; + } ivector &msg = messages.add(); msg.add(num); msg.add(rel); msg.add(type); va_list marker; Index: src/protos.h ================================================================== --- src/protos.h +++ src/protos.h @@ -138,11 +138,11 @@ // worldocull extern void computeraytable(float vx, float vy); extern int isoccluded(float vx, float vy, float cx, float cy, float csize); // main -extern void fatal(char *s, char *o = ""); +extern void fatal(OFString *s, OFString *o = @""); extern void *alloc(int s); extern void keyrepeat(bool on); // rendertext extern void draw_text(char *str, int left, int top, int gl_num); Index: src/rendercubes.mm ================================================================== --- src/rendercubes.mm +++ src/rendercubes.mm @@ -11,21 +11,21 @@ setarraypointers() { glVertexPointer(3, GL_FLOAT, sizeof(vertex), &verts[0].x); glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(vertex), &verts[0].r); glTexCoordPointer(2, GL_FLOAT, sizeof(vertex), &verts[0].u); -}; +} void reallocv() { verts = (vertex *)realloc(verts, (curmaxverts *= 2) * sizeof(vertex)); curmaxverts -= 10; if (!verts) - fatal("no vertex memory!"); + fatal(@"no vertex memory!"); setarraypointers(); -}; +} // generating the actual vertices is done dynamically every frame and sits at // the leaves of all these functions, and are part of the cpu bottleneck on // really slow machines, hence the macros. Index: src/rendergl.mm ================================================================== --- src/rendergl.mm +++ src/rendergl.mm @@ -54,11 +54,11 @@ glGetIntegerv(GL_MAX_TEXTURE_SIZE, &glmaxtexsize); purgetextures(); if (!(qsphere = gluNewQuadric())) - fatal("glu sphere"); + fatal(@"glu sphere"); gluQuadricDrawStyle(qsphere, GLU_FILL); gluQuadricOrientation(qsphere, GLU_INSIDE); gluQuadricTexture(qsphere, GL_TRUE); glNewList(1, GL_COMPILE); gluSphere(qsphere, 1, 12, 6); @@ -109,11 +109,11 @@ gluScaleImage(GL_RGB, s->w, s->h, GL_UNSIGNED_BYTE, s->pixels, xs, ys, GL_UNSIGNED_BYTE, scaledimg); }; if (gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB, xs, ys, GL_RGB, GL_UNSIGNED_BYTE, scaledimg)) - fatal("could not build mipmaps"); + fatal(@"could not build mipmaps"); if (xs != s->w) free(scaledimg); SDL_FreeSurface(s); return true; }; @@ -189,11 +189,11 @@ return tid; }; }; if (curtex == MAXTEX) - fatal("loaded too many textures"); + fatal(@"loaded too many textures"); int tnum = curtex + FIRSTTEX; strcpy_s(texname[curtex], mapname[tex][frame]); sprintf_sd(name)("packages%c%s", PATHDIV, texname[curtex]); Index: src/rendermd2.mm ================================================================== --- src/rendermd2.mm +++ src/rendermd2.mm @@ -236,11 +236,11 @@ if (!m.loaded) { @autoreleasepool { sprintf_sd(name1)("packages/models/%s/tris.md2", m.loadname.UTF8String); if (![m loadWithPath:path(name1)]) - fatal("loadmodel: ", name1); + fatal(@"loadmodel: ", @(name1)); sprintf_sd(name2)("packages/models/%s/skin.jpg", m.loadname.UTF8String); int xs, ys; installtex(FIRSTMDL + m.mdlnum, path(name2), xs, ys); m.loaded = true; Index: src/savegamedemo.mm ================================================================== --- src/savegamedemo.mm +++ src/savegamedemo.mm @@ -38,11 +38,11 @@ void gzcheck(int a, int b) { if (a != b) - fatal("savegame file corrupt (short)"); + fatal(@"savegame file corrupt (short)"); } int gzget() { Index: src/server.mm ================================================================== --- src/server.mm +++ src/server.mm @@ -521,13 +521,13 @@ ENetAddress address = {ENET_HOST_ANY, CUBE_SERVER_PORT}; if (*ip && enet_address_set_host(&address, ip) < 0) printf("WARNING: server ip not resolved"); serverhost = enet_host_create(&address, MAXCLIENTS, 0, uprate); if (!serverhost) - fatal("could not create server host\n"); + fatal(@"could not create server host\n"); loopi(MAXCLIENTS) serverhost->peers[i].data = (void *)-1; - }; + } resetserverifempty(); if (isdedicated) // do not return, this becomes main loop { Index: src/serverms.mm ================================================================== --- src/serverms.mm +++ src/serverms.mm @@ -141,12 +141,12 @@ strcat_s(mname, smapname); sendstring(mname, p); sendstring(serverdesc, p); buf.dataLength = p - pong; enet_socket_send(pongsock, &addr, &buf, 1); - }; -}; + } +} void servermsinit(const char *master, const char *sdesc, bool listen) { const char *mid = strstr(master, "/"); @@ -159,8 +159,8 @@ if (listen) { ENetAddress address = {ENET_HOST_ANY, CUBE_SERVINFO_PORT}; pongsock = enet_socket_create(ENET_SOCKET_TYPE_DATAGRAM, &address); if (pongsock == ENET_SOCKET_NULL) - fatal("could not create server info socket\n"); - }; -}; + fatal(@"could not create server info socket\n"); + } +} Index: src/serverutil.mm ================================================================== --- src/serverutil.mm +++ src/serverutil.mm @@ -130,26 +130,31 @@ return packet; } #ifdef STANDALONE -void localservertoclient(uchar *buf, int len) {}; +void +localservertoclient(uchar *buf, int len) +{ +} + void -fatal(char *s, char *o) +fatal(OFString *s, OFString *o) { cleanupserver(); - printf("servererror: %s\n", s); + [OFStdOut writeFormat:@"servererror: %@\n", s]; exit(1); -}; +} + void * alloc(int s) { void *b = calloc(1, s); if (!b) - fatal("no memory!"); + fatal(@"no memory!"); return b; -}; +} int main(int argc, char *argv[]) { int uprate = 0, maxcl = 4; @@ -181,10 +186,10 @@ printf("WARNING: unknown commandline option\n"); }; }; if (enet_initialize() < 0) - fatal("Unable to initialise network module"); + fatal(@"Unable to initialise network module"); initserver(true, uprate, sdesc, ip, master, @(passwd), maxcl); return 0; } #endif Index: src/sound.mm ================================================================== --- src/sound.mm +++ src/sound.mm @@ -68,11 +68,11 @@ nosound = true; }; Mix_AllocateChannels(MAXCHAN); #else if (FSOUND_GetVersion() < FMOD_VERSION) - fatal("old FMOD dll"); + fatal(@"old FMOD dll"); if (!FSOUND_Init(SOUNDFREQ, MAXCHAN, FSOUND_INIT_GLOBALFOCUS)) { conoutf(@"sound init failed (FMOD): %d", FSOUND_GetError()); nosound = true; } #endif Index: src/worldio.mm ================================================================== --- src/worldio.mm +++ src/worldio.mm @@ -260,15 +260,15 @@ return; } gzread(f, &hdr, sizeof(header) - sizeof(int) * 16); endianswap(&hdr.version, sizeof(int), 4); if (strncmp(hdr.head, "CUBE", 4) != 0) - fatal("while reading map: header malformatted"); + fatal(@"while reading map: header malformatted"); if (hdr.version > MAPVERSION) - fatal("this map requires a newer version of cube"); + fatal(@"this map requires a newer version of cube"); if (sfactor < SMALLEST_FACTOR || sfactor > LARGEST_FACTOR) - fatal("illegal map size"); + fatal(@"illegal map size"); if (hdr.version >= 4) { gzread(f, &hdr.waterlevel, sizeof(int) * 16); endianswap(&hdr.waterlevel, sizeof(int), 16); } else { hdr.waterlevel = -100000; @@ -327,12 +327,13 @@ s->ceil = 16; break; } default: { if (type < 0 || type >= MAXTYPE) { - sprintf_sd(t)("%d @ %d", type, k); - fatal("while reading map: type out of range: ", + OFString *t = [OFString + stringWithFormat:@"%d @ %d", type, k]; + fatal(@"while reading map: type out of range: ", t); } s->type = type; s->floor = gzgetc(f); s->ceil = gzgetc(f);