@@ -125,7 +125,13 @@ impl<'a> EventHandler for EventQueue<'a> {
125125
126126#[ cfg( test) ]
127127mod test {
128- use bevy:: time:: { TimePlugin , TimeUpdateStrategy } ;
128+ use bevy:: {
129+ app:: { App , Startup , Update } ,
130+ prelude:: { Commands , Component , Entity , Query , With } ,
131+ time:: { TimePlugin , TimeUpdateStrategy } ,
132+ transform:: { bundles:: TransformBundle , components:: Transform , TransformPlugin } ,
133+ MinimalPlugins ,
134+ } ;
129135 use systems:: tests:: HeadlessRenderPlugin ;
130136
131137 use crate :: { plugin:: * , prelude:: * } ;
@@ -231,4 +237,76 @@ mod test {
231237 ) ) ;
232238 }
233239 }
240+
241+ #[ test]
242+ pub fn spam_remove_rapier_entity_interpolated ( ) {
243+ let mut app = App :: new ( ) ;
244+ app. add_plugins ( (
245+ HeadlessRenderPlugin ,
246+ MinimalPlugins ,
247+ TransformPlugin ,
248+ RapierPhysicsPlugin :: < NoUserData > :: default ( ) ,
249+ ) )
250+ . insert_resource ( RapierConfiguration {
251+ timestep_mode : TimestepMode :: Interpolated {
252+ dt : 1.0 / 30.0 ,
253+ time_scale : 1.0 ,
254+ substeps : 2 ,
255+ } ,
256+ ..RapierConfiguration :: new ( 1f32 )
257+ } )
258+ . add_systems ( Startup , setup_physics)
259+ . add_systems ( Update , remove_collider) ;
260+ // Simulates 60 updates per seconds
261+ app. insert_resource ( TimeUpdateStrategy :: ManualDuration (
262+ std:: time:: Duration :: from_secs_f32 ( 1f32 / 60f32 ) ,
263+ ) ) ;
264+
265+ for i in 0 ..100 {
266+ dbg ! ( i) ;
267+ app. update ( ) ;
268+ }
269+ return ;
270+
271+ #[ derive( Component ) ]
272+ pub struct ToRemove ;
273+
274+ #[ cfg( feature = "dim3" ) ]
275+ fn cuboid ( hx : Real , hy : Real , hz : Real ) -> Collider {
276+ Collider :: cuboid ( hx, hy, hz)
277+ }
278+ #[ cfg( feature = "dim2" ) ]
279+ fn cuboid ( hx : Real , hy : Real , _hz : Real ) -> Collider {
280+ Collider :: cuboid ( hx, hy)
281+ }
282+ pub fn setup_physics ( mut commands : Commands ) {
283+ for _i in 0 ..100 {
284+ commands. spawn ( (
285+ TransformBundle :: from ( Transform :: from_xyz ( 0.0 , 0.0 , 0.0 ) ) ,
286+ RigidBody :: Dynamic ,
287+ cuboid ( 0.5 , 0.5 , 0.5 ) ,
288+ ActiveEvents :: all ( ) ,
289+ ToRemove ,
290+ ) ) ;
291+ }
292+ /*
293+ * Ground
294+ */
295+ let ground_size = 5.1 ;
296+ let ground_height = 0.1 ;
297+ let starting_y = -0.5 - ground_height;
298+
299+ commands. spawn ( (
300+ TransformBundle :: from ( Transform :: from_xyz ( 0.0 , starting_y, 0.0 ) ) ,
301+ cuboid ( ground_size, ground_height, ground_size) ,
302+ ) ) ;
303+ }
304+
305+ fn remove_collider ( mut commands : Commands , query : Query < Entity , With < ToRemove > > ) {
306+ let Some ( entity) = query. iter ( ) . next ( ) else {
307+ return ;
308+ } ;
309+ commands. entity ( entity) . despawn ( ) ;
310+ }
311+ }
234312}
0 commit comments