41 lines
No EOL
2.6 KiB
HTML
41 lines
No EOL
2.6 KiB
HTML
<!doctype html>
|
||
<html lang="en">
|
||
<head>
|
||
<meta charset="utf-8">
|
||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||
<title>@Owned — Ludic</title>
|
||
<meta name="description" content="Give a model a network owner slot so its instances can be assigned to a peer.">
|
||
<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#annotations">Annotations</a> <span>›</span> <span class="here">@Owned</span></div>
|
||
<div class="item-head">
|
||
<span class="kind-badge kind-annotation">annotation</span>
|
||
<h1 id="top">@Owned</h1>
|
||
</div>
|
||
<code class="sig">@Owned model Name { … }</code>
|
||
<div class="desc"><p><code>@Owned</code> declares that every instance of a model carries a network owner — it adds an owner slot to the model (the runtime's <code>@L_owner</code> array), which the builtins <code>owner</code>, <code>set_owner</code>, and <code>is_owner</code> read and assign. A fresh instance starts unowned (<code>-1</code>) until the authority assigns it. Ownership is what gates who may write <code>@Sync(to: owner)</code> fields and who runs <code>@Predicted</code> control handlers, and it is stored in the world snapshot so it round-trips through replication and rollback. Mark the models that represent a player's avatar or units; leave shared scenery unowned.</p></div>
|
||
|
||
<div class="examples"><h2>Example</h2><pre data-lang="ludic">program OwnedModel {
|
||
@Sync property Position { column: int = 0, row: int = 0 }
|
||
@Owned model Player { @Sync Position } # each Player instance has an owner slot
|
||
|
||
entry {
|
||
spawn Player { Position { column: 5, row: 6 } }
|
||
for (Position) in query [Position, {Player}] {
|
||
let player_id = self()
|
||
print(owner(player_id)) # -1 — unowned until assigned
|
||
set_owner(player_id, 0)
|
||
print(is_owner(player_id)) # 1 — the local peer now owns it
|
||
}
|
||
}
|
||
}</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> |