Debian Codegraph @

prboom2/src/dsda/hud_components/fps.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 FPS HUD Component
16 //
17
18 #include "base.h"
19
20 #include "fps.h"
21
22 typedef struct {
23 dsda_text_t component;
24 } local_component_t;
25
26 static local_component_t* local;
27
28 static void dsda_UpdateComponentText(char* str, size_t max_size) {
29 extern int dsda_render_stats_fps;
30
31 snprintf(
32 str,
33 max_size,
34 "%s%4d",
35 dsda_render_stats_fps < 35 ? dsda_TextColor(dsda_tc_exhud_fps_bad) :
36 dsda_TextColor(dsda_tc_exhud_fps_fine),
37 dsda_render_stats_fps
38 );
39 }
40
41 void dsda_InitFPSHC(int x_offset, int y_offset, int vpt, int* args, int arg_count, void** data) {
42 *data = Z_Calloc(1, sizeof(local_component_t));
43 local = *data;
44
45 dsda_InitTextHC(&local->component, x_offset, y_offset, vpt);
46 }
47
48 void dsda_UpdateFPSHC(void* data) {
49 local = data;
50
51 dsda_UpdateComponentText(local->component.msg, sizeof(local->component.msg));
52 dsda_RefreshHudText(&local->component);
53 }
54
55 void dsda_DrawFPSHC(void* data) {
56 local = data;
57
58 dsda_DrawBasicText(&local->component);
59 }