Index: src/Command.mm ================================================================== --- src/Command.mm +++ src/Command.mm @@ -122,18 +122,19 @@ break; case ARG_1EXP: if (isDown) { arguments = padArguments(arguments, 2); return ((int(__cdecl *)(int))_function)( - execute(arguments[1])); + execute(arguments[1], isDown)); } break; case ARG_2EXP: if (isDown) { arguments = padArguments(arguments, 3); return ((int(__cdecl *)(int, int))_function)( - execute(arguments[1]), execute(arguments[2])); + execute(arguments[1], isDown), + execute(arguments[2], isDown)); } break; case ARG_1EST: if (isDown) { arguments = padArguments(arguments, 2); Index: src/Cube.mm ================================================================== --- src/Cube.mm +++ src/Cube.mm @@ -294,11 +294,11 @@ } - (void)applicationWillTerminate:(OFNotification *)notification { stop(); - disconnect(true); + disconnect(true, false); writecfg(); cleangl(); cleansound(); cleanupserver(); SDL_ShowCursor(1); @@ -355,15 +355,21 @@ writeservercfg(); [OFApplication terminateWithStatus:0]; } @end +// failure exit void -fatal(OFString *s, OFString *o) // failure exit +fatal(OFConstantString *s, ...) { - OFString *msg = - [OFString stringWithFormat:@"%@%@ (%s)\n", s, o, SDL_GetError()]; + va_list args; + va_start(args, s); + OFMutableString *msg = [[OFMutableString alloc] initWithFormat:s + arguments:args]; + va_end(args); + + [msg appendFormat:@" (%s)\n", SDL_GetError()]; [Cube.sharedInstance showMessage:msg]; [OFApplication terminateWithStatus:1]; } Index: src/clientgame.mm ================================================================== --- src/clientgame.mm +++ src/clientgame.mm @@ -249,11 +249,11 @@ { if (lastmillis) { curtime = millis - lastmillis; if (sleepwait && lastmillis > sleepwait) { sleepwait = 0; - execute(sleepcmd); + execute(sleepcmd, true); } physicsframe(); checkquad(curtime); if (m_arena) arenarespawn(); @@ -443,15 +443,15 @@ player1.lifesequence++; player1.attacking = false; player1.state = CS_DEAD; player1.pitch = 0; player1.roll = 60; - playsound(S_DIE1 + rnd(2)); + playsound(S_DIE1 + rnd(2), NULL); spawnstate(player1); player1.lastaction = lastmillis; } else - playsound(S_PAIN6); + playsound(S_PAIN6, NULL); } void timeupdate(int timeremain) { Index: src/clients.mm ================================================================== --- src/clients.mm +++ src/clients.mm @@ -92,11 +92,11 @@ } void connects(OFString *servername) { - disconnect(1); // reset state + disconnect(true, false); // reset state addserver(servername); conoutf(@"attempting to connect to %@", servername); ENetAddress address = { ENET_HOST_ANY, CUBE_SERVER_PORT }; if (enet_address_set_host(&address, servername.UTF8String) < 0) { @@ -111,16 +111,16 @@ enet_host_flush(clienthost); connecting = lastmillis; connattempts = 0; } else { conoutf(@"could not connect to server"); - disconnect(); + disconnect(false, false); } } void -disconnect(int onlyclean, int async) +disconnect(bool onlyclean, bool async) { if (clienthost) { if (!connecting && !disconnecting) { enet_peer_disconnect(clienthost->peers); enet_host_flush(clienthost); @@ -160,11 +160,11 @@ conoutf(@"not connected"); return; } if (connecting) { conoutf(@"aborting connection attempt"); - disconnect(); + disconnect(false, false); return; } conoutf(@"attempting to disconnect..."); disconnect(0, !disconnecting); } @@ -231,11 +231,11 @@ void server_err() { conoutf(@"server network error, disconnecting..."); - disconnect(); + disconnect(false, false); } int lastupdate = 0, lastping = 0; OFString *toservermap; bool senditemstoserver = @@ -380,11 +380,11 @@ conoutf(@"attempting to connect..."); connecting = lastmillis; ++connattempts; if (connattempts > 3) { conoutf(@"could not connect to server"); - disconnect(); + disconnect(false, false); return; } } while ( clienthost != NULL && enet_host_service(clienthost, &event, 0) > 0) @@ -404,11 +404,11 @@ enet_packet_destroy(event.packet); break; case ENET_EVENT_TYPE_DISCONNECT: if (disconnecting) - disconnect(); + disconnect(false, false); else server_err(); return; } } Index: src/clients2c.mm ================================================================== --- src/clients2c.mm +++ src/clients2c.mm @@ -12,11 +12,11 @@ void neterr(OFString *s) { conoutf(@"illegal network message (%@)", s); - disconnect(); + disconnect(false, false); } void changemapserv(OFString *name, int mode) // forced map change from the server { @@ -65,11 +65,11 @@ void localservertoclient(uchar *buf, int len) { if (ENET_NET_TO_HOST_16(*(ushort *)buf) != len) neterr(@"packet length"); - incomingdemodata(buf, len); + incomingdemodata(buf, len, false); uchar *end = buf + len; uchar *p = buf + 2; char text[MAXTRANS]; int cn = -1, type; @@ -84,11 +84,11 @@ int prot = getint(&p); if (prot != PROTOCOL_VERSION) { conoutf(@"you are using a different game " @"protocol (you: %d, server: %d)", PROTOCOL_VERSION, prot); - disconnect(); + disconnect(false, false); return; } toservermap = @""; clientnum = cn; // we are now fully connected if (!getint(&p)) @@ -98,11 +98,11 @@ sgetstr(); if (text[0] && strcmp(text, clientpassword.UTF8String)) { conoutf(@"you need to set the correct password " @"to join this server!"); - disconnect(); + disconnect(false, false); return; } if (getint(&p) == 1) conoutf(@"server is FULL, disconnecting.."); break; @@ -219,11 +219,11 @@ e.x = getint(&p) / DMF; e.y = getint(&p) / DMF; e.z = getint(&p) / DMF; if (gun == GUN_SG) createrays(&s, &e); - shootv(gun, &s, &e, d); + shootv(gun, &s, &e, d, false); break; } case SV_DAMAGE: { int target = getint(&p); Index: src/commands.mm ================================================================== --- src/commands.mm +++ src/commands.mm @@ -121,11 +121,12 @@ } char *s = strndup(word, p - word - 1); if (left == '(') { OFString *t; @try { - t = [OFString stringWithFormat:@"%d", execute(@(s))]; + t = [OFString + stringWithFormat:@"%d", execute(@(s), true)]; } @finally { free(s); } s = strdup(t.UTF8String); } @@ -327,11 +328,11 @@ return false; } @catch (OFReadFailedException *e) { return false; } - execute(command); + execute(command, true); return true; } void exec(OFString *cfgfile) @@ -405,11 +406,11 @@ } void ifthen(OFString *cond, OFString *thenp, OFString *elsep) { - execute((![cond hasPrefix:@"0"] ? thenp : elsep)); + execute((![cond hasPrefix:@"0"] ? thenp : elsep), true); } void loopa(OFString *times, OFString *body) { @@ -416,26 +417,26 @@ int t = times.cube_intValue; loopi(t) { intset(@"i", i); - execute(body); + execute(body, true); } } void whilea(OFString *cond, OFString *body) { - while (execute(cond)) - execute(body); + while (execute(cond, true)) + execute(body, true); } void onrelease(bool on, OFString *body) { if (!on) - execute(body); + execute(body, true); } void concat(OFString *s) { Index: src/console.mm ================================================================== --- src/console.mm +++ src/console.mm @@ -175,11 +175,11 @@ { static bool rec = false; if (!rec && n >= 0 && n < vhistory.count) { rec = true; - execute(vhistory[vhistory.count - n - 1]); + execute(vhistory[vhistory.count - n - 1], true); rec = false; } } COMMAND(history, ARG_1INT) Index: src/editing.mm ================================================================== --- src/editing.mm +++ src/editing.mm @@ -35,11 +35,11 @@ loop(x, sel->xs) loop(y, sel->ys) \ { \ sqr *s = S(sel->x + x, sel->y + y); \ b; \ } \ - remip(sel); \ + remip(sel, 0); \ } int cx, cy, ch; int curedittex[] = { -1, -1, -1 }; @@ -438,11 +438,11 @@ s->utex = lasttex; break; } } block b = { 0, 0, ssize, ssize }; - remip(&b); + remip(&b, 0); } void edittypexy(int type, const block *sel) { @@ -516,11 +516,11 @@ void setvdeltaxy(int delta, const block *sel) { loopselxy(s->vdelta = max(s->vdelta + delta, 0)); - remipmore(sel); + remipmore(sel, 0); } void setvdelta(int delta) { @@ -561,11 +561,11 @@ loopselxy(s->vdelta = sel->xs > sel->ys ? (archverts[sel->xs - 1][x] + (y == 0 || y == sel->ys - 1 ? sidedelta : 0)) : (archverts[sel->ys - 1][y] + (x == 0 || x == sel->xs - 1 ? sidedelta : 0))); - remipmore(sel); + remipmore(sel, 0); } void slope(int xd, int yd) { @@ -579,11 +579,11 @@ sel.ys++; block *sel_ = &sel; // Ugly hack to make the macro work. block *sel = sel_; loopselxy(s->vdelta = xd * x + yd * y + off); - remipmore(sel); + remipmore(sel, 0); } void perlin(int scale, int seed, int psize) { @@ -594,11 +594,11 @@ sel.xs--; sel.ys--; perlinarea(&sel, scale, seed, psize); sel.xs++; sel.ys++; - remipmore(&sel); + remipmore(&sel, 0); sel.xs--; sel.ys--; } VARF( Index: src/entities.mm ================================================================== --- src/entities.mm +++ src/entities.mm @@ -52,11 +52,11 @@ rendermodel(mmi.name, 0, 1, e.attr4, (float)mmi.rad, OFMakeVector3D(e.x, (float)S(e.x, e.y)->floor + mmi.zoff + e.attr3, e.y), (float)((e.attr1 + 7) - (e.attr1 + 7) % 15), 0, - false, 1.0f, 10.0f, mmi.snap); + false, 1.0f, 10.0f, mmi.snap, 0); } else { if (OUTBORD(e.x, e.y)) continue; if (e.type != CARROT) { if (!e.spawned && e.type != TELEPORT) Index: src/protos.h ================================================================== --- src/protos.h +++ src/protos.h @@ -5,11 +5,11 @@ void (*fun)(), bool persist); extern void setvar(OFString *name, int i); extern int getvar(OFString *name); extern bool identexists(OFString *name); extern bool addcommand(OFString *name, void (*fun)(), int narg); -extern int execute(OFString *p, bool down = true); +extern int execute(OFString *p, bool down); extern void exec(OFString *cfgfile); extern bool execfile(OFIRI *cfgfile); extern void resetcomplete(); extern void complete(OFMutableString *s); extern void alias(OFString *name, OFString *action); @@ -69,11 +69,11 @@ extern void setarraypointers(); // client extern void localservertoclient(uchar *buf, int len); extern void connects(OFString *servername); -extern void disconnect(int onlyclean = 0, int async = 0); +extern void disconnect(bool onlyclean, bool async); extern void toserver(OFString *text); extern void addmsg(int rel, int num, int type, ...); extern bool multiplayer(); extern bool allowedittoggle(); extern void sendpackettoserv(void *packet); @@ -112,14 +112,14 @@ extern void renderscores(); // world extern void setupworld(int factor); extern void empty_world(int factor, bool force); -extern void remip(const block *b, int level = 0); -extern void remipmore(const block *b, int level = 0); +extern void remip(const block *b, int level); +extern void remipmore(const block *b, int level); extern int closestent(); -extern int findentity(int type, int index = 0); +extern int findentity(int type, int index); extern void trigger(int tag, int type, bool savegame); extern void resettagareas(); extern void settagareas(); extern Entity *newentity( int x, int y, int z, OFString *what, int v1, int v2, int v3, int v4); @@ -139,11 +139,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(OFString *s, OFString *o = @""); +extern void fatal(OFConstantString *s, ...); // rendertext extern void draw_text(OFString *string, int left, int top, int gl_num); extern void draw_textf( OFConstantString *format, int left, int top, int gl_num, ...); @@ -158,11 +158,11 @@ extern void editequalisexy(bool isfloor, const block *sel); extern void edittypexy(int type, const block *sel); extern void edittexxy(int type, int t, const block *sel); extern void editheightxy(bool isfloor, int amount, const block *sel); extern bool noteditmode(); -extern void pruneundos(int maxremain = 0); +extern void pruneundos(int maxremain); // renderextras extern void line(int x1, int y1, float z1, int x2, int y2, float z2); extern void box(const block *b, float z1, float z2, float z3, float z4); extern void dot(int x, int y, float z); @@ -186,11 +186,11 @@ extern void save_world(OFString *fname); extern void load_world(OFString *mname); extern void writemap(OFString *mname, int msize, uchar *mdata); extern OFData *readmap(OFString *mname); extern void loadgamerest(); -extern void incomingdemodata(uchar *buf, int len, bool extras = false); +extern void incomingdemodata(uchar *buf, int len, bool extras); extern void demoplaybackstep(); extern void stop(); extern void stopifrecording(); extern void demodamage(int damage, const OFVector3D *o); extern void demoblend(int damage); @@ -201,19 +201,19 @@ extern void entinmap(DynamicEntity *d); extern void setentphysics(int mml, int mmr); extern void physicsframe(); // sound -extern void playsound(int n, const OFVector3D *loc = NULL); +extern void playsound(int n, const OFVector3D *loc); extern void playsoundc(int n); extern void initsound(); extern void cleansound(); // rendermd2 extern void rendermodel(OFString *mdl, int frame, int range, int tex, float rad, OFVector3D position, float yaw, float pitch, bool teammate, float scale, - float speed, int snap = 0, int basetime = 0); + float speed, int snap, int basetime); @class MapModelInfo; extern MapModelInfo *getmminfo(int i); // server extern void initserver(bool dedicated, int uprate, OFString *sdesc, @@ -235,14 +235,14 @@ extern void servermsinit(OFString *master, OFString *sdesc, bool listen); extern void sendmaps(int n, OFString *mapname, int mapsize, uchar *mapdata); extern ENetPacket *recvmap(int n); // weapon -extern void selectgun(int a = -1, int b = -1, int c = -1); +extern void selectgun(int a, int b, int c); extern void shoot(DynamicEntity *d, const OFVector3D *to); extern void shootv(int gun, const OFVector3D *from, const OFVector3D *to, - DynamicEntity *d = 0, bool local = false); + DynamicEntity *d, bool local); extern void createrays(const OFVector3D *from, const OFVector3D *to); extern void moveprojectiles(float time); extern void projreset(); extern OFString *playerincrosshair(); extern int reloadtime(int gun); Index: src/rendermd2.mm ================================================================== --- src/rendermd2.mm +++ src/rendermd2.mm @@ -21,11 +21,11 @@ OFIRI *baseIRI = [Cube.sharedInstance.gameDataIRI IRIByAppendingPathComponent:path]; OFIRI *IRI1 = [baseIRI IRIByAppendingPathComponent:@"tris.md2"]; if (![m loadWithIRI:IRI1]) - fatal(@"loadmodel: ", IRI1.string); + fatal(@"loadmodel: %@", IRI1.string); OFIRI *IRI2 = [baseIRI IRIByAppendingPathComponent:@"skin.jpg"]; int xs, ys; installtex(FIRSTMDL + m.mdlnum, IRI2, &xs, &ys, false); m.loaded = true; Index: src/savegamedemo.mm ================================================================== --- src/savegamedemo.mm +++ src/savegamedemo.mm @@ -349,11 +349,11 @@ stopreset() { conoutf(@"demo stopped (%d msec elapsed)", lastmillis - starttime); stop(); [players removeAllObjects]; - disconnect(0, 0); + disconnect(false, false); } VAR(demoplaybackspeed, 10, 100, 1000); int scaletime(int t) Index: src/serverbrowser.mm ================================================================== --- src/serverbrowser.mm +++ src/serverbrowser.mm @@ -271,11 +271,11 @@ if (!*reply || strstr((char *)reply, "") || strstr((char *)reply, "")) conoutf(@"master server not replying"); else { [servers removeAllObjects]; - execute(@((char *)reply)); + execute(@((char *)reply), true); } servermenu(); } COMMAND(addserver, ARG_1STR) Index: src/serverutil.mm ================================================================== --- src/serverutil.mm +++ src/serverutil.mm @@ -138,14 +138,21 @@ localservertoclient(uchar *buf, int len) { } void -fatal(OFString *s, OFString *o) +fatal(OFConstantString *s, ...) { cleanupserver(); - [OFStdOut writeFormat:@"servererror: %@\n", s]; + + va_list args; + va_start(args, s); + OFString *msg = [[OFString alloc] initWithFormat:s arguments:args]; + va_end(args); + + [OFStdOut writeFormat:@"servererror: %@\n", msg]; + exit(1); } void * alloc(int s) Index: src/sound.mm ================================================================== --- src/sound.mm +++ src/sound.mm @@ -157,11 +157,11 @@ void playsoundc(int n) { addmsg(0, 2, SV_SOUND, n); - playsound(n); + playsound(n, NULL); } int soundsatonce = 0, lastsoundmillis = 0; void Index: src/world.mm ================================================================== --- src/world.mm +++ src/world.mm @@ -40,11 +40,11 @@ miny = y; } } block b = { minx, miny, maxx - minx + 1, maxy - miny + 1 }; if (maxx) - remip(&b); // remip minimal area of changed geometry + remip(&b, 0); // remip minimal area of changed geometry } void resettagareas() { @@ -68,17 +68,17 @@ return; settag(tag, type); if (!savegame && type != 3) - playsound(S_RUMBLE); + playsound(S_RUMBLE, NULL); OFString *aliasname = [OFString stringWithFormat:@"level_trigger_%d", tag]; if (identexists(aliasname)) - execute(aliasname); + execute(aliasname, true); if (type == 2) endsp(false); } COMMAND(trigger, ARG_2INT) @@ -455,11 +455,11 @@ empty_world(int factor, bool force) { if (!force && noteditmode()) return; cleardlights(); - pruneundos(); + pruneundos(0); sqr *oldworld = world; bool copy = false; if (oldworld && factor < 0) { factor = sfactor + 1; copy = true; @@ -514,11 +514,11 @@ calclight(); startmap(@"base/unnamed"); if (oldworld) { OFFreeMemory(oldworld); toggleedit(); - execute(@"fullbright 1"); + execute(@"fullbright 1", true); } } void mapenlarge() Index: src/worldio.mm ================================================================== --- src/worldio.mm +++ src/worldio.mm @@ -260,11 +260,11 @@ load_world(OFString *mname) // still supports all map formats that have existed // since the earliest cube betas! { stopifrecording(); cleardlights(); - pruneundos(); + pruneundos(0); setnames(mname); gzFile f = gzopen([cgzname cStringWithEncoding:OFLocale.encoding], "rb9"); if (!f) { conoutf(@"could not read map %@", cgzname); @@ -348,17 +348,14 @@ s->floor = 0; s->ceil = 16; break; } default: { - if (type < 0 || type >= MAXTYPE) { - OFString *t = [OFString - stringWithFormat:@"%d @ %d", type, k]; - fatal(@"while reading map: type out of " - @"range: ", - t); - } + if (type < 0 || type >= MAXTYPE) + fatal(@"while reading map: type out of range: " + @"%d @ %d", + type, k); s->type = type; s->floor = gzgetc(f); s->ceil = gzgetc(f); if (s->floor >= s->ceil) s->floor = s->ceil - 1; // for pre 12_13 Index: src/worldlight.mm ================================================================== --- src/worldlight.mm +++ src/worldlight.mm @@ -163,11 +163,11 @@ median(r); median(g); median(b); } - remip(&a); + remip(&a, 0); } void calclight() { @@ -266,7 +266,7 @@ { sqr *q = (sqr *)(b + 1); for (int x = b->x; x < b->xs + b->x; x++) for (int y = b->y; y < b->ys + b->y; y++) *S(x, y) = *q++; - remipmore(b); + remipmore(b, 0); }