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/gfx/ps1 | |
| 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/gfx/ps1')
| -rw-r--r-- | src/gfx/ps1/src/heap.c | 41 | ||||
| -rw-r--r-- | src/gfx/ps1/src/sort.c | 1 |
2 files changed, 38 insertions, 4 deletions
diff --git a/src/gfx/ps1/src/heap.c b/src/gfx/ps1/src/heap.c index b67ee3e..ab45d94 100644 --- a/src/gfx/ps1/src/heap.c +++ b/src/gfx/ps1/src/heap.c @@ -3,17 +3,52 @@ #include <stddef.h> static unsigned int sel; +static size_t heap_i; void gfx_swapheap(void) { sel ^= 1; + heap_i = 0; } -void *gfx_port_heap(size_t *const n) +static void *get_element(const size_t sz) { enum {HEAP_SZ = 5120, N_HEAPS = 2}; static char heaps[N_HEAPS][HEAP_SZ]; + const size_t new_sz = heap_i + sz; + void *ret = NULL; - *n = sizeof *heaps / sizeof **heaps; - return heaps[sel]; + if (new_sz < sizeof *heaps / sizeof **heaps) + { + ret = &heaps[sel][heap_i]; + heap_i += sz; + } + else + { + fprintf(stderr, "%s: exceeded heap size (%zu/%zu)\n", + __func__, new_sz, sizeof *heaps / sizeof **heaps); + return NULL; + } + + return ret; +} + +struct sprite *sprite_get(void) +{ + return get_element(sizeof (struct sprite)); +} + +struct quad *quad_get(void) +{ + return get_element(sizeof (struct quad)); +} + +struct rect *rect_get(void) +{ + return get_element(sizeof (struct rect)); +} + +struct stp_4line *stp_4line_get(void) +{ + return get_element(sizeof (struct stp_4line)); } diff --git a/src/gfx/ps1/src/sort.c b/src/gfx/ps1/src/sort.c index 5cc14aa..03449fc 100644 --- a/src/gfx/ps1/src/sort.c +++ b/src/gfx/ps1/src/sort.c @@ -55,7 +55,6 @@ void gfx_draw(void) D2_BCR = 0; D2_CHCR = (1 << 0xa) | 1 | (1 << 0x18); first = NULL; - gfx_reset_heap(); } void gfx_sync(void) |
