aboutsummaryrefslogtreecommitdiff
path: root/src/player
diff options
context:
space:
mode:
authorXavier Del Campo Romero <xavi.dcr@tutanota.com>2022-06-26 23:41:15 +0200
committerXavier Del Campo Romero <xavi.dcr@tutanota.com>2022-06-26 23:42:48 +0200
commitbac711c5b36a2491c2bb3bb44d3fac6166a06277 (patch)
tree32ec9ecc286a6000ef92623f1cc12ad023dadfd9 /src/player
parent88713427f730001cd1c2a7046183c28c16262d1e (diff)
downloadjancity-bac711c5b36a2491c2bb3bb44d3fac6166a06277.tar.gz
human_player: deprecate memset(3) for zero-init
Diffstat (limited to 'src/player')
-rw-r--r--src/player/inc/human_player.h2
-rw-r--r--src/player/src/human_player.c17
2 files changed, 12 insertions, 7 deletions
diff --git a/src/player/inc/human_player.h b/src/player/inc/human_player.h
index fc6dd07..7d28b34 100644
--- a/src/player/inc/human_player.h
+++ b/src/player/inc/human_player.h
@@ -52,7 +52,7 @@ struct human_player
} d;
} sel[MAX_SELECTED_INSTANCES];
- struct
+ struct human_player_target
{
const struct instance *ins;
unsigned char t, n;
diff --git a/src/player/src/human_player.c b/src/player/src/human_player.c
index ffc4fd4..1d2af7d 100644
--- a/src/player/src/human_player.c
+++ b/src/player/src/human_player.c
@@ -430,9 +430,12 @@ static void set_target(struct human_player *const h, struct unit *const u,
const struct unit_target *const t)
{
unit_set_target(u, t);
- memset(&h->target, 0, sizeof h->target);
- h->target.ins = t->ins;
- h->target.render = true;
+
+ h->target = (const struct human_player_target)
+ {
+ .ins = t->ins,
+ .render = true
+ };
}
static void target_from_pos(struct player *const p,
@@ -487,7 +490,9 @@ static void move_units(struct human_player *const h,
static void deselect_instances(struct human_player *const h)
{
- memset(h->sel, 0, sizeof h->sel);
+ for (size_t i = 0; i < sizeof h->sel / sizeof *h->sel; i++)
+ h->sel[i] = (const struct sel_instance){0};
+
h->n_sel = 0;
}
@@ -520,7 +525,7 @@ static void update_target(struct human_player *const h)
enum {TOGGLE = 10};
if (!i->alive)
- memset(&h->target, 0, sizeof h->target);
+ h->target = (const struct human_player_target){0};
else if (++h->target.t >= TOGGLE)
{
enum {TIMES = 5};
@@ -529,7 +534,7 @@ static void update_target(struct human_player *const h)
h->target.t = 0;
if (++h->target.n >= TIMES)
- memset(&h->target, 0, sizeof h->target);
+ h->target = (const struct human_player_target){0};
}
}
}