Feature: Entity Component System (ECS) with Query API & Serialization#162
Feature: Entity Component System (ECS) with Query API & Serialization#162MichaelFisher1997 merged 4 commits intomainfrom
Conversation
- Added src/engine/ecs/ with Entity, Component, Storage, and Registry implementation. - Implemented PhysicsSystem (gravity/collision) and RenderSystem (wireframe debug). - Integrated ECS into GameSession. - Fixed a crash in Vulkan RHI initialization related to ArrayListUnmanaged cleanup.
Code Review Summary1. Previous Code Review IssuesI don't see any previous code review comments in the PR. The PR description mentions fixing a crash in 2. Code Quality IssuesCritical Rendering Bug in self.rhi.draw(self.buffer_handle, 288, .triangles);The entire wireframe cube (288 vertices) is drawn for EVERY entity as separate draw calls. This should use instanced rendering or draw with a vertex count of 6 (for a single point/line) instead of 288. Incorrect World Positioning in const rel_pos = transform.position.add(offset).sub(camera_pos);Entities are rendered relative to camera position, meaning they appear "glued" to the screen rather than at their actual world positions. Remove the Dead Code:
Memory Safety:
3. Potential BugsInteger Overflow:
Render System Issues:
ECS Integration:
4. Suggested ImprovementsHigh Priority:
Medium Priority: Architecture: |
|
User opencode-agent[bot] does not have write permissions |
|
User opencode-agent[bot] does not have write permissions |
|
User opencode-agent[bot] does not have write permissions |
|
User opencode-agent[bot] does not have write permissions |
|
User opencode-agent[bot] does not have write permissions |
|
Based on my review of the code, here's my analysis: Previous Review Issues StatusFIXED:
NOT FIXED:
New Issues FoundDuplicate Code in Render System Inconsistency: Test Entity Code: Lines 328-342 in Suggested ImprovementsHigh Priority:
Medium Priority: Low Priority: |
|
User opencode-agent[bot] does not have write permissions |
|
User opencode-agent[bot] does not have write permissions |
3e92914 to
606f4d4
Compare
|
Based on my review of the current code, here's the status of previous code review issues: Previous Review Issues StatusFIXED:
NOT FIXED:
Code Quality Issues
Potential Bugs
Suggested ImprovementsHigh Priority:
Medium Priority: Low Priority: |
606f4d4 to
13177c9
Compare
Code Review Status✅ PREVIOUS ISSUES - FIXED:
❌ PREVIOUS ISSUES - NOT FIXED:
🔍 NEW ISSUES FOUND:
RECOMMENDED FIXES:
|
13177c9 to
6bcb4d4
Compare
|
Based on my review of the code, here's the current status: Previous Code Review Issues - Status✅ FIXED:
❌ NOT FIXED:
Code Quality Issues
Potential Bugs
Suggested ImprovementsHigh Priority:
Medium Priority: Low Priority: |
6bcb4d4 to
0c5d2a7
Compare
Code Review SummaryPrevious Issues Status✅ FIXED:
❌ NOT FIXED:
New Issues Found
Potential Bugs
Code Quality Issues
Suggested ImprovementsHigh Priority:
Medium Priority: Low Priority: |
0c5d2a7 to
77712c5
Compare
Code Review SummaryPrevious Issues Status✅ FIXED:
❌ NOT FIXED:
Code Quality Issues
Potential Bugs
Suggested ImprovementsHigh Priority:
Medium Priority: Low Priority: |
77712c5 to
a046fec
Compare
Code Review SummaryPrevious Issues Status✅ FIXED:
❌ NOT FIXED:
Code Quality Issues
Potential Bugs
Suggested ImprovementsHigh Priority:
Medium Priority: Low Priority: |
a046fec to
4b6c34f
Compare
Code Review SummaryPrevious Issues StatusFIXED:
NOT FIXED:
Current Code Quality IssuesRHI Storage (render.zig:118-119): rhi: *const RHI,RHI is stored by pointer (not value) - this is consistent with Zig patterns for trait objects/interfaces. Previous reviews marked this as "by value" but that's incorrect. Unused Function (render.zig:111-115): fn toCameraRelative(position: Vec3, camera_pos: Vec3) Vec3 {
// Floating origin: rendering uses getViewMatrixOriginCentered() (see WorldScreen/world_renderer),
// so world positions must be shifted into camera-relative space.
return position.sub(camera_pos);
}This function is used at line 168, so it's not dead code. However, the comment raises questions about whether this subtraction is correct if the view matrix already handles camera-relative transformation. Potential BugsInefficient Rendering Loop (render.zig:173-186): if (!self.has_last_color or !colorEquals(mesh.color, self.last_color)) {
self.scratch_vertices = outline_vertices;
for (self.scratch_vertices[0..]) |*vertex| {
vertex.color = .{ mesh.color.x, mesh.color.y, mesh.color.z };
}
self.rhi.*.updateBuffer(self.buffer_handle, 0, std.mem.asBytes(&self.scratch_vertices));
self.last_color = mesh.color;
self.has_last_color = true;
}This works but is inefficient. Each entity causes a buffer upload. Consider:
Component Validation: Suggested ImprovementsHigh Priority:
Medium Priority: pub fn query(self: *Registry, comptime Components: type) QueryIterator(Components) { ... }Low Priority: |
4b6c34f to
cc2174d
Compare
Code Review Status✅ PREVIOUS ISSUES - FIXED:
❌ PREVIOUS ISSUES - NOT FIXED:
Code Quality IssuesRHI Storage Pattern ( rhi: RHI,Stores RHI by value. This may cause unnecessary copying. Other systems may use handles for consistency. Unused Function ( fn toCameraRelative(position: Vec3, camera_pos: Vec3) Vec3 {
return position.sub(camera_pos);
}The comment at line 112-113 suggests this is for "floating origin" rendering. Need to verify if this is correct. Potential Bugs
Suggested ImprovementsHigh Priority:
Medium Priority: Low Priority: |
cc2174d to
ee853c3
Compare
Code Review SummaryPrevious Issues Status✅ FIXED:
❌ NOT FIXED:
Code Quality Issues
Potential Bugs
Suggested ImprovementsHigh Priority:
Medium Priority: Low Priority: |
ee853c3 to
db82038
Compare
Code Review SummaryPrevious Issues Status✅ FIXED:
❌ NOT FIXED:
Code Quality Issues
Potential Bugs
Suggested ImprovementsHigh Priority:
Medium Priority: Low Priority: |
db82038 to
ecbcce6
Compare
|
Now I have a complete picture of the current code state. Here's the code review summary: Code Review SummaryPrevious Issues - Status✅ FIXED (7/9 issues):
❌ NOT FIXED (2/9 issues):
Code Quality Issues
Potential Bugs
Suggested ImprovementsHigh Priority:
Medium Priority: Low Priority: |
ecbcce6 to
1ec2f4a
Compare
Code Review SummaryPrevious Issues - Status✅ FIXED (8/9):
❌ NOT FIXED (1/9):
Code Quality Issues
Potential Bugs
Suggested ImprovementsHigh Priority:
Medium Priority: pub fn query(self: *Registry, comptime Components: type) QueryIterator(Components) { ... }Low Priority: |
|
Camera-relative ECS rendering is intentional for floating origin. The renderer uses getViewMatrixOriginCentered() and world_renderer.zig subtracts camera position as well, so ECS must do the same to stay in the same coordinate frame and avoid large-world precision jitter. We'll keep this behavior. |
1ec2f4a to
ddbbb64
Compare
|
Based on my review of the current code, here's the status of previous code review issues: Previous Issues Status✅ FIXED (8/9):
✅ INTENTIONAL (not a bug):
Code Quality Issues
Potential Bugs
Suggested ImprovementsHigh Priority:
Medium Priority: Low Priority: |
ddbbb64 to
767ed2f
Compare
Code Review Status - ECS Implementation✅ PREVIOUS ISSUES - ALL FIXED:
CODE QUALITY ISSUES:
POTENTIAL BUGS:
SUGGESTED IMPROVEMENTS:High Priority:
Medium Priority: Low Priority: SUMMARY:All 10 previously reported issues have been FIXED. The ECS implementation is now in good shape with:
The main remaining improvements are architectural: adding query API and potential performance optimizations for large entity counts. |
…ty, cleanup RHI ArrayList crash and unused code - Rendering: Subtract camera position from entity position as view matrix is origin-centered. - ECS: Removed unused EntityManager in entity.zig. - Storage: Fixed potential crash in map update during removal. - Session: Uncommented test entity spawning. - RHI: Fixed crash due to double-free of uninitialized ArrayListUnmanaged in buffer_deletion_queue.
767ed2f to
c623007
Compare
Code Review SummaryPrevious Issues Status✅ ALL 10 PREVIOUS ISSUES FIXED:
Code Quality Issues
Potential BugsNo bugs detected - All previously reported issues have been properly addressed. Suggested ImprovementsHigh Priority:
Medium Priority: Low Priority: SummaryThe ECS implementation is now in good shape. All previously reported issues have been fixed. The remaining improvements are architectural enhancements rather than bug fixes. The implementation correctly handles memory safety, component validation with logging, and proper rendering with camera-relative positioning for the floating origin system. |
- Implemented generic type-safe Query API in Registry. - Added Snapshot and JSON serialization/deserialization for entities and components. - Refactored PhysicsSystem and RenderSystem to use Query API. - Added validation logging for entities with missing components. - Added comprehensive unit tests in src/ecs_tests.zig.
Code Review StatusAll 10 previously reported issues are FIXED:
Code Quality Issues
Potential BugsNone detected - all previously reported issues properly addressed. Suggested ImprovementsHigh Priority:
Medium Priority:
Low Priority:
|
…y API - Updated RHI setModelMatrix to support per-object color override via push constants. - Updated terrain.vert shader to apply color_override to vertex colors. - Refactored RenderSystem to use the new color uniform, eliminating vertex buffer re-uploads for color changes. - Implemented generic type-safe Query API in Registry for efficient component iteration. - Implemented ECS state serialization (Snapshot/JSON) for game save/load support. - Centralized wireframe cube geometry and switched to 24-vertex line list. - Added comprehensive unit tests for ECS core, Query API, and Serialization.
Code Review StatusAll 10 previously reported issues are FIXED:
Code Quality Issues:
Potential Bugs: None detected. Suggested Improvements:
|



















Summary
src/engine/ecs/.registry.query(.{ Transform, Mesh })).src/ecs_tests.zigwith 100% coverage of core ECS logic.