A little toolkit for single-quad fragment shader demos
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

37 lines
838 B

  1. #include <map>
  2. #include <cerrno>
  3. #include <Inotify.h>
  4. #include <FileSystemEvent.h>
  5. #include <experimental/filesystem>
  6. #include "project.h"
  7. namespace fs = std::experimental::filesystem;
  8. #define MAX_WDS 16
  9. class NotifyService {
  10. public:
  11. NotifyService() : inotify{IN_MODIFY | IN_MOVED_TO} {}
  12. void watch(std::shared_ptr<Project> project) {
  13. inotify.watchDirectoryRecursively(project->basepath);
  14. projects[project->basepath]= project;
  15. }
  16. void _poll() {
  17. auto event = inotify.nb_getNextEvent();
  18. if (event) {
  19. if (event->recursive_root_path) {
  20. auto path = *event->recursive_root_path;
  21. if (projects.find(path) != projects.end()) {
  22. std::cout << "=== reloading shaders ===\n";
  23. projects[path]->reload_shaders();
  24. }
  25. }
  26. }
  27. }
  28. private:
  29. Inotify inotify;
  30. std::map<fs::path, std::shared_ptr<Project>> projects;
  31. };