human_player: deprecate memset(3) for zero-init

This commit is contained in:
Xavier Del Campo Romero 2022-06-26 23:41:15 +02:00
parent 4305732e0a
commit e869bfd0f6
2 changed files with 12 additions and 7 deletions

View File

@ -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;

View File

@ -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};
}
}
}