43 lines
No EOL
2.8 KiB
HTML
43 lines
No EOL
2.8 KiB
HTML
<!doctype html>
|
||
<html lang="en">
|
||
<head>
|
||
<meta charset="utf-8">
|
||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||
<title>world_load — Ludic</title>
|
||
<meta name="description" content="Restore the whole world from a serialized byte buffer.">
|
||
<link rel="stylesheet" href="base.css">
|
||
<link rel="stylesheet" href="docs.css">
|
||
</head>
|
||
<body>
|
||
<header class="nav"><div class="wrap nav-in"><a class="brand" href="index.html"><span class="logo">L</span> Ludic</a><button class="nav-toggle" aria-label="Toggle menu" aria-expanded="false">☰</button><nav class="nav-links"><a href="index.html">Home</a><a href="api.html">API Reference</a><a class="nav-cta" href="https://git.workshopsoft.io/workshopsoft/ludic">Source ↗</a></nav></div></header>
|
||
<main class="wrap item">
|
||
<div class="crumbs"><a href="api.html">API Reference</a> <span>›</span> <a href="api.html#ecs">Entities & the ECS</a> <span>›</span> <span class="here">world_load</span></div>
|
||
<div class="item-head">
|
||
<span class="kind-badge kind-builtin">function</span>
|
||
<h1 id="top">world_load</h1>
|
||
</div>
|
||
<code class="sig">world_load(buf, len)</code>
|
||
<div class="desc"><p><code>world_load</code> restores the ECS world from a byte buffer previously produced by <code>world_save</code>, replacing the current world with the snapshot's instances and their fields. You pass the buffer and the number of valid bytes in it (the count <code>world_save</code> returned), and the world is rebuilt in place; it returns nothing. This is the low-level, buffer-based counterpart of <code>world_save</code> — the pair a mod or tool uses to move a whole world across the ABI or between storage. For a simple whole-game load from the default slot, the higher-level <code>load()</code> builtin is usually enough.</p></div>
|
||
<div class="params"><h2>Parameters</h2><div class="param" id="param-buf"><code class="pname">buf</code><span class="pdesc">the source byte buffer holding a snapshot</span></div><div class="param" id="param-len"><code class="pname">len</code><span class="pdesc">the number of valid bytes in <code>buf</code></span></div></div>
|
||
<div class="examples"><h2>Example</h2><pre data-lang="ludic">program SnapshotRoundTrip {
|
||
property Position { column: int = 0, row: int = 0 }
|
||
model Enemy { Position }
|
||
|
||
var snapshot_length: int = 0
|
||
|
||
handler Boot phase Start {
|
||
spawn Grunt { Position { column: 3, row: 3 } }
|
||
}
|
||
|
||
handler RoundTrip phase Update {
|
||
let buffer = bytes(4096)
|
||
if Input.key() == 's' { snapshot_length = world_save(buffer) }
|
||
if Input.key() == 'l' { world_load(buffer, snapshot_length) }
|
||
}
|
||
}</pre></div>
|
||
|
||
<a class="back" href="api.html">← All symbols</a>
|
||
</main>
|
||
<script src="ludic-highlight.js"></script>
|
||
<script>Ludic.highlightAll(); Ludic.installCards(); Ludic.flashTarget();</script>
|
||
</body></html> |