ludic/annot-enginesystem.html
2026-09-17 22:10:03 +00:00

45 lines
No EOL
3 KiB
HTML
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>@EngineSystem — Ludic</title>
<meta name="description" content="Register a package&#x27;s engine-owned system so the frame loop runs it each phase.">
<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">@EngineSystem</span></div>
<div class="item-head">
<span class="kind-badge kind-annotation">annotation</span>
<h1 id="top">@EngineSystem</h1>
</div>
<code class="sig">"@EngineSystem(Component, Phase) function esys_name() { … }"</code>
<div class="desc"><p><code>@EngineSystem(Component, Phase)</code> marks a function as an engine-owned system: the compiler adds it to the engine-system registry, and the frame loop calls it every <code>Phase</code> — after the game's own handlers — whenever the named <code>Component</code> is present in the program. It is the package-declarable form of the built-in engine systems (the ones that advance <code>SpriteAnim</code>/<code>Motion</code>/<code>Light2D</code>), so a third-party controller ships a system the same way the standard library does, with no compiler edit. The function reads and writes components by name through the reflection ABI, so it stays layout-independent and additive: a build that never declares the component compiles byte-for-byte the same. Phases are <code>Input</code>, <code>FixedUpdate</code>, <code>Update</code>, <code>LateUpdate</code> and <code>Render</code>.</p></div>
<div class="examples"><h2>Example</h2><pre data-lang="ludic">program EngineSystemDemo {
property Score { value: int = 0 }
model Player { Score }
@EngineSystem(Score, Update) function esys_score() -&gt; void { # runs every Update
let P = world_prop_id("Score")
let e = world_query_next(P, 0)
if e &gt;= 0 { world_set(e, P, 0, world_get(e, P, 0) + 1) } # advance by name
}
@OnSpawn(Player) handler Init { }
handler Boot phase Start { let e = world_spawn(world_model_id("Player")) }
handler Run phase Update {
let P = world_prop_id("Score")
print(world_get(world_query_next(P, 0), P, 0)) # grows each frame
quit()
}
}</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>