From cac7cebba0bcb1a1d7a112c508377fb50264126d Mon Sep 17 00:00:00 2001 From: Jonathan Schleifer Date: Wed, 5 Mar 2025 21:55:28 +0000 Subject: [PATCH] Clean up console output functions FossilOrigin-Name: 003b06901f169b5d97cbbaa313ad31a2493d2a56b295cffda136500ecc5d4f05 --- src/Cube.mm | 26 +++++++++++++------------- src/client.mm | 32 ++++++++++++++++---------------- src/clientextras.mm | 9 ++++----- src/clientgame.mm | 8 ++++---- src/clients2c.mm | 25 ++++++++++++------------- src/command.mm | 6 +++--- src/console.mm | 39 ++++++++++++++++++++++----------------- src/editing.mm | 18 +++++++++--------- src/entities.mm | 2 +- src/monster.mm | 11 ++++++----- src/protos.h | 4 ++-- src/rendergl.mm | 16 +++++++--------- src/savegamedemo.mm | 6 +++--- src/sound.mm | 3 ++- src/weapon.mm | 2 +- src/world.mm | 6 +++--- 16 files changed, 108 insertions(+), 105 deletions(-) diff --git a/src/Cube.mm b/src/Cube.mm index 0a959d6..5c164fb 100644 --- a/src/Cube.mm +++ b/src/Cube.mm @@ -36,8 +36,8 @@ VARP(minmillis, 0, 5, 1000); 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}, @@ -83,7 +83,7 @@ VARP(minmillis, 0, 5, 1000); 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"); @@ -92,14 +92,14 @@ VARP(minmillis, 0, 5, 1000); 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, @@ -108,15 +108,15 @@ VARP(minmillis, 0, 5, 1000); 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; @@ -157,10 +157,10 @@ VARP(minmillis, 0, 5, 1000); 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"); @@ -172,12 +172,12 @@ VARP(minmillis, 0, 5, 1000); 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; diff --git a/src/client.mm b/src/client.mm index da9060c..1240f15 100644 --- a/src/client.mm +++ b/src/client.mm @@ -85,29 +85,29 @@ writeclientinfo(FILE *f) 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); + 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(); - } + if (clienthost) { + enet_host_connect(clienthost, &address, 1); + enet_host_flush(clienthost); + connecting = lastmillis; + connattempts = 0; + } else { + conoutf(@"could not connect to server"); + disconnect(); } } diff --git a/src/clientextras.mm b/src/clientextras.mm index 72f8ea1..e36edd2 100644 --- a/src/clientextras.mm +++ b/src/clientextras.mm @@ -180,8 +180,7 @@ sendmap(OFString *mapname) 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; } @@ -190,10 +189,10 @@ sendmap(OFString *mapname) *(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); } } diff --git a/src/clientgame.mm b/src/clientgame.mm index 2632e6f..7f782d7 100644 --- a/src/clientgame.mm +++ b/src/clientgame.mm @@ -160,7 +160,7 @@ arenarespawn() arenarespawnwait = 0; conoutf(@"new round starting... fight!"); respawnself(); - }; + } } else if (arenadetectwait == 0 || arenadetectwait < lastmillis) { arenadetectwait = 0; int alive = 0, dead = 0; @@ -302,7 +302,7 @@ entinmap(dynent * 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 @@ -477,9 +477,9 @@ 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()); diff --git a/src/clients2c.mm b/src/clients2c.mm index e9a7e84..676c6f9 100644 --- a/src/clients2c.mm +++ b/src/clients2c.mm @@ -8,9 +8,9 @@ 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(); } @@ -59,7 +59,7 @@ 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; @@ -81,7 +81,7 @@ localservertoclient( PROTOCOL_VERSION, prot); disconnect(); return; - }; + } toservermap = @""; clientnum = cn; // we are now fully connected if (!getint(p)) @@ -94,10 +94,9 @@ localservertoclient( @"to join this server!"); disconnect(); return; - }; - if (getint(p) == 1) { + } + if (getint(p) == 1) conoutf(@"server is FULL, disconnecting.."); - }; break; }; @@ -172,17 +171,17 @@ localservertoclient( // 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); @@ -385,7 +384,7 @@ localservertoclient( } default: - neterr("type"); + neterr(@"type"); return; } } diff --git a/src/command.mm b/src/command.mm index bc7eb25..32c0410 100644 --- a/src/command.mm +++ b/src/command.mm @@ -54,8 +54,8 @@ alias(OFString *name, OFString *action) 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) @@ -577,7 +577,7 @@ exec(OFString *cfgfile) { if (!execfile(cfgfile)) { @autoreleasepool { - conoutf(@"could not read \"%s\"", cfgfile.UTF8String); + conoutf(@"could not read \"%@\"", cfgfile); } } } diff --git a/src/console.mm b/src/console.mm index fc825e4..d19d6bb 100644 --- a/src/console.mm +++ b/src/console.mm @@ -27,8 +27,8 @@ setconskip(int n) } 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 @@ -40,10 +40,10 @@ conline(const char *sf, bool highlight) // add a line to the console buffer { 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); @@ -51,20 +51,25 @@ conline(const char *sf, bool highlight) // add a line to the console buffer } void -conoutf(OFString *str, ...) +conoutf(OFConstantString *format, ...) { - 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; + @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); } - conline(s, n != 0); -}; +} void renderconsole() // render buffer taking into account time & scrolling diff --git a/src/editing.mm b/src/editing.mm index f03bc9f..e063eb6 100644 --- a/src/editing.mm +++ b/src/editing.mm @@ -95,7 +95,7 @@ noteditmode() if (!editmode) conoutf(@"this function is only allowed in edit mode"); return !editmode; -}; +} bool noselection() @@ -103,7 +103,7 @@ noselection() if (!selset) conoutf(@"no selection"); return !selset; -}; +} #define EDITSEL \ if (noteditmode() || noselection()) \ @@ -266,11 +266,11 @@ editundo() if (undos.empty()) { conoutf(@"nothing more to undo"); return; - }; + } block *p = undos.pop(); blockpaste(*p); free(p); -}; +} block *copybuf = NULL; @@ -290,19 +290,19 @@ paste() 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 @@ -447,10 +447,10 @@ edittype(int type) 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) diff --git a/src/entities.mm b/src/entities.mm index 1db9a09..5b44eaa 100644 --- a/src/entities.mm +++ b/src/entities.mm @@ -217,7 +217,7 @@ teleport(int n, dynent *d) // also used by monsters if (e == beenhere || e < 0) { conoutf(@"no teleport destination for tag %d", tag); return; - }; + } if (beenhere < 0) beenhere = e; if (ents[e].attr2 == tag) { diff --git a/src/monster.mm b/src/monster.mm index fa9a959..285ae04 100644 --- a/src/monster.mm +++ b/src/monster.mm @@ -11,12 +11,13 @@ 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 @@ -345,7 +346,7 @@ monsterpain(dynent *m, int damage, dynent *d) conoutf(@"only %d monster(s) remaining", remain); } else { playsound(monstertypes[m->mtype].painsound, &m->o); - }; + } }; void @@ -357,7 +358,7 @@ endsp(bool allkilled) (lastmillis - mtimestart) / 1000); monstertotal = 0; startintermission(); -}; +} void monsterthink() @@ -401,7 +402,7 @@ monsterthink() loopv(monsters) if (monsters[i]->state == CS_ALIVE) monsteraction(monsters[i]); -}; +} void monsterrender() diff --git a/src/protos.h b/src/protos.h index 19e6e02..26e685f 100644 --- a/src/protos.h +++ b/src/protos.h @@ -19,7 +19,7 @@ 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); @@ -78,7 +78,7 @@ 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(); diff --git a/src/rendergl.mm b/src/rendergl.mm index 6e58388..fd91421 100644 --- a/src/rendergl.mm +++ b/src/rendergl.mm @@ -79,8 +79,7 @@ installtex(int tnum, OFIRI *IRI, int *xs, int *ys, bool clamp) 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; } @@ -89,8 +88,8 @@ installtex(int tnum, OFIRI *IRI, int *xs, int *ys, bool clamp) 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; } @@ -99,8 +98,8 @@ installtex(int tnum, OFIRI *IRI, int *xs, int *ys, bool clamp) 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; } @@ -135,9 +134,8 @@ installtex(int tnum, OFIRI *IRI, int *xs, int *ys, bool clamp) 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); diff --git a/src/savegamedemo.mm b/src/savegamedemo.mm index 6fc28a9..0ee757a 100644 --- a/src/savegamedemo.mm +++ b/src/savegamedemo.mm @@ -95,7 +95,7 @@ savestate(char *fn) if (!f) { conoutf(@"could not write %s", fn); return; - }; + } gzwrite(f, (void *)"CUBESAVE", 8); gzputc(f, islittleendian); gzputi(SAVEGAMEVERSION); @@ -186,7 +186,7 @@ loadgameout() stop(); conoutf(@"loadgame incomplete: savegame from a different version of " @"this map"); -}; +} void loadgamerest() @@ -237,7 +237,7 @@ loadgamerest() startdemo(); else stop(); -}; +} // demo functions diff --git a/src/sound.mm b/src/sound.mm index 39fb738..445d97e 100644 --- a/src/sound.mm +++ b/src/sound.mm @@ -113,7 +113,8 @@ music(OFString *name) FSOUND_SetPaused(chan, false); } } else { - conoutf(@"could not play music: %s", sn); + conoutf( + @"could not play music: %@", IRI.string); } #endif } diff --git a/src/weapon.mm b/src/weapon.mm index ee1b193..546d0a2 100644 --- a/src/weapon.mm +++ b/src/weapon.mm @@ -50,7 +50,7 @@ selectgun(int a, int b, int c) 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 diff --git a/src/world.mm b/src/world.mm index edc0ac2..e56137a 100644 --- a/src/world.mm +++ b/src/world.mm @@ -306,10 +306,10 @@ delent() 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); @@ -322,7 +322,7 @@ 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; } }