feat: vbuf and licence
This commit is contained in:
parent
b3873798f3
commit
55aee8c40b
1 changed files with 25 additions and 4 deletions
27
main.c
27
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 <stdio.h>
|
#include <stdio.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
@ -60,6 +69,9 @@ struct Quaternions {
|
||||||
double interpolationStep = 0;
|
double interpolationStep = 0;
|
||||||
double zBuffer[SCREEN_HEIGHT * SCREEN_WIDTH];
|
double zBuffer[SCREEN_HEIGHT * SCREEN_WIDTH];
|
||||||
char output[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 shouldBreak = 1;
|
||||||
static volatile char currentlyMoving = 0;
|
static volatile char currentlyMoving = 0;
|
||||||
|
@ -325,7 +337,6 @@ printCV(char face, struct json_object_element_s *r)
|
||||||
void
|
void
|
||||||
printAscii(struct json_value_s *json)
|
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;
|
struct json_object_element_s *root = json_value_as_object(json)->start;
|
||||||
printCV(face, root);
|
printCV(face, root);
|
||||||
|
@ -333,7 +344,7 @@ printAscii(struct json_value_s *json)
|
||||||
for (int k = 0; k < SCREEN_WIDTH * SCREEN_HEIGHT; ++k)
|
for (int k = 0; k < SCREEN_WIDTH * SCREEN_HEIGHT; ++k)
|
||||||
printf("%s", k % SCREEN_WIDTH ? chooseColor(output[k]) : "\r\n");
|
printf("%s", k % SCREEN_WIDTH ? chooseColor(output[k]) : "\r\n");
|
||||||
printf("\r\n");
|
printf("\r\n");
|
||||||
fcntl(STDIN_FILENO, F_SETFL, O_NONBLOCK);
|
fflush(stdout);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -482,6 +493,7 @@ handleAngle(char *input)
|
||||||
char
|
char
|
||||||
getInput(char *keyboardInput)
|
getInput(char *keyboardInput)
|
||||||
{
|
{
|
||||||
|
fcntl(STDIN_FILENO, F_SETFL, O_NONBLOCK);
|
||||||
char c = getchar();
|
char c = getchar();
|
||||||
if (c == '\033') {
|
if (c == '\033') {
|
||||||
if ((c = getchar()) == '[')
|
if ((c = getchar()) == '[')
|
||||||
|
@ -505,6 +517,8 @@ getInput(char *keyboardInput)
|
||||||
if (c != EOF)
|
if (c != EOF)
|
||||||
*keyboardInput = c;
|
*keyboardInput = c;
|
||||||
while ((c = getchar()) != '\n' && c != EOF) {} //clean stdin
|
while ((c = getchar()) != '\n' && c != EOF) {} //clean stdin
|
||||||
|
//
|
||||||
|
fcntl(STDIN_FILENO, F_SETFL, ~O_NONBLOCK);
|
||||||
handleAngle(keyboardInput);
|
handleAngle(keyboardInput);
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
@ -540,11 +554,18 @@ main()
|
||||||
t.c_cc[VINTR] = 3;
|
t.c_cc[VINTR] = 3;
|
||||||
tcsetattr(STDIN_FILENO, TCSANOW, &t);
|
tcsetattr(STDIN_FILENO, TCSANOW, &t);
|
||||||
|
|
||||||
|
#ifdef VBUF
|
||||||
|
setvbuf(stdout, buf, _IOFBF, sizeof(buf));
|
||||||
|
#endif
|
||||||
|
|
||||||
Current = GET_ROTATE_Z_Q(0);
|
Current = GET_ROTATE_Z_Q(0);
|
||||||
|
|
||||||
struct json_value_s *json = readJson();
|
struct json_value_s *json = readJson();
|
||||||
|
|
||||||
while (shouldBreak) {
|
while (shouldBreak) {
|
||||||
|
#ifdef VBUF
|
||||||
|
memset(buf, ' ', sizeof(buf));
|
||||||
|
#endif
|
||||||
memset(output, ' ', SCREEN_WIDTH * SCREEN_HEIGHT);
|
memset(output, ' ', SCREEN_WIDTH * SCREEN_HEIGHT);
|
||||||
memset(zBuffer, DBL_MIN, SCREEN_WIDTH * SCREEN_HEIGHT * sizeof(double));
|
memset(zBuffer, DBL_MIN, SCREEN_WIDTH * SCREEN_HEIGHT * sizeof(double));
|
||||||
|
|
||||||
|
@ -562,6 +583,6 @@ main()
|
||||||
printf("\x1b[2J");
|
printf("\x1b[2J");
|
||||||
printAscii(json);
|
printAscii(json);
|
||||||
getInput(&keyboardInput);
|
getInput(&keyboardInput);
|
||||||
usleep(10000);
|
usleep(1000000 / 60); // 60fps max
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue