载入中...
搜索中...
未找到
ReloadSession.cpp
浏览该文件的文档.
2
4
5namespace eve::dev {
6
8 static ReloadSession inst;
9 return inst;
10}
11
12bool ReloadSession::begin(HSQUIRRELVM vm, std::string* err) {
13 if (active_) {
14 if (err) *err = "reload session already active";
15 return false;
16 }
17 if (!Snapshot::instance().captureState(vm, buffer_, err)) {
18 buffer_ = StateValue::null();
19 return false;
20 }
21 // Best-effort manual rollback point (same file as the F6/F7 snapshot).
22 std::string saveErr;
23 Snapshot::instance().saveFile(vm, "eve_snapshot.json", &saveErr);
24 active_ = true;
25 return true;
26}
27
28bool ReloadSession::commit(HSQUIRRELVM vm, std::string* err) {
29 if (!active_) {
30 if (err) *err = "no active reload session";
31 return false;
32 }
33 StateValue merged = buffer_;
34
35 // Merge freshly-defined roots under the captured values: captured values
36 // win, fields the reloaded script added are kept.
37 StateValue current;
38 std::string captureErr;
39 if (Snapshot::instance().captureState(vm, current, &captureErr)) {
40 StateValue* mergedRoots = merged.find("roots");
41 const StateValue* currentRoots = current.find("roots");
42 if (mergedRoots && mergedRoots->isObject() && currentRoots && currentRoots->isObject()) {
43 for (const auto& name : mergedRoots->keys()) {
44 StateValue* oldRoot = mergedRoots->find(name);
45 const StateValue* newRoot = currentRoots->find(name);
46 if (oldRoot && oldRoot->isObject() && newRoot && newRoot->isObject()) {
47 oldRoot->mergeDefaults(*newRoot);
48 }
49 }
50 }
51 }
52
53 const bool ok = restore(vm, merged, err);
54 buffer_ = StateValue::null();
55 active_ = false;
56 return ok;
57}
58
59bool ReloadSession::abort(HSQUIRRELVM vm, std::string* err) {
60 if (!active_) {
61 if (err) *err = "no active reload session";
62 return false;
63 }
64 const bool ok = restore(vm, buffer_, err);
65 buffer_ = StateValue::null();
66 active_ = false;
67 return ok;
68}
69
70bool ReloadSession::restore(HSQUIRRELVM vm, const StateValue& state, std::string* err) {
72}
73
74} // namespace eve::dev
struct SQVM * HSQUIRRELVM
HSQUIRRELVM vm
Definition ECS.cpp:20
JobSystemThreadPool::State * state
const char * name
Definition RockMesh.cpp:21
JSON-compatible state value tree used by state hot reload.
Definition StateValue.h:20
bool mergeDefaults(const StateValue &defaults)
Fill missing members from defaults; object members merge recursively, existing values are never overw...
bool isObject() const
Definition StateValue.h:49
const StateValue * find(const std::string &key) const
Look up key; nullptr when absent.
static StateValue null()
Null value.
Definition StateValue.h:27
std::vector< std::string > keys() const
Member names in insertion order.
One state hot-reload transaction: capture → reload → restore.
bool commit(HSQUIRRELVM vm, std::string *err=nullptr)
End the session, restoring captured state over the new definitions (old values win; newly added field...
bool abort(HSQUIRRELVM vm, std::string *err=nullptr)
End the session, rolling back to the captured state.
static ReloadSession & instance()
bool begin(HSQUIRRELVM vm, std::string *err=nullptr)
Start a session: capture current script + native state.
bool restoreState(HSQUIRRELVM vm, const StateValue &state, std::string *error=nullptr) const
Restore a captured state; v1-shaped values restore roots only.
Definition Snapshot.cpp:418
bool saveFile(HSQUIRRELVM vm, const std::string &path, std::string *error=nullptr) const
Definition Snapshot.cpp:482
static Snapshot & instance()
Definition Snapshot.cpp:285