1---2name: c99-game-opinionated-guide3description: Use when editing C99 game-engine or runtime code in projects that follow the opinionated caller-owns-memory, SoA, builder-pattern style. A focused overlay that covers only game/engine house-style decisions, not generic C99 idioms. Triggers on `.c`/`.h` files in game/engine directories and on prompts about vectors, matrices, quaternions, physics, meshes, spatial structures, tagged unions, inverse mass, builder patterns, even when the user doesn't say 'opinionated'.4---56# C99 Game Engine Opinionated Guidelines78## Requirements910- **Overlay on c99-guide** - This guide carries only the game/engine opinionated decisions; for generic C99 idioms: `const`-correctness, designated initializers (ZII), fixed-width types, value-oriented APIs, and baseline error/return patterns, follow **c99-guide**1112## Math1314- **Types** - 16-byte aligned vectors/matrices/quaternions, see [references/math-types.md](references/math-types.md)15- **Access** - Use accessor functions for matrices, direct fields for vectors, see [references/math-types.md](references/math-types.md)16- **Coordinates** - Right-handed Y-up, CCW winding, configurable clip depth, see [references/coordinate-system.md](references/coordinate-system.md)17- **Suffixes** - `_aos/_soa` layouts, `_simde` SIMD, `2d/3d` dimensions1819## Geometry Pipeline2021- **Analytic → Discrete → Packing** - Separate logic/rendering/GPU layers, see [references/geometry-pipeline.md](references/geometry-pipeline.md)22- **Builder pattern** - `*_req()` query size, `*_build()` write to caller buffer, see [references/builder-pattern.md](references/builder-pattern.md)2324## Patterns2526- **Inverse mass** - Store `1/mass`, static objects use `0.0`, see [references/physics-patterns.md](references/physics-patterns.md)27- **SoA optimization** - AoS for single objects, SoA for batches, see [references/mesh-types.md](references/mesh-types.md)28- **Validation** - Check capacity, bounds, NULL, overflow before operations2930## Gotchas3132- Vertex packing order matters for GPU upload: pack tightly and match the shader's attribute layout, not the C struct's natural padding33- Quaternion math is sensitive to normalization drift: re-normalize after long chains of multiplications34- Tagged unions with a sentinel `TYPE_INVALID = 0` save initialization bugs; designated initializers default fields to zero35- Builder patterns in C99 work via opaque structs + functions; never expose mutable struct fields across the public boundary3637## Progressive disclosure3839- Read [references/math-types.md](references/math-types.md) - Load when working with vectors, matrices, or quaternions40- Read [references/coordinate-system.md](references/coordinate-system.md) - Load when setting up camera, projection, or mesh normals41- Read [references/physics-patterns.md](references/physics-patterns.md) - Load when implementing rigid bodies, collision, or constraints42- Read [references/geometry-pipeline.md](references/geometry-pipeline.md) - Load when converting analytic shapes to renderable meshes43- Read [references/builder-pattern.md](references/builder-pattern.md) - Load when generating meshes or other variable-size data44- Read [references/vertex-packing.md](references/vertex-packing.md) - Load when preparing vertex data for GPU upload45- Read [references/mesh-types.md](references/mesh-types.md) - Load when working with 2D or 3D mesh structures46- Read [references/spatial-structures.md](references/spatial-structures.md) - Load when implementing broad-phase collision or spatial queries