From a7e593f33371d5e919fb26dd22334b1be9ce9503 Mon Sep 17 00:00:00 2001 From: farisawan-2000 Date: Fri, 11 Dec 2020 22:51:58 -0500 Subject: [PATCH] add arbitrary scaling functionality --- fixed_point_math.c | 14 +++++++++++++- mtx.c | 1 + s2d_draw.c | 7 ++++--- s2d_draw.h | 2 +- s2d_parse.c | 40 ++++++++++++++++------------------------ s2d_print.h | 14 ++++++++++++++ 6 files changed, 49 insertions(+), 29 deletions(-) create mode 100644 s2d_print.h diff --git a/fixed_point_math.c b/fixed_point_math.c index e20372d9..7f0e7e01 100644 --- a/fixed_point_math.c +++ b/fixed_point_math.c @@ -1 +1,13 @@ -// jk i dont think this file is needed lol \ No newline at end of file +// jk i dont think this file is needed lol +// update: it was needed :( + +// hopefully I'll only need s15.16 +// ^ clueless + +f32 qtof(int q) { + f32 lit = (float) ((q >> 16) & 0x7FFF); + if (q < 0) lit = -lit; + f32 dec = (float) ((float)(q & 0xFFFF) / (float)2^16); + return lit + dec; +} + diff --git a/mtx.c b/mtx.c index 4c8b77f6..fb513625 100644 --- a/mtx.c +++ b/mtx.c @@ -2,6 +2,7 @@ #include #include "stack.h" +// TODO: implement fixed point math instead of... this... void mat2_dst_mul(uObjMtx *dst, uObjMtx *m1, uObjMtx *m2) { int m1A = m1->m.A >> 16; int m1B = m1->m.B >> 16; diff --git a/s2d_draw.c b/s2d_draw.c index cf066060..96536ff0 100644 --- a/s2d_draw.c +++ b/s2d_draw.c @@ -20,6 +20,7 @@ static Gfx s2d_init_dl[] = { void setup_font(int idx) { gDPPipeSync(gDisplayListHead++); + gDPSetTextureFilter(gDisplayListHead++, G_TF_POINT); gSPDisplayList(gDisplayListHead++, s2d_init_dl); gDPSetCycleType(gDisplayListHead++, G_CYC_1CYCLE); gDPSetRenderMode(gDisplayListHead++, G_RM_XLU_SPRITE, G_RM_XLU_SPRITE2); @@ -37,9 +38,9 @@ void mtx_pipeline(uObjMtx *m, int x, int y) { gSPObjMatrix(gDisplayListHead++, m); } -void print_s2d(char c) { +void draw_s2d_glyph(char c, int x, int y, uObjMtx *mt) { setup_font(c); - mtx_pipeline(&final_mtx, 50, 50); + mtx_pipeline(mt, x, y); // gSPObjMatrix(gDisplayListHead++, &s2d_mat); gSPObjSprite(gDisplayListHead++, &s2d_font); -} \ No newline at end of file +} diff --git a/s2d_draw.h b/s2d_draw.h index 6d9b7ec2..835c2bfc 100644 --- a/s2d_draw.h +++ b/s2d_draw.h @@ -10,6 +10,6 @@ extern void setup_font(int idx); extern void mtx_pipeline(uObjMtx *m, int x, int y); -extern void print_s2d(char c); +extern void draw_s2d_glyph(char c, int x, int y, uObjMtx *mt); #endif \ No newline at end of file diff --git a/s2d_parse.c b/s2d_parse.c index 9ec72e32..c332ca15 100644 --- a/s2d_parse.c +++ b/s2d_parse.c @@ -2,39 +2,31 @@ #include #include "s2d_draw.h" +#include "s2d_print.h" -#define SCALE '\x80' -#define ROT '\x81' -#define TRANSLATE '\x82' - -#define CH_GET_NEXT(x) (*(++x)) - - - - - - -void s2d_parse(const char *str) { +void s2d_print(int x, int y, const char *str, uObjMtx *buf) { char *p = str; - while (*(p++) != '\0') { + do { char r = *p; - char s, t, x, y; + char s, rd, tx, ty; + if (*p == '\0') break; switch (r) { - case SCALE: + case CH_SCALE: s = CH_GET_NEXT(p); myScale = s; break; - case ROT: - t = CH_GET_NEXT(p); - degrees = t; + case CH_ROT: + rd = CH_GET_NEXT(p); + degrees = rd; break; - case TRANSLATE: - x = CH_GET_NEXT(p); - y = CH_GET_NEXT(p); + case CH_TRANSLATE: + tx = CH_GET_NEXT(p); + ty = CH_GET_NEXT(p); default: - x = 0; - // print(r); + draw_s2d_glyph(r, x += (29 * myScale), y, (buf++)); } - } + } while (*(p++) != '\0'); + myScale = 1; } + diff --git a/s2d_print.h b/s2d_print.h new file mode 100644 index 00000000..97ce74b8 --- /dev/null +++ b/s2d_print.h @@ -0,0 +1,14 @@ +#include +#include + +#define SCALE "\x80" +#define ROT "\x81" +#define TRANSLATE "\x82" + +#define CH_SCALE '\x80' +#define CH_ROT '\x81' +#define CH_TRANSLATE '\x82' + +#define CH_GET_NEXT(x) (*(++x)) + +extern void s2d_print(int x, int y, const char *str, uObjMtx *buf);