载入中...
搜索中...
未找到
HotReload.h
浏览该文件的文档.
1#pragma once
2
3#include "common/Module.h"
4
5#include <atomic>
6#include <condition_variable>
7#include <cstdint>
8#include <deque>
9#include <map>
10#include <mutex>
11#include <string>
12#include <thread>
13#include <unordered_map>
14#include <vector>
15
16namespace eve::filesystem {
17
34class HotReload : public Module {
35public:
37
38 HotReload() = default;
39 ~HotReload() override;
40
46 void bind(std::string path, std::string kind = "auto");
47 void unbind(std::string path);
48
50 bool tryReload(std::string path);
51
53 int watchTree(std::string root = ".");
54
63 bool startRemoteSync(std::string url, int pollMs = 1000);
64
66 void stopRemoteSync();
67
73 void setRemoteHotDir(std::string dir);
74
76 bool isRemoteSyncing() const;
77
79 std::string remoteSyncStatus() const;
80
85 std::string pollRemoteChange();
86
87 static std::string normalizePath(std::string path);
88
89private:
90 struct RemoteFile {
91 std::string path;
92 int64_t size = -1;
93 int64_t mtime = -1;
94 };
95
96 // --- Remote sync internals ---
97
99 std::string ensureHotDir();
100
102 bool mountHotDir();
103
105 bool fetchManifest(std::vector<RemoteFile> &out);
106
108 bool downloadFile(const std::string &relPath);
109
111 void applyManifest(const std::vector<RemoteFile> &manifest);
112
114 std::map<std::string, std::pair<int64_t, int64_t>> loadRecord() const;
115 void saveRecord(const std::map<std::string, std::pair<int64_t, int64_t>> &record) const;
116
117 void syncLoop(int pollMs);
118
119 void queueChange(std::string path);
120
121 std::unordered_map<std::string, std::string> bindings_; // norm path → kind
122
123 // Remote sync state (guarded by syncMu_).
124 mutable std::mutex syncMu_;
125 std::thread syncThread_;
126 std::condition_variable syncCv_;
127 std::atomic<bool> syncRunning_{false};
128 bool syncStarted_ = false;
129 bool hotDirMounted_ = false;
130 std::string syncUrl_;
131 mutable std::string syncStatus_ = "idle";
132 mutable std::deque<std::string> changedQueue_;
133 std::string hotDir_;
134};
135
136} // namespace eve::filesystem
Tok kind
V3 dir
Definition TreeMesh.cpp:121
Path→reload dispatcher for soft hot reload. Driven from load.nut via pollWatch → tryReload; also used...
Definition HotReload.h:34
void setRemoteHotDir(std::string dir)
int watchTree(std::string root=".")
Recursively watch root and all subdirectories. Returns number of watches added.
std::string pollRemoteChange()
bool tryReload(std::string path)
Offer a (normalized) path to the registered reloaders; true if any reloaded.
void unbind(std::string path)
bool startRemoteSync(std::string url, int pollMs=1000)
std::string remoteSyncStatus() const
void bind(std::string path, std::string kind="auto")
Pin a path to one reloader kind ("particle" / "tilemap" / "texture" / whatever a linked module regist...
static std::string normalizePath(std::string path)