Index: src/Cube.mm ================================================================== --- src/Cube.mm +++ src/Cube.mm @@ -34,12 +34,12 @@ OFString *__autoreleasing sdesc, *__autoreleasing ip; OFString *__autoreleasing master, *__autoreleasing passwd; processInitQueue(); -#define log(s) conoutf(@"init: %s", s) - log("sdl"); +#define log(s) conoutf(@"init: %@", s) + log(@"sdl"); const OFOptionsParserOption options[] = { {'d', @"dedicated", 0, &dedicated, NULL}, {'t', @"window", 0, &windowed, NULL}, {'w', @"width", 1, NULL, NULL}, {'h', @"height", 1, NULL, NULL}, @@ -81,44 +81,44 @@ passwd = @""; if (SDL_Init(SDL_INIT_TIMER | SDL_INIT_VIDEO | par) < 0) fatal(@"Unable to initialize SDL"); - log("net"); + log(@"net"); if (enet_initialize() < 0) fatal(@"Unable to initialise network module"); initclient(); // never returns if dedicated initserver(dedicated, uprate, sdesc.UTF8String, ip.UTF8String, master.UTF8String, passwd, maxcl); - log("world"); + log(@"world"); empty_world(7, true); - log("video: sdl"); + log(@"video: sdl"); if (SDL_InitSubSystem(SDL_INIT_VIDEO) < 0) fatal(@"Unable to initialize SDL Video"); - log("video: mode"); + log(@"video: mode"); SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); if ((_window = SDL_CreateWindow("cube engine", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, _width, _height, SDL_WINDOW_SHOWN | SDL_WINDOW_OPENGL | (!windowed ? SDL_WINDOW_FULLSCREEN : 0))) == NULL || SDL_GL_CreateContext(_window) == NULL) fatal(@"Unable to create OpenGL screen"); - log("video: misc"); + log(@"video: misc"); SDL_SetWindowGrab(_window, SDL_TRUE); SDL_SetRelativeMouseMode(SDL_TRUE); SDL_ShowCursor(0); - log("gl"); + log(@"gl"); gl_init(_width, _height); - log("basetex"); + log(@"basetex"); _gameDataIRI = [OFFileManager.defaultManager currentDirectoryIRI]; _userDataIRI = [OFFileManager.defaultManager currentDirectoryIRI]; int xs, ys; if (!installtex(2, [_userDataIRI IRIByAppendingPathComponent:@"data/newchars.png"], @@ -155,14 +155,14 @@ IRIByAppendingPathComponent:@"data/crosshair.png"], &xs, &ys, false)) fatal(@"could not find core textures (hint: run cube from the " @"parent of the bin directory)"); - log("sound"); + log(@"sound"); initsound(); - log("cfg"); + log(@"cfg"); newmenu(@"frags\tpj\tping\tteam\tname"); newmenu(@"ping\tplr\tserver"); exec(@"data/keymap.cfg"); exec(@"data/menus.cfg"); exec(@"data/prefabs.cfg"); @@ -170,16 +170,16 @@ exec(@"servers.cfg"); if (!execfile(@"config.cfg")) execfile(@"data/defaults.cfg"); exec(@"autoexec.cfg"); - log("localconnect"); + log(@"localconnect"); localconnect(); // if this map is changed, also change depthcorrect() changemap(@"metl3"); - log("mainloop"); + log(@"mainloop"); int ignore = 5; for (;;) { int millis = SDL_GetTicks() * gamespeed / 100; if (millis - lastmillis > 200) lastmillis = millis - 200; Index: src/client.mm ================================================================== --- src/client.mm +++ src/client.mm @@ -83,33 +83,33 @@ } void connects(OFString *servername) { - @autoreleasepool { - disconnect(1); // reset state - addserver(servername); + disconnect(1); // reset state + addserver(servername); - conoutf(@"attempting to connect to %s", servername.UTF8String); - ENetAddress address = {ENET_HOST_ANY, CUBE_SERVER_PORT}; + conoutf(@"attempting to connect to %@", servername); + ENetAddress address = {ENET_HOST_ANY, CUBE_SERVER_PORT}; + @autoreleasepool { if (enet_address_set_host(&address, servername.UTF8String) < 0) { - conoutf(@"could not resolve server %s", servername); + conoutf(@"could not resolve server %@", servername); return; } - - clienthost = enet_host_create(NULL, 1, rate, rate); - - if (clienthost) { - enet_host_connect(clienthost, &address, 1); - enet_host_flush(clienthost); - connecting = lastmillis; - connattempts = 0; - } else { - conoutf(@"could not connect to server"); - disconnect(); - } + } + + clienthost = enet_host_create(NULL, 1, rate, rate); + + if (clienthost) { + enet_host_connect(clienthost, &address, 1); + enet_host_flush(clienthost); + connecting = lastmillis; + connattempts = 0; + } else { + conoutf(@"could not connect to server"); + disconnect(); } } void disconnect(int onlyclean, int async) Index: src/clientextras.mm ================================================================== --- src/clientextras.mm +++ src/clientextras.mm @@ -178,24 +178,23 @@ uchar *p = start + 2; putint(p, SV_SENDMAP); sendstring(mapname.UTF8String, p); putint(p, mapsize); if (65535 - (p - start) < mapdata.count) { - conoutf( - @"map %s is too large to send", mapname.UTF8String); + conoutf(@"map %@ is too large to send", mapname); enet_packet_destroy(packet); return; } memcpy(p, mapdata.items, mapdata.count); p += mapsize; *(ushort *)start = ENET_HOST_TO_NET_16(p - start); enet_packet_resize(packet, p - start); sendpackettoserv(packet); - conoutf(@"sending map %s to server...", mapname.UTF8String); + conoutf(@"sending map %@ to server...", mapname); sprintf_sd(msg)( - "[map %s uploaded to server, \"getmap\" to receive it]", - mapname.UTF8String); + "[map %@ uploaded to server, \"getmap\" to receive it]", + mapname); toserver(msg); } } void Index: src/clientgame.mm ================================================================== --- src/clientgame.mm +++ src/clientgame.mm @@ -158,11 +158,11 @@ if (arenarespawnwait) { if (arenarespawnwait < lastmillis) { arenarespawnwait = 0; conoutf(@"new round starting... fight!"); respawnself(); - }; + } } else if (arenadetectwait == 0 || arenadetectwait < lastmillis) { arenadetectwait = 0; int alive = 0, dead = 0; char *lastteam = NULL; bool oneteam = true; @@ -300,11 +300,11 @@ d->o.y += dy; if (collide(d, true, 0, 0)) return; d->o.x -= dx; d->o.y -= dy; - }; + } conoutf(@"can't find entity spawn spot! (%d, %d)", (int)d->o.x, (int)d->o.y); // leave ent at original pos, possibly stuck }; @@ -475,13 +475,13 @@ dynent * getclient(int cn) // ensure valid entity { if (cn < 0 || cn >= MAXCLIENTS) { - neterr("clientnum"); + neterr(@"clientnum"); return NULL; - }; + } while (cn >= players.length()) players.add(NULL); return players[cn] ? players[cn] : (players[cn] = newdynent()); } Index: src/clients2c.mm ================================================================== --- src/clients2c.mm +++ src/clients2c.mm @@ -6,13 +6,13 @@ extern bool c2sinit, senditemstoserver; extern OFString *toservermap; extern string clientpassword; void -neterr(char *s) +neterr(OFString *s) { - conoutf(@"illegal network message (%s)", s); + conoutf(@"illegal network message (%@)", s); disconnect(); } void changemapserv(char *name, int mode) // forced map change from the server @@ -57,11 +57,11 @@ void localservertoclient( uchar *buf, int len) // processes any updates from the server { if (ENET_NET_TO_HOST_16(*(ushort *)buf) != len) - neterr("packet length"); + neterr(@"packet length"); incomingdemodata(buf, len); uchar *end = buf + len; uchar *p = buf + 2; char text[MAXTRANS]; @@ -79,11 +79,11 @@ conoutf(@"you are using a different game " @"protocol (you: %d, server: %d)", PROTOCOL_VERSION, prot); disconnect(); return; - }; + } toservermap = @""; clientnum = cn; // we are now fully connected if (!getint(p)) // we are the first client on this server, set // map @@ -92,14 +92,13 @@ if (text[0] && strcmp(text, clientpassword)) { conoutf(@"you need to set the correct password " @"to join this server!"); disconnect(); return; - }; - if (getint(p) == 1) { + } + if (getint(p) == 1) conoutf(@"server is FULL, disconnecting.."); - }; break; }; case SV_POS: // position of another client { @@ -170,21 +169,21 @@ case SV_INITC2S: // another client either connected or changed // name/team { sgetstr(); - if (d->name[0]) // already connected - { + if (d->name[0]) { + // already connected if (strcmp(d->name, text)) conoutf(@"%s is now known as %s", d->name, text); - } else // new client - { + } else { + // new client c2sinit = false; // send new players my info again conoutf(@"connected: %s", text); - }; + } strcpy_s(d->name, text); sgetstr(); strcpy_s(d->team, text); d->lifesequence = getint(p); break; @@ -383,9 +382,9 @@ getint(p); break; } default: - neterr("type"); + neterr(@"type"); return; } } Index: src/command.mm ================================================================== --- src/command.mm +++ src/command.mm @@ -52,12 +52,12 @@ idents[b.name] = b; } else { if (b.type == ID_ALIAS) b.action = action; else - conoutf(@"cannot redefine builtin %s with an alias", - name.UTF8String); + conoutf( + @"cannot redefine builtin %@ with an alias", name); } } COMMAND(alias, ARG_2STR) int @@ -575,11 +575,11 @@ void exec(OFString *cfgfile) { if (!execfile(cfgfile)) { @autoreleasepool { - conoutf(@"could not read \"%s\"", cfgfile.UTF8String); + conoutf(@"could not read \"%@\"", cfgfile); } } } void Index: src/console.mm ================================================================== --- src/console.mm +++ src/console.mm @@ -25,12 +25,12 @@ if (conskip < 0) conskip = 0; } COMMANDN(conskip, setconskip, ARG_1INT) -void -conline(const char *sf, bool highlight) // add a line to the console buffer +static void +conline(OFString *sf, bool highlight) // add a line to the console buffer { cline cl; cl.cref = conlines.length() > 100 ? conlines.pop().cref : newstringbuf(""); // constrain the buffer size @@ -38,35 +38,40 @@ conlines.insert(0, cl); if (highlight) // show line in a different colour, for chat etc. { cl.cref[0] = '\f'; cl.cref[1] = 0; - strcat_s(cl.cref, sf); + strcat_s(cl.cref, sf.UTF8String); } else { - strcpy_s(cl.cref, sf); - }; + strcpy_s(cl.cref, sf.UTF8String); + } puts(cl.cref); #ifndef OF_WINDOWS fflush(stdout); #endif } void -conoutf(OFString *str, ...) -{ - sprintf_sdv(sf, str.UTF8String); - const char *s = sf; - int n = 0; - while (strlen(s) > WORDWRAP) // cut strings to fit on screen - { - string t; - strn0cpy(t, s, WORDWRAP + 1); - conline(t, n++ != 0); - s += WORDWRAP; - } - conline(s, n != 0); -}; +conoutf(OFConstantString *format, ...) +{ + @autoreleasepool { + va_list arguments; + va_start(arguments, format); + + OFString *string = [[OFString alloc] initWithFormat:format + arguments:arguments]; + + va_end(arguments); + + int n = 0; + while (string.length > WORDWRAP) { + conline([string substringToIndex:WORDWRAP], n++ != 0); + string = [string substringFromIndex:WORDWRAP]; + } + conline(string, n != 0); + } +} void renderconsole() // render buffer taking into account time & scrolling { int nd = 0; Index: src/editing.mm ================================================================== --- src/editing.mm +++ src/editing.mm @@ -93,19 +93,19 @@ { correctsel(); if (!editmode) conoutf(@"this function is only allowed in edit mode"); return !editmode; -}; +} bool noselection() { if (!selset) conoutf(@"no selection"); return !selset; -}; +} #define EDITSEL \ if (noteditmode() || noselection()) \ return; #define EDITSELMP \ @@ -264,15 +264,15 @@ { EDITMP; if (undos.empty()) { conoutf(@"nothing more to undo"); return; - }; + } block *p = undos.pop(); blockpaste(*p); free(p); -}; +} block *copybuf = NULL; void copy() @@ -288,23 +288,23 @@ { EDITMP; if (!copybuf) { conoutf(@"nothing to paste"); return; - }; + } sel.xs = copybuf->xs; sel.ys = copybuf->ys; correctsel(); if (!selset || sel.xs != copybuf->xs || sel.ys != copybuf->ys) { conoutf(@"incorrect selection"); return; - }; + } makeundo(); copybuf->x = sel.x; copybuf->y = sel.y; blockpaste(*copybuf); -}; +} void tofronttex() // maintain most recently used of the texture lists when applying // texture { @@ -445,14 +445,14 @@ if (type == CORNER && (sel.xs != sel.ys || sel.xs == 3 || sel.xs > 4 && sel.xs != 8 || sel.x & ~-sel.xs || sel.y & ~-sel.ys)) { conoutf(@"corner selection must be power of 2 aligned"); return; - }; + } edittypexy(type, sel); addmsg(1, 6, SV_EDITS, sel.x, sel.y, sel.xs, sel.ys, type); -}; +} void heightfield(int t) { edittype(t == 0 ? FHF : CHF); Index: src/entities.mm ================================================================== --- src/entities.mm +++ src/entities.mm @@ -215,11 +215,11 @@ for (;;) { e = findentity(TELEDEST, e + 1); if (e == beenhere || e < 0) { conoutf(@"no teleport destination for tag %d", tag); return; - }; + } if (beenhere < 0) beenhere = e; if (ents[e].attr2 == tag) { d->o.x = ents[e].x; d->o.y = ents[e].y; Index: src/monster.mm ================================================================== --- src/monster.mm +++ src/monster.mm @@ -9,16 +9,17 @@ dvector & getmonsters() { return monsters; -}; +} + void restoremonsterstate() { loopv(monsters) if (monsters[i]->state == CS_DEAD) numkilled++; -}; // for savegames +} // for savegames #define TOTMFREQ 13 #define NUMMONSTERTYPES 8 struct monstertype // see docs for how these values modify behaviour @@ -343,11 +344,11 @@ int remain = monstertotal - numkilled; if (remain > 0 && remain <= 5) conoutf(@"only %d monster(s) remaining", remain); } else { playsound(monstertypes[m->mtype].painsound, &m->o); - }; + } }; void endsp(bool allkilled) { @@ -355,11 +356,11 @@ : @"you reached the exit!"); conoutf(@"score: %d kills in %d seconds", numkilled, (lastmillis - mtimestart) / 1000); monstertotal = 0; startintermission(); -}; +} void monsterthink() { if (m_dmsp && spawnremain && lastmillis > nextmonster) { @@ -399,14 +400,14 @@ }; }; loopv(monsters) if (monsters[i]->state == CS_ALIVE) monsteraction(monsters[i]); -}; +} void monsterrender() { loopv(monsters) renderclient(monsters[i], false, monstertypes[monsters[i]->mtype].mdlname, monsters[i]->mtype == 5, monstertypes[monsters[i]->mtype].mscale / 10.0f); } Index: src/protos.h ================================================================== --- src/protos.h +++ src/protos.h @@ -17,11 +17,11 @@ extern void writecfg(); // console extern void keypress(int code, bool isdown, int cooked); extern void renderconsole(); -extern void conoutf(OFString *s, ...); +extern void conoutf(OFConstantString *format, ...); extern char *getcurcommand(); extern void writebinds(FILE *f); // init extern void enqueueInit(void (^init)(void)); @@ -76,11 +76,11 @@ extern bool multiplayer(); extern bool allowedittoggle(); extern void sendpackettoserv(void *packet); extern void gets2c(); extern void c2sinfo(dynent *d); -extern void neterr(char *s); +extern void neterr(OFString *s); extern void initclientnet(); extern bool netmapstart(); extern int getclientnum(); extern void changemapserv(char *name, int mode); extern void writeclientinfo(FILE *f); Index: src/rendergl.mm ================================================================== --- src/rendergl.mm +++ src/rendergl.mm @@ -77,32 +77,31 @@ { @autoreleasepool { SDL_Surface *s = IMG_Load(IRI.fileSystemRepresentation.UTF8String); if (s == NULL) { - conoutf( - @"couldn't load texture %s", IRI.string.UTF8String); + conoutf(@"couldn't load texture %@", IRI.string); return false; } if (s->format->BitsPerPixel != 24) { SDL_PixelFormat *format = SDL_AllocFormat(SDL_PIXELFORMAT_RGB24); if (format == NULL) { conoutf( - @"texture cannot be converted to 24bpp: %s", - IRI.string.UTF8String); + @"texture cannot be converted to 24bpp: %@", + IRI.string); return false; } @try { SDL_Surface *converted = SDL_ConvertSurface(s, format, 0); if (converted == NULL) { conoutf(@"texture cannot be converted " - @"to 24bpp: %s", - IRI.string.UTF8String); + @"to 24bpp: %@", + IRI.string); return false; } SDL_FreeSurface(s); s = converted; @@ -133,13 +132,12 @@ } void *scaledimg = s->pixels; if (*xs != s->w) { - conoutf(@"warning: quality loss: scaling %s", - IRI.string - .UTF8String); // for voodoo cards under linux + conoutf(@"warning: quality loss: scaling %@", + IRI.string); // for voodoo cards under linux scaledimg = alloc(*xs * *ys * 3); gluScaleImage(GL_RGB, s->w, s->h, GL_UNSIGNED_BYTE, s->pixels, *xs, *ys, GL_UNSIGNED_BYTE, scaledimg); } Index: src/savegamedemo.mm ================================================================== --- src/savegamedemo.mm +++ src/savegamedemo.mm @@ -93,11 +93,11 @@ stop(); f = gzopen(fn, "wb9"); if (!f) { conoutf(@"could not write %s", fn); return; - }; + } gzwrite(f, (void *)"CUBESAVE", 8); gzputc(f, islittleendian); gzputi(SAVEGAMEVERSION); gzputi(sizeof(dynent)); @autoreleasepool { @@ -184,11 +184,11 @@ loadgameout() { stop(); conoutf(@"loadgame incomplete: savegame from a different version of " @"this map"); -}; +} void loadgamerest() { if (demoplayback || !f) @@ -235,11 +235,11 @@ conoutf(@"savegame restored"); if (demoloading) startdemo(); else stop(); -}; +} // demo functions int starttime = 0; int playbacktime = 0; Index: src/sound.mm ================================================================== --- src/sound.mm +++ src/sound.mm @@ -111,11 +111,12 @@ FSOUND_SetVolume( chan, (musicvol * MAXVOL) / 255); FSOUND_SetPaused(chan, false); } } else { - conoutf(@"could not play music: %s", sn); + conoutf( + @"could not play music: %@", IRI.string); } #endif } } } Index: src/weapon.mm ================================================================== --- src/weapon.mm +++ src/weapon.mm @@ -48,11 +48,11 @@ else s = GUN_FIST; if (s != player1->gunselect) playsoundc(S_WEAPLOAD); player1->gunselect = s; - // conoutf(@"%s selected", (int)guns[s].name.UTF8String); + // conoutf(@"%@ selected", (int)guns[s].name); } int reloadtime(int gun) { Index: src/world.mm ================================================================== --- src/world.mm +++ src/world.mm @@ -304,14 +304,14 @@ { int e = closestent(); if (e < 0) { conoutf(@"no more entities"); return; - }; + } int t = ents[e].type; @autoreleasepool { - conoutf(@"%s entity deleted", entnames[t].UTF8String); + conoutf(@"%@ entity deleted", entnames[t]); } ents[e].type = NOTUSED; addmsg(1, 10, SV_EDITENT, e, NOTUSED, 0, 0, 0, 0, 0, 0, 0); if (t == LIGHT) calclight(); @@ -320,11 +320,11 @@ int findtype(OFString *what) { @autoreleasepool { loopi(MAXENTTYPES) if ([what isEqual:entnames[i]]) return i; - conoutf(@"unknown entity type \"%s\"", what.UTF8String); + conoutf(@"unknown entity type \"%@\"", what); return NOTUSED; } } entity *