diff --git a/src/main.c b/src/main.c index 8553c0c..a652611 100644 --- a/src/main.c +++ b/src/main.c @@ -1,6 +1,7 @@ #include #include #include +#include #include "log.h" #include "renderer.h" @@ -17,10 +18,32 @@ int main(int argc, char *argv[]) { struct renderer_state state = {0}; + /* Create inotify instance */ + state.inotify_fd = inotify_init(); + if (state.inotify_fd == -1) { + log_error("Cannot initialize inotify"); + perror("inotify_init"); + return EXIT_FAILURE; + } + state.screen_shader.filename = argv[1]; + state.screen_shader.wd = + inotify_add_watch(state.inotify_fd, state.screen_shader.filename, IN_MODIFY); + if (state.screen_shader.wd == -1) { + log_error("Cannot watch file %s", state.screen_shader.filename); + perror("inotify_add_watch"); + return EXIT_FAILURE; + } log_debug("Screen shader file: %s", state.screen_shader.filename); if (argc >= 3) { state.buffer_shader.filename = argv[2]; + state.buffer_shader.wd = + inotify_add_watch(state.inotify_fd, state.buffer_shader.filename, IN_MODIFY); + if (state.buffer_shader.wd == -1) { + log_error("Cannot watch file %s", state.buffer_shader.filename); + perror("inotify_add_watch"); + return EXIT_FAILURE; + } log_debug("Buffer shader file: %s", state.buffer_shader.filename); } diff --git a/src/renderer.h b/src/renderer.h index 604d336..0fb17f3 100644 --- a/src/renderer.h +++ b/src/renderer.h @@ -9,6 +9,7 @@ struct shader_state { unsigned int program; /**< Shader program ID. */ const char *filename; /**< Shader file name. */ + int wd; /**< inotify watch descriptor. */ }; /** @@ -19,9 +20,10 @@ struct renderer_state { GLFWwindow *window; /**< GLFW window where the shaders are rendered. */ struct shader_state screen_shader; /**< Shader for the main screen. */ struct shader_state buffer_shader; /**< Shader for the framebuffer. */ + int inotify_fd; /**< inotify file descriptor. */ size_t frame_count; /**< Frame count since the start of the render loop. */ size_t prev_frame_count; /**< Frame count at the last log. */ - double time; /**< Time in seconds since the beginning of the render loop. */ + double time; /**< Time in seconds since the start of the render loop. */ double prev_time; /**< Time in seconds at the last log. */ };