Debian Codegraph @

prboom2/src/dsda/hud_components/map_time.c

raw
1 //
2 // Copyright(C) 2023 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 Map Time HUD Component
16 //
17
18 #include "base.h"
19
20 #include "map_time.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 int length;
30 int level_time;
31 int total_time;
32
33 total_time = hexen ?
34 players[consoleplayer].worldTimer :
35 totalleveltimes + leveltime;
36 level_time = leveltime;
37
38 total_time /= 35;
39 level_time /= 35;
40
41 length = snprintf(
42 str,
43 max_size,
44 "%s%02d:%02d:%02d\n",
45 dsda_TextColor(dsda_tc_map_time_level),
46 level_time / 3600,
47 (level_time % 3600) / 60,
48 level_time % 60
49 );
50
51 if (total_time != level_time)
52 snprintf(
53 str + length,
54 max_size - length,
55 "%s%02d:%02d:%02d\n",
56 dsda_TextColor(dsda_tc_map_time_total),
57 total_time / 3600,
58 (total_time % 3600) / 60,
59 total_time % 60
60 );
61 }
62
63 void dsda_InitMapTimeHC(int x_offset, int y_offset, int vpt, int* args, int arg_count, void** data) {
64 *data = Z_Calloc(1, sizeof(local_component_t));
65 local = *data;
66
67 dsda_InitBlockyHC(&local->component, x_offset, y_offset, vpt);
68 }
69
70 void dsda_UpdateMapTimeHC(void* data) {
71 local = data;
72
73 dsda_UpdateComponentText(local->component.msg, sizeof(local->component.msg));
74 dsda_RefreshHudText(&local->component);
75 }
76
77 void dsda_DrawMapTimeHC(void* data) {
78 local = data;
79
80 dsda_DrawBasicText(&local->component);
81 }