Browse Source

Add rendering cleanup plan for texture management and code simplification

main
cinnaboot 5 months ago
parent
commit
ba67611701
  1. 110
      docs/planning/rendering-cleanup-plan.md

110
docs/planning/rendering-cleanup-plan.md

@ -0,0 +1,110 @@
# Rendering Cleanup Plan - Texture Management and Code Simplification
## Objective
Clean up rendering code by removing unused spacecraft texture system, consolidating texture loading to initialization, and simplifying other rendering functions.
## Background
The renderer has several inefficiencies:
- `ensure_textures_loaded()` called every frame instead of once during initialization
- Spacecraft texture system now redundant with `render_child_indicators()` providing visibility
- Unused `render_body()` function with FIXME comment
- Hardcoded constants scattered throughout rendering code
- Documentation inconsistency between RenderState and UIState
## Implementation
### Step 1: Save Plan (Current)
- Create this plan document in docs/planning/
- **PAUSE** for user review
### Step 2: Move Texture Loading to Initialization
- Modify `init_renderer()` or `setup_camera()` to call `ensure_textures_loaded()` once
- Remove `ensure_textures_loaded()` calls from:
- `render_spacecraft_screen_space()` (renderer.cpp:385)
- `render_maneuver_marker_screen_space()` (renderer.cpp:420)
- Update docs/technical_reference.md if it references texture loading behavior
- **PAUSE** for user review
### Step 3: Remove Spacecraft Texture System
Remove all spacecraft texture-related code:
- From RenderState struct (renderer.h:19): `Texture2D spacecraft_texture;`
- From renderer.cpp:
- `generate_spacecraft_texture()` function (lines 112-124)
- `calculate_spacecraft_angle()` function (lines 156-164)
- `render_spacecraft_screen_space()` function (lines 373-402)
- Texture initialization in `setup_camera()` (line 178)
- Texture unloading in `close_renderer()` (line 103)
- Remove spacecraft rendering from main loop in `render_simulation()` (lines 694-697)
- Remove from renderer.h:
- Function declaration for `generate_spacecraft_texture()` (line 29)
- Function declaration for `calculate_spacecraft_angle()` (line 36)
- Function declaration for `render_spacecraft_screen_space()` (line 45)
- Update docs/rendering.md to remove spacecraft texture references
- **PAUSE** for user review
### Step 4: Remove Unused `render_body()` Function
- Remove `render_body()` function from renderer.cpp (lines 359-371)
- Remove function declaration from renderer.h (line 44)
- Remove FIXME comment on line 357
- Update docs/rendering.md line 315 (references to render_body)
- Update docs/technical_reference.md line 531 (references to render_body)
- **PAUSE** for user review
### Step 5: Simplify Maneuver Texture Selection
- Replace switch statement (renderer.cpp:426-449) with direct array indexing
- Since BurnDirection enum values are sequential (0-5), use `maneuver->direction` directly as texture_index
- Handle BURN_CUSTOM case separately if needed
- **PAUSE** for user review
### Step 6: Extract UI Panel Constants
- Add constants to ui_renderer.cpp:
- `INFO_PANEL_WIDTH = 300`
- `INFO_PANEL_HEIGHT = 300`
- `BODY_LIST_WIDTH = 200`
- `BODY_LIST_HEIGHT = 400`
- `BODY_INFO_WIDTH = 250`
- `BODY_INFO_HEIGHT = 300`
- `MANEUVER_LIST_WIDTH = 300`
- `MANEUVER_LIST_HEIGHT = 400`
- `MANEUVER_LIST_Y_OFFSET = 320`
- Replace magic numbers in all UI rendering functions
- **PAUSE** for user review
### Step 7: Extract Child Indicator Constants
- Add constants to renderer.cpp:
- `CHILD_INDICATOR_RADIUS = 20.0f`
- `CHILD_INDICATOR_FONT_SIZE = 10`
- Replace magic numbers in `draw_child_indicator()` function
- **PAUSE** for user review
### Step 8: Fix Documentation Inconsistency
- Update docs/rendering.md line 16 to reflect that `selected_craft_index` is in UIState, not RenderState
- Update any other documentation that references this field location
- **PAUSE** for user review
### Step 9: Final Testing
- Build project: `make`
- Run simulation: `make run`
- Verify spacecraft still visible via child indicators
- Verify maneuver markers still render correctly
- Verify UI panels still display correctly
- Check for any texture-related warnings or errors
- **PAUSE** for user review
## Testing Plan
- Build succeeds without errors
- Spacecraft visible in child indicators when parent body selected
- Maneuver markers display with correct colors and sizes
- UI panels render with correct dimensions
- No memory leaks from texture cleanup
- Performance improvement (fewer function calls per frame)
## References
- docs/rendering.md - Rendering system documentation
- docs/technical_reference.md - Technical reference
- src/renderer.cpp/h - Main rendering code
- src/ui_renderer.cpp/h - UI rendering code
- AGENTS.md - Coding rules (no comments, C-style)
## Date
Created: 2026-01-30
Loading…
Cancel
Save