diff options
Diffstat (limited to 'src/main.c')
| -rw-r--r-- | src/main.c | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/src/main.c b/src/main.c new file mode 100644 index 0000000..952dd45 --- /dev/null +++ b/src/main.c @@ -0,0 +1,86 @@ +#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", 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", \ + #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(); + + 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(); + } + + CloseAudioDevice(); + CloseWindow(); + + return 0; +} |
