rewrite settemp system to handle "quit" right
authorRudolf Polzer <divverent@xonotic.org>
Tue, 27 Dec 2011 14:24:48 +0000 (15:24 +0100)
committerRudolf Polzer <divverent@xonotic.org>
Tue, 27 Dec 2011 14:24:48 +0000 (15:24 +0100)
13 files changed:
defaultXonotic.cfg
qcsrc/client/Main.qc
qcsrc/client/main.qh
qcsrc/common/gamecommand.qc
qcsrc/common/mapinfo.qc
qcsrc/common/mapinfo.qh
qcsrc/common/util.qc
qcsrc/common/util.qh
qcsrc/csqcmodellib/cl_player.qc
qcsrc/dpdefs/menudefs.qc
qcsrc/menu/menu.qc
qcsrc/server/g_world.qc
qcsrc/server/progs.src

index d1b82b6..692d9f0 100644 (file)
@@ -1400,14 +1400,8 @@ alias unban "sv_cmd unban $*"     // usage: unban 3 (number from bans)
 r_labelsprites_scale 0.40625 // labels sprites get displayed at 0.5x from 640x480 to 1280x1024, and at 1x from 1600x1200 onwards
 
 // settemp subsystem. Do not touch. Usage: settemp variable value, next map resets it.
-set settemp_list 0
-set settemp_idx 0
-set _settemp_var UNUSED
-alias settemp "_settemp_var \"_settemp_x$settemp_idx\"; qc_cmd rpn /settemp_idx settemp_idx 1 add def; _settemp \"$1\" \"$2\""
-alias _settemp "settemp_list \"1 $1 $_settemp_var $settemp_list\"; set $_settemp_var \"${$1}\"; $1 \"$2\""
-alias settemp_restore "_settemp_restore_${settemp_list asis}"
-alias _settemp_restore_0 "set settemp_var 0; set settemp_list 0"
-alias _settemp_restore_1 "$1 \"${$2}\"; _settemp_restore_${3- asis}"
+alias settemp "cl_cmd settemp $*"
+alias settemp_restore "cl_cmd settemp_restore"
 
 // usercommands. These can be edited and bound by the menu.
 seta "userbind1_press" "say_team quad soon";  seta "userbind1_release" "";  seta "userbind1_description" "team: quad soon"
index 8c7c6bc..cde4c5c 100644 (file)
@@ -4,27 +4,6 @@
 
 #define DP_CSQC_ENTITY_REMOVE_IS_B0RKED
 
-void cvar_clientsettemp(string cv, string val)
-{
-       entity e;
-       for(e = world; (e = find(e, classname, "saved_cvar_value")); )
-               if(e.netname == cv)
-                       goto saved;
-       e = spawn();
-       e.classname = "saved_cvar_value";
-       e.netname = strzone(cv);
-       e.message = strzone(cvar_string(cv));
-:saved
-       cvar_set(cv, val);
-}
-
-void cvar_clientsettemp_restore()
-{
-       entity e;
-       for(e = world; (e = find(e, classname, "saved_cvar_value")); )
-                       cvar_set(e.netname, e.message);
-}
-
 void menu_show_error()
 {
        drawstring('0 200 0', _("ERROR - MENU IS VISIBLE BUT NO MENU WAS DEFINED!"), '8 8 0', '1 0 0', 1, 0);
@@ -234,7 +213,7 @@ void CSQC_Init(void)
 }
 
 // CSQC_Shutdown : Called every time the CSQC code is shutdown (changing maps, quitting, etc)
-void CSQC_Shutdown(void)
+void Shutdown(void)
 {
 #ifdef USE_FTE
 #pragma TARGET id
@@ -255,8 +234,6 @@ void CSQC_Shutdown(void)
                db_save(ClientProgsDB, "client.db");
        db_close(ClientProgsDB);
 
-       cvar_clientsettemp_restore();
-
        if(camera_active)
                cvar_set("chase_active",ftos(chase_active_backup));
 
@@ -547,7 +524,6 @@ void GameCommand(string msg)
        if(argv(0) == "help" || argc == 0)
        {
                print(_("Usage: cl_cmd COMMAND..., where possible commands are:\n"));
-               print(_("  settemp cvar value\n"));
                print(_("  scoreboard_columns_set ...\n"));
                print(_("  scoreboard_columns_help\n"));
                GameCommand_Generic("help");
@@ -569,9 +545,6 @@ void GameCommand(string msg)
                else
                        hud_panel_radar_maximized = (stof(argv(1)) != 0);
        }
-       else if(cmd == "settemp") {
-               cvar_clientsettemp(argv(1), argv(2));
-       }
        else if(cmd == "scoreboard_columns_set") {
                Cmd_HUD_SetFields(argc);
        }
index bd9ffe6..9349d9c 100644 (file)
@@ -158,5 +158,3 @@ entity entcs_receiver[255]; // 255 is the engine limit on maxclients
 
 float hud;
 float view_quality;
-
-void cvar_clientsettemp(string cv, string val);
index 9595ed5..1d21f08 100644 (file)
@@ -206,6 +206,8 @@ float GameCommand_Generic(string command)
                print("  addtolist variable addedvalue\n");
                print("  records\n");
                print("  rankings (map argument optional)\n");
+               print("  settemp cvar value\n");
+               print("  settemp_restore\n");
                return TRUE;
        }
        
@@ -848,6 +850,14 @@ float GameCommand_Generic(string command)
                return TRUE;
 #endif
        }
+       else if(argv(0) == "settemp") {
+               cvar_settemp(argv(1), argv(2));
+               return TRUE;
+       }
+       else if(argv(0) == "settemp_restore") {
+               cvar_settemp_restore();
+               return TRUE;
+       }
 
        return FALSE;
 }
index a419e39..699a132 100644 (file)
@@ -1300,10 +1300,11 @@ void MapInfo_LoadMap(string s, float reinit)
        //      MapInfo_SwitchGameType(MAPINFO_TYPE_DEATHMATCH);
        //}
        
+       cvar_settemp_restore();
        if(reinit)
-               localcmd(strcat("\nsettemp_restore\nmap ", s, "\n"));
+               localcmd(strcat("\nmap ", s, "\n"));
        else
-               localcmd(strcat("\nsettemp_restore\nchangelevel ", s, "\n"));
+               localcmd(strcat("\nchangelevel ", s, "\n"));
 }
 
 string MapInfo_ListAllowedMaps(float pRequiredFlags, float pForbiddenFlags)
index 4de17c9..0d03912 100644 (file)
@@ -92,4 +92,4 @@ void MapInfo_ClearTemps(); // call this when done with mapinfo for this frame
 void MapInfo_Shutdown(); // call this in the shutdown handler
 
 #define MAPINFO_SETTEMP_ACL_USER cvar_string("g_mapinfo_settemp_acl")
-#define MAPINFO_SETTEMP_ACL_SYSTEM "-g_mapinfo_* -rcon_* -settemp_* -_* -g_ban* +*"
+#define MAPINFO_SETTEMP_ACL_SYSTEM "-g_mapinfo_* -rcon_* -_* -g_ban* +*"
index 10f77b6..f38b115 100644 (file)
@@ -523,31 +523,31 @@ float invertLengthLog(float x)
 vector decompressShortVector(float data)
 {
        vector out;
-       float pitch, yaw, len;
+       float p, y, len;
        if(data == 0)
                return '0 0 0';
-       pitch = (data & 0xF000) / 0x1000;
-       yaw =   (data & 0x0F80) / 0x80;
-       len =   (data & 0x007F);
+       p   = (data & 0xF000) / 0x1000;
+       y   = (data & 0x0F80) / 0x80;
+       len = (data & 0x007F);
 
-       //print("\ndecompress: pitch ", ftos(pitch)); print("yaw ", ftos(yaw)); print("len ", ftos(len), "\n");
+       //print("\ndecompress: p ", ftos(p)); print("y ", ftos(y)); print("len ", ftos(len), "\n");
 
-       if(pitch == 0)
+       if(p == 0)
        {
                out_x = 0;
                out_y = 0;
-               if(yaw == 31)
+               if(y == 31)
                        out_z = -1;
                else
                        out_z = +1;
        }
        else
        {
-               yaw   = .19634954084936207740 * yaw;
-               pitch = .19634954084936207740 * pitch - 1.57079632679489661922;
-               out_x = cos(yaw) *  cos(pitch);
-               out_y = sin(yaw) *  cos(pitch);
-               out_z =            -sin(pitch);
+               y   = .19634954084936207740 * y;
+               p = .19634954084936207740 * p - 1.57079632679489661922;
+               out_x = cos(y) *  cos(p);
+               out_y = sin(y) *  cos(p);
+               out_z =          -sin(p);
        }
 
        //print("decompressed: ", vtos(out), "\n");
@@ -558,7 +558,7 @@ vector decompressShortVector(float data)
 float compressShortVector(vector vec)
 {
        vector ang;
-       float pitch, yaw, len;
+       float p, y, len;
        if(vlen(vec) == 0)
                return 0;
        //print("compress: ", vtos(vec), "\n");
@@ -570,21 +570,21 @@ float compressShortVector(vector vec)
                error("BOGUS vectoangles");
        //print("angles: ", vtos(ang), "\n");
 
-       pitch = floor(0.5 + (ang_x + 90) * 16 / 180) & 15; // -90..90 to 0..14
-       if(pitch == 0)
+       p = floor(0.5 + (ang_x + 90) * 16 / 180) & 15; // -90..90 to 0..14
+       if(p == 0)
        {
                if(vec_z < 0)
-                       yaw = 31;
+                       y = 31;
                else
-                       yaw = 30;
+                       y = 30;
        }
        else
-               yaw = floor(0.5 + ang_y * 32 / 360)          & 31; // 0..360 to 0..32
+               y = floor(0.5 + ang_y * 32 / 360)          & 31; // 0..360 to 0..32
        len = invertLengthLog(vlen(vec));
 
-       //print("compressed: pitch ", ftos(pitch)); print("yaw ", ftos(yaw)); print("len ", ftos(len), "\n");
+       //print("compressed: p ", ftos(p)); print("y ", ftos(y)); print("len ", ftos(len), "\n");
 
-       return (pitch * 0x1000) + (yaw * 0x80) + len;
+       return (p * 0x1000) + (y * 0x80) + len;
 }
 
 void compressShortVector_init()
@@ -863,45 +863,29 @@ void get_mi_min_max_texcoords(float mode)
 }
 #endif
 
-#ifdef CSQC
-void cvar_settemp(string pKey, string pValue)
-{
-       error("cvar_settemp called from CSQC - use cvar_clientsettemp instead!");
-}
-void cvar_settemp_restore()
+void cvar_settemp(string cv, string val)
 {
-       error("cvar_settemp_restore called from CSQC - use cvar_clientsettemp instead!");
-}
-#else
-void cvar_settemp(string pKey, string pValue)
-{
-       float i;
-       string settemp_var;
-       if(cvar_string(pKey) == pValue)
-               return;
-       i = cvar("settemp_idx");
-       cvar_set("settemp_idx", ftos(i+1));
-       settemp_var = strcat("_settemp_x", ftos(i));
-#ifdef MENUQC
-       registercvar(settemp_var, "", 0);
-#else
-       registercvar(settemp_var, "");
-#endif
-       cvar_set("settemp_list", strcat("1 ", pKey, " ", settemp_var, " ", cvar_string("settemp_list")));
-       cvar_set(settemp_var, cvar_string(pKey));
-       cvar_set(pKey, pValue);
+       entity e;
+       for(e = world; (e = find(e, classname, "saved_cvar_value")); )
+               if(e.netname == cv)
+                       goto saved;
+       e = spawn();
+       e.classname = "saved_cvar_value";
+       e.netname = strzone(cv);
+       e.message = strzone(cvar_string(cv));
+:saved
+       cvar_set(cv, val);
 }
 
 void cvar_settemp_restore()
 {
-       // undo what cvar_settemp did
-       float n, i;
-       n = tokenize_console(cvar_string("settemp_list"));
-       for(i = 0; i < n - 3; i += 3)
-               cvar_set(argv(i + 1), cvar_string(argv(i + 2)));
-       cvar_set("settemp_list", "0");
+       entity e;
+       while((e = find(world, classname, "saved_cvar_value")))
+       {
+               cvar_set(e.netname, e.message);
+               remove(e);
+       }
 }
-#endif
 
 float almost_equals(float a, float b)
 {
@@ -1757,11 +1741,11 @@ float ReadInt24_t()
        return v;
 }
 #else
-void WriteInt24_t(float dest, float val)
+void WriteInt24_t(float dst, float val)
 {
        float v;
-       WriteShort(dest, (v = floor(val / 256)));
-       WriteByte(dest, val - v * 256); // 0..255
+       WriteShort(dst, (v = floor(val / 256)));
+       WriteByte(dst, val - v * 256); // 0..255
 }
 #endif
 #endif
@@ -2118,3 +2102,26 @@ entity ReadCSQCEntity()
        return findfloat(world, entnum, f);
 }
 #endif
+
+float shutdown_running;
+#ifdef SVQC
+void SV_Shutdown()
+#endif
+#ifdef CSQC
+void CSQC_Shutdown()
+#endif
+#ifdef MENUQC
+void m_shutdown()
+#endif
+{
+       if(shutdown_running)
+       {
+               print("Recursive shutdown detected! Only restoring cvars...\n");
+       }
+       else
+       {
+               shutdown_running = 1;
+               Shutdown();
+       }
+       cvar_settemp_restore(); // this must be done LAST, but in any case
+}
index e2dfcb3..470a826 100644 (file)
@@ -85,6 +85,7 @@ float CheckWireframeBox(entity forent, vector v0, vector dvx, vector dvy, vector
 #endif
 
 string fixPriorityList(string pl, float from, float to, float subtract, float complete);
+string mapPriorityList(string order, string(string) mapfunc);
 string swapInPriorityList(string order, float i, float j);
 
 float cvar_value_issafe(string s);
@@ -271,6 +272,11 @@ float xdecode(string s);
 #define sound(e,c,s,v,a) sound7(e,c,s,v,a,0,0)
 #endif
 
+float lowestbit(float f);
+
 #ifdef CSQC
 entity ReadCSQCEntity()
 #endif
+
+// generic shutdown handler
+void Shutdown();
index 8eaa5c3..c48dc41 100644 (file)
@@ -251,7 +251,7 @@ void CSQCPlayer_SetCamera()
 void CSQCPlayer_Remove()
 {
        csqcplayer = world;
-       cvar_clientsettemp("cl_movement_replay", "1");
+       cvar_settemp("cl_movement_replay", "1");
 }
 
 float CSQCPlayer_PreUpdate()
@@ -269,7 +269,7 @@ float CSQCPlayer_PostUpdate()
                return 0;
        csqcplayer = self;
        csqcplayer_status = CSQCPLAYERSTATUS_FROMSERVER;
-       cvar_clientsettemp("cl_movement_replay", "0");
+       cvar_settemp("cl_movement_replay", "0");
        self.entremove = CSQCPlayer_Remove;
        return 1;
 }
index 4b56257..8fc5f56 100644 (file)
@@ -202,7 +202,7 @@ float       stof(string val,...)  = #21;
 entity spawn(void)             = #22;
 void   remove(entity e)        = #23;
 
-entity findstring(entity start, .string field, string match)   = #24;
+entity find(entity start, .string field, string match)         = #24;
 entity findfloat(entity start, .float field, float match)      = #25;
 entity findentity(entity start, .entity field, entity match)   = #25;
 
index 2b0a636..640581b 100644 (file)
@@ -835,7 +835,7 @@ void m_toggle(float mode)
        }
 }
 
-void m_shutdown()
+void Shutdown()
 {
        entity e;
 
@@ -919,7 +919,7 @@ void m_goto(string itemname)
        }
        else
        {
-               for(e = NULL; (e = findstring(e, name, itemname)); )
+               for(e = NULL; (e = find(e, name, itemname)); )
                        if(e.classname != "vtbl")
                                break;
                if(e)
index 32b6928..4837397 100644 (file)
@@ -302,7 +302,6 @@ void cvar_changes_init()
                BADPREFIX("g_respawn_ghosts");
                BADPREFIX("g_voice_flood_");
                BADPREFIX("rcon_");
-               BADPREFIX("settemp_");
                BADPREFIX("sv_allowdownloads");
                BADPREFIX("sv_autodemo");
                BADPREFIX("sv_curl_");
@@ -1137,15 +1136,8 @@ void Map_Goto_SetFloat(float position)
        Map_Goto_SetStr(argv(position));
 }
 
-void GameResetCfg()
-{
-       // settings persist, except...
-       localcmd("\nsettemp_restore\n");
-}
-
 void Map_Goto(float reinit)
 {
-       GameResetCfg();
        MapInfo_LoadMap(getmapname_stored, reinit);
 }
 
@@ -1321,8 +1313,8 @@ float DoNextMapOverride(float reinit)
                }
        if(autocvar_lastlevel)
        {
-               GameResetCfg();
-               localcmd("set lastlevel 0\ntogglemenu\n");
+               cvar_settemp_restore();
+               localcmd("set lastlevel 0\ntogglemenu 1\n");
                alreadychangedlevel = TRUE;
                return TRUE;
        }
@@ -2960,14 +2952,11 @@ void RestoreGame()
        TargetMusic_RestoreGame();
 }
 
-void SV_Shutdown()
+void Shutdown()
 {
        entity e;
 
-       if(gameover > 1) // shutting down already?
-               return;
-
-       gameover = 2; // 2 = server shutting down
+       gameover = 2;
 
        if(world_initialized > 0)
        {
index 083feb4..a1e9f9e 100644 (file)
@@ -34,7 +34,6 @@ vehicles/vehicles_def.qh
 campaign.qh
 ../common/campaign_common.qh
 ../common/mapinfo.qh
-../common/util.qc
 
 accuracy.qh
 csqcprojectile.qh
@@ -208,4 +207,6 @@ mutators/sandbox.qc
 ../warpzonelib/util_server.qc
 ../warpzonelib/server.qc
 
+../common/util.qc
+
 ../common/if-this-file-errors-scroll-up-and-fix-the-warnings.fteqccfail