Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
301 changes: 25 additions & 276 deletions pufferlib/ocean/drive/drive.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@
#define GOAL_GENERATE_NEW 1
#define GOAL_STOP 2

// Offsets
#define COLLISION_RANGE 5
Comment on lines +103 to +104
Copy link

Copilot AI Jan 17, 2026

Choose a reason for hiding this comment

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

The new defines COLLISION_RANGE and Z_RANGE lack documentation explaining what they represent. Consider adding comments explaining that these define the grid dimensions for collision detection and z-coordinate updates, respectively. For example: "Grid dimension for collision detection (creates a 5x5 grid)" and "Grid dimension for z-coordinate updates (creates a 15x15 grid)".

Suggested change
// Offsets
#define COLLISION_RANGE 5
// Offsets
// Grid dimension for collision detection (creates a 5x5 grid)
#define COLLISION_RANGE 5
// Grid dimension for z-coordinate updates (creates a 15x15 grid)

Copilot uses AI. Check for mistakes.
#define Z_RANGE 15

// Jerk action space (for JERK dynamics model)
static const float JERK_LONG[4] = {-15.0f, -4.0f, 0.0f, 4.0f};
static const float JERK_LAT[3] = {-4.0f, 0.0f, 4.0f};
Expand All @@ -116,281 +120,23 @@ static const float offsets[4][2] = {
{-1, -1} // bottom-left
};

Copy link

Copilot AI Jan 17, 2026

Choose a reason for hiding this comment

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

The generate_offsets function lacks documentation explaining its purpose, parameters, and behavior. Consider adding a comment block above the function explaining that it generates a square grid of 2D offsets centered at (0,0), the offset_range parameter determines the grid dimensions (e.g., 5 creates a 5x5 grid from -2 to 2), and the offsets array must be pre-allocated to size offset_range^2.

Suggested change
/**
* Generates a square grid of 2D integer offsets centered at (0,0).
*
* The resulting grid has dimensions offset_range x offset_range. For example,
* an offset_range of 5 will generate offsets in the inclusive range [-2, 2]
* for both x and y, producing 25 (dx, dy) pairs.
*
* Parameters:
* offsets Pre-allocated array of size offset_range^2 by 2 that will
* be filled with the generated (dx, dy) offset pairs.
* offset_range Side length of the square grid. Typically a positive odd
* integer so that the grid is symmetrically centered on (0,0).
*/

Copilot uses AI. Check for mistakes.
static const int collision_offsets[25][2] = {
/* 5x5 grid: dx, dy from -2 to 2 */
/* Row -2 */
{-2, -2},
{-1, -2},
{0, -2},
{1, -2},
{2, -2},
/* Row -1 */
{-2, -1},
{-1, -1},
{0, -1},
{1, -1},
{2, -1},
/* Row 0 */
{-2, 0},
{-1, 0},
{0, 0},
{1, 0},
{2, 0},
/* Row 1 */
{-2, 1},
{-1, 1},
{0, 1},
{1, 1},
{2, 1},
/* Row 2 */
{-2, 2},
{-1, 2},
{0, 2},
{1, 2},
{2, 2}};

static const int z_offsets[225][2] = {
/* 15x15 grid: dx, dy from -7 to 7 */
/* Row -7 */
{-7, -7},
{-6, -7},
{-5, -7},
{-4, -7},
{-3, -7},
{-2, -7},
{-1, -7},
{0, -7},
{1, -7},
{2, -7},
{3, -7},
{4, -7},
{5, -7},
{6, -7},
{7, -7},
/* Row -6 */
{-7, -6},
{-6, -6},
{-5, -6},
{-4, -6},
{-3, -6},
{-2, -6},
{-1, -6},
{0, -6},
{1, -6},
{2, -6},
{3, -6},
{4, -6},
{5, -6},
{6, -6},
{7, -6},
/* Row -5 */
{-7, -5},
{-6, -5},
{-5, -5},
{-4, -5},
{-3, -5},
{-2, -5},
{-1, -5},
{0, -5},
{1, -5},
{2, -5},
{3, -5},
{4, -5},
{5, -5},
{6, -5},
{7, -5},
/* Row -4 */
{-7, -4},
{-6, -4},
{-5, -4},
{-4, -4},
{-3, -4},
{-2, -4},
{-1, -4},
{0, -4},
{1, -4},
{2, -4},
{3, -4},
{4, -4},
{5, -4},
{6, -4},
{7, -4},
/* Row -3 */
{-7, -3},
{-6, -3},
{-5, -3},
{-4, -3},
{-3, -3},
{-2, -3},
{-1, -3},
{0, -3},
{1, -3},
{2, -3},
{3, -3},
{4, -3},
{5, -3},
{6, -3},
{7, -3},
/* Row -2 */
{-7, -2},
{-6, -2},
{-5, -2},
{-4, -2},
{-3, -2},
{-2, -2},
{-1, -2},
{0, -2},
{1, -2},
{2, -2},
{3, -2},
{4, -2},
{5, -2},
{6, -2},
{7, -2},
/* Row -1 */
{-7, -1},
{-6, -1},
{-5, -1},
{-4, -1},
{-3, -1},
{-2, -1},
{-1, -1},
{0, -1},
{1, -1},
{2, -1},
{3, -1},
{4, -1},
{5, -1},
{6, -1},
{7, -1},
/* Row 0 */
{-7, 0},
{-6, 0},
{-5, 0},
{-4, 0},
{-3, 0},
{-2, 0},
{-1, 0},
{0, 0},
{1, 0},
{2, 0},
{3, 0},
{4, 0},
{5, 0},
{6, 0},
{7, 0},
/* Row 1 */
{-7, 1},
{-6, 1},
{-5, 1},
{-4, 1},
{-3, 1},
{-2, 1},
{-1, 1},
{0, 1},
{1, 1},
{2, 1},
{3, 1},
{4, 1},
{5, 1},
{6, 1},
{7, 1},
/* Row 2 */
{-7, 2},
{-6, 2},
{-5, 2},
{-4, 2},
{-3, 2},
{-2, 2},
{-1, 2},
{0, 2},
{1, 2},
{2, 2},
{3, 2},
{4, 2},
{5, 2},
{6, 2},
{7, 2},
/* Row 3 */
{-7, 3},
{-6, 3},
{-5, 3},
{-4, 3},
{-3, 3},
{-2, 3},
{-1, 3},
{0, 3},
{1, 3},
{2, 3},
{3, 3},
{4, 3},
{5, 3},
{6, 3},
{7, 3},
/* Row 4 */
{-7, 4},
{-6, 4},
{-5, 4},
{-4, 4},
{-3, 4},
{-2, 4},
{-1, 4},
{0, 4},
{1, 4},
{2, 4},
{3, 4},
{4, 4},
{5, 4},
{6, 4},
{7, 4},
/* Row 5 */
{-7, 5},
{-6, 5},
{-5, 5},
{-4, 5},
{-3, 5},
{-2, 5},
{-1, 5},
{0, 5},
{1, 5},
{2, 5},
{3, 5},
{4, 5},
{5, 5},
{6, 5},
{7, 5},
/* Row 6 */
{-7, 6},
{-6, 6},
{-5, 6},
{-4, 6},
{-3, 6},
{-2, 6},
{-1, 6},
{0, 6},
{1, 6},
{2, 6},
{3, 6},
{4, 6},
{5, 6},
{6, 6},
{7, 6},
/* Row 7 */
{-7, 7},
{-6, 7},
{-5, 7},
{-4, 7},
{-3, 7},
{-2, 7},
{-1, 7},
{0, 7},
{1, 7},
{2, 7},
{3, 7},
{4, 7},
{5, 7},
{6, 7},
{7, 7}};
static inline void generate_offsets(int offsets[][2], int offset_range) {
int half_grid = offset_range / 2;
int left_most = -half_grid;
int right_most = offset_range + left_most - 1;
int index = 0;
for (int dy = left_most; dy <= right_most; dy++) {
for (int dx = left_most; dx <= right_most; dx++) {
offsets[index][0] = dx;
offsets[index][1] = dy;
index++;
}
}
}

// Offset arrays
int collision_offsets[COLLISION_RANGE * COLLISION_RANGE][2] = {0};
int z_offsets[Z_RANGE * Z_RANGE][2] = {0};

const Color STONE_GRAY = (Color){80, 80, 80, 255};
const Color PUFF_RED = (Color){187, 0, 0, 255};
Expand Down Expand Up @@ -1427,7 +1173,8 @@ void compute_agent_metrics(Drive *env, int agent_idx) {
}
float buffer = 4.0f; // 4.0m buffer for offroad checking
int list_size = 0;
GridMapEntity *entity_list = checkNeighbors(env, agent->x, agent->y, collision_offsets, 25, &list_size);
GridMapEntity *entity_list =
checkNeighbors(env, agent->x, agent->y, collision_offsets, COLLISION_RANGE * COLLISION_RANGE, &list_size);
for (int i = 0; i < list_size; i++) {
if (entity_list[i].entity_idx == -1)
continue;
Expand Down Expand Up @@ -1734,6 +1481,8 @@ void init(Drive *env) {
env->entities = load_map_binary(env->map_name, env);
set_means(env);
init_grid_map(env);
generate_offsets(collision_offsets, COLLISION_RANGE);
generate_offsets(z_offsets, Z_RANGE);
env->grid_map->vision_range = 21;
init_neighbor_offsets(env);
cache_neighbor_offsets(env);
Expand Down