summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpommicket <pommicket@gmail.com>2021-10-02 16:14:18 -0400
committerpommicket <pommicket@gmail.com>2021-10-02 16:14:18 -0400
commitd7a8776869ca5fab3cc4653615ff3f0861b039d6 (patch)
tree0da263a34897e95d469cbd6cf157c42a36f5314f
parentecb11d81d16a6add9b85d64a90d6f2fccfdd93c5 (diff)
config auto-reload
-rw-r--r--main.c27
-rw-r--r--sandboxes/test.txt2
2 files changed, 26 insertions, 3 deletions
diff --git a/main.c b/main.c
index 93f13ed..d122556 100644
--- a/main.c
+++ b/main.c
@@ -1,5 +1,4 @@
// @TODO:
-// - auto-reload config file
// - config selection menu
// - optional opacity (color1,2 can have alpha)
#define V_GL 1
@@ -289,6 +288,21 @@ static Function *sandbox_create(const char *filename) {
return functions;
}
+static void sandbox_clear(Function **fs) {
+ arr_foreachp(*fs, Function, f) {
+ gl_vbo_delete(&f->update_vbo);
+ gl_vbo_delete(&f->grain_vbo);
+ gl_vao_delete(&f->update_vao);
+ gl_vao_delete(&f->grain_vao);
+ gl.DeleteFramebuffers(1, &f->fbo);
+ GLuint tex[2] = {f->grains_tex1, f->grains_tex2};
+ gl.DeleteTextures(2, tex);
+ gl.DeleteProgram(f->update_program.id);
+ gl.DeleteProgram(f->grain_program.id);
+ }
+ arr_clear(*fs);
+}
+
int main(int argc, char **argv) {
if (!window_create("sandbox", 1280, 720, 0)) {
return -1;
@@ -327,7 +341,9 @@ int main(int argc, char **argv) {
g_grain_vshader = V_gl_shader_compile_code("grainv.glsl", NULL, vshader_code, GL_VERTEX_SHADER);
}
- Function *functions = sandbox_create("sandboxes/test.txt");
+ const char *config_filename = "sandboxes/test.txt";
+ Time config_last_modified = {0};
+ Function *functions = NULL;
bool fullscreen = false;
@@ -336,6 +352,13 @@ int main(int argc, char **argv) {
float dt = window_frame();
+ if (!time_eq(fs_last_modified(config_filename), config_last_modified)) {
+ sleep_ms(10); // wait a bit to make sure whatever's writing here is done
+ sandbox_clear(&functions);
+ functions = sandbox_create(config_filename);
+ config_last_modified = fs_last_modified(config_filename);
+ }
+
while (SDL_PollEvent(&event)) {
switch (event.type) {
case SDL_QUIT:
diff --git a/sandboxes/test.txt b/sandboxes/test.txt
index b786ca4..45e584b 100644
--- a/sandboxes/test.txt
+++ b/sandboxes/test.txt
@@ -4,5 +4,5 @@ color #0000ff
color2 #ff00ff
color_scale 0.5
add vec3(-z, 0.0, x)
-color2 #00ff00
+color2 #ffff00
add vec3(-y, x, 0.0)