Conversation
There was a problem hiding this comment.
Pull request overview
This PR refactors island splitting to be faster by switching to a union-find approach and by changing island body storage from a linked list to an indexable array. It also extends the samples app UI with an ImPlot-based “Frame Time” plot and adds new container unit tests.
Changes:
- Replace island body linked-list bookkeeping with an array + per-body
islandIndex, enabling union-find based island splitting. - Introduce a lightweight dynamic/stack array utility (
container.h) and add a dedicated container test suite. - Add ImPlot to the samples build and render a new real-time frame/profile plot UI.
Reviewed changes
Copilot reviewed 23 out of 26 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
src/island.c |
Implements union-find based island split and updates island lifecycle for new body storage. |
src/island.h |
Updates b2Island to store bodies as a dynamic array instead of a linked list. |
src/body.h |
Replaces island linked-list pointers with islandIndex for O(1) union-find mapping. |
src/body.c |
Updates island membership add/remove logic to maintain islandIndex and island body arrays. |
src/solver_set.c |
Updates sleep logic and migration loops to iterate island body arrays. |
src/solver.c |
Switches island lookup to the new container access helper. |
src/physics_world.h |
Changes world island storage to a persistent dynamic array and declares its container type. |
src/physics_world.c |
Updates world island initialization/destruction and island debug drawing iteration. |
src/container.h |
Adds new dynamic array + stack array utilities and helpers. |
src/core.h |
Adds B2_TYPE_OF/B2_SWAP helpers and tweaks B2_ARRAY_COUNT. |
src/core.c |
Renames and changes behavior of internal assert function (breakpoint handling). |
include/box2d/base.h |
Updates B2_ASSERT macro and exported internal assert symbol name. |
src/CMakeLists.txt |
Adds container.h to the source list. |
test/test_container.c |
Adds a new container-focused test suite for dynamic/stack arrays. |
test/main.c |
Registers and runs the new ContainerTest. |
test/CMakeLists.txt |
Adds test_container.c to the test target sources. |
samples/sample.h |
Adds persistent profile ring-buffer fields and frameTime flag plumbing. |
samples/sample.cpp |
Records per-step profiles into a ring buffer and adds ImPlot-based plotting UI. |
samples/sample_benchmark.cpp |
Ensures benchmark sample UI calls base Sample::UpdateGui(). |
samples/main.cpp |
Initializes/shuts down ImPlot context and adds “Frame Time” checkbox. |
samples/CMakeLists.txt |
Builds and links ImPlot into the samples app. |
extern/implot/implot.h |
Adds vendored ImPlot public header. |
extern/implot/implot_internal.h |
Adds vendored ImPlot internal header. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 24 out of 27 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
test/CMakeLists.txt
Outdated
| main.c | ||
| test_bitset.c | ||
| test_collision.c | ||
| test_container.c |
There was a problem hiding this comment.
Indentation uses a tab for test_container.c while the surrounding entries use spaces. This can create noisy diffs and inconsistent formatting in generated project files; align the indentation with the rest of the list.
|
Claude finished @erincatto's task in 3m 18s —— View job Code Review — Faster Island Split
Overall AssessmentThe union-find approach for island splitting is algorithmically sound. The data structure changes (linked list → body array + Issues1.
#else
#define B2_TYPE_OF( A ) __typeof__( A ) // MSVC C does not support __typeof__
#endif
The 2.
( a ).data = (B2_TYPE_OF( ( a ).data ))b2GrowAlloc( NULL, 0, ( n ) * sizeof( *( a ).data ) );
3.
maxValue = b2MaxFloat( stepTimes[i], maxValue );The y-axis limit is computed only from Correctness Observations (No Action Needed)
Memory safety in Union-find contact/joint counting — The accumulation of
Nitimplot vendored as raw source files — Vendoring ~13k lines directly into |
Using union find. This required changing how bodies are stored in islands.
Added implot to samples app.