From 6477265539fffa3728edcd8efdbd627a6abea182 Mon Sep 17 00:00:00 2001 From: farisawan-2000 Date: Wed, 16 Dec 2020 18:06:46 -0500 Subject: [PATCH] cleanup; refactoring --- config.h | 1 + s2d_draw.c | 6 +++--- s2d_parse.c | 30 ++++++++++-------------------- s2d_ustdlib.h | 3 --- 4 files changed, 14 insertions(+), 26 deletions(-) diff --git a/config.h b/config.h index aee063fa..1acb6416 100644 --- a/config.h +++ b/config.h @@ -25,6 +25,7 @@ extern Gfx *gdl_head; // The frame timer that is used to time s2d_type_print #define s2d_timer gGlobalTimer +extern u32 s2d_timer; // The equivalent vsprintf in your game (defaults to libultra _Printf) #define vsprintf(dst, str, fmt, args) _Printf(proutSprintf, dst, fmt, args) diff --git a/s2d_draw.c b/s2d_draw.c index 09a3d4ac..10b528f4 100644 --- a/s2d_draw.c +++ b/s2d_draw.c @@ -7,7 +7,7 @@ int myDegrees = 0; uObjMtx final_mtx, rot_mtx; int s2d_red = 255, s2d_green = 255, s2d_blue = 255, s2d_alpha = 255; -static Gfx s2d_init_dl[] = { +Gfx s2d_text_init_dl[] = { gsDPPipeSync(), gsDPSetTexturePersp(G_TP_NONE), gsDPSetTextureLOD(G_TL_TILE), @@ -28,7 +28,7 @@ static Gfx s2d_init_dl[] = { void setup_font(int idx) { gDPPipeSync(gdl_head++); gDPSetTextureFilter(gdl_head++, G_TF_POINT); - gSPDisplayList(gdl_head++, s2d_init_dl); + gSPDisplayList(gdl_head++, s2d_text_init_dl); gDPSetEnvColor(gdl_head++, s2d_red, s2d_green, s2d_blue, s2d_alpha); gDPSetCycleType(gdl_head++, G_CYC_1CYCLE); gDPSetRenderMode(gdl_head++, G_RM_XLU_SPRITE, G_RM_XLU_SPRITE2); @@ -55,7 +55,7 @@ void mtx_pipeline(uObjMtx *m, int x, int y) { // New matrix pipeline // Works with both rotation and scale, -// but is slow due to more float operations being performed +// but is (probably not noticeably) slower void mtx_pipeline2(uObjMtx *m, int x, int y) { // init Mat4 tmp, rot, scal, translate; diff --git a/s2d_parse.c b/s2d_parse.c index 98f6178c..bad3bd7e 100644 --- a/s2d_parse.c +++ b/s2d_parse.c @@ -9,12 +9,6 @@ #include "s2d_print.h" #include "s2d_ustdlib.h" -int saved_degrees = 0; -int s2d_colorFrames = 0; - - -extern u32 gGlobalTimer; - void s2d_snprint(int x, int y, const char *str, uObjMtx *buf, int len) { char *p = str; int tx = 0, ty = 0; @@ -22,25 +16,22 @@ void s2d_snprint(int x, int y, const char *str, uObjMtx *buf, int len) { int orig_x = x; int orig_y = y; + if (*p == '\0') return; + + // resets colors s2d_red = s2d_green = s2d_blue = 255; s2d_alpha = 255; - if (*p == '\0') return; do { - char r = *p; - int s, rd; + char current_char = *p; - - switch (r) { + switch (current_char) { case CH_SCALE: CH_SKIP(p); - s = s2d_atoi(p, &p); - myScale = s; + myScale = s2d_atoi(p, &p); break; case CH_ROT: CH_SKIP(p); - rd = s2d_atoi(p, &p); - saved_degrees = rd; - myDegrees = rd; + myDegrees = s2d_atoi(p, &p); break; case CH_TRANSLATE: CH_SKIP(p); @@ -50,7 +41,6 @@ void s2d_snprint(int x, int y, const char *str, uObjMtx *buf, int len) { y = s2d_atoi(p, &p); break; case CH_COLOR: - s2d_colorFrames++; CH_SKIP(p); s2d_red = s2d_atoi(p, &p); CH_SKIP(p); CH_SKIP(p); @@ -75,11 +65,11 @@ void s2d_snprint(int x, int y, const char *str, uObjMtx *buf, int len) { y += TEX_HEIGHT; break; default: - if (r != '\0') { + if (current_char != '\0') { if (myDegrees == 0) - draw_s2d_glyph(r, (x += (8 * myScale)) + tx, y + ty, (buf++)); + draw_s2d_glyph(current_char, (x += (8 * myScale)) + tx, y + ty, (buf++)); else - draw_s2d_glyph(r, (x += ((8 * myScale))) + tx, y + ty, (buf++)); + draw_s2d_glyph(current_char, (x += ((8 * myScale))) + tx, y + ty, (buf++)); } } if (*p == '\0') break; diff --git a/s2d_ustdlib.h b/s2d_ustdlib.h index d68df011..8d1ee5cd 100644 --- a/s2d_ustdlib.h +++ b/s2d_ustdlib.h @@ -1,6 +1,3 @@ -// ustdlib means un-standard library -// i'm going to abuse so much of my power here lol - extern int s2d_atoi(char *s, char **s2); extern int s2d_ilen(char *s);