diff options
author | quou <quou@disroot.org> | 2024-07-13 23:46:14 +1000 |
---|---|---|
committer | quou <quou@disroot.org> | 2024-07-13 23:46:31 +1000 |
commit | d7160d62b5d78e9191b4d61d7f491deb728cb478 (patch) | |
tree | 0bbb087df0fa32b2e47f00d8fc602f4921eec5a7 /standard.c | |
parent | a43eb70ebe7844db0a4ffece47c22ae12384781b (diff) |
Model loading and basic lighting.
Diffstat (limited to 'standard.c')
-rw-r--r-- | standard.c | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/standard.c b/standard.c new file mode 100644 index 0000000..96677ea --- /dev/null +++ b/standard.c @@ -0,0 +1,74 @@ +#include "maths.h" +#include "standard.h" + +int string_equal(const char* a, const char* b) { + while (*a && *b) { + if (*a != *b) { return 0; } + a++; b++; + } + return 1; +} + +int string_copy(char* dst, const char* src) { + int i; + for (i = 0; *src; src++, dst++, i++) { + *dst = *src; + } + return i; +} + +int int_to_buf(int n, char* buf) { + int i, sign, t; + unsigned n1; + + if(n == 0) { + buf[0] = '0'; + buf[1] = '\0'; + return 1; + } + + i = 0; + sign = n < 0; + + n1 = sign ? -n : n; + + while (n1 != 0) { + buf[i++] = n1 % 10 + '0'; + n1 =n1 / 10; + } + + if(sign) { + buf[i++] = '-'; + } + + buf[i] = '\0'; + + for (t = 0; t < i/2; t++) { + buf[t] ^= buf[i-t-1]; + buf[i-t-1] ^= buf[t]; + buf[t] ^= buf[i-t-1]; + } + + return i; +} + +int f_to_buf(int f, char* buf) { + int frac, w, i; + + frac = (((f) % (1 << fbits)) * 100) / (1 << fbits); + w = f >> fbits; + + i = 0; + + if (f < 0) { + buf[i] = '-'; + i++; + } + + i += int_to_buf(absolute(w), buf + i); + buf[i] = '.'; + i++; + i += int_to_buf(absolute(frac), buf + i); + + return i; +} |