From 55aee8c40bd7e1106138c126bbc4f613a46ff53c Mon Sep 17 00:00:00 2001 From: violette Date: Fri, 2 May 2025 12:43:00 -0400 Subject: [PATCH] feat: vbuf and licence --- main.c | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/main.c b/main.c index eebb8f8..f6254b3 100644 --- a/main.c +++ b/main.c @@ -1,3 +1,12 @@ +/* + * ---------------------------------------------------------------------------- + * "THE BEER-WARE LICENSE" (Revision 43): + * vi@violette.town wrote this file. You can do whatever you want with this + * stuff. If we meet some day, and you think this stuff is worth it, + * you can buy me a beer in return. Violette Paulin + * ---------------------------------------------------------------------------- + */ + #include #include #include @@ -60,6 +69,9 @@ struct Quaternions { double interpolationStep = 0; double zBuffer[SCREEN_HEIGHT * SCREEN_WIDTH]; char output[SCREEN_HEIGHT * SCREEN_WIDTH]; +#ifdef VBUF +char buf[SCREEN_HEIGHT * SCREEN_WIDTH + 30 * 20]; // stdout buffer +#endif static volatile char shouldBreak = 1; static volatile char currentlyMoving = 0; @@ -325,15 +337,14 @@ printCV(char face, struct json_object_element_s *r) void printAscii(struct json_value_s *json) { - fcntl(STDOUT_FILENO, F_SETFL, ~O_NONBLOCK); - char face = chooseMainFace(); + char face = chooseMainFace(); struct json_object_element_s *root = json_value_as_object(json)->start; printCV(face, root); for (int k = 0; k < SCREEN_WIDTH * SCREEN_HEIGHT; ++k) printf("%s", k % SCREEN_WIDTH ? chooseColor(output[k]) : "\r\n"); printf("\r\n"); - fcntl(STDIN_FILENO, F_SETFL, O_NONBLOCK); + fflush(stdout); } void @@ -482,6 +493,7 @@ handleAngle(char *input) char getInput(char *keyboardInput) { + fcntl(STDIN_FILENO, F_SETFL, O_NONBLOCK); char c = getchar(); if (c == '\033') { if ((c = getchar()) == '[') @@ -505,6 +517,8 @@ getInput(char *keyboardInput) if (c != EOF) *keyboardInput = c; while ((c = getchar()) != '\n' && c != EOF) {} //clean stdin + // + fcntl(STDIN_FILENO, F_SETFL, ~O_NONBLOCK); handleAngle(keyboardInput); return c; } @@ -540,11 +554,18 @@ main() t.c_cc[VINTR] = 3; tcsetattr(STDIN_FILENO, TCSANOW, &t); +#ifdef VBUF + setvbuf(stdout, buf, _IOFBF, sizeof(buf)); +#endif + Current = GET_ROTATE_Z_Q(0); struct json_value_s *json = readJson(); while (shouldBreak) { +#ifdef VBUF + memset(buf, ' ', sizeof(buf)); +#endif memset(output, ' ', SCREEN_WIDTH * SCREEN_HEIGHT); memset(zBuffer, DBL_MIN, SCREEN_WIDTH * SCREEN_HEIGHT * sizeof(double)); @@ -562,6 +583,6 @@ main() printf("\x1b[2J"); printAscii(json); getInput(&keyboardInput); - usleep(10000); + usleep(1000000 / 60); // 60fps max } }