Skip to content

added new sub-types for entities Agent, RoadMapElement, TrafficControlElement#278

Merged
riccardosavorgnan merged 1 commit into3.0_betafrom
3.0_beta_newdatatypes
Feb 6, 2026
Merged

added new sub-types for entities Agent, RoadMapElement, TrafficControlElement#278
riccardosavorgnan merged 1 commit into3.0_betafrom
3.0_beta_newdatatypes

Conversation

@riccardosavorgnan
Copy link
Copy Markdown
Collaborator

This PR introduces the new datatypes.h file and the new datatypes that will eventually replace the Entity struct.
It also adds support for the declaration of the new macros in datatypes.h. This PR does not implement ANY new method, the working code remains as is.

Copy link
Copy Markdown

@mpragnay mpragnay left a comment

Choose a reason for hiding this comment

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

lgtm!

@riccardosavorgnan riccardosavorgnan marked this pull request as ready for review February 6, 2026 15:10
@riccardosavorgnan riccardosavorgnan merged commit 90f2077 into 3.0_beta Feb 6, 2026
10 checks passed
@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented Feb 6, 2026

Greptile Overview

Greptile Summary

This PR introduces a new datatypes.h header file containing specialized structs (Agent, RoadMapElement, TrafficControlElement) that will eventually replace the generic Entity struct. The new types provide more structured and type-safe representations of agents, road elements, and traffic control elements with domain-specific fields. The PR also modifies drive.h to include the new header and adds placeholder fields in the Drive struct for the new types.

Key changes:

  • Created datatypes.h with new struct definitions and helper functions for type checking and normalization
  • Added typedef declarations in drive.h for the new structs
  • Implemented a transition strategy using #undef to temporarily avoid conflicts between old and new macro definitions
  • Added placeholder fields in the Drive struct (agents, road_elements, traffic_elements) alongside the existing entities field

Critical issues found:

  • Missing header guards in datatypes.h will cause compilation errors if the file is included multiple times
  • Function definitions in the header (lines 76-140) will cause multiple definition linker errors when included in multiple translation units
  • Undefined macros (ROAD_LANE, ROAD_LINE, ROAD_EDGE) that don't exist in datatypes.h are being referenced in drive.h
  • Memory management functions (free_agent, free_road_element, free_traffic_element) may have incomplete cleanup logic

Confidence Score: 2/5

  • This PR has critical compilation issues that will prevent the code from building correctly
  • The PR introduces well-structured new data types and a reasonable migration strategy, but has several critical issues: missing header guards will cause compilation failures, function definitions in headers will cause linker errors, and undefined macro references will cause build failures. These are blocking issues that must be resolved before merging
  • Pay close attention to datatypes.h which needs header guards and function definition fixes before it can be safely used

Important Files Changed

Filename Overview
pufferlib/ocean/drive/datatypes.h New header file with Agent, RoadMapElement, and TrafficControlElement structs. Has critical issues: missing header guards, function definitions that will cause linker errors, and potentially incorrect memory management in free functions
pufferlib/ocean/drive/drive.h Added include for datatypes.h, typedef declarations for new structs, and placeholder fields in Drive struct. Has issue with undefined macros (ROAD_LANE, ROAD_LINE, ROAD_EDGE) that don't exist in datatypes.h

Sequence Diagram

sequenceDiagram
    participant PR as Pull Request
    participant DH as drive.h
    participant DT as datatypes.h
    participant DS as Drive Struct
    
    Note over PR,DS: New Type System Introduction
    
    PR->>DT: Create new datatypes.h
    DT->>DT: Define Agent struct
    DT->>DT: Define RoadMapElement struct
    DT->>DT: Define TrafficControlElement struct
    DT->>DT: Define helper functions
    DT->>DT: Define free_agent/free_road_element/free_traffic_element
    
    PR->>DH: Modify drive.h
    DH->>DT: Include datatypes.h
    Note over DH: Conflicts with existing defines
    DH->>DH: Save STOP_SIGN as DT_STOP_SIGN
    DH->>DH: Save CROSSWALK as DT_CROSSWALK
    DH->>DH: Undef conflicting macros from datatypes.h
    DH->>DH: Redefine macros with legacy values
    
    DH->>DS: Add typedef for Agent
    DH->>DS: Add typedef for RoadMapElement
    DH->>DS: Add typedef for TrafficControlElement
    DH->>DS: Add placeholder fields (agents, road_elements, traffic_elements)
    
    Note over DS: Legacy Entity struct still active
    Note over DS: New structs available but unused
Loading

Copy link
Copy Markdown

@greptile-apps greptile-apps Bot left a comment

Choose a reason for hiding this comment

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

2 files reviewed, 4 comments

Edit Code Review Agent Settings | Greptile

@@ -0,0 +1,277 @@
#define UNKNOWN 0
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Missing header guards - this file needs #ifndef, #define, and #endif to prevent multiple inclusion issues

Comment on lines +76 to +104
int is_road_lane(int type) { return (type >= 0 && type <= 9); }

int is_drivable_road_lane(int type) { return (type == LANE_FREEWAY || type == LANE_SURFACE_STREET); }

int is_road_line(int type) { return (type >= 10 && type <= 19); }

int is_road_edge(int type) { return (type >= 20 && type <= 29); }

int is_road(int type) { return is_road_lane(type) || is_road_line(type) || is_road_edge(type); }

int is_controllable_agent(int type) { return (type == VEHICLE || type == PEDESTRIAN || type == CYCLIST); }

int is_traffic_light_red(int state) { return state == 1 || state == 4 || state == 7; }

int is_traffic_light_green(int state) { return state == 3 || state == 6 || state == 9; }

int is_traffic_light_yellow(int state) { return state == 2 || state == 5 || state == 8; }

int normalize_road_type(int type) {
if (is_road_lane(type)) {
return 0;
} else if (is_road_line(type)) {
return 1;
} else if (is_road_edge(type)) {
return 2;
} else {
return -1;
}
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Functions defined in header will cause multiple definition errors when included in multiple .c files. These should be declared static inline or moved to a .c file

Comment on lines +251 to +264
void free_agent(struct Agent *agent) {
free(agent->log_trajectory_x);
free(agent->log_trajectory_y);
free(agent->log_trajectory_z);
free(agent->log_heading);
free(agent->log_velocity_x);
free(agent->log_velocity_y);
free(agent->log_length);
free(agent->log_width);
free(agent->log_height);
free(agent->log_valid);
free(agent->route);
free(agent->path);
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

free_agent frees agent->path but Path is a struct containing a static array, not a pointer. If path was allocated with malloc, this is correct, but the function should also free the path struct itself. If path points to a struct with nested dynamic allocations, those need to be freed first. Same issue applies to free_road_element and free_traffic_element

Comment on lines +23 to +33
#undef NONE
#undef VEHICLE
#undef PEDESTRIAN
#undef CYCLIST
#undef ROAD_LANE
#undef ROAD_LINE
#undef ROAD_EDGE
#undef STOP_SIGN
#undef CROSSWALK
#undef SPEED_BUMP
#undef DRIVEWAY
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

ROAD_LANE, ROAD_LINE, and ROAD_EDGE are undefined but don't exist in datatypes.h - only specific types like LANE_FREEWAY, ROAD_LINE_UNKNOWN, ROAD_EDGE_UNKNOWN are defined

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.

2 participants