diff options
| author | Xavier Del Campo Romero <xavi.dcr@tutanota.com> | 2022-09-27 17:03:06 +0200 |
|---|---|---|
| committer | Xavier Del Campo Romero <xavi.dcr@tutanota.com> | 2022-11-01 16:26:16 +0100 |
| commit | 980858186149651df5543b6fc99a4f7db0cdd089 (patch) | |
| tree | d347200b0a562d84df505097651ad0642f207fdd /src/player | |
| parent | 39f50e601d395bbd2d78d0147ac530b756da2fff (diff) | |
| download | jancity-980858186149651df5543b6fc99a4f7db0cdd089.tar.gz | |
WIP
Diffstat (limited to 'src/player')
| -rw-r--r-- | src/player/inc/human_player.h | 5 | ||||
| -rw-r--r-- | src/player/src/human_player.c | 30 | ||||
| -rw-r--r-- | src/player/src/human_player_gui.c | 5 |
3 files changed, 16 insertions, 24 deletions
diff --git a/src/player/inc/human_player.h b/src/player/inc/human_player.h index 173ff80..abc25e9 100644 --- a/src/player/inc/human_player.h +++ b/src/player/inc/human_player.h @@ -22,9 +22,8 @@ enum {MAX_SELECTED_INSTANCES = 4}; struct human_player_cfg { - enum peripheral_type sel_periph; struct player_cfg pl; - int padn; + union peripheral *p; struct camera_dim dim; }; @@ -32,7 +31,7 @@ struct human_player { struct player pl; struct camera cam; - union peripheral periph; + union peripheral *periph; struct input in; struct sel_instance diff --git a/src/player/src/human_player.c b/src/player/src/human_player.c index 314581b..cded3b0 100644 --- a/src/player/src/human_player.c +++ b/src/player/src/human_player.c @@ -543,7 +543,7 @@ static void update_target(struct human_player *const h) static void update_from_pad(struct human_player *const h, struct player_others *const o) { - const struct pad *const p = &h->periph.pad.pad; + const struct pad *const p = &h->periph->pad.pad; const struct input *const in = &h->in; if (input_pad_justpressed(in, p, PAD_KEY_A)) @@ -559,9 +559,9 @@ static void update_from_pad(struct human_player *const h, static void update_from_touch(struct human_player *const h, struct player_others *const o) { - const struct mouse *const m = &h->periph.kbm.mouse; + const struct mouse *const m = &h->periph->kbm.mouse; const struct input *const in = &h->in; - struct peripheral_kbm *const kbm = &h->periph.kbm; + struct peripheral_kbm *const kbm = &h->periph->kbm; bool *const pan = &h->cam.pan; if (input_mouse_pressed(in, m, MOUSE_BUTTON_LEFT) && !*pan) @@ -590,8 +590,8 @@ static void update_from_touch(struct human_player *const h, static void update_from_keyboard_mouse(struct human_player *const h, struct player_others *const o) { - const struct mouse *const m = &h->periph.kbm.mouse; - const struct keyboard *const k = &h->periph.kbm.keyboard; + const struct mouse *const m = &h->periph->kbm.mouse; + const struct keyboard *const k = &h->periph->kbm.keyboard; const struct input *const in = &h->in; if (input_mouse_justreleased(in, m, MOUSE_BUTTON_LEFT)) @@ -619,10 +619,10 @@ void human_player_update(struct human_player *const h, human_player_gui_update(h); update_selected(h); update_target(h); - peripheral_update(&h->periph); - input_update(&h->in, &h->periph); + peripheral_update(h->periph); + input_update(&h->in, h->periph); - switch (h->periph.common.type) + switch (h->periph->common.type) { case PERIPHERAL_TYPE_PAD: update_from_pad(h, o); @@ -637,7 +637,7 @@ void human_player_update(struct human_player *const h, break; } - camera_update(&h->cam, &h->periph, &h->in); + camera_update(&h->cam, h->periph, &h->in); player_update(p); } } @@ -710,10 +710,10 @@ int human_player_render(const struct human_player *const h, || render_own_buildings(h) || render_resources(h, o->res, o->n_res) || human_player_gui_render(h) - || input_render(&h->in, &h->periph)) + || input_render(&h->in, h->periph)) return -1; - switch (h->periph.common.type) + switch (h->periph->common.type) { case PERIPHERAL_TYPE_PAD: /* Fall through. */ @@ -739,14 +739,8 @@ int human_player_init(const struct human_player_cfg *const cfg, if (player_init(&cfg->pl, &h->pl)) return -1; - const struct peripheral_cfg p_cfg = - { - .type = cfg->sel_periph, - .padn = cfg->padn - }; - - peripheral_init(&p_cfg, &h->periph); cursor_init(&h->cam.cursor); + h->periph = cfg->p; h->cam.dim = cfg->dim; h->top_gui = true; UTIL_STATIC_ASSERT(sizeof h->gui_res == sizeof h->pl.resources, diff --git a/src/player/src/human_player_gui.c b/src/player/src/human_player_gui.c index fce749e..79245dc 100644 --- a/src/player/src/human_player_gui.c +++ b/src/player/src/human_player_gui.c @@ -248,14 +248,13 @@ static int render_sel_multiple(const struct human_player *const h, static int render_sel(const struct human_player *const h) { - enum {OFFSET = 60}; struct gui_rounded_rect r; gui_rounded_rect_init(&r); r.common.x = 16; - r.common.y = screen_h - OFFSET; r.w = screen_w - (r.common.x * 2); - r.h = OFFSET; + r.h = screen_h / 4; + r.common.y = screen_h - r.h; if (h->n_sel == 1) return render_sel_single(h, &r.common); |
