]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - sbar.c
Fix engine not starting on Windows if linked against SDL > 2.0.5
[xonotic/darkplaces.git] / sbar.c
diff --git a/sbar.c b/sbar.c
index 1da2be0804fec7fd950e7bc7c05f7f7b1c3e10bd..5028909f4fe8c5129f1748bff619585af3b28d3b 100644 (file)
--- a/sbar.c
+++ b/sbar.c
@@ -156,12 +156,12 @@ static void sbar_start(void)
        if (gamemode == GAME_DELUXEQUAKE || gamemode == GAME_BLOODOMNICIDE)
        {
        }
-       else if (gamemode == GAME_NEXUIZ)
+       else if (IS_OLDNEXUIZ_DERIVED(gamemode))
        {
                for (i = 0;i < 10;i++)
                        sb_nums[0][i] = Draw_CachePic_Flags (va(vabuf, sizeof(vabuf), "gfx/num_%i",i), CACHEPICFLAG_QUIET);
                sb_nums[0][10] = Draw_CachePic_Flags ("gfx/num_minus", CACHEPICFLAG_QUIET);
-               sb_colon = Draw_CachePic_Flags ("gfx/num_colon", CACHEPICFLAG_QUIET);
+               sb_colon = Draw_CachePic_Flags ("gfx/num_colon", CACHEPICFLAG_QUIET | CACHEPICFLAG_FAILONMISSING);
 
                sb_ammo[0] = Draw_CachePic_Flags ("gfx/sb_shells", CACHEPICFLAG_QUIET);
                sb_ammo[1] = Draw_CachePic_Flags ("gfx/sb_bullets", CACHEPICFLAG_QUIET);
@@ -219,7 +219,7 @@ static void sbar_start(void)
                sb_nums[0][10] = Draw_CachePic_Flags ("gfx/num_minus", CACHEPICFLAG_QUIET);
                sb_nums[1][10] = Draw_CachePic_Flags ("gfx/anum_minus", CACHEPICFLAG_QUIET);
 
-               sb_colon = Draw_CachePic_Flags ("gfx/num_colon", CACHEPICFLAG_QUIET);
+               sb_colon = Draw_CachePic_Flags ("gfx/num_colon", CACHEPICFLAG_QUIET | CACHEPICFLAG_FAILONMISSING);
                sb_slash = Draw_CachePic_Flags ("gfx/num_slash", CACHEPICFLAG_QUIET);
 
                sb_weapons[0][0] = Draw_CachePic_Flags ("gfx/inv_shotgun", CACHEPICFLAG_QUIET);
@@ -291,7 +291,7 @@ static void sbar_start(void)
                sb_scorebar = Draw_CachePic_Flags ("gfx/scorebar", CACHEPICFLAG_QUIET);
 
        //MED 01/04/97 added new hipnotic weapons
-               if (gamemode == GAME_HIPNOTIC)
+               if (gamemode == GAME_HIPNOTIC || gamemode == GAME_QUOTH)
                {
                        hsb_weapons[0][0] = Draw_CachePic_Flags ("gfx/inv_laser", CACHEPICFLAG_QUIET);
                        hsb_weapons[0][1] = Draw_CachePic_Flags ("gfx/inv_mjolnir", CACHEPICFLAG_QUIET);
@@ -515,7 +515,7 @@ static void Sbar_DrawXNum (int x, int y, int num, int digits, int lettersize, fl
 static int Sbar_IsTeammatch(void)
 {
        // currently only nexuiz uses the team score board
-       return ((gamemode == GAME_NEXUIZ)
+       return (IS_OLDNEXUIZ_DERIVED(gamemode)
                && (teamplay.integer > 0));
 }
 
@@ -692,7 +692,7 @@ static void Sbar_SoloScoreboard (void)
        int             minutes, seconds, tens, units;
        int             l;
 
-       if (gamemode != GAME_NEXUIZ) {
+       if (IS_OLDNEXUIZ_DERIVED(gamemode)) {
                dpsnprintf (str, sizeof(str), "Monsters:%3i /%3i", cl.stats[STAT_MONSTERS], cl.stats[STAT_TOTALMONSTERS]);
                Sbar_DrawString (8, 4, str);
 
@@ -709,7 +709,7 @@ static void Sbar_SoloScoreboard (void)
        Sbar_DrawString (184, 4, str);
 
 // draw level name
-       if (gamemode == GAME_NEXUIZ) {
+       if (IS_OLDNEXUIZ_DERIVED(gamemode)) {
                l = (int) strlen (cl.worldname);
                Sbar_DrawString (232 - l*4, 12, cl.worldname);
        } else {
@@ -804,7 +804,7 @@ static void Sbar_DrawInventory (void)
 
        // MED 01/04/97
        // hipnotic weapons
-       if (gamemode == GAME_HIPNOTIC)
+       if (gamemode == GAME_HIPNOTIC || gamemode == GAME_QUOTH)
        {
                int grenadeflashing=0;
                for (i=0 ; i<4 ; i++)
@@ -879,13 +879,13 @@ static void Sbar_DrawInventory (void)
                if (cl.stats[STAT_ITEMS] & (1<<(17+i)))
                {
                        //MED 01/04/97 changed keys
-                       if (gamemode != GAME_HIPNOTIC || (i>1))
+                       if (!(gamemode == GAME_HIPNOTIC || gamemode == GAME_QUOTH) || (i>1))
                                Sbar_DrawPic (192 + i*16, -16, sb_items[i]);
                }
 
        //MED 01/04/97 added hipnotic items
        // hipnotic items
-       if (gamemode == GAME_HIPNOTIC)
+       if (gamemode == GAME_HIPNOTIC || gamemode == GAME_QUOTH)
        {
                for (i=0 ; i<2 ; i++)
                        if (cl.stats[STAT_ITEMS] & (1<<(24+i)))
@@ -1037,7 +1037,7 @@ static void get_showspeed_unit(int unitnumber, double *conversion_factor, const
        {
                default:
                case 1:
-                       if(gamemode == GAME_NEXUIZ || gamemode == GAME_XONOTIC)
+                       if(IS_NEXUIZ_DERIVED(gamemode))
                                *unit = "in/s";
                        else
                                *unit = "qu/s";
@@ -1046,23 +1046,27 @@ static void get_showspeed_unit(int unitnumber, double *conversion_factor, const
                case 2:
                        *unit = "m/s";
                        *conversion_factor = 0.0254;
-                       if(gamemode != GAME_NEXUIZ && gamemode != GAME_XONOTIC) *conversion_factor *= 1.5;
+                       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
                        break;
                case 3:
                        *unit = "km/h";
                        *conversion_factor = 0.0254 * 3.6;
-                       if(gamemode != GAME_NEXUIZ && gamemode != GAME_XONOTIC) *conversion_factor *= 1.5;
+                       if(!IS_NEXUIZ_DERIVED(gamemode))
+                               *conversion_factor *= 1.5;
                        break;
                case 4:
                        *unit = "mph";
                        *conversion_factor = 0.0254 * 3.6 * 0.6213711922;
-                       if(gamemode != GAME_NEXUIZ && gamemode != GAME_XONOTIC) *conversion_factor *= 1.5;
+                       if(!IS_NEXUIZ_DERIVED(gamemode))
+                               *conversion_factor *= 1.5;
                        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(gamemode != GAME_NEXUIZ && gamemode != GAME_XONOTIC) *conversion_factor *= 1.5;
+                       if(!IS_NEXUIZ_DERIVED(gamemode))
+                               *conversion_factor *= 1.5;
                        break;
        }
 }
@@ -1101,6 +1105,7 @@ void Sbar_ShowFPS(void)
        char blurstring[32];
        char topspeedstring[48];
        char texstring[MAX_QPATH];
+       char entstring[32];
        qboolean red = false;
        soundstring[0] = 0;
        fpsstring[0] = 0;
@@ -1110,8 +1115,9 @@ void Sbar_ShowFPS(void)
        datestring[0] = 0;
        speedstring[0] = 0;
        blurstring[0] = 0;
-       texstring[0] = 0;
        topspeedstring[0] = 0;
+       texstring[0] = 0;
+       entstring[0] = 0;
        if (showfps.integer)
        {
                red = (showfps_framerate < 1.0f);
@@ -1193,20 +1199,51 @@ void Sbar_ShowFPS(void)
                vec3_t org;
                vec3_t dest;
                vec3_t temp;
-               trace_t trace;
+               trace_t svtrace, cltrace;
+               int hitnetentity = -1;
 
                Matrix4x4_OriginFromMatrix(&r_refdef.view.matrix, org);
                VectorSet(temp, 65536, 0, 0);
                Matrix4x4_Transform(&r_refdef.view.matrix, temp, dest);
-               trace.hittexture = NULL; // to make sure
-               // TODO change this trace to be stopped by anything "visible" (i.e. with a drawsurface), but not stuff like weapclip
-               // probably needs adding a new SUPERCONTENTS type
-               trace = CL_TraceLine(org, dest, MOVE_NORMAL, NULL, SUPERCONTENTS_SOLID, true, false, NULL, true, true);
-               if(trace.hittexture)
-                       strlcpy(texstring, trace.hittexture->name, sizeof(texstring));
+               // clear the traces as we may or may not fill them out, and mark them with an invalid fraction so we know if we did
+               memset(&svtrace, 0, sizeof(svtrace));
+               memset(&cltrace, 0, sizeof(cltrace));
+               svtrace.fraction = 2.0;
+               cltrace.fraction = 2.0;
+               // ray hits models (even animated ones) and ignores translucent materials
+               if (SVVM_prog != NULL)
+                       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));
                else
                        strlcpy(texstring, "(no texture hit)", sizeof(texstring));
                fps_strings++;
+               if (svtrace.fraction < cltrace.fraction)
+               {
+                       if (svtrace.ent != NULL)
+                       {
+                               prvm_prog_t *prog = SVVM_prog;
+                               dpsnprintf(entstring, sizeof(entstring), "server entity %i", (int)PRVM_EDICT_TO_PROG(svtrace.ent));
+                       }
+                       else
+                               strlcpy(entstring, "(no entity hit)", sizeof(entstring));
+               }
+               else
+               {
+                       if (CLVM_prog != NULL && cltrace.ent != NULL)
+                       {
+                               prvm_prog_t *prog = CLVM_prog;
+                               dpsnprintf(entstring, sizeof(entstring), "client entity %i", (int)PRVM_EDICT_TO_PROG(cltrace.ent));
+                       }
+                       else if (hitnetentity > 0)
+                               dpsnprintf(entstring, sizeof(entstring), "network entity %i", hitnetentity);
+                       else if (hitnetentity == 0)
+                               strlcpy(entstring, "world entity", sizeof(entstring));
+                       else
+                               strlcpy(entstring, "(no entity hit)", sizeof(entstring));
+               }
+               fps_strings++;
        }
        if (fps_strings)
        {
@@ -1290,6 +1327,13 @@ void Sbar_ShowFPS(void)
                        DrawQ_String(fps_x, fps_y, texstring, 0, fps_scalex, fps_scaley, 1, 1, 1, 1, 0, NULL, true, FONT_INFOBAR);
                        fps_y += fps_scaley;
                }
+               if (entstring[0])
+               {
+                       fps_x = vid_conwidth.integer - DrawQ_TextWidth(entstring, 0, fps_scalex, fps_scaley, true, FONT_INFOBAR);
+                       DrawQ_Fill(fps_x, fps_y, vid_conwidth.integer - fps_x, fps_scaley, 0, 0, 0, 0.5, 0);
+                       DrawQ_String(fps_x, fps_y, entstring, 0, fps_scalex, fps_scaley, 1, 1, 1, 1, 0, NULL, true, FONT_INFOBAR);
+                       fps_y += fps_scaley;
+               }
        }
 }
 
@@ -1332,7 +1376,7 @@ void Sbar_Draw (void)
                        Sbar_DrawScoreboard ();
                else if (cl.intermission == 1)
                {
-                       if(gamemode == GAME_NEXUIZ) // display full scoreboard (that is, show scores + map name)
+                       if(IS_OLDNEXUIZ_DERIVED(gamemode)) // display full scoreboard (that is, show scores + map name)
                        {
                                Sbar_DrawScoreboard();
                                return;
@@ -1344,7 +1388,7 @@ void Sbar_Draw (void)
                else if (gamemode == GAME_DELUXEQUAKE)
                {
                }
-               else if (gamemode == GAME_NEXUIZ)
+               else if (IS_OLDNEXUIZ_DERIVED(gamemode))
                {
                        if (sb_showscores || (cl.stats[STAT_HEALTH] <= 0 && cl_deathscoreboard.integer))
                        {
@@ -1636,7 +1680,7 @@ void Sbar_Draw (void)
 
                                // keys (hipnotic only)
                                //MED 01/04/97 moved keys here so they would not be overwritten
-                               if (gamemode == GAME_HIPNOTIC)
+                               if (gamemode == GAME_HIPNOTIC || gamemode == GAME_QUOTH)
                                {
                                        if (cl.stats[STAT_ITEMS] & IT_KEY1)
                                                Sbar_DrawPic (209, 3, sb_items[0]);
@@ -1730,7 +1774,7 @@ void Sbar_Draw (void)
        if (cl.csqc_vidvars.drawcrosshair && crosshair.integer >= 1 && !cl.intermission && !r_letterbox.value)
        {
                pic = Draw_CachePic (va(vabuf, sizeof(vabuf), "gfx/crosshair%i", crosshair.integer));
-               DrawQ_Pic((vid_conwidth.integer - pic->width * crosshair_size.value) * 0.5f, (vid_conheight.integer - pic->height * crosshair_size.value) * 0.5f, pic, pic->width * crosshair_size.value, pic->height * crosshair_size.value, crosshair_color_red.value, crosshair_color_green.value, crosshair_color_blue.value, crosshair_color_alpha.value, 0);
+               DrawQ_Pic((vid_conwidth.integer - Draw_GetPicWidth(pic) * crosshair_size.value) * 0.5f, (vid_conheight.integer - Draw_GetPicHeight(pic) * crosshair_size.value) * 0.5f, pic, Draw_GetPicWidth(pic) * crosshair_size.value, Draw_GetPicHeight(pic) * crosshair_size.value, crosshair_color_red.value, crosshair_color_green.value, crosshair_color_blue.value, crosshair_color_alpha.value, 0);
        }
 
        if (cl_prydoncursor.integer > 0)
@@ -1867,10 +1911,10 @@ void Sbar_DeathmatchOverlay (void)
                xmin = (int) (vid_conwidth.integer - (16 + 25) * 8 * FONT_SBAR->maxwidth) / 2; // 16 characters until name, then we assume 25 character names (they can be longer but usually aren't)
        xmax = vid_conwidth.integer - xmin;
 
-       if(gamemode == GAME_NEXUIZ)
+       if(IS_OLDNEXUIZ_DERIVED(gamemode))
                DrawQ_Pic (xmin - 8, ymin - 8, 0, xmax-xmin+1 + 2*8, ymax-ymin+1 + 2*8, 0, 0, 0, sbar_alpha_bg.value, 0);
 
-       DrawQ_Pic ((vid_conwidth.integer - sb_ranking->width)/2, 8, sb_ranking, 0, 0, 1, 1, 1, 1 * sbar_alpha_fg.value, 0);
+       DrawQ_Pic ((vid_conwidth.integer - Draw_GetPicWidth(sb_ranking))/2, 8, sb_ranking, 0, 0, 1, 1, 1, 1 * sbar_alpha_fg.value, 0);
 
        // draw the text
        y = 40;
@@ -2118,14 +2162,14 @@ void Sbar_Score (int margin)
                if (minutes >= 5)
                {
                        Sbar_DrawXNum(-12*6, 32, minutes,  3, 12, 1, 1, 1, 1, 0);
-                       if(sb_colon && sb_colon->tex != r_texture_notexture)
+                       if (Draw_IsPicLoaded(sb_colon))
                                DrawQ_Pic(sbar_x + -12*3, sbar_y + 32, sb_colon, 12, 12, 1, 1, 1, sbar_alpha_fg.value, 0);
                        Sbar_DrawXNum(-12*2, 32, seconds, -2, 12, 1, 1, 1, 1, 0);
                }
                else if (minutes >= 1)
                {
                        Sbar_DrawXNum(-12*6, 32, minutes,  3, 12, 1, 1, 0, 1, 0);
-                       if(sb_colon && sb_colon->tex != r_texture_notexture)
+                       if (Draw_IsPicLoaded(sb_colon))
                                DrawQ_Pic(sbar_x + -12*3, sbar_y + 32, sb_colon, 12, 12, 1, 1, 0, sbar_alpha_fg.value, 0);
                        Sbar_DrawXNum(-12*2, 32, seconds, -2, 12, 1, 1, 0, 1, 0);
                }
@@ -2139,7 +2183,7 @@ void Sbar_Score (int margin)
                minutes = (int)floor(cl.time / 60);
                seconds = (int)(floor(cl.time) - minutes * 60);
                Sbar_DrawXNum(-12*6, 32, minutes,  3, 12, 1, 1, 1, 1, 0);
-               if(sb_colon && sb_colon->tex != r_texture_notexture)
+               if (Draw_IsPicLoaded(sb_colon))
                        DrawQ_Pic(sbar_x + -12*3, sbar_y + 32, sb_colon, 12, 12, 1, 1, 1, sbar_alpha_fg.value, 0);
                Sbar_DrawXNum(-12*2, 32, seconds, -2, 12, 1, 1, 1, 1, 0);
        }
@@ -2183,7 +2227,7 @@ void Sbar_IntermissionOverlay (void)
        if(cl.stats[STAT_TOTALSECRETS])
        {
                Sbar_DrawNum (160, 104, cl.stats[STAT_SECRETS], 3, 0);
-               if (gamemode != GAME_NEXUIZ)
+               if (!IS_OLDNEXUIZ_DERIVED(gamemode))
                        Sbar_DrawPic (232, 104, sb_slash);
                Sbar_DrawNum (240, 104, cl.stats[STAT_TOTALSECRETS], 3, 0);
        }
@@ -2195,7 +2239,7 @@ void Sbar_IntermissionOverlay (void)
        if(cl.stats[STAT_TOTALMONSTERS])
        {
                Sbar_DrawNum (160, 144, cl.stats[STAT_MONSTERS], 3, 0);
-               if (gamemode != GAME_NEXUIZ)
+               if (!IS_OLDNEXUIZ_DERIVED(gamemode))
                        Sbar_DrawPic (232, 144, sb_slash);
                Sbar_DrawNum (240, 144, cl.stats[STAT_TOTALMONSTERS], 3, 0);
        }
@@ -2214,6 +2258,6 @@ Sbar_FinaleOverlay
 */
 void Sbar_FinaleOverlay (void)
 {
-       DrawQ_Pic((vid_conwidth.integer - sb_finale->width)/2, 16, sb_finale, 0, 0, 1, 1, 1, 1 * sbar_alpha_fg.value, 0);
+       DrawQ_Pic((vid_conwidth.integer - Draw_GetPicWidth(sb_finale))/2, 16, sb_finale, 0, 0, 1, 1, 1, 1 * sbar_alpha_fg.value, 0);
 }