Commit: 2f8020d0efaa918c1e544800bfa1a806780def67
Parent: 272a24c00d46f0006276ee2b8c15e55785c1e875
Author: Randy Palamar
Date: Sun, 9 Jun 2024 09:06:55 -0600
support building without hot reloading
Hot reloading is enabled in _DEBUG mode only.
Diffstat:
4 files changed, 39 insertions(+), 13 deletions(-)
diff --git a/build.sh b/build.sh
@@ -1,9 +1,12 @@
#!/bin/sh
-cflags="-march=native -O2 -Wall"
+cflags="-march=native -O0 -Wall"
ldflags="-lraylib"
-libcflags="-march=native -Wall -O2 -fPIC"
+# Hot Reloading/Debugging
+cflags="$cflags -D_DEBUG"
+
+libcflags="$cflags -fPIC"
libldflags="$ldflags -shared"
cc $libcflags colourpicker.c -o libcolourpicker.so $libldflags
diff --git a/colourpicker.c b/colourpicker.c
@@ -1,6 +1,7 @@
/* See LICENSE for copyright details */
#include <stdio.h>
#include <raylib.h>
+
#include "util.c"
static const char *mode_labels[CPM_LAST][4] = {
diff --git a/main.c b/main.c
@@ -7,13 +7,14 @@
#include "util.c"
+static const char *fontpath = "/home/rnp/.local/share/fonts/Aozora Mincho Medium.ttf";
+
+#ifdef _DEBUG
typedef struct timespec Filetime;
static const char *libname = "./libcolourpicker.so";
static void *libhandle;
-static const char *fontpath = "/home/rnp/.local/share/fonts/Aozora Mincho Medium.ttf";
-
typedef void (do_colour_picker_fn)(ColourPickerCtx *);
static do_colour_picker_fn *do_colour_picker;
@@ -42,6 +43,24 @@ load_library(const char *lib)
fprintf(stderr, "Couldn't Hot Reload ColourPicker\n");
}
+static void
+do_debug(void)
+{
+ static Filetime updated_time;
+ Filetime test_time = get_filetime(libname);
+ if (compare_filetime(test_time, updated_time)) {
+ load_library(libname);
+ updated_time = test_time;
+ }
+
+}
+#else
+
+static void do_debug(void) { }
+#include "colourpicker.c"
+
+#endif /* _DEBUG */
+
int
main(void)
{
@@ -53,20 +72,14 @@ main(void)
SetConfigFlags(FLAG_VSYNC_HINT);
InitWindow(ctx.window_size.w, ctx.window_size.h, "Colour Picker");
- load_library(libname);
ctx.font = LoadFontEx(fontpath, 128, 0, 0);
- Filetime updated_time = get_filetime(libname);
while(!WindowShouldClose()) {
+ do_debug();
+
BeginDrawing();
do_colour_picker(&ctx);
EndDrawing();
-
- Filetime test_time = get_filetime(libname);
- if (compare_filetime(test_time, updated_time)) {
- load_library(libname);
- updated_time = test_time;
- }
}
}
diff --git a/util.c b/util.c
@@ -1,8 +1,15 @@
/* See LICENSE for copyright details */
+#ifndef _UTIL_C_
+#define _UTIL_C_
+
#include <stddef.h>
#include <stdint.h>
-#define ASSERT(c) do { if (!(c)) __builtin_debugtrap(); } while (0);
+#ifdef _DEBUG
+#define ASSERT(c) do { if (!(c)) asm("int3; nop"); } while (0);
+#else
+#define ASSERT(c)
+#endif
typedef int32_t i32;
typedef uint32_t u32;
@@ -52,3 +59,5 @@ typedef struct {
} ColourPickerCtx;
#define CLAMP(x, a, b) ((x) = (x) < (a) ? (a) : (x) > (b) ? (b) : (x))
+
+#endif /* _UTIL_C_ */