1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
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;
}
|