aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authornathansmith117 <nathansmith117@sdf.org>2025-02-10 08:12:55 +0000
committernathansmith117 <nathansmith117@sdf.org>2025-02-10 08:12:55 +0000
commitb04d5702719eca30a95d1db2a927b6605ebd3477 (patch)
treec388a6b152c117e2903e7acf63054211739e6df4 /include
parentfe9b718f8978cfd792f7303214b2dd45172b8d4b (diff)
downloadsldj-b04d5702719eca30a95d1db2a927b6605ebd3477.tar.gz
sldj-b04d5702719eca30a95d1db2a927b6605ebd3477.tar.bz2
sldj-b04d5702719eca30a95d1db2a927b6605ebd3477.zip
Some fast math stuff added
Diffstat (limited to 'include')
-rw-r--r--include/libsldj/util.h32
1 files changed, 31 insertions, 1 deletions
diff --git a/include/libsldj/util.h b/include/libsldj/util.h
index fd89d1c..2c8dff6 100644
--- a/include/libsldj/util.h
+++ b/include/libsldj/util.h
@@ -1,6 +1,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
+#include <math.h>
#ifndef UTIL_H
#define UTIL_H
@@ -11,7 +12,17 @@
#define TOGGLE_BIT(b, n) (b ^ (0x1 << n))
#define HAS_FLAG(v, f) ((v & f) == f)
-// Just the same color structure as the raylib name.
+// Fast math macros.
+#define SLDJ_SQRT(number) sldjSqrtTable[(uint16_t)(number)]
+
+#define SLDJ_SIN(number) sldjSinTable[(uint16_t)(number)]
+#define SLDJ_COS(number) sldjCosTable[(uint16_t)(number)]
+#define SLDJ_TAN(number) sldjTanTable[(uint16_t)(number)]
+
+#define SLDJ_HYPOT2(x, y) (SLDJ_SQRT(x * x + y * y))
+#define SLDJ_HYPOT3(x, y, z) (SLDJ_SQRT(x * x + y * y + z * z))
+
+// Stuff stolen from raylib/raymath
#ifndef RL_COLOR_TYPE
#define RL_COLOR_TYPE
typedef struct Color {
@@ -22,6 +33,18 @@ typedef struct Color {
} Color;
#endif
+#ifndef PI
+ #define PI 3.14159265358979323846f
+#endif
+
+#ifndef DEG2RAD
+ #define DEG2RAD (PI/180.0f)
+#endif
+
+#ifndef RAD2DEG
+ #define RAD2DEG (180.0f/PI)
+#endif
+
// Used for sending information to a scanner.
typedef struct SldjContext {
uint16_t viewportWidth;
@@ -31,5 +54,12 @@ typedef struct SldjContext {
uint16_t yCount;
} SldjContext;
+// Tables.
+extern float sldjSqrtTable[65536];
+
+extern float sldjSinTable[65536];
+extern float sldjCosTable[65536];
+extern float sldjTanTable[65536];
+
#endif