Files
GhostEngine/doc/_site/docs/getting-started.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

185 lines
7.3 KiB
HTML

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Getting Started with Ghost.Entities | GhostEngine </title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="title" content="Getting Started with Ghost.Entities | 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="getting-started-with-ghostentities">Getting Started with Ghost.Entities</h1>
<p>GhostEngine's Entity Component System (ECS) is a high-performance, Data-Oriented architecture designed for C# .NET 10. The ECS runtime is strictly AOT-compatible and focuses on unmanaged data structures to maximize cache locality and performance.</p>
<h2 id="initialization">Initialization</h2>
<p>The core of the ECS is the <code>World</code>. A <code>World</code> contains an <code>EntityManager</code>, <code>ComponentManager</code>, and <code>SystemManager</code>.</p>
<p>To get started, you must create a <code>World</code>:</p>
<pre><code class="lang-csharp">using Ghost.Entities;
// Create a new World with a default entity capacity of 16
World world = World.Create();
</code></pre>
<h2 id="creating-entities-and-adding-components">Creating Entities and Adding Components</h2>
<p>Entities are simply IDs that point to a combination of components. You use the <code>EntityManager</code> to create and modify them.</p>
<p>First, define your unmanaged components:</p>
<pre><code class="lang-csharp">public struct Position : IComponent
{
public float X, Y, Z;
}
public struct Velocity : IComponent
{
public float X, Y, Z;
}
</code></pre>
<p>Then, create entities and attach components:</p>
<pre><code class="lang-csharp">using Ghost.Core;
using Misaki.HighPerformance.LowLevel.Buffer;
// Creating a ComponentSet for fast archetype initialization
using var scope = AllocationManager.CreateStackScope();
var componentSet = new ComponentSet(
scope.AllocationHandle,
ComponentTypeID&lt;Position&gt;.Value,
ComponentTypeID&lt;Velocity&gt;.Value
);
// Create 1000 entities with both Position and Velocity
world.EntityManager.CreateEntities(1000, componentSet);
</code></pre>
<h2 id="adding-systems-and-updating">Adding Systems and Updating</h2>
<p>Systems contain the logic that operates on the component data. You add systems to the <code>SystemManager</code> and run them inside a loop.</p>
<pre><code class="lang-csharp">// Get the DefaultSystemGroup to attach systems
var group = world.SystemManager.GetSystem&lt;DefaultSystemGroup&gt;();
// Add custom systems
group.AddSystem&lt;MovementSystem&gt;();
// Sort systems based on their dependencies
group.SortSystems();
// Initialize all systems
world.SystemManager.InitializeAll(new TimeData());
// Update loop
while (running)
{
world.SystemManager.UpdateAll(timeData);
world.PlaybackEntityCommandBuffers();
}
// Cleanup at the end
world.Dispose();
</code></pre>
<h2 id="summary">Summary</h2>
<p>In GhostEngine ECS:</p>
<ol>
<li><strong>World</strong> manages the lifecycle of your ECS data.</li>
<li><strong>Components</strong> (<code>IComponent</code>) are unmanaged data structures.</li>
<li><strong>Entities</strong> are logical containers combining those components into archetypes.</li>
<li><strong>Systems</strong> (<code>SystemBase</code>) execute logic over arrays of components using <code>EntityQuery</code>.</li>
</ol>
</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>