Skip to content

Commit

Permalink
Faster continuous (#847)
Browse files Browse the repository at this point in the history
Re-organized fast body handling in solver, cutting the cost of
continuous in half.
Fixes for Linux samples.
b2World_GetAwakeBodyCount
Removed unused code from dynamic tree
  • Loading branch information
erincatto authored Dec 2, 2024
1 parent 41e067c commit 2c939c2
Show file tree
Hide file tree
Showing 59 changed files with 1,339 additions and 1,348 deletions.
16 changes: 8 additions & 8 deletions benchmark/amd7950x_avx2/joint_grid.csv
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
threads,fps
1,200.145
2,340.128
3,496.707
4,607.243
5,698.173
6,782.174
7,856.148
8,916.514
1,197.415
2,338.192
3,485.363
4,590.58
5,678.894
6,755.337
7,830.03
8,889.992
16 changes: 8 additions & 8 deletions benchmark/amd7950x_avx2/large_pyramid.csv
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
threads,fps
1,325.321
2,615.892
3,878.262
4,1111.8
5,1322.39
6,1511.06
7,1719
8,1738.61
1,337.398
2,599.766
3,853.652
4,1095.24
5,1288.22
6,1467.1
7,1669.81
8,1704.72
16 changes: 8 additions & 8 deletions benchmark/amd7950x_avx2/many_pyramids.csv
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
threads,fps
1,83.1212
2,162.42
3,238.035
4,307.18
5,374.76
6,432.28
7,501.138
8,544.638
1,82.5412
2,156.573
3,233.64
4,294.31
5,357.121
6,420.298
7,487.163
8,537.355
16 changes: 8 additions & 8 deletions benchmark/amd7950x_avx2/rain.csv
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
threads,fps
1,154.443
2,249.524
3,323.318
4,384.953
5,434.035
6,483.406
7,527.558
8,556.645
1,158.379
2,253.381
3,337.197
4,408.427
5,475.14
6,530.178
7,583.798
8,633.102
16 changes: 8 additions & 8 deletions benchmark/amd7950x_avx2/smash.csv
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
threads,fps
1,197.528
2,300.994
3,385.163
4,455.355
5,508.735
6,553.648
7,589.206
8,614.934
1,194.531
2,299.76
3,389.501
4,469.022
5,532.045
6,580.977
7,620.559
8,655.217
16 changes: 8 additions & 8 deletions benchmark/amd7950x_avx2/spinner.csv
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
threads,fps
1,346.759
2,538.038
3,710.87
4,871.698
5,983.994
6,1084.08
7,1178.67
8,1242.13
1,342.697
2,549.335
3,711.477
4,889.473
5,1011.82
6,1141.73
7,1261.39
8,1338.51
16 changes: 8 additions & 8 deletions benchmark/amd7950x_avx2/tumbler.csv
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
threads,fps
1,464.164
2,705.539
3,932.064
4,1133.55
5,1297.75
6,1444.39
7,1563.34
8,1633.51
1,461.248
2,726.229
3,947.347
4,1152.31
5,1335.66
6,1483.59
7,1613.59
8,1715.86
16 changes: 8 additions & 8 deletions benchmark/amd7950x_avx2_nc/joint_grid.csv
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
threads,fps
1,196.348
2,335.206
3,493.878
4,598.194
5,691.697
6,776.717
7,848.272
8,910.073
1,191.305
2,335.535
3,485.589
4,591.62
5,682.079
6,762.346
7,834.071
8,896.952
16 changes: 8 additions & 8 deletions benchmark/amd7950x_avx2_nc/large_pyramid.csv
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
threads,fps
1,326.839
2,605.397
3,874.098
4,1108.62
5,1311.67
6,1500.33
7,1684.32
8,1736.04
1,337.272
2,606.512
3,867.572
4,1096.58
5,1297.5
6,1495.5
7,1668.46
8,1700.88
16 changes: 8 additions & 8 deletions benchmark/amd7950x_avx2_nc/many_pyramids.csv
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
threads,fps
1,84.1153
2,163.509
3,240.109
4,302.481
5,368.738
6,428.312
7,498.302
8,545.101
1,82.3111
2,160.585
3,236.095
4,300.733
5,362.227
6,423.2
7,496.346
8,544.392
16 changes: 8 additions & 8 deletions benchmark/amd7950x_avx2_nc/rain.csv
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
threads,fps
1,161.863
2,276.688
3,358.757
4,434.589
5,500.599
6,563.324
7,620.21
8,672.701
1,161.455
2,275.894
3,354.968
4,429.525
5,495.056
6,556.892
7,612.256
8,664.778
16 changes: 8 additions & 8 deletions benchmark/amd7950x_avx2_nc/smash.csv
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
threads,fps
1,190.875
2,302.452
3,391.787
4,472.507
5,531.519
6,582.197
7,623.562
8,654.127
1,191.697
2,296.907
3,387.265
4,466.151
5,524.415
6,571.353
7,614.959
8,650.434
16 changes: 8 additions & 8 deletions benchmark/amd7950x_avx2_nc/spinner.csv
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
threads,fps
1,344.368
2,562.345
3,738.154
4,916.335
5,1049.29
6,1167.4
7,1280.44
8,1362.46
1,339.941
2,558.533
3,730.695
4,913.45
5,1038.29
6,1153.58
7,1265.97
8,1355.59
16 changes: 8 additions & 8 deletions benchmark/amd7950x_avx2_nc/tumbler.csv
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
threads,fps
1,449.556
2,717.776
3,934.15
4,1136.18
5,1315.11
6,1470.1
7,1599.57
8,1700.46
1,440.223
2,707.306
3,929.712
4,1127.08
5,1313.66
6,1461.68
7,1588.84
8,1690.27
2 changes: 2 additions & 0 deletions benchmark/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ int GetNumberOfCores()
return (int)sysconf( _SC_NPROCESSORS_ONLN );
#elif defined( __linux__ )
return (int)sysconf( _SC_NPROCESSORS_ONLN );
#elif defined( __EMSCRIPTEN__ )
return (int)sysconf( _SC_NPROCESSORS_ONLN );
#else
return 1;
#endif
Expand Down
5 changes: 4 additions & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,8 @@
rm -rf build
mkdir build
cd build
cmake -DBOX2D_BUILD_DOCS=OFF ..

# I haven't been able to get Wayland working on WSL but X11 works.
# https://www.glfw.org/docs/latest/compile.html
cmake -DBOX2D_BUILD_DOCS=OFF -DGLFW_BUILD_WAYLAND=OFF ..
cmake --build .
26 changes: 25 additions & 1 deletion include/box2d/base.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// using the Windows DLL
#define BOX2D_EXPORT __declspec( dllimport )
#elif defined( box2d_EXPORTS )
// building or using the Box2D shared library
// building or using the shared library
#define BOX2D_EXPORT __attribute__( ( visibility( "default" ) ) )
#else
// static library
Expand Down Expand Up @@ -66,6 +66,30 @@ B2_API int b2GetByteCount( void );
/// @param assertFcn a non-null assert callback
B2_API void b2SetAssertFcn( b2AssertFcn* assertFcn );

// see https://github.com/scottt/debugbreak
#if defined( _MSC_VER )
#define B2_BREAKPOINT __debugbreak()
#elif defined( __GNUC__ ) || defined( __clang__ )
#define B2_BREAKPOINT __builtin_trap()
#else
// Unknown compiler
#include <assert.h>
#define B2_BREAKPOINT assert( 0 )
#endif

#if !defined( NDEBUG ) || defined( B2_ENABLE_ASSERT )
B2_API int b2InternalAssertFcn( const char* condition, const char* fileName, int lineNumber );
#define B2_ASSERT( condition ) \
do \
{ \
if ( !( condition ) && b2InternalAssertFcn( #condition, __FILE__, (int)__LINE__ ) ) \
B2_BREAKPOINT; \
} \
while ( 0 )
#else
#define B2_ASSERT( ... ) ( (void)0 )
#endif

/// Version numbering scheme.
/// See https://semver.org/
typedef struct b2Version
Expand Down
8 changes: 7 additions & 1 deletion include/box2d/box2d.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,9 @@ B2_API void b2World_EnableWarmStarting( b2WorldId worldId, bool flag );
/// Is constraint warm starting enabled?
B2_API bool b2World_IsWarmStartingEnabled( b2WorldId worldId );

/// Get the number of awake bodies.
B2_API int b2World_GetAwakeBodyCount( b2WorldId worldId );

/// Get the current world performance profile
B2_API b2Profile b2World_GetProfile( b2WorldId worldId );

Expand Down Expand Up @@ -444,7 +447,10 @@ B2_API int b2Body_GetJoints( b2BodyId bodyId, b2JointId* jointArray, int capacit
/// Get the maximum capacity required for retrieving all the touching contacts on a body
B2_API int b2Body_GetContactCapacity( b2BodyId bodyId );

/// Get the touching contact data for a body
/// Get the touching contact data for a body.
/// @note Box2D uses speculative collision so some contact points may be separated.
/// @returns the number of elements filled in the provided array
/// @warning do not ignore the return value, it specifies the valid number of elements
B2_API int b2Body_GetContactData( b2BodyId bodyId, b2ContactData* contactData, int capacity );

/// Get the current world AABB that contains all the attached shapes. Note that this may not encompass the body origin.
Expand Down
27 changes: 9 additions & 18 deletions include/box2d/collision.h
Original file line number Diff line number Diff line change
Expand Up @@ -492,9 +492,11 @@ B2_API b2TOIOutput b2TimeOfImpact( const b2TOIInput* input );
* @{
*/

/// A manifold point is a contact point belonging to a contact
/// manifold. It holds details related to the geometry and dynamics
/// of the contact points.
/// A manifold point is a contact point belonging to a contact manifold.
/// It holds details related to the geometry and dynamics of the contact points.
/// Box2D uses speculative collision so some contact points may be separated.
/// You may use the maxNormalImpulse to determine if there was an interaction during
/// the time step.
typedef struct b2ManifoldPoint
{
/// Location of the contact point in world space. Subject to precision loss at large coordinates.
Expand All @@ -518,8 +520,8 @@ typedef struct b2ManifoldPoint
/// The friction impulse
float tangentImpulse;

/// The maximum normal impulse applied during sub-stepping
/// This could be a bool to indicate the point is confirmed (may be a speculative point)
/// The maximum normal impulse applied during sub-stepping. This is important
/// to identify speculative contact points that had an interaction in the time step.
float maxNormalImpulse;

/// Relative normal velocity pre-solve. Used for hit events. If the normal impulse is
Expand All @@ -533,7 +535,8 @@ typedef struct b2ManifoldPoint
bool persisted;
} b2ManifoldPoint;

/// A contact manifold describes the contact points between colliding shapes
/// A contact manifold describes the contact points between colliding shapes.
/// @note Box2D uses speculative collision so some contact points may be separated.
typedef struct b2Manifold
{
/// The manifold points, up to two are possible in 2D
Expand Down Expand Up @@ -779,27 +782,15 @@ B2_API void b2DynamicTree_Validate( const b2DynamicTree* tree );
/// called often.
B2_API int b2DynamicTree_GetHeight( const b2DynamicTree* tree );

/// Get the maximum balance of the tree. The balance is the difference in height of the two children of a node.
B2_API int b2DynamicTree_GetMaxBalance( const b2DynamicTree* tree );

/// Get the ratio of the sum of the node areas to the root area.
B2_API float b2DynamicTree_GetAreaRatio( const b2DynamicTree* tree );

/// Build an optimal tree. Very expensive. For testing.
B2_API void b2DynamicTree_RebuildBottomUp( b2DynamicTree* tree );

/// Get the number of proxies created
B2_API int b2DynamicTree_GetProxyCount( const b2DynamicTree* tree );

/// Rebuild the tree while retaining subtrees that haven't changed. Returns the number of boxes sorted.
B2_API int b2DynamicTree_Rebuild( b2DynamicTree* tree, bool fullBuild );

/// Shift the world origin. Useful for large worlds.
/// The shift formula is: position -= newOrigin
/// @param tree the tree to shift
/// @param newOrigin the new origin with respect to the old origin
B2_API void b2DynamicTree_ShiftOrigin( b2DynamicTree* tree, b2Vec2 newOrigin );

/// Get the number of bytes used by this tree
B2_API int b2DynamicTree_GetByteCount( const b2DynamicTree* tree );

Expand Down
Loading

0 comments on commit 2c939c2

Please sign in to comment.