Debian Codegraph @

prboom2/src/dsda/hud_components/composite_time.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 Composite Time HUD Component
16 //
17
18 #include "base.h"
19
20 #include "composite_time.h"
21
22 typedef struct {
23 dsda_text_t component;
24 char label[8];
25 } local_component_t;
26
27 static local_component_t* local;
28
29 static void dsda_UpdateComponentText(char* str, size_t max_size) {
30 extern dboolean dsda_reborn;
31
32 int total_time;
33 int length;
34
35 total_time = hexen ?
36 players[consoleplayer].worldTimer :
37 totalleveltimes + leveltime;
38
39 if (total_time != leveltime)
40 length = snprintf(
41 str,
42 max_size,
43 "%s%s%d:%02d %s%d:%05.2f ",
44 local->label,
45 dsda_TextColor(dsda_tc_exhud_total_time),
46 total_time / 35 / 60,
47 (total_time % (60 * 35)) / 35,
48 dsda_TextColor(dsda_tc_exhud_level_time),
49 leveltime / 35 / 60,
50 (float) (leveltime % (60 * 35)) / 35
51 );
52 else
53 length = snprintf(
54 str,
55 max_size,
56 "%s%s%d:%05.2f ",
57 local->label,
58 dsda_TextColor(dsda_tc_exhud_level_time),
59 leveltime / 35 / 60,
60 (float) (leveltime % (60 * 35)) / 35
61 );
62
63 if (dsda_reborn && (demorecording || demoplayback)) {
64 int demo_tic = dsda_DemoTic();
65
66 snprintf(
67 str + length,
68 max_size - length,
69 "%s%d:%02d ",
70 dsda_TextColor(dsda_tc_exhud_demo_length),
71 demo_tic / 35 / 60,
72 (demo_tic % (60 * 35)) / 35
73 );
74 }
75 }
76
77 void dsda_InitCompositeTimeHC(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 if (arg_count < 1 || args[0])
82 snprintf(local->label, sizeof(local->label), "%stime ", dsda_TextColor(dsda_tc_exhud_time_label));
83 else
84 local->label[0] = '\0';
85
86 dsda_InitTextHC(&local->component, x_offset, y_offset, vpt);
87 }
88
89 void dsda_UpdateCompositeTimeHC(void* data) {
90 local = data;
91
92 dsda_UpdateComponentText(local->component.msg, sizeof(local->component.msg));
93 dsda_RefreshHudText(&local->component);
94 }
95
96 void dsda_DrawCompositeTimeHC(void* data) {
97 local = data;
98
99 dsda_DrawBasicText(&local->component);
100 }