Skip to content

Compact code grid code#485

Merged
vcharraut merged 2 commits into
emerge/temp_trainingfrom
vcha-emerge/compact-code
Jun 15, 2026
Merged

Compact code grid code#485
vcharraut merged 2 commits into
emerge/temp_trainingfrom
vcha-emerge/compact-code

Conversation

@vcharraut

@vcharraut vcharraut commented Jun 15, 2026

Copy link
Copy Markdown
Collaborator

What

Cleanup-only refactor of the grid-map code in drive.h plus a small
behavioral fix to how the grid's spatial bounds are computed. No change to
the training loop or Python side.

Changes

GridMap struct (drive.h)

  • Drop unused cell_size_x / cell_size_y fields (always equal to
    GRID_CELL_SIZE).
  • Regroup fields by kind (scalars, count arrays, entity arrays) and remove
    stale inline comments.

init_grid_map

  • Restrict the grid's bounding box to lanes and road edges via the new is_road_grid_candidate() helper (datatypes.h), instead of all road elements. Road lines no longer stretch the grid extent.
  • Use an element pointer alias in the count/populate passes.
  • Merge the two INVALID_POSITION guards into one.
  • Remove the dead cell_entities_insert_index != 0 re-zeroing loop
    (the array comes straight from calloc).

apply_infraction_behavior() helper

  • Extract the repeated STOP_AGENT / REMOVE_AGENT block (offroad,
    collision, red-light) into one inline helper in compute_metrics.

Misc

  • init_neighbor_offsets, cache_neighbor_offsets,
    get_neighbors_entities, get_grid_index: shorter local names
    (vr, rel_x, cell_x/cell_y, cols) and dropped redundant comments.

Net

+72 / −128 across drive.h and datatypes.h.

Refactor code to enhance readability and optimize performance by reducing redundancy and improving structure.
Copilot AI review requested due to automatic review settings June 15, 2026 09:10

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors and “compacts” the Drive grid-map code in drive.h, mainly by reorganizing GridMap fields, simplifying several grid/neighbor helper routines, and deduplicating infraction behavior handling.

Changes:

  • Reordered/trimmed GridMap struct members (including removing unused cell_size_x/y fields).
  • Added apply_infraction_behavior() to centralize STOP/REMOVE handling for offroad/collision/red-light infractions.
  • Simplified variable naming and small logic cleanup in grid index calculation, grid map initialization, and neighbor offset caching.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread pufferlib/ocean/drive/drive.h
@vcharraut vcharraut merged commit 56778e4 into emerge/temp_training Jun 15, 2026
12 checks passed
@vcharraut vcharraut deleted the vcha-emerge/compact-code branch June 15, 2026 12:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants