Files
Claude-Code-Game-Studios/.claude/rules/engine-code.md
T
DonchitosandClaude Opus 5.5 b21fa0f7f2 Release 1.1.2 — the default path works end to end
Fix release for 1.1.1: the minimal path end to end, engine commands that
run on Godot, Unity and Unreal, hook warnings you can see, and verdicts
that say when they could not check. Details in CHANGELOG.md; upgrade
steps in UPGRADING.md (v1.1.1 → v1.1.2).

Fixes #67
Fixes #131

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WuJn2FdynEybfL5KC697nJ
2026-09-29 21:32:19 +10:00

63 lines
2.0 KiB
Markdown

---
paths:
- "src/core/**"
- "Assets/**/{Core,core}/**/*.cs"
- "Source/**/{Core,core}/**/*.{h,cpp}"
---
# Engine Code Rules
- ZERO allocations in hot paths (update loops, rendering, physics) — pre-allocate, pool, reuse
- All engine APIs must be thread-safe OR explicitly documented as single-thread-only
- Profile before AND after every optimization — document the measured numbers
- Engine code must NEVER depend on gameplay code (strict dependency direction: engine <- gameplay)
- Every public API must have usage examples in its doc comment
- Changes to public interfaces require a deprecation period and migration guide
- Use RAII / deterministic cleanup for all resources
- All engine systems must support graceful degradation
- Before writing engine API code, consult `docs/engine-reference/` for the current engine version and verify APIs against the reference docs
## Examples
**Correct** (zero-alloc hot path) — Godot:
```gdscript
# Pre-allocated array reused each frame
var _nearby_cache: Array[Node3D] = []
func _physics_process(delta: float) -> void:
_nearby_cache.clear() # Reuse, don't reallocate
_spatial_grid.query_radius(position, radius, _nearby_cache)
```
Unity:
```csharp
private readonly Collider[] _nearbyCache = new Collider[64]; // allocated once
void FixedUpdate()
{
int count = Physics.OverlapSphereNonAlloc(transform.position, radius, _nearbyCache);
}
```
Unreal:
```cpp
// TArray member, reserved once; Reset() keeps the allocation
void UProximityComponent::TickComponent(float DeltaTime, ELevelTick TickType,
FActorComponentTickFunction* ThisTickFunction)
{
NearbyCache.Reset();
SpatialGrid->QueryRadius(GetComponentLocation(), Radius, NearbyCache);
}
```
**Incorrect** (allocating in hot path):
```gdscript
func _physics_process(delta: float) -> void:
var nearby: Array[Node3D] = [] # VIOLATION: allocates every frame
nearby = get_tree().get_nodes_in_group("enemies") # VIOLATION: tree query every frame
```