- Refactor D3D12 backend and RenderGraph module - Update graphics RHI and core rendering components - Add Random.hlsl shader include - Regenerate API documentation and update user guides
214 lines
8.3 KiB
HTML
214 lines
8.3 KiB
HTML
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<title>ECS Architecture | GhostEngine </title>
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<meta name="title" content="ECS Architecture | GhostEngine ">
|
|
|
|
|
|
<link rel="icon" href="../favicon.ico">
|
|
<link rel="stylesheet" href="../public/docfx.min.css">
|
|
<link rel="stylesheet" href="../public/main.css">
|
|
<meta name="docfx:navrel" content="../toc.html">
|
|
<meta name="docfx:tocrel" content="toc.html">
|
|
|
|
<meta name="docfx:rel" content="../">
|
|
|
|
|
|
|
|
<meta name="loc:inThisArticle" content="In this article">
|
|
<meta name="loc:searchResultsCount" content="{count} results for "{query}"">
|
|
<meta name="loc:searchNoResults" content="No results for "{query}"">
|
|
<meta name="loc:tocFilter" content="Filter by title">
|
|
<meta name="loc:nextArticle" content="Next">
|
|
<meta name="loc:prevArticle" content="Previous">
|
|
<meta name="loc:themeLight" content="Light">
|
|
<meta name="loc:themeDark" content="Dark">
|
|
<meta name="loc:themeAuto" content="Auto">
|
|
<meta name="loc:changeTheme" content="Change theme">
|
|
<meta name="loc:copy" content="Copy">
|
|
<meta name="loc:downloadPdf" content="Download PDF">
|
|
|
|
<script type="module" src="./../public/docfx.min.js"></script>
|
|
|
|
<script>
|
|
const theme = localStorage.getItem('theme') || 'auto'
|
|
document.documentElement.setAttribute('data-bs-theme', theme === 'auto' ? (window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light') : theme)
|
|
</script>
|
|
|
|
</head>
|
|
|
|
<body class="tex2jax_ignore" data-layout="" data-yaml-mime="">
|
|
<header class="bg-body border-bottom">
|
|
<nav id="autocollapse" class="navbar navbar-expand-md" role="navigation">
|
|
<div class="container-xxl flex-nowrap">
|
|
<a class="navbar-brand" href="../index.html">
|
|
<img id="logo" class="svg" src="../logo.svg" alt="GhostEngine">
|
|
GhostEngine
|
|
</a>
|
|
<button class="btn btn-lg d-md-none border-0" type="button" data-bs-toggle="collapse" data-bs-target="#navpanel" aria-controls="navpanel" aria-expanded="false" aria-label="Toggle navigation">
|
|
<i class="bi bi-three-dots"></i>
|
|
</button>
|
|
<div class="collapse navbar-collapse" id="navpanel">
|
|
<div id="navbar">
|
|
<form class="search" role="search" id="search">
|
|
<i class="bi bi-search"></i>
|
|
<input class="form-control" id="search-query" type="search" disabled placeholder="Search" autocomplete="off" aria-label="Search">
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</nav>
|
|
</header>
|
|
|
|
<main class="container-xxl">
|
|
<div class="toc-offcanvas">
|
|
<div class="offcanvas-md offcanvas-start" tabindex="-1" id="tocOffcanvas" aria-labelledby="tocOffcanvasLabel">
|
|
<div class="offcanvas-header">
|
|
<h5 class="offcanvas-title" id="tocOffcanvasLabel">Table of Contents</h5>
|
|
<button type="button" class="btn-close" data-bs-dismiss="offcanvas" data-bs-target="#tocOffcanvas" aria-label="Close"></button>
|
|
</div>
|
|
<div class="offcanvas-body">
|
|
<nav class="toc" id="toc"></nav>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="content">
|
|
<div class="actionbar">
|
|
<button class="btn btn-lg border-0 d-md-none" type="button" data-bs-toggle="offcanvas" data-bs-target="#tocOffcanvas" aria-controls="tocOffcanvas" aria-expanded="false" aria-label="Show table of contents">
|
|
<i class="bi bi-list"></i>
|
|
</button>
|
|
|
|
<nav id="breadcrumb"></nav>
|
|
</div>
|
|
|
|
<article data-uid="">
|
|
<h1 id="ecs-architecture">ECS Architecture</h1>
|
|
|
|
<p>This page describes how <code>Ghost.Entities</code> is organized internally and how the main pieces interact.</p>
|
|
<h2 id="core-objects">Core Objects</h2>
|
|
<ul>
|
|
<li><code>World</code>
|
|
<ul>
|
|
<li>Root owner for ECS runtime state.</li>
|
|
<li>Holds <code>EntityManager</code>, <code>ComponentManager</code>, <code>SystemManager</code>, and command buffers.</li>
|
|
<li>Carries a monotonic <code>Version</code> used by change tracking.</li>
|
|
</ul>
|
|
</li>
|
|
<li><code>Entity</code>
|
|
<ul>
|
|
<li>Lightweight handle (<code>ID</code>, <code>Generation</code>) used to validate stale references.</li>
|
|
</ul>
|
|
</li>
|
|
<li><code>EntityManager</code>
|
|
<ul>
|
|
<li>Responsible for create/destroy and structural changes (add/remove component).</li>
|
|
<li>Tracks entity location <code>(archetype, chunk, row)</code> in a slot map.</li>
|
|
</ul>
|
|
</li>
|
|
<li><code>ComponentManager</code>
|
|
<ul>
|
|
<li>Owns archetypes and query cache.</li>
|
|
<li>Maps signature hashes to archetype IDs.</li>
|
|
<li>Maps query-mask hashes to query IDs.</li>
|
|
</ul>
|
|
</li>
|
|
<li><code>EntityQuery</code>
|
|
<ul>
|
|
<li>Stores a compiled query mask.</li>
|
|
<li>Maintains a list of matching archetypes.</li>
|
|
<li>Exposes iterators (<code>chunk</code>, <code>component</code>, <code>entity+component</code>) and scheduling APIs.</li>
|
|
</ul>
|
|
</li>
|
|
</ul>
|
|
<h2 id="archetype-and-chunk-model">Archetype and Chunk Model</h2>
|
|
<p>Entities are grouped by exact component signature into archetypes.</p>
|
|
<ul>
|
|
<li>Each archetype owns N chunks.</li>
|
|
<li>Each chunk stores:
|
|
<ul>
|
|
<li>packed entity IDs,</li>
|
|
<li>packed component arrays,</li>
|
|
<li>optional enable bitmasks for enableable components,</li>
|
|
<li>per-component change versions,</li>
|
|
<li>chunk structural version.</li>
|
|
</ul>
|
|
</li>
|
|
</ul>
|
|
<p>Effects:</p>
|
|
<ul>
|
|
<li>Data for the same component is contiguous per chunk.</li>
|
|
<li>Iteration can be cache-friendly and branch-light.</li>
|
|
<li>Structural operations move entities between archetypes.</li>
|
|
</ul>
|
|
<h2 id="structural-changes">Structural Changes</h2>
|
|
<p>Adding/removing components changes an entity signature, so the entity moves:</p>
|
|
<ol>
|
|
<li>Resolve current <code>EntityLocation</code>.</li>
|
|
<li>Resolve or create destination archetype.</li>
|
|
<li>Allocate destination row.</li>
|
|
<li>Copy shared component bytes from old to new archetype layout.</li>
|
|
<li>Write the new/removed component result.</li>
|
|
<li>Remove old row with swap-back compaction.</li>
|
|
<li>Update <code>EntityLocation</code> for moved entities.</li>
|
|
</ol>
|
|
<p>Archetypes cache transition edges (<code>Add</code> / <code>Remove</code>) to avoid recomputing destination lookups repeatedly.</p>
|
|
<h2 id="query-compilation-and-matching">Query Compilation and Matching</h2>
|
|
<p><code>QueryBuilder</code> compiles high-level filter methods into bitset masks.</p>
|
|
<p>Main mask dimensions:</p>
|
|
<ul>
|
|
<li>structural requirements (<code>All</code>, <code>Any</code>, <code>Absent</code>),</li>
|
|
<li>enabled/disabled semantic filters,</li>
|
|
<li>write access intent.</li>
|
|
</ul>
|
|
<p>A query first filters at archetype level (signature match), then performs per-entity checks for enablement semantics when needed.</p>
|
|
<h2 id="systems-and-update-flow">Systems and Update Flow</h2>
|
|
<ul>
|
|
<li><code>SystemManager</code> owns system instances.</li>
|
|
<li><code>SystemGroup</code> can sort systems using <code>[UpdateAfter]</code> / <code>[UpdateBefore]</code>.</li>
|
|
<li><code>SystemBase</code> supports <code>RequireQueryForUpdate</code> gating and lifecycle hooks:
|
|
<ul>
|
|
<li><code>OnInitialize</code>,</li>
|
|
<li><code>OnStartRunning</code> / <code>OnStopRunning</code>,</li>
|
|
<li><code>OnUpdate</code>,</li>
|
|
<li><code>OnCleanup</code>.</li>
|
|
</ul>
|
|
</li>
|
|
</ul>
|
|
<h2 id="deferred-structural-writes">Deferred Structural Writes</h2>
|
|
<p><code>EntityCommandBuffer</code> records structural commands into a compact byte buffer.</p>
|
|
<ul>
|
|
<li>Record in gameplay/jobs.</li>
|
|
<li>Playback at controlled sync points.</li>
|
|
<li>Avoid invalidating iterators while iterating live chunks.</li>
|
|
</ul>
|
|
<p>Use per-thread command buffers (<code>World.GetThreadLocalEntityCommandBuffer</code>) in multithreaded pipelines.</p>
|
|
|
|
</article>
|
|
|
|
<div class="contribution d-print-none">
|
|
</div>
|
|
|
|
<div class="next-article d-print-none border-top" id="nextArticle"></div>
|
|
|
|
</div>
|
|
|
|
<div class="affix">
|
|
<nav id="affix"></nav>
|
|
</div>
|
|
</main>
|
|
|
|
<div class="container-xxl search-results" id="search-results"></div>
|
|
|
|
<footer class="border-top text-secondary">
|
|
<div class="container-xxl">
|
|
<div class="flex-fill">
|
|
<span>Made with <a href="https://dotnet.github.io/docfx">docfx</a></span>
|
|
</div>
|
|
</div>
|
|
</footer>
|
|
</body>
|
|
</html>
|