Files
mrgameeng/CLAUDE.md
T
Leonid PershinandClaude Fable 5 e06f24a319 Parallel rendering pipeline, ring vertex buffer, phase timings
Five optimizations measured on the 100k-entity stress scene (Release,
vsync off): 103 FPS baseline -> 297 FPS.

- Sprite submission and vertex building run on all cores above
  Renderer2DOptions.ParallelThreshold (default 8192). Work is sliced
  into 4096-entity segments: a Friflo chunk holds a whole archetype,
  so per-chunk parallelism degenerates to one thread. Segments merge
  in deterministic order, preserving radix sort stability.
- Vertex buffer is ring-written with SetDataOptions.NoOverwrite
  (GPU buffer 2x frame size); Discard only on wrap-around.
- Texture2DRegion precomputes UVs - four float divisions per sprite
  per frame removed.
- Renderer2D exposes per-phase timings (submit/sort/build/upload/draw),
  shown in the sample HUD - all further optimization is data-driven.
- Sample BounceSystem parallelized the same segmented way.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-06-11 05:06:55 +03:00

63 lines
3.1 KiB
Markdown

# mrgameeng
2D game engine built on MonoGame 3.8.4 (DesktopGL), .NET 8, C#.
ECS-first: Friflo.Engine.ECS 3.6 is tightly integrated into the core — all gameplay
state lives in components, all logic in systems.
Design docs and developer documentation live in `docs/` and are written in **Russian**.
Keep them up to date when architecture or conventions change.
## Solution layout
```
src/ MrGameEng.* engine libraries (one per functional area)
samples/ MrGameEng.Sample — demo game showcasing every engine feature
tests/ xUnit test projects, one per engine library
docs/ architecture, conventions, roadmap (Russian)
```
Engine modules: `Core` (game loop, ECS world, scenes, time), `Graphics` (custom batched
renderer, camera, sprites), `Input`, `Audio`, `Assets` (runtime loading, no content
pipeline), `Assets.Generator` (Roslyn source generator for typed asset handles),
`UI` (Myra integration: `scene.UseUI()` after `UseRenderer2D()`).
Dependency rule: every module may depend only on `Core`; `Core` depends only on
MonoGame and Friflo.Engine.ECS. `Assets.Generator` is a netstandard2.0 analyzer.
Documented exception: Myra renders with its own SpriteBatch internally.
## Commands
```
dotnet build MrGameEng.sln
dotnet test MrGameEng.sln
dotnet run --project samples/MrGameEng.Sample
```
## Architecture rules
- ECS-first: components are plain data (`struct` implementing `IComponent`),
behavior goes into Friflo systems (`QuerySystem`), wired through `SystemRoot`.
No `Update()` methods on game objects, no inheritance-based entities.
- Hot paths (per-frame systems) must be allocation-free below the renderer's parallel
threshold; above it Parallel.For scheduler overhead is the accepted trade.
A Friflo chunk holds a whole archetype — parallelize by slicing chunks into segments,
never by chunk alone. Measure in Release only, using the Renderer2D phase timings.
- Rendering: custom batcher in `Graphics` (vertex buffers, layer→depth→texture sort,
atlas support); `SpriteBatch` is not used in engine code. Draw systems write vertices
directly from Friflo chunk iteration. Orthographic camera (one active per scene),
registered render layers (World or Screen space, optional Y-sort), AABB culling
against the camera rect before vertices are written.
- No MGCB content pipeline. Assets are raw files under `Assets/`, loaded at runtime
(textures via `Texture2D.FromFile`, fonts via FontStashSharp, ogg via NVorbis,
shaders precompiled by `dotnet-mgfxc` at build time). Game code references assets
only through generated typed handles (`AssetRef<T>`), never string paths.
- New engine functionality goes into the matching module, or a new
`MrGameEng.<Area>` library if it is a distinct area — never into `Core` by default.
- Every public engine feature must be demonstrated in `MrGameEng.Sample`
and covered by tests where logic is testable without a GPU.
## Code conventions
- Nullable reference types enabled, warnings as errors, file-scoped namespaces.
- Public engine API requires XML doc comments (English).
- Tests: xUnit, named `Method_Scenario_Expectation`.