Description
src/world/lod_manager.zig (1,198 lines) mixes high-level LOD region management with low-level GPU operations through a generic RHI parameter. This violates Single Responsibility Principle and creates tight coupling.
Current Problems
- SRP Violation: Manages both logical LOD state AND rendering/GPU concerns
- ISP Violation:
LODManager(RHI) uses only subset of RHI but has full interface access
- DIP Violation: Direct dependency on concrete RHI type through generics
Technical Details
Current generic pattern:
pub fn LODManager(comptime RHI: type) type {
return struct {
rhi: RHI, // Direct RHI dependency
// LOD logic (should remain)
regions: [LODLevel.count]std.HashMap(...),
gen_queues: [LODLevel.count]std.ArrayList(...),
// GPU operations (should be extracted)
fn processUploads() { mesh.upload(self.rhi); }
fn unloadDistantRegions() { mesh.deinit(self.rhi); }
fn render() { LODRenderer.render(self.rhi); }
};
}
Mixed responsibilities:
- LOD Logic: Region tracking, generation queuing, state transitions, distance-based selection
- GPU Operations: Buffer uploads (
processUploads), deferred deletion (unloadDistantRegions), rendering coordination
Proposed Solution
- Extract
LODRenderer - Already partially exists, ensure complete separation
- Create
LODUploadQueue - Handles all GPU upload/deletion operations
- Define callback interface - LODManager uses callbacks instead of direct RHI access
New architecture:
// LODManager - pure logic, no RHI
pub const LODManager = struct {
regions: [...],
upload_queue: LODUploadQueue, // Callback-based
renderer: LODRenderer, // Already separate
pub fn update(self: *Self, player_pos: Vec3) void {
// Pure LOD logic
self.queueUploads();
}
};
// LODUploadQueue - handles GPU operations
pub const LODUploadQueue = struct {
on_upload: *const fn(mesh: LODMesh) void,
on_delete: *const fn(mesh: LODMesh) void,
};
Pass Criteria
Description
src/world/lod_manager.zig(1,198 lines) mixes high-level LOD region management with low-level GPU operations through a genericRHIparameter. This violates Single Responsibility Principle and creates tight coupling.Current Problems
LODManager(RHI)uses only subset of RHI but has full interface accessTechnical Details
Current generic pattern:
Mixed responsibilities:
processUploads), deferred deletion (unloadDistantRegions), rendering coordinationProposed Solution
LODRenderer- Already partially exists, ensure complete separationLODUploadQueue- Handles all GPU upload/deletion operationsNew architecture:
Pass Criteria
LODManagerhas norhifield (removed from struct)LODManageruses callback interface for GPU operationsLODRendererfully separated with clean interfaceLODUploadQueueextracted as standalone modulenix develop --command zig build test