Debian Codegraph @

prboom2/src/dsda/hud_components/render_stats.c

raw
1 //
2 // Copyright(C) 2022 by Ryan Krafnick
3 //
4 // This program is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU General Public License
6 // as published by the Free Software Foundation; either version 2
7 // of the License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // DESCRIPTION:
15 // DSDA Render Stats HUD Component
16 //
17
18 #include "dsda/render_stats.h"
19
20 #include "base.h"
21
22 #include "render_stats.h"
23
24 typedef struct {
25 dsda_text_t component[2];
26 } local_component_t;
27
28 static local_component_t* local;
29
30 static void dsda_UpdateCurrentComponentText(char* str, size_t max_size) {
31 extern dsda_render_stats_t dsda_render_stats;
32 extern int dsda_render_stats_fps;
33
34 snprintf(
35 str, max_size,
36 "%sFPS %s%4d %sSEGS %s%4d %sPLANES %s%4d %sSPRITES %s%4d",
37 dsda_TextColor(dsda_tc_exhud_render_label),
38 dsda_render_stats_fps < 35 ? dsda_TextColor(dsda_tc_exhud_render_bad) :
39 dsda_TextColor(dsda_tc_exhud_render_good),
40 dsda_render_stats_fps,
41 dsda_TextColor(dsda_tc_exhud_render_label),
42 dsda_render_stats.drawsegs > 256 ? dsda_TextColor(dsda_tc_exhud_render_bad) :
43 dsda_TextColor(dsda_tc_exhud_render_good),
44 dsda_render_stats.drawsegs,
45 dsda_TextColor(dsda_tc_exhud_render_label),
46 dsda_render_stats.visplanes > 128 ? dsda_TextColor(dsda_tc_exhud_render_bad) :
47 dsda_TextColor(dsda_tc_exhud_render_good),
48 dsda_render_stats.visplanes,
49 dsda_TextColor(dsda_tc_exhud_render_label),
50 dsda_render_stats.vissprites > 128 ? dsda_TextColor(dsda_tc_exhud_render_bad) :
51 dsda_TextColor(dsda_tc_exhud_render_good),
52 dsda_render_stats.vissprites
53 );
54 }
55
56 static void dsda_UpdateMaxComponentText(char* str, size_t max_size) {
57 extern dsda_render_stats_t dsda_render_stats_max;
58
59 snprintf(
60 str, max_size,
61 "%sMAX SEGS %s%4d %sPLANES %s%4d %sSPRITES %s%4d",
62 dsda_TextColor(dsda_tc_exhud_render_label),
63 dsda_render_stats_max.drawsegs > 256 ? dsda_TextColor(dsda_tc_exhud_render_bad) :
64 dsda_TextColor(dsda_tc_exhud_render_good),
65 dsda_render_stats_max.drawsegs,
66 dsda_TextColor(dsda_tc_exhud_render_label),
67 dsda_render_stats_max.visplanes > 128 ? dsda_TextColor(dsda_tc_exhud_render_bad) :
68 dsda_TextColor(dsda_tc_exhud_render_good),
69 dsda_render_stats_max.visplanes,
70 dsda_TextColor(dsda_tc_exhud_render_label),
71 dsda_render_stats_max.vissprites > 128 ? dsda_TextColor(dsda_tc_exhud_render_bad) :
72 dsda_TextColor(dsda_tc_exhud_render_good),
73 dsda_render_stats_max.vissprites
74 );
75 }
76
77 void dsda_InitRenderStatsHC(int x_offset, int y_offset, int vpt, int* args, int arg_count, void** data) {
78 *data = Z_Calloc(1, sizeof(local_component_t));
79 local = *data;
80
81 dsda_InitTextHC(&local->component[0], x_offset, y_offset, vpt);
82 dsda_InitTextHC(&local->component[1], x_offset, y_offset + 8, vpt);
83 }
84
85 void dsda_UpdateRenderStatsHC(void* data) {
86 local = data;
87
88 dsda_UpdateCurrentComponentText(local->component[0].msg, sizeof(local->component[0].msg));
89 dsda_UpdateMaxComponentText(local->component[1].msg, sizeof(local->component[1].msg));
90 dsda_RefreshHudText(&local->component[0]);
91 dsda_RefreshHudText(&local->component[1]);
92 }
93
94 void dsda_DrawRenderStatsHC(void* data) {
95 local = data;
96
97 dsda_DrawBasicText(&local->component[0]);
98 dsda_DrawBasicText(&local->component[1]);
99 }