summaryrefslogtreecommitdiff
path: root/src/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c97
1 files changed, 97 insertions, 0 deletions
diff --git a/src/main.c b/src/main.c
new file mode 100644
index 0000000..2639aae
--- /dev/null
+++ b/src/main.c
@@ -0,0 +1,97 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <string.h>
+#include <assert.h>
+#include <raylib.h>
+#include <complex.h>
+#include <math.h>
+
+#include <dlfcn.h>
+
+#include "plug.h"
+
+#define ARRAY_LEN(xs) sizeof(xs)/sizeof(xs[0])
+
+const char *libplug_file_name = "libplug.so";
+void *libplug = NULL;
+
+#ifdef HOTRELOAD
+#define PLUG(name, ...) name##_t *name = NULL;
+#else
+#define PLUG(name, ...) name##_t name;
+#endif
+LIST_OF_PLUGS
+#undef PLUG
+
+#ifdef HOTRELOAD
+bool reload_plugin(void)
+{
+ if (libplug != NULL) dlclose(libplug);
+
+ libplug = dlopen(libplug_file_name, RTLD_NOW);
+ if (libplug == NULL) {
+ fprintf(stderr, "ERROR: could not load %s: %s\n", libplug_file_name, dlerror());
+ return false;
+ }
+
+ #define PLUG(name, ...) \
+ name = dlsym(libplug, #name); \
+ if (name == NULL) { \
+ fprintf(stderr, "ERROR: could not find %s symbol in %s: %s\n", \
+ #name, libplug_file_name, dlerror()); \
+ return false; \
+ }
+ LIST_OF_PLUGS
+ #undef PLUG
+
+ return true;
+}
+#else
+#define reload_plugin() true
+#endif
+
+int main(void)
+{
+ if (!reload_plugin()) return 1;
+
+ size_t factor = 60;
+ SetConfigFlags(FLAG_WINDOW_RESIZABLE);
+
+ InitWindow(factor*16, factor*9, "MVis");
+ SetTargetFPS(60);
+ InitAudioDevice();
+
+ plug_init();
+
+#ifdef HOTRELOAD
+ while (!WindowShouldClose()) {
+ if (IsKeyPressed(KEY_O)) {
+ void *state = plug_pre_reload();
+ if (!reload_plugin()) return 1;
+ plug_post_reload(state);
+ }
+ if (IsKeyPressed(KEY_X)) {
+ break;
+ }
+
+ plug_update();
+ }
+
+#else
+ while (!WindowShouldClose()) {
+ if (IsKeyPressed(KEY_O)) {
+ fprintf(stderr, "INFO: MVis not compiled with HOTRELOAD\n");
+ }
+ if (IsKeyPressed(KEY_X)) {
+ break;
+ }
+
+ plug_update();
+ }
+#endif
+ CloseAudioDevice();
+ CloseWindow();
+
+ return 0;
+}