载入中...
搜索中...
未找到

Script + native state snapshot for state hot reload. 更多...

#include <Snapshot.hpp>

Public 成员函数

 Snapshot (const Snapshot &)=delete
 
Snapshot & operator= (const Snapshot &)=delete
 
void markRoot (std::string name)
 Mark a root as persistent, replacing a transient declaration.
 
void unmarkRoot (const std::string &name)
 Remove an explicit persistent-root declaration.
 
void markTransientRoot (std::string name)
 Mark a root for reconstruction from new script definitions.
 
void unmarkTransientRoot (const std::string &name)
 Remove an explicit transient-root declaration.
 
void clearRoots ()
 Clear every explicit persistent and transient declaration.
 
std::vector< std::string > roots () const
 Return the explicit persistent roots.
 
std::vector< std::string > transientRoots () const
 Return the explicit transient roots.
 
void setRootPolicies (std::vector< std::string > persistent, std::vector< std::string > transient)
 Atomically replace explicit persistent/transient root policy.
 
std::string capture (HSQUIRRELVM vm, std::string *error=nullptr) const
 Capture marked roots, or heuristic roots when none marked.
 
bool restore (HSQUIRRELVM vm, const std::string &json, std::string *error=nullptr) const
 
bool saveFile (HSQUIRRELVM vm, const std::string &path, std::string *error=nullptr) const
 
bool loadFile (HSQUIRRELVM vm, const std::string &path, std::string *error=nullptr) const
 
std::vector< std::string > rootsFor (HSQUIRRELVM vm) const
 Marked roots, or heuristic roots when none marked (script-facing).
 
bool captureState (HSQUIRRELVM vm, StateValue &out, std::string *error=nullptr) const
 Capture script roots plus every Preserve IStateProvider.
 
Result< StateValue > mergeDefaultsState (const StateValue &captured, const StateValue &defaults) const
 Merge v3 script defaults while retaining captured values and identities.
 
bool restoreState (HSQUIRRELVM vm, const StateValue &state, std::string *error=nullptr) const
 Restore a captured state; v1-shaped values restore roots only.
 

静态 Public 成员函数

static Snapshot & instance ()
 
static bool isEngineBinding (const std::string &name)
 Built-in names never auto-captured (modules / boot bindings).
 

详细描述

Script + native state snapshot for state hot reload.

Captures serializable Squirrel values from the root table — either explicitly persistent roots (markRoot) or a compatibility heuristic that skips engine module bindings. Roots marked transient are excluded. Native providers choose Preserve or Reset through IStateProvider::reloadPolicy(). Closures / native userdata are skipped, not fatal: the reloaded script recreates them, so a value the capture cannot represent is left out and named in the skipped array inside the captured state. Failing the whole capture instead meant that moving an entity from a global into a container — the entity list the script ECS encourages — turned a working reload into a refused one.

Which omissions are named: everything unserializable inside a captured root (that root was accepted as state, so e.g. gameState.tick = function(){} or gameState.leader = Hero() is a real loss), and live objects at the root (hero <- Hero()). Function and class definitions at the root are ordinary script bindings, so they stay silently skipped rather than flooding the list.

Script tables (string keys) and arrays preserve identity, including aliases across roots, self references and mutual cycles. Non-string table keys are rejected. Capture rejects more than 65536 containers or first-visit nesting deeper than 32 edges; repeated references close immediately without further recursion. Failed capture leaves the output and VM unchanged. Restore validates the entire graph, allocates all containers, then fills their edges before committing roots. Native providers are rolled back on failure. Providers must accept their own captured state for rollback; rollback failures are reported explicitly.

@thread Owner thread during a paused reload; borrowed VM handles remain valid for the synchronous call. Snapshot values independently own their data.

Format (v3): JSON object { "version":3, "roots": { name: scalar_or_ref, ... }, "objects": [{ "type":"table", "value": { key: scalar_or_ref, ... } }, { "type":"array", "value": [scalar_or_ref, ...] }, ...], "native": { "<stateKind>": <captured>, ... }, "skipped": ["squad[0] (class instance)", ...] }. A ref is exactly { "$ref": index }, with a zero-based index into objects. User containers are always nodes, so user keys cannot collide with ref metadata. skipped is only emitted when non-empty. Legacy v1/v2 tree files remain readable; unknown versions and malformed/dangling references fail before live state changes.

在文件 Snapshot.hpp 第 58 行定义.

构造及析构函数说明

◆ Snapshot()

eve::dev::Snapshot::Snapshot ( const Snapshot &  )
delete

成员函数说明

◆ capture()

std::string eve::dev::Snapshot::capture ( HSQUIRRELVM  vm,
std::string *  error = nullptr 
) const

Capture marked roots, or heuristic roots when none marked.

在文件 Snapshot.cpp 第 659 行定义.

引用了 error, state , 以及 vm.

◆ captureState()

bool eve::dev::Snapshot::captureState ( HSQUIRRELVM  vm,
StateValue &  out,
std::string *  error = nullptr 
) const

Capture script roots plus every Preserve IStateProvider.

参数
outReceives the owning v3 object graph described above, plus "skipped" (array of path (type) strings) when values had to be left out. Keeping the omissions inside the captured state means no extra out-parameter and one channel for whoever reads the snapshot.
返回
false on a missing VM, unsupported keys, exceeded capture limits or provider failure. Unserializable live values are skipped as documented above.

在文件 Snapshot.cpp 第 561 行定义.

引用了 eve::StateValue::array(), error, graph, eve::StateValue::integer(), key, name, eve::StateValue::object(), out, p, eve::caps::Reset, eve::StateValue::set(), eve::StateValue::string(), eve::toLegacyStateValue(), top , 以及 vm.

◆ clearRoots()

void eve::dev::Snapshot::clearRoots ( )

Clear every explicit persistent and transient declaration.

在文件 Snapshot.cpp 第 501 行定义.

◆ instance()

◆ isEngineBinding()

bool eve::dev::Snapshot::isEngineBinding ( const std::string &  name)
static

Built-in names never auto-captured (modules / boot bindings).

在文件 Snapshot.cpp 第 473 行定义.

引用了 name.

◆ loadFile()

bool eve::dev::Snapshot::loadFile ( HSQUIRRELVM  vm,
const std::string &  path,
std::string *  error = nullptr 
) const

在文件 Snapshot.cpp 第 897 行定义.

引用了 error, path , 以及 vm.

◆ markRoot()

void eve::dev::Snapshot::markRoot ( std::string  name)

Mark a root as persistent, replacing a transient declaration.

在文件 Snapshot.cpp 第 475 行定义.

引用了 name , 以及 r.

◆ markTransientRoot()

void eve::dev::Snapshot::markTransientRoot ( std::string  name)

Mark a root for reconstruction from new script definitions.

在文件 Snapshot.cpp 第 488 行定义.

引用了 name , 以及 r.

◆ mergeDefaultsState()

Result< StateValue > eve::dev::Snapshot::mergeDefaultsState ( const StateValue &  captured,
const StateValue &  defaults 
) const

Merge v3 script defaults while retaining captured values and identities.

参数
capturedBorrowed owning snapshot; unchanged by this operation.
defaultsBorrowed v3 snapshot of freshly defined state; unchanged.
返回
An independent owning snapshot, or a diagnostic for invalid graphs/limits.
注解
Missing table fields are imported with their aliases/cycles; array items and existing roots retain captured values. Native state stays captured. @thread Owner thread during a paused reload; no VM access or script callbacks.

在文件 Snapshot.cpp 第 676 行定义.

引用了 eve::StateValue::arraySize(), eve::StateValue::at(), defaults, error, eve::Diagnostic::error(), eve::Result< T >::failure(), eve::StateValue::find(), found, imported, eve::InvalidArgument, eve::StateValue::isObject(), key, eve::StateValue::keys(), name, node, eve::StateValue::null(), objects, pairs, remap, result, eve::StateValue::set(), eve::Result< T >::success() , 以及 value.

◆ operator=()

Snapshot & eve::dev::Snapshot::operator= ( const Snapshot &  )
delete

◆ restore()

bool eve::dev::Snapshot::restore ( HSQUIRRELVM  vm,
const std::string &  json,
std::string *  error = nullptr 
) const

在文件 Snapshot.cpp 第 871 行定义.

引用了 error, result , 以及 vm.

◆ restoreState()

bool eve::dev::Snapshot::restoreState ( HSQUIRRELVM  vm,
const StateValue &  state,
std::string *  error = nullptr 
) const

Restore a captured state; v1-shaped values restore roots only.

返回
false on invalid input or provider failure. Script roots are unchanged on failure; native providers are restored from pre-operation backups.

在文件 Snapshot.cpp 第 769 行定义.

引用了 error, eve::StateValue::find(), eve::StateValue::isObject(), eve::StateValue::keys(), message, name, eve::Value::null(), p, provider, registry, eve::caps::Reset, result, root, state, eve::toCanonicalStateValue(), value, version , 以及 vm.

◆ roots()

std::vector< std::string > eve::dev::Snapshot::roots ( ) const

Return the explicit persistent roots.

在文件 Snapshot.cpp 第 506 行定义.

◆ rootsFor()

std::vector< std::string > eve::dev::Snapshot::rootsFor ( HSQUIRRELVM  vm) const
inline

Marked roots, or heuristic roots when none marked (script-facing).

在文件 Snapshot.hpp 第 91 行定义.

引用了 vm.

◆ saveFile()

bool eve::dev::Snapshot::saveFile ( HSQUIRRELVM  vm,
const std::string &  path,
std::string *  error = nullptr 
) const

在文件 Snapshot.cpp 第 885 行定义.

引用了 error, path , 以及 vm.

◆ setRootPolicies()

void eve::dev::Snapshot::setRootPolicies ( std::vector< std::string >  persistent,
std::vector< std::string >  transient 
)

Atomically replace explicit persistent/transient root policy.

在文件 Snapshot.cpp 第 510 行定义.

引用了 name.

◆ transientRoots()

std::vector< std::string > eve::dev::Snapshot::transientRoots ( ) const

Return the explicit transient roots.

在文件 Snapshot.cpp 第 508 行定义.

◆ unmarkRoot()

void eve::dev::Snapshot::unmarkRoot ( const std::string &  name)

Remove an explicit persistent-root declaration.

在文件 Snapshot.cpp 第 484 行定义.

引用了 name.

◆ unmarkTransientRoot()

void eve::dev::Snapshot::unmarkTransientRoot ( const std::string &  name)

Remove an explicit transient-root declaration.

在文件 Snapshot.cpp 第 497 行定义.

引用了 name.


该类的文档由以下文件生成: