Files
GhostEngine/doc/_site/docs/ecs-concepts.html
Misaki d8a7b07624 feat(graphics): improve rendering pipeline and docs
- 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
2026-03-27 22:23:44 +09:00

135 lines
7.0 KiB
HTML

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>ECS Concepts | GhostEngine </title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="title" content="ECS Concepts | 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 &quot;{query}&quot;">
<meta name="loc:searchNoResults" content="No results for &quot;{query}&quot;">
<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-concepts">ECS Concepts</h1>
<p>GhostEngine's ECS implementation relies on several key concepts rooted in Data-Oriented Design. Understanding these concepts is essential to writing performant engine code and gameplay logic.</p>
<h2 id="world">World</h2>
<p>A <code>World</code> encapsulates all data and logic for an independent ECS simulation. It owns three core managers:</p>
<ul>
<li><strong>EntityManager:</strong> Handles the creation, destruction, and structural modification of Entities.</li>
<li><strong>ComponentManager:</strong> Manages Archetypes and EntityQueries, keeping track of component memory layouts and chunk allocations.</li>
<li><strong>SystemManager:</strong> Manages the lifecycle and execution order of all Systems.</li>
</ul>
<p>Multiple Worlds can exist simultaneously (e.g., one for logic, one for rendering, or server/client splits in multiplayer).</p>
<h2 id="entity">Entity</h2>
<p>An <code>Entity</code> in Ghost.Entities is not an object or a class; it is merely an integer ID (often accompanied by a version number). It serves as a lookup key to find a specific set of component data.</p>
<h2 id="component">Component</h2>
<p>A <code>Component</code> is a pure, unmanaged data structure (<code>struct</code>). It implements <code>IComponent</code> or <code>IEnableableComponent</code>. Components contain no logic. By restricting components to unmanaged types, the engine ensures they can be packed tightly into continuous blocks of memory (Chunks), entirely avoiding Garbage Collection (GC) overhead and ensuring fast CPU cache lines.</p>
<h2 id="archetype-and-chunks">Archetype and Chunks</h2>
<p>When you create an entity with a specific set of components (e.g., <code>Position</code> and <code>Velocity</code>), the ECS groups it into an <strong>Archetype</strong>. An Archetype represents a unique signature of components.</p>
<p>Entities of the same Archetype have their component data stored in <strong>Chunks</strong>. A Chunk is a fixed-size block of unmanaged memory (e.g., 16KB).</p>
<p>Instead of storing arrays of Entities containing objects (Array of Structures), the Chunk stores independent arrays for each component type (Structure of Arrays). This means when a system queries for <code>Position</code>, it receives a contiguous unmanaged memory <code>Span&lt;Position&gt;</code>, allowing the CPU to aggressively prefetch data and vectorize operations.</p>
<h2 id="system">System</h2>
<p>A <code>System</code> provides the logic that transforms component data from one state to the next. Systems iterate over matching Archetypes using <code>EntityQuery</code> and process component data in bulk. Systems can be managed manually or grouped into a <code>SystemGroup</code> which topologically sorts execution order based on dependencies.</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>