babylon-box3d 0.8.0 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/wasm/box3d_shim.c CHANGED
@@ -126,6 +126,8 @@ static void bxFloatBuffer_Reserve( bxFloatBuffer* buf, int count )
126
126
 
127
127
  #define BX_MAX_WORLDS 8
128
128
  static b3WorldId s_worlds[BX_MAX_WORLDS];
129
+ // the worlds whose steps leave Box3D's clock off (bx_World_EnableTimer); zero, the default, is on
130
+ static int s_timerOff[BX_MAX_WORLDS];
129
131
 
130
132
  // Height fields have no local transform in box3d, so an offset height field is placed on a static
131
133
  // helper body that shares the Babylon body's slot.
@@ -771,6 +773,7 @@ BX_EXPORT int bx_CreateWorld( float gx, float gy, float gz, int workerCount )
771
773
  // both only run for shapes with pre-solve events, which only clip planes turn on
772
774
  b3World_SetManifoldCallback( s_worlds[i], bxClipManifolds, NULL );
773
775
  b3World_SetPreSolveCallback( s_worlds[i], bxClipPreSolve, NULL );
776
+ s_timerOff[i] = 0;
774
777
  return i + 1;
775
778
  }
776
779
  }
@@ -819,7 +822,27 @@ BX_EXPORT void bx_World_Step( int w, float dt, int subSteps )
819
822
  #ifdef __EMSCRIPTEN_PTHREADS__
820
823
  bxResetTasks();
821
824
  #endif
825
+ // Box3D's clock is one switch for every world, so each world's step sets it for itself and puts it back after
826
+ b3EnableTimer( s_timerOff[w - 1] == 0 );
822
827
  b3World_Step( worldId, dt, subSteps );
828
+ b3EnableTimer( true );
829
+ }
830
+
831
+ /// Turns Box3D's clock on or off for this world's steps (b3EnableTimer, wasm/patches/0007). It is on by default. A step
832
+ /// reads the clock dozens of times, only to time itself for the profile and the stall logs, and in JavaScript each read
833
+ /// is a call out of the module that allocates. Off, a step reads no clock and the timings bx_World_GetStats reports are
834
+ /// zero; the world steps the same, bit for bit, either way.
835
+ BX_EXPORT void bx_World_EnableTimer( int w, int flag )
836
+ {
837
+ if ( B3_IS_NON_NULL( bxGetWorld( w ) ) )
838
+ {
839
+ s_timerOff[w - 1] = flag == 0;
840
+ }
841
+ }
842
+
843
+ BX_EXPORT int bx_World_IsTimerEnabled( int w )
844
+ {
845
+ return B3_IS_NON_NULL( bxGetWorld( w ) ) && s_timerOff[w - 1] == 0;
823
846
  }
824
847
 
825
848
  BX_EXPORT void bx_World_SetGravity( int w, float gx, float gy, float gz )
@@ -1465,6 +1488,22 @@ BX_EXPORT int bx_Body_IsContinuousEnabled( int slot )
1465
1488
  return b3Body_IsContinuousEnabled( body->id ) ? 1 : 0;
1466
1489
  }
1467
1490
 
1491
+ // The fat AABB margin of the body's shapes (wasm/patches/0008), m: how far each may move past its bounds before the
1492
+ // broad phase moves its proxy. Zero, the default, leaves each shape its own, an eighth of its extent up to 5 cm. A fast
1493
+ // body of many small shapes moves every proxy every step at the default; a wider margin moves them seldom, and finds
1494
+ // pairs sooner. The world steps the same either way: a pair touches only when its shapes do.
1495
+ BX_EXPORT void bx_Body_SetAabbMargin( int slot, float margin )
1496
+ {
1497
+ BX_BODY( slot );
1498
+ b3Body_SetAabbMargin( body->id, margin > 0.0f ? margin : 0.0f );
1499
+ }
1500
+
1501
+ BX_EXPORT float bx_Body_GetAabbMargin( int slot )
1502
+ {
1503
+ BX_BODY_RET( slot, 0.0f );
1504
+ return b3Body_GetAabbMargin( body->id );
1505
+ }
1506
+
1468
1507
  // Crushable contacts for the body's shape i (wasm/patches/0003): each of its contacts pushes with at most maxForce
1469
1508
  // newtons, and a plastic one keeps its overlap instead of pushing out. A maxForce of zero or less makes it rigid.
1470
1509
  BX_EXPORT void bx_Body_SetShapeCrush( int slot, int index, float maxForce, int plastic )