From 24e3e0060cc3e1a899825d84a8e54ae3d5767fc8 Mon Sep 17 00:00:00 2001 From: farisawan-2000 Date: Sat, 13 Mar 2021 13:06:42 -0500 Subject: [PATCH] deferred prints! --- init.c | 1 + s2d_buffer.c | 39 +++++++++++++++++++++++++++++++++++++++ s2d_draw.c | 10 ++++++---- 3 files changed, 46 insertions(+), 4 deletions(-) create mode 100644 s2d_buffer.c diff --git a/init.c b/init.c index 27f8dcf4..9a702119 100644 --- a/init.c +++ b/init.c @@ -13,5 +13,6 @@ void s2d_stop(void) { gSPLoadUcode(gdl_head++, zex_text, zex_data); my_rdp_init(); my_rsp_init(); + s2d_reset_defer_index(); } diff --git a/s2d_buffer.c b/s2d_buffer.c new file mode 100644 index 00000000..06376886 --- /dev/null +++ b/s2d_buffer.c @@ -0,0 +1,39 @@ +#include "config.h" +#include "s2d_error.h" +#include "s2d_print.h" + +#define S2D_BUFFERSIZE 100 + +struct s2d_pos { + int x; + int y; +}; +static struct s2d_pos s2d_positions[S2D_BUFFERSIZE]; +static char *s2d_charBuffer[S2D_BUFFERSIZE]; +static int s2d_charBuffer_index = 0; + +void s2d_reset_defer_index(void) { + s2d_charBuffer_index = 0; +} + +// TODO: these DO NOT work +// pls debug :) +void s2d_print_deferred(int x, int y, const char *str) { + s2d_charBuffer[s2d_charBuffer_index] = str; + s2d_positions[s2d_charBuffer_index].x = x; + s2d_positions[s2d_charBuffer_index].y = y; + + s2d_charBuffer_index++; +} + +void s2d_handle_deferred(void) { + for (int i = 0; i < s2d_charBuffer_index; i++) { + s2d_print_alloc( + s2d_positions[i].x, + s2d_positions[i].y, + ALIGN_LEFT, + s2d_charBuffer[i] + ); + } +} + diff --git a/s2d_draw.c b/s2d_draw.c index 8bd6a502..a7bbb460 100644 --- a/s2d_draw.c +++ b/s2d_draw.c @@ -19,10 +19,12 @@ Gfx s2d_text_init_dl[] = { // IA8 // TODO: add more formats - gsDPSetCombineLERP(0, 0, 0, ENVIRONMENT, - 0, 0, 0, TEXEL0, - 0, 0, 0, ENVIRONMENT, - 0, 0, 0, TEXEL0), + gsDPSetCombineLERP( + 0, 0, 0, ENVIRONMENT, + 0, 0, 0, TEXEL0, + 0, 0, 0, ENVIRONMENT, + 0, 0, 0, TEXEL0 + ), gsSPEndDisplayList(), };