From 75de54ad4685e2320fd2b9743b8e53bdd5cd73b6 Mon Sep 17 00:00:00 2001 From: sauerbraten Date: Sat, 28 Nov 2020 23:28:57 +0100 Subject: [PATCH] svn r6410 --- src/engine/command.cpp | 66 ++++++++++++++++++++++++++++++++++++++ src/engine/octaedit.cpp | 4 +-- src/fpsgame/capture.h | 2 +- src/fpsgame/scoreboard.cpp | 10 +++--- src/fpsgame/server.cpp | 15 ++++++--- src/xcode/macbuild.sh | 4 +-- 6 files changed, 87 insertions(+), 14 deletions(-) diff --git a/src/engine/command.cpp b/src/engine/command.cpp index 630bf13..477a051 100644 --- a/src/engine/command.cpp +++ b/src/engine/command.cpp @@ -2639,6 +2639,31 @@ void substr(char *s, int *start, int *count, int *numargs) } COMMAND(substr, "siiN"); +void chopstr(char *s, int *lim, char *ellipsis) +{ + int len = strlen(s), maxlen = abs(*lim); + if(len > maxlen) + { + int elen = strlen(ellipsis); + maxlen = max(maxlen, elen); + char *chopped = newstring(maxlen); + if(*lim < 0) + { + memcpy(chopped, ellipsis, elen); + memcpy(&chopped[elen], &s[len - (maxlen - elen)], maxlen - elen); + } + else + { + memcpy(chopped, s, maxlen - elen); + memcpy(&chopped[maxlen - elen], ellipsis, elen); + } + chopped[maxlen] = '\0'; + commandret->setstr(chopped); + } + else result(s); +} +COMMAND(chopstr, "sis"); + void sublist(const char *s, int *skip, int *count, int *numargs) { int offset = max(*skip, 0), len = *numargs >= 3 ? max(*count, 0) : -1; @@ -2709,6 +2734,21 @@ void looplist(ident *id, const char *list, const uint *body) } COMMAND(looplist, "rse"); +void loopsublist(ident *id, const char *list, int *skip, int *count, const uint *body) +{ + if(id->type!=ID_ALIAS) return; + identstack stack; + int n = 0, offset = max(*skip, 0), len = *count < 0 ? INT_MAX : offset + *count; + for(const char *s = list, *start, *end; parselist(s, start, end) && n < len; n++) if(n >= offset) + { + char *val = newstring(start, end-start); + setiter(*id, val, stack); + execute(body); + } + if(n) poparg(*id); +} +COMMAND(loopsublist, "rsiie"); + void looplistconc(ident *id, const char *list, const uint *body, bool space) { if(id->type!=ID_ALIAS) return; @@ -3136,6 +3176,32 @@ ICOMMAND(codestr, "i", (int *i), { char *s = newstring(1); s[0] = char(*i); s[1] ICOMMAND(struni, "si", (char *s, int *i), intret(*i > 0 ? (memchr(s, 0, *i) ? 0 : cube2uni(s[*i])) : cube2uni(s[0]))); ICOMMAND(unistr, "i", (int *i), { char *s = newstring(1); s[0] = uni2cube(*i); s[1] = '\0'; stringret(s); }); +int naturalsort(const char *a, const char *b) +{ + for(;;) + { + int ac = *a, bc = *b; + if(!ac) return bc ? -1 : 0; + else if(!bc) return 1; + else if(isdigit(ac) && isdigit(bc)) + { + while(*a == '0') a++; + while(*b == '0') b++; + const char *a0 = a, *b0 = b; + while(isdigit(*a)) a++; + while(isdigit(*b)) b++; + int alen = a - a0, blen = b - b0; + if(alen != blen) return alen - blen; + int n = memcmp(a0, b0, alen); + if(n < 0) return -1; + else if(n > 0) return 1; + } + else if(ac != bc) return ac - bc; + else { ++a; ++b; } + } +} +ICOMMAND(naturalsort, "ss", (char *a, char *b), intret(naturalsort(a,b)<=0)); + #define STRMAPCOMMAND(name, map) \ ICOMMAND(name, "s", (char *s), \ { \ diff --git a/src/engine/octaedit.cpp b/src/engine/octaedit.cpp index e58e5f4..4fa82b3 100644 --- a/src/engine/octaedit.cpp +++ b/src/engine/octaedit.cpp @@ -733,7 +733,7 @@ struct undolist }; undolist undos, redos; -VARP(undomegs, 0, 5, 100); // bounded by n megs +VARP(undomegs, 0, 8, 100); // bounded by n megs int totalundos = 0; void pruneundos(int maxremain) // bound memory @@ -2754,7 +2754,7 @@ COMMAND(editmat, "ss"); extern int menudistance, menuautoclose; -VARP(texguiwidth, 1, 15, 1000); +VARP(texguiwidth, 1, 16, 1000); VARP(texguiheight, 1, 8, 1000); VARP(texguitime, 0, 15, 1000); diff --git a/src/fpsgame/capture.h b/src/fpsgame/capture.h index 0a0c7de..f99271e 100644 --- a/src/fpsgame/capture.h +++ b/src/fpsgame/capture.h @@ -531,7 +531,7 @@ struct captureclientmode : clientmode defformatstring(alias, "base_%d", e->attr2); const char *name = getalias(alias); copystring(b.name, name); - b.tag = e->attr2 || name[0] ? e->attr2 : bases.length(); + b.tag = e->attr2>0 ? e->attr2 : bases.length(); b.light = e->light; } } diff --git a/src/fpsgame/scoreboard.cpp b/src/fpsgame/scoreboard.cpp index 82b51aa..5d85bd4 100644 --- a/src/fpsgame/scoreboard.cpp +++ b/src/fpsgame/scoreboard.cpp @@ -190,7 +190,7 @@ namespace game g.spring(); g.poplist(); - g.space(.5); + g.space(.75f); int numgroups = groupplayers(); loopk(numgroups) @@ -338,18 +338,20 @@ namespace game else { g.poplist(); // horizontal - if(k+1privilege>=PRIV_MASTER) { g.pushlist(); g.pushlist(); - g.text("spectator", COL_GRAY, " "); + g.text("spectator", COL_GRAY); g.strut(12); loopv(spectators) { @@ -391,7 +393,7 @@ namespace game } else { - g.textf("%d spectator%s", COL_GRAY, " ", spectators.length(), spectators.length()!=1 ? "s" : ""); + g.textf("%d spectator%s", COL_GRAY, NULL, spectators.length(), spectators.length()!=1 ? "s" : ""); loopv(spectators) { if((i%3)==0) diff --git a/src/fpsgame/server.cpp b/src/fpsgame/server.cpp index d96e155..46a5a8e 100644 --- a/src/fpsgame/server.cpp +++ b/src/fpsgame/server.cpp @@ -607,7 +607,7 @@ namespace server VAR(maxdemos, 0, 5, 25); VAR(maxdemosize, 0, 16, 31); VAR(restrictdemos, 0, 1, 1); - VAR(autorecorddemo, 0, 0, 1); + VARF(autorecorddemo, 0, 0, 1, demonextmatch = autorecorddemo!=0); VAR(restrictpausegame, 0, 1, 1); VAR(restrictgamespeed, 0, 1, 1); @@ -982,10 +982,15 @@ namespace server loopi(sizeof(team)/sizeof(team[0])) { addteaminfo(teamnames[i]); - if(!persistteams) loopvj(team[i]) + loopvj(team[i]) { clientinfo *ci = team[i][j]; if(!strcmp(ci->team, teamnames[i])) continue; + if(persistteams && ci->team[0] && (!smode || smode->canchangeteam(ci, teamnames[i], ci->team))) + { + addteaminfo(ci->team); + continue; + } copystring(ci->team, teamnames[i], MAXTEAMLEN+1); sendf(-1, 1, "riisi", N_SETTEAM, ci->clientnum, teamnames[i], -1); } @@ -2048,14 +2053,14 @@ namespace server sendf(-1, 1, "risii", N_MAPCHANGE, smapname, gamemode, 1); - clearteaminfo(); - if(m_teammode) autoteam(); - if(m_capture) smode = &capturemode; else if(m_ctf) smode = &ctfmode; else if(m_collect) smode = &collectmode; else smode = NULL; + clearteaminfo(); + if(m_teammode) autoteam(); + if(m_timed && smapname[0]) sendf(-1, 1, "ri2", N_TIMEUP, gamemillis < gamelimit && !interm ? max((gamelimit - gamemillis)/1000, 1) : 0); loopv(clients) { diff --git a/src/xcode/macbuild.sh b/src/xcode/macbuild.sh index 6bb3b90..87dc05b 100755 --- a/src/xcode/macbuild.sh +++ b/src/xcode/macbuild.sh @@ -5,12 +5,12 @@ while [ -n "$1" ]; do clean) xcodebuild -project sauerbraten.xcodeproj clean -configuration Release ;; - all) + build) xcodebuild -project sauerbraten.xcodeproj -configuration Release -alltargets ;; install) cp -v build/Release/sauerbraten.app/Contents/MacOS/sauerbraten ../../sauerbraten.app/Contents/MacOS/sauerbraten_universal - chmod +x ../sauerbraten.app/Contents/MacOS/sauerbraten_universal + chmod +x ../../sauerbraten.app/Contents/MacOS/sauerbraten_universal ;; package) exec ./package.sh