text typing now works; implemented initial vsprint

This commit is contained in:
farisawan-2000
2020-12-15 22:57:04 -05:00
parent 3a5aac7c23
commit 63bdf9ddec
5 changed files with 53 additions and 34 deletions

View File

@@ -21,4 +21,7 @@ extern Gfx *gdl_head;
// The frame timer that is used to time s2d_type_print
#define s2d_timer gGlobalTimer
// The equivalent vsprintf in your game (defaults to libultra _Printf)
#define vsprintf _Printf
#endif

View File

@@ -1,6 +1,7 @@
#include <ultra64.h>
#include <PR/gs2dex.h>
#include <PR/gu.h>
#include <stdarg.h>
#include "config.h"
@@ -9,19 +10,22 @@
#include "s2d_ustdlib.h"
int saved_degrees = 0;
int s2d_colorFrames = 0;
extern u32 gGlobalTimer;
void s2d_print(int x, int y, const char *str, uObjMtx *buf) {
void s2d_snprint(int x, int y, char *str, uObjMtx *buf, int len) {
char *p = str;
int tx = 0, ty = 0;
int tmp_len = 0;
// int r = 0, g = 0, b = 0, a = 0;
if (*p == '\0') return;
do {
char r = *p;
int s, rd;
switch (r) {
case CH_SCALE:
CH_SKIP(p);
@@ -42,6 +46,7 @@ void s2d_print(int x, int y, const char *str, uObjMtx *buf) {
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);
@@ -55,15 +60,23 @@ void s2d_print(int x, int y, const char *str, uObjMtx *buf) {
s2d_alpha = s2d_atoi(p, &p);
break;
default:
if (myDegrees == 0)
draw_s2d_glyph(r, (x += (8 * myScale)) + tx, y + ty, (buf++));
else
draw_s2d_glyph(r, (x += ((8 * myScale))) + tx, y + ty, (buf++));
// if (s2d_colorFrames > 2) {
// s2d_colorFrames = 0;
// s2d_red = s2d_green = s2d_blue = 255;
// s2d_alpha = 255;
// }
if (r != '\0') {
if (myDegrees == 0)
draw_s2d_glyph(r, (x += (8 * myScale)) + tx, y + ty, (buf++));
else
draw_s2d_glyph(r, (x += ((8 * myScale))) + tx, y + ty, (buf++));
}
}
// myDegrees += saved_degrees;
if (*p == '\0') break;
p++;
} while (*p != '\0');
tmp_len++;
} while (tmp_len < len);
myScale = 1;
myDegrees = 0;
// saved_degrees = 0;
@@ -71,31 +84,25 @@ void s2d_print(int x, int y, const char *str, uObjMtx *buf) {
ty = 0;
}
int ilen = 0;
void s2d_type_print(int x, int y, char *str, uObjMtx *buf, int *pos) {
char *temp_str = str;
char tmp = temp_str[*pos];
int len = s2d_strlen(str);
switch(tmp) {
case CH_SCALE:
ilen = s2d_ilen(str + *pos + 2);
if (ilen <= 1) {
(*pos) += ilen;
} else {
(*pos) += ilen + 1;
}
break;
case CH_ROT:
(*pos) += s2d_ilen(str + *pos);
break;
}
temp_str[*pos] = '\0';
s2d_print(x, y, temp_str, buf);
temp_str[*pos] = tmp;
void s2d_print(int x, int y, const char *str, uObjMtx *buf) {
s2d_snprint(x, y, str, buf, s2d_strlen(str));
}
void s2d_type_print(int x, int y, char *str, uObjMtx *buf, int *pos) {
int len = s2d_strlen(str);
s2d_snprint(x, y, str, buf, *pos);
if (s2d_timer % 2 == 0) {
if (*pos < len) (*pos)++;
if (*pos < len) {
(*pos)++;
}
}
}
void s2d_vsprint(int x, int y, uObjMtx *buf, char *str, ...) {
va_list args;
va_start(args, str);
sprintf()
}

View File

@@ -15,6 +15,6 @@
#define CH_NEWLINE '\n'
#define CH_GET_NEXT(x) (*(++x))
#define CH_SKIP(x) ((x++))
#define CH_SKIP(x) {x++;}
extern void s2d_print(int x, int y, const char *str, uObjMtx *buf);

Binary file not shown.

View File

@@ -183,13 +183,22 @@ char myS[] = "small test"
ROTATE "26"
"italic chungus";
int pos;
char my2[] = "small test"
ROTATE "2"
"big test"
ROTATE "0000046"
"big italic chungus"
ROTATE "124335";
int pos = 0;
int main(void) {
// printf("%d\n", s2d_atoi(s, &s));
// printf("%s\n", s);
// s2d_print(0,0, t);
while (pos != strlen(myS)) {
s2d_type_print(0, 0, myS, &pos);
while (pos != strlen(my2)) {
// s2d_type_print(0, 0, myS, &pos);
printf("%d %s\n",s2d_ilen(my2 + pos), my2 + pos);
pos++;
}
// printf("%d\n", s2d_ilen(sss + 1));
}