12#include <Poco/Dynamic/Var.h>
13#include <Poco/JSON/Array.h>
14#include <Poco/JSON/Object.h>
23constexpr int kMaxArgumentDepth = 16;
26 if (
depth > kMaxArgumentDepth ||
value.isEmpty()) {
30 if (
value.isBoolean()) {
31 sq_pushbool(
vm,
value.convert<
bool>() ? SQTrue : SQFalse);
34 if (
value.isInteger()) {
35 sq_pushinteger(
vm,
static_cast<SQInteger
>(
value.convert<Poco::Int64>()));
38 if (
value.isNumeric()) {
39 sq_pushfloat(
vm,
static_cast<SQFloat
>(
value.convert<
double>()));
42 if (
value.isString()) {
43 const std::string
text =
value.convert<std::string>();
44 sq_pushstring(
vm,
text.c_str(),
static_cast<SQInteger
>(
text.size()));
47 if (
value.type() ==
typeid(Poco::JSON::Array::Ptr)) {
48 auto array =
value.extract<Poco::JSON::Array::Ptr>();
50 const SQInteger
target = sq_gettop(
vm);
57 if (
value.type() ==
typeid(Poco::JSON::Object::Ptr)) {
58 auto object =
value.extract<Poco::JSON::Object::Ptr>();
60 const SQInteger
target = sq_gettop(
vm);
61 for (
const auto& entry : *
object) {
62 sq_pushstring(
vm, entry.first.c_str(),
static_cast<SQInteger
>(entry.first.size()));
63 pushJsonValue(
vm, entry.second,
depth + 1);
74 return "soft restart failed";
78Result<void> installRestartArgs(
HSQUIRRELVM vm, Poco::JSON::Object::Ptr args) {
79 const SQInteger
top = sq_gettop(
vm);
81 sq_pushstring(
vm, _SC(
"eve"), -1);
82 if (SQ_FAILED(sq_get(
vm, -2)) || sq_gettype(
vm, -1) != OT_TABLE) {
87 sq_pushstring(
vm, _SC(
"restartArgs"), -1);
89 pushJsonValue(
vm, Poco::Dynamic::Var(args), 0);
92 if (SQ_FAILED(sq_newslot(
vm, -3, SQFalse))) {
102Result<bool> callSoftRestartGame(
HSQUIRRELVM vm,
bool reloadScripts) {
103 const SQInteger
top = sq_gettop(
vm);
104 sq_pushroottable(
vm);
105 sq_pushstring(
vm, _SC(
"soft_restart_game"), -1);
106 if (SQ_FAILED(sq_get(
vm, -2)) || sq_gettype(
vm, -1) != OT_CLOSURE) {
110 "soft_restart_game is missing; start the game with load.nut (eve run --mcp-port ...)",
111 "soft_restart_game"));
113 sq_pushroottable(
vm);
114 sq_pushbool(
vm, reloadScripts ? SQTrue : SQFalse);
115 if (SQ_FAILED(sq_call(
vm, 2, SQTrue, SQTrue))) {
116 const std::string err = lastVmError(
vm);
122 if (sq_gettype(
vm, -1) == OT_BOOL) sq_getbool(
vm, -1, &
ok);
127 "soft_restart_game"));
135 std::uint32_t
ok = 0;
138 auto reset =
provider->resetToDefaults();
139 if (reset.ok()) ++
ok;
159 report.
args =
request.args ?
request.args : Poco::JSON::Object::Ptr(
new Poco::JSON::Object());
166 auto installed = installRestartArgs(
vm, report.
args);
169 if (
auto* capture = cap::query<IRenderFrameCapture>()) capture->invalidate();
170 auto restarted = callSoftRestartGame(
vm,
request.reloadScripts);
181 "resource cache shrank during soft restart (expected resources to be kept)",
struct SQVM * HSQUIRRELVM
Runtime game-world Discover snapshot for MCP / Play Host.
const GltfImportRequest & request
ScriptProviderHandle provider
Soft-restart a live game without unloading the resource cache.
static Diagnostic error(DiagnosticCode code, std::string message, std::string path={})
Construct an error diagnostic with the standard error severity.
size_t count() const
Number of cached entries.
static ResourceManager & getInstance()
Returns the instance.
Move-only operation result carrying either a value or Status.
static Result success(T value)
Construct a successful result owning value.
static Result failure(Status status)
Construct a failed result from a structured status.
Runtime-state serialization for state hot reload.
static ReloadSession & instance()
Instance.
std::size_t resourceCacheCount()
Current ResourceManager cache entry count (for restart telemetry).
std::uint32_t resetNativeStateProviders()
Reset every registered IStateProvider to its defaults.
Result< SoftRestartReport > executeSoftRestart(HSQUIRRELVM vm, SoftRestartRequest request)
Soft-restart the game attached to vm.
void clearWorldContext()
Drop the runtime world brief (soft restart with script reload).
std::string formatScriptError(const ScriptErrorContext &ctx)
Formats a context into a human-readable multi-line report.
ScriptErrorContext takeLastScriptError(HSQUIRRELVM vm)
Consumes and clears the last recorded error for a VM.
Outcome of a successful soft restart. @ownership Owning value; safe to keep across frames.
bool scriptsReloaded
Whether tracked scripts were re-dofile'd.
Poco::JSON::Object::Ptr args
Echo of the args table that was installed (may be empty).
std::size_t resourceCountBefore
Cached resource entries before the restart (must equal after).
bool initCalled
Whether eve_init / eve_restart ran.
std::size_t resourceCountAfter
Cached resource entries after the restart.
Inputs for one soft restart. @thread Game / MCP poll thread only.
Structured snapshot of a script error: message, throw site and stack.
bool empty() const noexcept
True when no error payload was captured.