summaryrefslogtreecommitdiff
path: root/src/util/file_watcher.cc
diff options
context:
space:
mode:
authorskal <pascal.massimino@gmail.com>2026-02-09 17:35:32 +0100
committerskal <pascal.massimino@gmail.com>2026-02-09 17:35:32 +0100
commitd5f78a4c2e7b626a492643efd62ddeb394276722 (patch)
treecdf38c3d64f6bf417975ce396572fc425d6f8910 /src/util/file_watcher.cc
parent802e97ee695de1bc8657c5cbca653bb2f13b90a8 (diff)
feat: Add debug-only file change detection for rapid iteration
Enables --hot-reload flag to watch config files and notify on changes. Detects modifications to assets/sequences/music for rebuild workflow. Completely stripped from release builds (0 bytes overhead). Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Diffstat (limited to 'src/util/file_watcher.cc')
-rw-r--r--src/util/file_watcher.cc44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/util/file_watcher.cc b/src/util/file_watcher.cc
new file mode 100644
index 0000000..22eb824
--- /dev/null
+++ b/src/util/file_watcher.cc
@@ -0,0 +1,44 @@
+// file_watcher.cc - Hot-reload file change detection (debug only)
+
+#include "file_watcher.h"
+
+#if !defined(STRIP_ALL)
+
+#include <sys/stat.h>
+
+void FileWatcher::add_file(const char* path) {
+ WatchEntry entry;
+ entry.path = path;
+ entry.last_mtime = get_mtime(path);
+ entry.changed = false;
+ files_.push_back(entry);
+}
+
+bool FileWatcher::check_changes() {
+ bool any_changed = false;
+ for (auto& entry : files_) {
+ time_t current_mtime = get_mtime(entry.path.c_str());
+ if (current_mtime != entry.last_mtime && current_mtime != 0) {
+ entry.changed = true;
+ entry.last_mtime = current_mtime;
+ any_changed = true;
+ }
+ }
+ return any_changed;
+}
+
+void FileWatcher::reset() {
+ for (auto& entry : files_) {
+ entry.changed = false;
+ }
+}
+
+time_t FileWatcher::get_mtime(const char* path) {
+ struct stat st;
+ if (stat(path, &st) == 0) {
+ return st.st_mtime;
+ }
+ return 0;
+}
+
+#endif // !defined(STRIP_ALL)