diff options
| author | Xavier Del Campo Romero <xavi.dcr@tutanota.com> | 2022-02-08 15:39:56 +0100 |
|---|---|---|
| committer | Xavier Del Campo Romero <xavi.dcr@tutanota.com> | 2022-03-30 08:20:21 +0200 |
| commit | 98f0d3e026f978d556cc91cfaa815d92a0b182c8 (patch) | |
| tree | bd9f39354da8fcbed0453bf45152c39e803abbf6 /src/gui | |
| parent | 56286a0a962119ddebf26df58d4a7c5d2f6a3fc7 (diff) | |
| download | jancity-98f0d3e026f978d556cc91cfaa815d92a0b182c8.tar.gz | |
Replace x_get functions with macros
The PS1 port relies on a heap for primitives since the GPU renders the
scene asynchronously. However, SDL-based platforms render primitives
synchronously, so structures can be allocated on the stack instead.
Diffstat (limited to 'src/gui')
| -rw-r--r-- | src/gui/src/gui.c | 71 |
1 files changed, 25 insertions, 46 deletions
diff --git a/src/gui/src/gui.c b/src/gui/src/gui.c index 2a5e53b..187e0b4 100644 --- a/src/gui/src/gui.c +++ b/src/gui/src/gui.c @@ -12,10 +12,9 @@ struct sprite gui_sprites[MAX_GUI_SPRITES]; static int render_topleft(void) { - struct sprite *const s = sprite_get(); + sprite_get_or_ret(s, -1); - if (!s - || sprite_clone(&gui_sprites[GUI_BAR_LEFT], s)) + if (sprite_clone(&gui_sprites[GUI_BAR_LEFT], s)) return -1; sprite_sort(s); @@ -24,9 +23,9 @@ static int render_topleft(void) static int render_topright(void) { - struct sprite *const s = sprite_get(); + sprite_get_or_ret(s, -1); - if (!s || sprite_clone(&gui_sprites[GUI_BAR_RIGHT], s)) + if (sprite_clone(&gui_sprites[GUI_BAR_RIGHT], s)) return -1; s->x = screen_w - s->w; @@ -51,10 +50,9 @@ static int render_topmid(void) a.i < n_mid; a.i++, a.x += mid_w) { - struct sprite *const m = sprite_get(); + sprite_get_or_ret(m, -1); - if (!m - || sprite_clone(&gui_sprites[GUI_BAR_MID], m)) + if (sprite_clone(&gui_sprites[GUI_BAR_MID], m)) return -1; m->x = a.x; @@ -91,10 +89,9 @@ static int render_seltop(struct sprite *const up) up->x = 16; sprite_sort(up); - struct sprite *const right = sprite_get(); + sprite_get_or_ret(right, -1); - if (!right - || sprite_clone(&gui_sprites[GUI_SELECTION_UP_RIGHT], right)) + if (sprite_clone(&gui_sprites[GUI_SELECTION_UP_RIGHT], right)) return -1; right->x = screen_w - right->w - up->x; @@ -119,12 +116,11 @@ static int render_selvert(const struct sprite *const up, const short x) a.i < n_vert; a.i++, a.y += vert_h) { - struct sprite *const v = sprite_get(); + sprite_get_or_ret(v, -1); - if (!v) + if (sprite_clone(&gui_sprites[GUI_SELECTION_MID_VERT], v)) return -1; - *v = gui_sprites[GUI_SELECTION_MID_VERT]; v->y = a.y; v->x = x; @@ -152,24 +148,22 @@ static int render_selvertright(const struct sprite *const up) static int render_seldown(const struct sprite *const up) { { - struct sprite *const left = sprite_get(); + sprite_get_or_ret(left, -1); - if (!left) + if (sprite_clone(&gui_sprites[GUI_SELECTION_DOWN_LEFT], left)) return -1; - *left = gui_sprites[GUI_SELECTION_DOWN_LEFT]; left->x = up->x; left->y = screen_h - left->h; sprite_sort(left); } { - struct sprite *const right = sprite_get(); + sprite_get_or_ret(right, -1); - if (!right) + if (sprite_clone(&gui_sprites[GUI_SELECTION_DOWN_RIGHT], right)) return -1; - *right = gui_sprites[GUI_SELECTION_DOWN_RIGHT]; right->x = screen_w - right->w - up->x; right->y = screen_h - right->h; sprite_sort(right); @@ -180,10 +174,8 @@ static int render_seldown(const struct sprite *const up) static int render_selrect(const struct sprite *const up) { - struct rect *const sel = rect_get(true); - - if (!sel) - return -1; + rect_get_or_ret(sel, -1); + semitrans_rect_init(sel); const struct sprite *const mid = &gui_sprites[GUI_SELECTION_MID], *const vert = &gui_sprites[GUI_SELECTION_MID_VERT]; @@ -214,11 +206,7 @@ static int render_selmid(const struct sprite *const up, const short y) a.i < n_mid; a.i++, a.x += mid_w) { - struct sprite *const m = sprite_get(); - - if (!m) - return -1; - + sprite_get_or_ret(m, -1); *m = gui_sprites[GUI_SELECTION_MID]; m->x = a.x; m->y = y; @@ -272,11 +260,8 @@ static int draw_hp(const struct instance *const i, const short x, const short y, const short gw = (WIDTH * i->hp) / max_hp; { - struct rect *const gr = rect_get(true); - - if (!gr) - return -1; - + rect_get_or_ret(gr, -1); + semitrans_rect_init(gr); gr->x = x; gr->y = ry; gr->w = gw; @@ -286,11 +271,8 @@ static int draw_hp(const struct instance *const i, const short x, const short y, } { - struct rect *const rr = rect_get(true); - - if (!rr) - return -1; - + rect_get_or_ret(rr, -1); + semitrans_rect_init(rr); rr->x = x + gw; rr->y = ry; rr->w = WIDTH - gw; @@ -314,11 +296,9 @@ static int draw_miners(const struct resource *const r) if (g->miners[i]) { enum {OFFSET = 112, SZ = 16, GAP = 4}; - struct rect *const r = rect_get(true); - - if (!r) - return -1; + rect_get_or_ret(r, -1); + semitrans_rect_init(r); r->x = OFFSET + n * (SZ + GAP); r->y = screen_h - 40; r->r = r->g = r->b = 127; @@ -434,10 +414,9 @@ static int render_selinfo(const struct sprite *const up, static int render_sel(const struct human_player *const h) { - struct sprite *const up = sprite_get(); + sprite_get_or_ret(up, -1); - if (!up - || render_seltop(up) + if (render_seltop(up) || render_selrect(up) || render_selmidtop(up) || render_selmiddown(up) |
