Debian Codegraph @

prboom2/src/dsda/hud_components/event_split.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 Event Split HUD Component
16 //
17
18 #include "base.h"
19
20 #include "event_split.h"
21
22 typedef struct {
23 const char* msg;
24 int default_delay;
25 int delay;
26 } dsda_split_state_t;
27
28 static dsda_split_state_t dsda_split_state[DSDA_SPLIT_CLASS_COUNT] = {
29 [DSDA_SPLIT_BLUE_KEY] = { "Blue Key", 0, 0 },
30 [DSDA_SPLIT_YELLOW_KEY] = { "Yellow Key", 0, 0 },
31 [DSDA_SPLIT_RED_KEY] = { "Red Key", 0, 0 },
32 [DSDA_SPLIT_USE] = { "Use", 2, 0 },
33 [DSDA_SPLIT_SECRET] = { "Secret", 0, 0 },
34 };
35
36 typedef struct {
37 dsda_text_t component;
38 } local_component_t;
39
40 static local_component_t* local;
41
42 static int ticks;
43
44 void dsda_InitEventSplitHC(int x_offset, int y_offset, int vpt, int* args, int arg_count, void** data) {
45 *data = Z_Calloc(1, sizeof(local_component_t));
46 local = *data;
47
48 dsda_InitTextHC(&local->component, x_offset, y_offset, vpt);
49 }
50
51 void dsda_AddSplit(dsda_split_class_t split_class, int lifetime) {
52 int minutes;
53 float seconds;
54 dsda_split_state_t* split_state;
55
56 if (!local)
57 return;
58
59 split_state = &dsda_split_state[split_class];
60
61 if (split_state->delay > 0) {
62 split_state->delay = split_state->default_delay;
63 return;
64 }
65
66 split_state->delay = split_state->default_delay;
67
68 ticks = lifetime;
69
70 // To match the timer, we use the leveltime value at the end of the frame
71 minutes = (leveltime + 1) / 35 / 60;
72 seconds = (float)((leveltime + 1) % (60 * 35)) / 35;
73 snprintf(
74 local->component.msg, sizeof(local->component.msg), "%s%d:%05.2f - %s",
75 dsda_TextColor(dsda_tc_exhud_event_split),
76 minutes, seconds, split_state->msg
77 );
78
79 dsda_RefreshHudText(&local->component);
80 }
81
82 void dsda_UpdateEventSplitHC(void* data) {
83 int i;
84
85 local = data;
86
87 if (ticks > 0)
88 --ticks;
89
90 for (i = 0; i < DSDA_SPLIT_CLASS_COUNT; ++i)
91 if (dsda_split_state[i].delay > 0)
92 --dsda_split_state[i].delay;
93 }
94
95 void dsda_DrawEventSplitHC(void* data) {
96 local = data;
97
98 if (ticks > 0)
99 dsda_DrawBasicText(&local->component);
100 }