From e3f271bc7c61f65fef3d7b38ac070c44d7062750 Mon Sep 17 00:00:00 2001 From: Lee Salzman Date: Fri, 28 Dec 2012 20:46:06 +0200 Subject: [PATCH] integrate paused and pausegame --- data/defaults.cfg | 4 +-- data/stdlib.cfg | 6 ++++ src/engine/command.cpp | 71 ++++++++++++++++++++++---------------- src/engine/main.cpp | 4 +-- src/engine/world.cpp | 1 - src/fpsgame/client.cpp | 10 +++++- src/fpsgame/fps.cpp | 2 +- src/fpsgame/game.h | 1 + src/fpsgame/scoreboard.cpp | 2 +- src/fpsgame/server.cpp | 5 +++ src/shared/iengine.h | 4 +++ 11 files changed, 72 insertions(+), 38 deletions(-) diff --git a/data/defaults.cfg b/data/defaults.cfg index cfb3e52..92e6d56 100644 --- a/data/defaults.cfg +++ b/data/defaults.cfg @@ -82,8 +82,8 @@ bind RCTRL "allowspedit" bind KP_MINUS "conskip 5" bind KP_PLUS "conskip -1000" -bindvar F1 paused -bindvar PAUSE paused +bindvarquiet F1 paused +bindvarquiet PAUSE paused bind F11 "toggleconsole" bind F12 "screenshot" diff --git a/data/stdlib.cfg b/data/stdlib.cfg index a91e50c..f23ea15 100644 --- a/data/stdlib.cfg +++ b/data/stdlib.cfg @@ -11,11 +11,17 @@ macro = [ bindvar = [ bind $arg1 [@arg2 (= $@arg2 0); if (= $@arg2 0) [echo @@arg2 OFF] [ echo @@arg2 ON]] ] +bindvarquiet = [ + bind $arg1 [@arg2 (= $@arg2 0)] +] // same as above, but only binds for edit mode editbindvar = [ editbind $arg1 [@arg2 (= $@arg2 0); if (= $@arg2 0) [echo @@arg2 OFF] [ echo @@arg2 ON]] ] +editbindvarquiet = [ + editbind $arg1 [@arg2 (= $@arg2 0)] +] // binds a key so that it will set a modifier while held down bindmod = [ diff --git a/src/engine/command.cpp b/src/engine/command.cpp index abb760e..34f6110 100644 --- a/src/engine/command.cpp +++ b/src/engine/command.cpp @@ -641,7 +641,7 @@ bool addcommand(const char *name, identfun fun, const char *args) for(const char *fmt = args; *fmt; fmt++) switch(*fmt) { case 'i': case 'b': case 'f': case 't': case 'N': case 'D': if(numargs < MAXARGS) numargs++; break; - case 's': case 'e': case 'r': if(numargs < MAXARGS) { argmask |= 1< &code) code[start] |= uint(code.length() - (start + 1))<<8; } +static inline void compileident(vector &code, ident *id) +{ + code.add((id->index < MAXARGS ? CODE_IDENTARG : CODE_IDENT)|(id->index<<8)); +} + static inline void compileident(vector &code, const char *word = NULL) { - ident *id = word ? newident(word, IDF_UNKNOWN) : dummyident; - code.add((id->index < MAXARGS ? CODE_IDENTARG : CODE_IDENT)|(id->index<<8)); + compileident(code, word ? newident(word, IDF_UNKNOWN) : dummyident); } static inline void compileint(vector &code, const char *word = NULL) @@ -943,18 +947,19 @@ static void compilelookup(vector &code, const char *&p, int ltype) case ID_ALIAS: code.add((id->index < MAXARGS ? CODE_LOOKUPARG : CODE_LOOKUP)|((ltype >= VAL_ANY ? VAL_STR : ltype)<index<<8)); goto done; case ID_COMMAND: { - int comtype = CODE_COM, fakeargs = 0, numargs = 0; + int comtype = CODE_COM, numargs = 0; code.add(CODE_ENTER); for(const char *fmt = id->args; *fmt; fmt++) switch(*fmt) { - case 's': compilestr(code, NULL, 0, true); fakeargs++; numargs++; break; - case 'i': compileint(code); fakeargs++; numargs++; break; - case 'b': compileint(code, INT_MIN); fakeargs++; numargs++; break; - case 'f': compilefloat(code); fakeargs++; numargs++; break; - case 't': compilenull(code); fakeargs++; numargs++; break; - case 'e': compileblock(code); fakeargs++; numargs++; break; - case 'r': compileident(code); fakeargs++; numargs++; break; - case 'N': compileint(code, numargs-fakeargs); numargs++; break; + case 's': compilestr(code, NULL, 0, true); numargs++; break; + case 'i': compileint(code); numargs++; break; + case 'b': compileint(code, INT_MIN); numargs++; break; + case 'f': compilefloat(code); numargs++; break; + case 't': compilenull(code); numargs++; break; + case 'e': compileblock(code); numargs++; break; + case 'r': compileident(code); numargs++; break; + case '$': compileident(code, id); numargs++; break; + case 'N': compileint(code, -1); numargs++; break; #ifndef STANDALONE case 'D': comtype = CODE_COMD; numargs++; break; #endif @@ -1296,6 +1301,7 @@ static void compilestatements(vector &code, const char *&p, int rettype, i case 't': if(more) more = compilearg(code, p, VAL_ANY); if(!more) { if(rep) break; compilenull(code); fakeargs++; } numargs++; break; case 'e': if(more) more = compilearg(code, p, VAL_CODE); if(!more) { if(rep) break; compileblock(code); fakeargs++; } numargs++; break; case 'r': if(more) more = compilearg(code, p, VAL_IDENT); if(!more) { if(rep) break; compileident(code); fakeargs++; } numargs++; break; + case '$': compileident(code, id); numargs++; break; case 'N': compileint(code, numargs-fakeargs); numargs++; break; #ifndef STANDALONE case 'D': comtype = CODE_COMD; numargs++; break; @@ -1423,26 +1429,32 @@ void freecode(uint *code) } } -static void printvar(ident *id) +void printvar(ident *id, int i) +{ + if(i < 0) conoutf("%s = %d", id->name, i); + else if(id->flags&IDF_HEX && id->maxval==0xFFFFFF) + conoutf("%s = 0x%.6X (%d, %d, %d)", id->name, i, (i>>16)&0xFF, (i>>8)&0xFF, i&0xFF); + else + conoutf(id->flags&IDF_HEX ? "%s = 0x%X" : "%s = %d", id->name, i); +} + +void printfvar(ident *id, float f) +{ + conoutf("%s = %s", id->name, floatstr(f)); +} + +void printsvar(ident *id, const char *s) +{ + conoutf(strchr(s, '"') ? "%s = [%s]" : "%s = \"%s\"", id->name, s); +} + +void printvar(ident *id) { switch(id->type) { - case ID_VAR: - { - int i = *id->storage.i; - if(i < 0) conoutf("%s = %d", id->name, i); - else if(id->flags&IDF_HEX && id->maxval==0xFFFFFF) - conoutf("%s = 0x%.6X (%d, %d, %d)", id->name, i, (i>>16)&0xFF, (i>>8)&0xFF, i&0xFF); - else - conoutf(id->flags&IDF_HEX ? "%s = 0x%X" : "%s = %d", id->name, i); - break; - } - case ID_FVAR: - conoutf("%s = %s", id->name, floatstr(*id->storage.f)); - break; - case ID_SVAR: - conoutf(strchr(*id->storage.s, '"') ? "%s = [%s]" : "%s = \"%s\"", id->name, *id->storage.s); - break; + case ID_VAR: printvar(id, *id->storage.i); break; + case ID_FVAR: printfvar(id, *id->storage.f); break; + case ID_SVAR: printsvar(id, *id->storage.s); break; } } @@ -1523,6 +1535,7 @@ static inline void callcommand(ident *id, tagval *args, int numargs) } break; case 'r': if(++i >= numargs) { if(rep) break; args[i].setident(dummyident); fakeargs++; } else forceident(args[i]); break; + case '$': if(++i < numargs) freearg(args[i]); args[i].setident(id); break; case 'N': if(++i < numargs) freearg(args[i]); args[i].setint(i-fakeargs); fakeargs++; break; #ifndef STANDALONE case 'D': if(++i < numargs) freearg(args[i]); args[i].setint(addreleaseaction(conc(args, i, true, id->name)) ? 1 : 0); fakeargs++; break; diff --git a/src/engine/main.cpp b/src/engine/main.cpp index 73c355f..22de1d0 100644 --- a/src/engine/main.cpp +++ b/src/engine/main.cpp @@ -883,8 +883,6 @@ void swapbuffers() VARF(gamespeed, 10, 100, 1000, if(multiplayer()) gamespeed = 100); -VARF(paused, 0, 0, 1, if(multiplayer()) paused = 0); - VAR(menufps, 0, 60, 1000); VARP(maxfps, 0, 200, 1000); @@ -1240,7 +1238,7 @@ int main(int argc, char **argv) curtime = scaledtime/100; timeerr = scaledtime%100; if(curtime>200) curtime = 200; - if(paused || game::ispaused()) curtime = 0; + if(game::ispaused()) curtime = 0; } lastmillis += curtime; totalmillis = millis; diff --git a/src/engine/world.cpp b/src/engine/world.cpp index 51fdb2e..945dc83 100644 --- a/src/engine/world.cpp +++ b/src/engine/world.cpp @@ -1149,7 +1149,6 @@ void resetmap() clearmapcrc(); setvar("gamespeed", 100, false); - setvar("paused", 0, false); entities::clearents(); outsideents.setsize(0); diff --git a/src/fpsgame/client.cpp b/src/fpsgame/client.cpp index 6e30a71..3809208 100644 --- a/src/fpsgame/client.cpp +++ b/src/fpsgame/client.cpp @@ -691,9 +691,17 @@ namespace game void pausegame(int *val) { - addmsg(N_PAUSEGAME, "ri", *val > 0 ? 1 : 0); + if(!connected) return; + if(!remote) server::forcepaused(*val > 0); + else addmsg(N_PAUSEGAME, "ri", *val > 0 ? 1 : 0); } COMMAND(pausegame, "i"); + ICOMMAND(paused, "iN$", (int *val, int *numargs, ident *id), + { + if(*numargs > 0) pausegame(val); + else if(*numargs < 0) intret(gamepaused ? 1 : 0); + else printvar(id, gamepaused ? 1 : 0); + }); bool ispaused() { return gamepaused; } diff --git a/src/fpsgame/fps.cpp b/src/fpsgame/fps.cpp index b006845..561f5b0 100644 --- a/src/fpsgame/fps.cpp +++ b/src/fpsgame/fps.cpp @@ -83,7 +83,7 @@ namespace game void respawnself() { - if(paused || ispaused()) return; + if(ispaused()) return; if(m_mp(gamemode)) { if(player1->respawned!=player1->lifesequence) diff --git a/src/fpsgame/game.h b/src/fpsgame/game.h index 3ed99dd..1a7f6b4 100644 --- a/src/fpsgame/game.h +++ b/src/fpsgame/game.h @@ -776,6 +776,7 @@ namespace server extern void startintermission(); extern void stopdemo(); extern void forcemap(const char *map, int mode); + extern void forcepaused(bool paused); extern void hashpassword(int cn, int sessionid, const char *pwd, char *result, int maxlen = MAXSTRLEN); extern int msgsizelookup(int msg); extern bool serveroption(const char *arg); diff --git a/src/fpsgame/scoreboard.cpp b/src/fpsgame/scoreboard.cpp index f8c2c92..8e72b47 100644 --- a/src/fpsgame/scoreboard.cpp +++ b/src/fpsgame/scoreboard.cpp @@ -165,7 +165,7 @@ namespace game g.poplist(); } } - if(paused || ispaused()) { g.separator(); g.text("paused", 0xFFFF80); } + if(ispaused()) { g.separator(); g.text("paused", 0xFFFF80); } g.spring(); g.poplist(); diff --git a/src/fpsgame/server.cpp b/src/fpsgame/server.cpp index 27b5c14..3ca4b05 100644 --- a/src/fpsgame/server.cpp +++ b/src/fpsgame/server.cpp @@ -1212,6 +1212,11 @@ namespace server if(!admins) pausegame(false); } + void forcepaused(bool paused) + { + pausegame(paused); + } + SVAR(serverauth, ""); struct userkey diff --git a/src/shared/iengine.h b/src/shared/iengine.h index ea96efd..5f2993a 100644 --- a/src/shared/iengine.h +++ b/src/shared/iengine.h @@ -148,6 +148,10 @@ extern bool validateblock(const char *s); extern void explodelist(const char *s, vector &elems, int limit = -1); extern char *indexlist(const char *s, int pos); extern int listlen(const char *s); +extern void printvar(ident *id); +extern void printvar(ident *id, int i); +extern void printfvar(ident *id, float f); +extern void printsvar(ident *id, const char *s); // console