]> git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - sbar.c
Refactor game/mod cvar defaults
[xonotic/darkplaces.git] / sbar.c
diff --git a/sbar.c b/sbar.c
index b6903ba076c64c4abfc52aca4aab6a39b5b42ee0..43b64b9e3396f827d9c64aeffa55c27614b21025 100644 (file)
--- a/sbar.c
+++ b/sbar.c
@@ -53,7 +53,7 @@ cachepic_t *sb_face_quad;
 cachepic_t *sb_face_invuln;
 cachepic_t *sb_face_invis_invuln;
 
-qboolean sb_showscores;
+qbool sb_showscores;
 
 int sb_lines;                  // scan lines to draw
 
@@ -85,37 +85,37 @@ cachepic_t *sb_complete;
 cachepic_t *sb_inter;
 cachepic_t *sb_finale;
 
-cvar_t cl_showfps = {CVAR_CLIENT | CVAR_SAVE, "cl_showfps", "0", "shows your rendered fps (frames per second)"};
-cvar_t cl_showsound = {CVAR_CLIENT | CVAR_SAVE, "cl_showsound", "0", "shows number of active sound sources, sound latency, and other statistics"};
-cvar_t cl_showblur = {CVAR_CLIENT | CVAR_SAVE, "cl_showblur", "0", "shows the current alpha level of motionblur"};
-cvar_t cl_showspeed = {CVAR_CLIENT | CVAR_SAVE, "cl_showspeed", "0", "shows your current speed (qu per second); number selects unit: 1 = qu/s, 2 = m/s, 3 = km/h, 4 = mph, 5 = knots"};
-cvar_t cl_showtopspeed = {CVAR_CLIENT | CVAR_SAVE, "cl_showtopspeed", "0", "shows your top speed (kept on screen for max 3 seconds); value -1 takes over the unit from cl_showspeed, otherwise it's an unit number just like in cl_showspeed"};
-cvar_t cl_showtime = {CVAR_CLIENT | CVAR_SAVE, "cl_showtime", "0", "shows current time of day (useful on screenshots)"};
-cvar_t cl_showtime_format = {CVAR_CLIENT | CVAR_SAVE, "cl_showtime_format", "%H:%M:%S", "format string for time of day"};
-cvar_t cl_showdate = {CVAR_CLIENT | CVAR_SAVE, "cl_showdate", "0", "shows current date (useful on screenshots)"};
-cvar_t cl_showdate_format = {CVAR_CLIENT | CVAR_SAVE, "cl_showdate_format", "%Y-%m-%d", "format string for date"};
-cvar_t cl_showtex = {CVAR_CLIENT, "cl_showtex", "0", "shows the name of the texture on the crosshair (for map debugging)"};
-
-cvar_t sbar_alpha_bg = {CVAR_CLIENT | CVAR_SAVE, "sbar_alpha_bg", "0.4", "opacity value of the statusbar background image"};
-cvar_t sbar_alpha_fg = {CVAR_CLIENT | CVAR_SAVE, "sbar_alpha_fg", "1", "opacity value of the statusbar weapon/item icons and numbers"};
-cvar_t sbar_hudselector = {CVAR_CLIENT | CVAR_SAVE, "sbar_hudselector", "0", "selects which of the builtin hud layouts to use (meaning is somewhat dependent on gamemode, so nexuiz has a very different set of hud layouts than quake for example)"};
-cvar_t sbar_scorerank = {CVAR_CLIENT | CVAR_SAVE, "sbar_scorerank", "1", "shows an overlay for your score (or team score) and rank in the scoreboard"};
-cvar_t sbar_gametime = {CVAR_CLIENT | CVAR_SAVE, "sbar_gametime", "1", "shows an overlay for the time left in the current match/level (or current game time if there is no timelimit set)"};
-cvar_t sbar_miniscoreboard_size = {CVAR_CLIENT | CVAR_SAVE, "sbar_miniscoreboard_size", "-1", "sets the size of the mini deathmatch overlay in items, or disables it when set to 0, or sets it to a sane default when set to -1"};
-cvar_t sbar_flagstatus_right = {CVAR_CLIENT | CVAR_SAVE, "sbar_flagstatus_right", "0", "moves Nexuiz flag status icons to the right"};
-cvar_t sbar_flagstatus_pos = {CVAR_CLIENT | CVAR_SAVE, "sbar_flagstatus_pos", "115", "pixel position of the Nexuiz flag status icons, from the bottom"};
-cvar_t sbar_info_pos = {CVAR_CLIENT | CVAR_SAVE, "sbar_info_pos", "0", "pixel position of the info strings (such as showfps), from the bottom"};
-
-cvar_t cl_deathscoreboard = {CVAR_CLIENT, "cl_deathscoreboard", "1", "shows scoreboard (+showscores) while dead"};
-
-cvar_t crosshair_color_red = {CVAR_CLIENT | CVAR_SAVE, "crosshair_color_red", "1", "customizable crosshair color"};
-cvar_t crosshair_color_green = {CVAR_CLIENT | CVAR_SAVE, "crosshair_color_green", "0", "customizable crosshair color"};
-cvar_t crosshair_color_blue = {CVAR_CLIENT | CVAR_SAVE, "crosshair_color_blue", "0", "customizable crosshair color"};
-cvar_t crosshair_color_alpha = {CVAR_CLIENT | CVAR_SAVE, "crosshair_color_alpha", "1", "how opaque the crosshair should be"};
-cvar_t crosshair_size = {CVAR_CLIENT | CVAR_SAVE, "crosshair_size", "1", "adjusts size of the crosshair on the screen"};
+cvar_t cl_showfps = {CF_CLIENT | CF_ARCHIVE, "cl_showfps", "0", "shows your rendered fps (frames per second)"};
+cvar_t cl_showsound = {CF_CLIENT | CF_ARCHIVE, "cl_showsound", "0", "shows number of active sound sources, sound latency, and other statistics"};
+cvar_t cl_showblur = {CF_CLIENT | CF_ARCHIVE, "cl_showblur", "0", "shows the current alpha level of motionblur"};
+cvar_t cl_showspeed = {CF_CLIENT | CF_ARCHIVE, "cl_showspeed", "0", "shows your current speed (qu per second); number selects unit: 1 = qu/s, 2 = m/s, 3 = km/h, 4 = mph, 5 = knots"};
+cvar_t cl_showspeed_factor = {CF_CLIENT | CF_ARCHIVE, "cl_showspeed_factor", "2.54", "multiplier of the centimeter for cl_showspeed. 1 unit = 1 inch in Quake, so this should be 2.54 for Quake, etc"};
+cvar_t cl_showtopspeed = {CF_CLIENT | CF_ARCHIVE, "cl_showtopspeed", "0", "shows your top speed (kept on screen for max 3 seconds); value -1 takes over the unit from cl_showspeed, otherwise it's an unit number just like in cl_showspeed"};
+cvar_t cl_showtime = {CF_CLIENT | CF_ARCHIVE, "cl_showtime", "0", "shows current time of day (useful on screenshots)"};
+cvar_t cl_showtime_format = {CF_CLIENT | CF_ARCHIVE, "cl_showtime_format", "%H:%M:%S", "format string for time of day"};
+cvar_t cl_showdate = {CF_CLIENT | CF_ARCHIVE, "cl_showdate", "0", "shows current date (useful on screenshots)"};
+cvar_t cl_showdate_format = {CF_CLIENT | CF_ARCHIVE, "cl_showdate_format", "%Y-%m-%d", "format string for date"};
+cvar_t cl_showtex = {CF_CLIENT, "cl_showtex", "0", "shows the name of the texture on the crosshair (for map debugging)"};
+
+cvar_t sbar_alpha_bg = {CF_CLIENT | CF_ARCHIVE, "sbar_alpha_bg", "0.4", "opacity value of the statusbar background image"};
+cvar_t sbar_alpha_fg = {CF_CLIENT | CF_ARCHIVE, "sbar_alpha_fg", "1", "opacity value of the statusbar weapon/item icons and numbers"};
+cvar_t sbar_hudselector = {CF_CLIENT | CF_ARCHIVE, "sbar_hudselector", "0", "selects which of the builtin hud layouts to use (meaning is somewhat dependent on gamemode, so nexuiz has a very different set of hud layouts than quake for example)"};
+cvar_t sbar_scorerank = {CF_CLIENT | CF_ARCHIVE, "sbar_scorerank", "1", "shows an overlay for your score (or team score) and rank in the scoreboard"};
+cvar_t sbar_gametime = {CF_CLIENT | CF_ARCHIVE, "sbar_gametime", "1", "shows an overlay for the time left in the current match/level (or current game time if there is no timelimit set)"};
+cvar_t sbar_miniscoreboard_size = {CF_CLIENT | CF_ARCHIVE, "sbar_miniscoreboard_size", "-1", "sets the size of the mini deathmatch overlay in items, or disables it when set to 0, or sets it to a sane default when set to -1"};
+cvar_t sbar_flagstatus_right = {CF_CLIENT | CF_ARCHIVE, "sbar_flagstatus_right", "0", "moves Nexuiz flag status icons to the right"};
+cvar_t sbar_flagstatus_pos = {CF_CLIENT | CF_ARCHIVE, "sbar_flagstatus_pos", "115", "pixel position of the Nexuiz flag status icons, from the bottom"};
+cvar_t sbar_info_pos = {CF_CLIENT | CF_ARCHIVE, "sbar_info_pos", "0", "pixel position of the info strings (such as showfps), from the bottom"};
+
+cvar_t cl_deathscoreboard = {CF_CLIENT, "cl_deathscoreboard", "1", "shows scoreboard (+showscores) while dead"};
+
+cvar_t crosshair_color_red = {CF_CLIENT | CF_ARCHIVE, "crosshair_color_red", "1", "customizable crosshair color"};
+cvar_t crosshair_color_green = {CF_CLIENT | CF_ARCHIVE, "crosshair_color_green", "0", "customizable crosshair color"};
+cvar_t crosshair_color_blue = {CF_CLIENT | CF_ARCHIVE, "crosshair_color_blue", "0", "customizable crosshair color"};
+cvar_t crosshair_color_alpha = {CF_CLIENT | CF_ARCHIVE, "crosshair_color_alpha", "1", "how opaque the crosshair should be"};
+cvar_t crosshair_size = {CF_CLIENT | CF_ARCHIVE, "crosshair_size", "1", "adjusts size of the crosshair on the screen"};
 
 static void Sbar_MiniDeathmatchOverlay (int x, int y);
-static void Sbar_DeathmatchOverlay (void);
 static void Sbar_IntermissionOverlay (void);
 static void Sbar_FinaleOverlay (void);
 
@@ -358,15 +358,13 @@ static void sbar_newmap(void)
 
 void Sbar_Init (void)
 {
-       if(gamemode == GAME_NORMAL) // Workaround so Quake doesn't trample on Xonotic.
-       {
-               Cmd_AddCommand(CMD_CLIENT, "+showscores", Sbar_ShowScores_f, "show scoreboard");
-               Cmd_AddCommand(CMD_CLIENT, "-showscores", Sbar_DontShowScores_f, "hide scoreboard");
-       }
+       Cmd_AddCommand(CF_CLIENT, "+showscores", Sbar_ShowScores_f, "show scoreboard");
+       Cmd_AddCommand(CF_CLIENT, "-showscores", Sbar_DontShowScores_f, "hide scoreboard");
        Cvar_RegisterVariable(&cl_showfps);
        Cvar_RegisterVariable(&cl_showsound);
        Cvar_RegisterVariable(&cl_showblur);
        Cvar_RegisterVariable(&cl_showspeed);
+       Cvar_RegisterVariable(&cl_showspeed_factor);
        Cvar_RegisterVariable(&cl_showtopspeed);
        Cvar_RegisterVariable(&cl_showtime);
        Cvar_RegisterVariable(&cl_showtime_format);
@@ -374,16 +372,16 @@ void Sbar_Init (void)
        Cvar_RegisterVariable(&cl_showdate_format);
        Cvar_RegisterVariable(&cl_showtex);
        
-       Cvar_RegisterAlias(&cl_showfps, "showfps");
-       Cvar_RegisterAlias(&cl_showsound, "showsound");
-       Cvar_RegisterAlias(&cl_showblur, "showblur");
-       Cvar_RegisterAlias(&cl_showspeed, "showspeed");
-       Cvar_RegisterAlias(&cl_showtopspeed, "showtopspeed");
-       Cvar_RegisterAlias(&cl_showtime, "showtime");
-       Cvar_RegisterAlias(&cl_showtime_format, "showtime_format");
-       Cvar_RegisterAlias(&cl_showdate, "showdate");
-       Cvar_RegisterAlias(&cl_showdate_format, "showdate_format");
-       Cvar_RegisterAlias(&cl_showtex, "showtex");
+       Cvar_RegisterVirtual(&cl_showfps, "showfps");
+       Cvar_RegisterVirtual(&cl_showsound, "showsound");
+       Cvar_RegisterVirtual(&cl_showblur, "showblur");
+       Cvar_RegisterVirtual(&cl_showspeed, "showspeed");
+       Cvar_RegisterVirtual(&cl_showtopspeed, "showtopspeed");
+       Cvar_RegisterVirtual(&cl_showtime, "showtime");
+       Cvar_RegisterVirtual(&cl_showtime_format, "showtime_format");
+       Cvar_RegisterVirtual(&cl_showdate, "showdate");
+       Cvar_RegisterVirtual(&cl_showdate_format, "showdate_format");
+       Cvar_RegisterVirtual(&cl_showtex, "showtex");
        
        Cvar_RegisterVariable(&sbar_alpha_bg);
        Cvar_RegisterVariable(&sbar_alpha_fg);
@@ -393,6 +391,8 @@ void Sbar_Init (void)
        Cvar_RegisterVariable(&sbar_miniscoreboard_size);
        Cvar_RegisterVariable(&sbar_info_pos);
        Cvar_RegisterVariable(&cl_deathscoreboard);
+       // This cvar is found in Fitzquake-derived engines and FTEQW and is read by the Alkaline 1.2 and Arcane Dimensions 1.80 CSQC
+       Cvar_RegisterVirtual(&sbar_alpha_bg, "scr_sbaralpha");
 
        Cvar_RegisterVariable(&crosshair_color_red);
        Cvar_RegisterVariable(&crosshair_color_green);
@@ -621,7 +621,7 @@ void Sbar_SortFrags (void)
                                                teamname = "Total Team Score";
                                                break;
                                }
-                               strlcpy(teams[teamlines-1].name, teamname, sizeof(teams[teamlines-1].name));
+                               dp_strlcpy(teams[teamlines-1].name, teamname, sizeof(teams[teamlines-1].name));
 
                                teams[teamlines-1].frags = 0;
                                teams[teamlines-1].colors = color + 16 * color;
@@ -683,7 +683,7 @@ static void Sbar_SoloScoreboard (void)
                Sbar_DrawString(8+22*8, 4, va(vabuf, sizeof(vabuf), "Secrets:%3i", cl.stats[STAT_SECRETS]));
 
        // format is like this: e1m1:The Sligpate Complex
-       dpsnprintf(str, sizeof(str), "%s:%s", cl.worldbasename, cl.worldmessage);
+       dpsnprintf(str, sizeof(str), "%s:%.39s", cl.worldbasename, cl.worldmessage);
 
        // if there's a newline character, terminate the string there
        if (strchr(str, '\n'))
@@ -892,7 +892,7 @@ static void Sbar_DrawInventory (void)
 
        // items
        for (i=0 ; i<6 ; i++)
-               if (cl.stats[STAT_ITEMS] & (1<<(17+i)))
+               if (cl.stats[STAT_ITEMS] & (1u<<(17+i)))
                {
                        //MED 01/04/97 changed keys
                        if (!(gamemode == GAME_HIPNOTIC || gamemode == GAME_QUOTH) || (i>1))
@@ -904,7 +904,7 @@ static void Sbar_DrawInventory (void)
        if (gamemode == GAME_HIPNOTIC || gamemode == GAME_QUOTH)
        {
                for (i=0 ; i<2 ; i++)
-                       if (cl.stats[STAT_ITEMS] & (1<<(24+i)))
+                       if (cl.stats[STAT_ITEMS] & (1u<<(24+i)))
                                Sbar_DrawPic (288 + i*16, -16, hsb_items[i]);
        }
 
@@ -912,14 +912,14 @@ static void Sbar_DrawInventory (void)
        {
                // new rogue items
                for (i=0 ; i<2 ; i++)
-                       if (cl.stats[STAT_ITEMS] & (1<<(29+i)))
+                       if (cl.stats[STAT_ITEMS] & (1u<<(29+i)))
                                Sbar_DrawPic (288 + i*16, -16, rsb_items[i]);
        }
        else
        {
                // sigils
                for (i=0 ; i<4 ; i++)
-                       if (cl.stats[STAT_ITEMS] & (1<<(28+i)))
+                       if (cl.stats[STAT_ITEMS] & (1u<<(28+i)))
                                Sbar_DrawPic (320-32 + i*8, -16, sb_sigil[i]);
        }
 }
@@ -1053,36 +1053,24 @@ static void get_showspeed_unit(int unitnumber, double *conversion_factor, const
        {
                default:
                case 1:
-                       if(IS_NEXUIZ_DERIVED(gamemode))
-                               *unit = "in/s";
-                       else
-                               *unit = "qu/s";
+                       *unit = "qu/s";
                        *conversion_factor = 1.0;
                        break;
                case 2:
                        *unit = "m/s";
-                       *conversion_factor = 0.0254;
-                       if(!IS_NEXUIZ_DERIVED(gamemode))
-                               *conversion_factor *= 1.5;
-                       // 1qu=1.5in is for non-Nexuiz/Xonotic only - Nexuiz/Xonotic players are overly large, but 1qu=1in fixes that
+                       *conversion_factor = 1.0 * cl_showspeed_factor.value * 0.01;
                        break;
                case 3:
                        *unit = "km/h";
-                       *conversion_factor = 0.0254 * 3.6;
-                       if(!IS_NEXUIZ_DERIVED(gamemode))
-                               *conversion_factor *= 1.5;
+                       *conversion_factor = 1.0 * (cl_showspeed_factor.value * 0.01) * 3.6;
                        break;
                case 4:
                        *unit = "mph";
-                       *conversion_factor = 0.0254 * 3.6 * 0.6213711922;
-                       if(!IS_NEXUIZ_DERIVED(gamemode))
-                               *conversion_factor *= 1.5;
+                       *conversion_factor = 1.0 * (cl_showspeed_factor.value * 0.01 * 3.6) * 0.6213711922;
                        break;
                case 5:
                        *unit = "knots";
-                       *conversion_factor = 0.0254 * 1.943844492; // 1 m/s = 1.943844492 knots, because 1 knot = 1.852 km/h
-                       if(!IS_NEXUIZ_DERIVED(gamemode))
-                               *conversion_factor *= 1.5;
+                       *conversion_factor = 1.0 * (cl_showspeed_factor.value * 0.01 * 3.6) * 0.539957;
                        break;
        }
 }
@@ -1122,7 +1110,7 @@ void Sbar_ShowFPS(void)
        char topspeedstring[48];
        char texstring[MAX_QPATH];
        char entstring[32];
-       qboolean red = false;
+       qbool red = false;
        soundstring[0] = 0;
        fpsstring[0] = 0;
        timedemostring1[0] = 0;
@@ -1154,12 +1142,12 @@ void Sbar_ShowFPS(void)
        }
        if (cl_showtime.integer)
        {
-               strlcpy(timestring, Sys_TimeString(cl_showtime_format.string), sizeof(timestring));
+               dp_strlcpy(timestring, Sys_TimeString(cl_showtime_format.string), sizeof(timestring));
                fps_strings++;
        }
        if (cl_showdate.integer)
        {
-               strlcpy(datestring, Sys_TimeString(cl_showdate_format.string), sizeof(datestring));
+               dp_strlcpy(datestring, Sys_TimeString(cl_showdate_format.string), sizeof(datestring));
                fps_strings++;
        }
        if (cl_showblur.integer)
@@ -1186,7 +1174,7 @@ void Sbar_ShowFPS(void)
                }
                if (cl_showtopspeed.integer)
                {
-                       qboolean topspeed_latched = false, topspeedxy_latched = false;
+                       qbool topspeed_latched = false, topspeedxy_latched = false;
                        get_showspeed_unit(cl_showtopspeed.integer, &f, &unit);
                        if (speed >= topspeed || current_time - top_time > 3)
                        {
@@ -1217,7 +1205,7 @@ void Sbar_ShowFPS(void)
                vec3_t temp;
                trace_t svtrace, cltrace;
                int hitnetentity = -1;
-               // TODO: Use CL_TraceLine_FromViewOrigin
+
                Matrix4x4_OriginFromMatrix(&r_refdef.view.matrix, org);
                VectorSet(temp, 65536, 0, 0);
                Matrix4x4_Transform(&r_refdef.view.matrix, temp, dest);
@@ -1227,13 +1215,13 @@ void Sbar_ShowFPS(void)
                svtrace.fraction = 2.0;
                cltrace.fraction = 2.0;
                // ray hits models (even animated ones) and ignores translucent materials
-               if (SVVM_prog != NULL)
+               if (sv.active)
                        svtrace = SV_TraceLine(org, dest, MOVE_HITMODEL, NULL, SUPERCONTENTS_SOLID, 0, MATERIALFLAGMASK_TRANSLUCENT, collision_extendmovelength.value);
                cltrace = CL_TraceLine(org, dest, MOVE_HITMODEL, NULL, SUPERCONTENTS_SOLID, 0, MATERIALFLAGMASK_TRANSLUCENT, collision_extendmovelength.value, true, false, &hitnetentity, true, true);
                if (cltrace.hittexture)
-                       strlcpy(texstring, cltrace.hittexture->name, sizeof(texstring));
+                       dp_strlcpy(texstring, cltrace.hittexture->name, sizeof(texstring));
                else
-                       strlcpy(texstring, "(no texture hit)", sizeof(texstring));
+                       dp_strlcpy(texstring, "(no texture hit)", sizeof(texstring));
                fps_strings++;
                if (svtrace.fraction < cltrace.fraction)
                {
@@ -1243,11 +1231,11 @@ void Sbar_ShowFPS(void)
                                dpsnprintf(entstring, sizeof(entstring), "server entity %i", (int)PRVM_EDICT_TO_PROG(svtrace.ent));
                        }
                        else
-                               strlcpy(entstring, "(no entity hit)", sizeof(entstring));
+                               dp_strlcpy(entstring, "(no entity hit)", sizeof(entstring));
                }
                else
                {
-                       if (CLVM_prog != NULL && cltrace.ent != NULL)
+                       if (cltrace.ent != NULL)
                        {
                                prvm_prog_t *prog = CLVM_prog;
                                dpsnprintf(entstring, sizeof(entstring), "client entity %i", (int)PRVM_EDICT_TO_PROG(cltrace.ent));
@@ -1255,9 +1243,9 @@ void Sbar_ShowFPS(void)
                        else if (hitnetentity > 0)
                                dpsnprintf(entstring, sizeof(entstring), "network entity %i", hitnetentity);
                        else if (hitnetentity == 0)
-                               strlcpy(entstring, "world entity", sizeof(entstring));
+                               dp_strlcpy(entstring, "world entity", sizeof(entstring));
                        else
-                               strlcpy(entstring, "(no entity hit)", sizeof(entstring));
+                               dp_strlcpy(entstring, "(no entity hit)", sizeof(entstring));
                }
                fps_strings++;
        }
@@ -1808,7 +1796,7 @@ Sbar_DeathmatchOverlay
 static float Sbar_PrintScoreboardItem(scoreboard_t *s, float x, float y)
 {
        int minutes;
-       qboolean myself = false;
+       qbool myself = false;
        unsigned char *c;
        char vabuf[1024];
        minutes = (int)((cl.intermission ? cl.completed_time - s->qw_entertime : cl.time - s->qw_entertime) / 60.0);