Commit: 2a64126fc9cf1a5c754c1700a7dcc5d2f1bedcb3
Author: Randy Palamar
Date: Fri, 14 Jun 2024 10:08:52 -0600
start doing the thing
Diffstat:
A | LICENSE | | | 15 | +++++++++++++++ |
A | beamformer.c | | | 13 | +++++++++++++ |
A | build.sh | | | 13 | +++++++++++++ |
A | main.c | | | 90 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
A | util.c | | | 54 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
5 files changed, 185 insertions(+), 0 deletions(-)
diff --git a/LICENSE b/LICENSE
@@ -0,0 +1,15 @@
+ISC License (ISC)
+
+© 2024 Randy Palamar <randy@rnpnr.xyz>
+
+Permission to use, copy, modify, and distribute this software for any
+purpose with or without fee is hereby granted, provided that the above
+copyright notice and this permission notice appear in all copies.
+
+THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
diff --git a/beamformer.c b/beamformer.c
@@ -0,0 +1,13 @@
+/* See LICENSE for license details. */
+
+#include <raylib.h>
+#include <rlgl.h>
+
+#include "util.c"
+
+DEBUG_EXPORT void
+do_beamformer(BeamformerCtx *ctx)
+{
+ ClearBackground(DARKGRAY);
+ DrawFPS(20, 20);
+}
diff --git a/build.sh b/build.sh
@@ -0,0 +1,13 @@
+#!/bin/sh
+
+cflags="-march=native -ggdb -O0 -Wall"
+ldflags="-lraylib"
+
+# Hot Reloading/Debugging
+cflags="$cflags -D_DEBUG"
+
+libcflags="$cflags -fPIC -flto"
+libldflags="$ldflags -shared"
+
+cc $libcflags beamformer.c -o beamformer.so $libldflags
+cc $cflags -o ogl main.c $ldflags
diff --git a/main.c b/main.c
@@ -0,0 +1,90 @@
+/* See LICENSE for license details. */
+
+#include <raylib.h>
+#include <rlgl.h>
+
+#include "util.c"
+
+#ifndef _DEBUG
+
+#include "beamformer.c"
+static void do_debug(void) { }
+
+#else
+#include <dlfcn.h>
+#include <sys/stat.h>
+#include <time.h>
+#include <unistd.h>
+
+static const char *libname = "./beamformer.so";
+static void *libhandle;
+
+typedef void (do_beamformer_fn)(BeamformerCtx*);
+static do_beamformer_fn *do_beamformer;
+
+static struct timespec
+get_filetime(const char *name)
+{
+ struct stat sb;
+ if (stat(name, &sb) < 0)
+ return (struct timespec){0};
+ return sb.st_mtim;
+}
+
+static b32
+filetime_is_newer(struct timespec a, struct timespec b)
+{
+ return (a.tv_sec - b.tv_sec) + (a.tv_nsec - b.tv_nsec);
+}
+
+static void
+load_library(const char *lib)
+{
+ /* NOTE: glibc is buggy gnuware so we need to check this */
+ if (libhandle)
+ dlclose(libhandle);
+ libhandle = dlopen(lib, RTLD_NOW|RTLD_LOCAL);
+ if (!libhandle)
+ TraceLog(LOG_ERROR, "do_debug: dlopen: %s\n", dlerror());
+
+ do_beamformer = dlsym(libhandle, "do_beamformer");
+ if (!do_beamformer)
+ TraceLog(LOG_ERROR, "do_debug: dlsym: %s\n", dlerror());
+}
+
+static void
+do_debug(void)
+{
+ static struct timespec updated_time;
+ struct timespec test_time = get_filetime(libname);
+ if (filetime_is_newer(test_time, updated_time)) {
+ struct timespec sleep_time = {.tv_sec = 0, .tv_nsec = 100e6};
+ nanosleep(&sleep_time, &sleep_time);
+ load_library(libname);
+ updated_time = test_time;
+ }
+}
+
+#endif /* _DEBUG */
+
+int
+main(void)
+{
+ BeamformerCtx ctx = {0};
+
+ ctx.window_size = (uv2){.w = 720, .h = 720};
+
+ ctx.bg = DARKGRAY;
+ ctx.fg = (Color){ .r = 0xea, .g = 0xe1, .b = 0xb4, .a = 0xff };
+
+ SetConfigFlags(FLAG_VSYNC_HINT);
+ InitWindow(ctx.window_size.w, ctx.window_size.h, "OGL Beamformer");
+
+ while(!WindowShouldClose()) {
+ do_debug();
+
+ BeginDrawing();
+ do_beamformer(&ctx);
+ EndDrawing();
+ }
+}
diff --git a/util.c b/util.c
@@ -0,0 +1,54 @@
+/* See LICENSE for license details. */
+
+#ifndef _UTIL_C_
+#define _UTIL_C_
+
+#include <stdint.h>
+#include <stddef.h>
+
+#ifdef _DEBUG
+#define ASSERT(c) do { if (!(c)) asm("int3; nop"); } while (0);
+#define DEBUG_EXPORT
+#else
+#define ASSERT(c)
+#define DEBUG_EXPORT static
+#endif
+
+typedef int32_t i32;
+typedef uint32_t u32;
+typedef uint32_t b32;
+typedef float f32;
+typedef double f64;
+typedef ptrdiff_t size;
+
+typedef union {
+ struct { u32 x, y; };
+ struct { u32 w, h; };
+ u32 E[2];
+} uv2;
+
+typedef union {
+ struct { f32 x, y; };
+ f32 E[2];
+ Vector2 rl;
+} v2;
+
+typedef union {
+ struct { f32 x, y, z, w; };
+ struct { f32 r, g, b, a; };
+ f32 E[4];
+ Vector4 rl;
+} v4;
+
+typedef struct {
+ uv2 window_size;
+ u32 flags;
+
+ Color bg, fg;
+} BeamformerCtx;
+
+#define ARRAY_COUNT(a) (sizeof(a) / sizeof(*a))
+#define ABS(x) ((x) < 0 ? (-x) : (x))
+#define CLAMP(x, a, b) ((x) = (x) < (a) ? (a) : (x) > (b) ? (b) : (x))
+
+#endif /*_UTIL_C_ */