-
-
Notifications
You must be signed in to change notification settings - Fork 263
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Multiple worlds/pipelines #328
Closed
AnthonyTornetta
wants to merge
114
commits into
dimforge:master
from
AnthonyTornetta:multiple-worlds
Closed
Changes from all commits
Commits
Show all changes
114 commits
Select commit
Hold shift + click to select a range
d671d7a
Refactored context to have multiple worlds
AnthonyTornetta cdfafa4
Supporting multiple worlds
AnthonyTornetta 2010f94
Adding example + reworking to be faster. Disabled custom events for now
AnthonyTornetta d6fae15
Multiple worlds work together
AnthonyTornetta 55f2745
Improved example
AnthonyTornetta 1cb6d8c
Added docs
AnthonyTornetta 2eed336
Clippy --fix
AnthonyTornetta 23f8046
Added support for new changing worlds
AnthonyTornetta 83816cd
Making imports work
AnthonyTornetta 4b99318
Fixed imports
AnthonyTornetta e5af080
Removed error when removing DEFAULT_WORLD_ID
AnthonyTornetta a0dfceb
Fixed improper swapping of worlds
AnthonyTornetta d1dd55d
testing please ignore
AnthonyTornetta c534146
Fixed incorrect after
AnthonyTornetta 8b32f80
Made BodyWorld changes bubble down to children.
AnthonyTornetta b36c5dc
Testing ReadMass changes
AnthonyTornetta 455de13
Added debug statements to master
AnthonyTornetta a1a0a8f
More debug prints
AnthonyTornetta 1461aa6
Fixing bubble up
AnthonyTornetta ce8c335
Commented out useless code
AnthonyTornetta d6d378f
Debugging
AnthonyTornetta e52085c
Merge remote-tracking branch 'upstream/master' into multiple-worlds
AnthonyTornetta ed07c1b
Merge branch 'multiple-worlds'
AnthonyTornetta 87161ab
Got bevy events working
AnthonyTornetta 4fb4e7b
Clippy
AnthonyTornetta bc49212
Merge branch 'dimforge:master' into master
AnthonyTornetta a700a5e
Fixed merge issue
AnthonyTornetta 6296f3e
Fixed system ordering to support switching worlds
AnthonyTornetta 2bbb03e
Renamed BodyWorld to PhysicsWorld
AnthonyTornetta 1fa4c15
Debugging deleted colliders
AnthonyTornetta aca20f4
Merge branch 'master' of https://github.com/AnthonyTornetta/bevy_rapier
AnthonyTornetta 8a98afd
Removed debug print
AnthonyTornetta 97b849e
Fixed #285
AnthonyTornetta 5222375
Updated to own version of rapier
AnthonyTornetta 78a988a
Merge branch 'dimforge:master' into master
AnthonyTornetta 8f03231
Merge branch 'dimforge:master' into multiple-worlds
AnthonyTornetta ae56257
Fixed bug where removed entities didn't have a world component.
AnthonyTornetta dbc60bd
Merge branch 'master' into multiple-worlds
AnthonyTornetta 596d44b
Reverted custom rapier version change
AnthonyTornetta c85a9f1
Clippy --fix
AnthonyTornetta f310885
Cargo clippy --fix
AnthonyTornetta c8a10cd
Merge branch 'master' into multiple-worlds
AnthonyTornetta fb4f69a
Fixed #383
AnthonyTornetta 69f3f3e
Reverted version revert
AnthonyTornetta 9af3f45
Removed useless system
AnthonyTornetta 1a37074
Fixing stuff
AnthonyTornetta 824f168
Added debug prints
AnthonyTornetta a50235a
System reordering
AnthonyTornetta ee5460a
Revert "System reordering"
AnthonyTornetta a21969a
Revert "Fixed #383"
AnthonyTornetta 524d64c
Swapped to my version of rapier
AnthonyTornetta 53f9f67
Kinda got it working (ish)
AnthonyTornetta 78fc43c
Parnet + child relationships are now not super buggy
AnthonyTornetta 071287d
It *works*
AnthonyTornetta b08cad8
Removed printlns
AnthonyTornetta 45e69d2
Warnings be gone
AnthonyTornetta 3161c99
removed me
AnthonyTornetta 22ce456
Redoing fix
AnthonyTornetta b38f5fd
it no work
AnthonyTornetta e69d56d
Revert "it no work"
AnthonyTornetta 7714c24
Revert "Redoing fix"
AnthonyTornetta 7e044fd
"Working" for static bodies as children
AnthonyTornetta 761b506
Parent/child relationships properly work now
AnthonyTornetta 36e79d7
Fixed accidental overwriting of world_offset
AnthonyTornetta 9850a3f
Merge remote-tracking branch 'upstream/master' into child_parent_fix_…
AnthonyTornetta 6bb69e0
Merge branch 'child_parent_fix_vel_edition' of https://github.com/Ant…
AnthonyTornetta e837557
Merge branch 'child_parent_fix_vel_edition' into update-master
AnthonyTornetta 3b52e99
Removed dead code
AnthonyTornetta 90eb3d8
Downgraded rapier for this version
AnthonyTornetta 3de1455
Updated Examples
AnthonyTornetta 18d39ca
Updated Examples
AnthonyTornetta 09622de
Fixed warnings
AnthonyTornetta 33ea9e4
Fixed warnings
AnthonyTornetta 67c65bc
Merge branch 'dimforge/master'
AnthonyTornetta 759eb7e
Fixed warnings
AnthonyTornetta 417a44a
Fixed compiler warning
AnthonyTornetta fe8b5f4
cargo clippy --fix
AnthonyTornetta 3537322
Fixed most clippy issues
AnthonyTornetta 54633e0
Merge branch 'master' of https://github.com/AnthonyTornetta/bevy_rapier
AnthonyTornetta d859070
Merge branch 'master' into multiple-worlds
AnthonyTornetta c223be8
Removed private modifier because modifying this is used to work aroun…
AnthonyTornetta ab2aa0b
Merge branch 'master' into multiple-worlds
AnthonyTornetta 72e0acb
Debugging system order
AnthonyTornetta 932b6d5
Updating system ordering to use chain
AnthonyTornetta b7ee234
Testing system ordering
AnthonyTornetta a63c6ac
Merge branch 'testing'
AnthonyTornetta 38565b1
Fixed system ordering
AnthonyTornetta 7c266fe
Fixed system ordering
AnthonyTornetta c9ea6f9
Removed debug prints
AnthonyTornetta c8d4ccd
Preventing expensive unneeded change detections
AnthonyTornetta d8360b7
Fixed randomly occuring system ordering issue
AnthonyTornetta 423ab38
Merge branch 'master' into multiple-worlds
AnthonyTornetta 94ca628
Merge remote-tracking branch 'upstream/master'
AnthonyTornetta 3bed38d
Fixed imports
AnthonyTornetta 72d5d15
Merge branch 'master' into multiple-worlds
AnthonyTornetta 6d72181
Merge remote-tracking branch 'upstream/master'
AnthonyTornetta acd8502
Swapped back to custom version of rapier
AnthonyTornetta cca2ace
Merge branch 'master' into multiple-worlds
AnthonyTornetta 29a934d
Fixed wrong world-swapping logic
AnthonyTornetta 4738916
Formatting
AnthonyTornetta e737b9e
Merge remote-tracking branch 'upstream/master' into multiple-worlds
AnthonyTornetta 30b61be
Merge character controller
AnthonyTornetta 939fbab
Merge joints
AnthonyTornetta 0f081c0
Merge remove
AnthonyTornetta ca5d879
Merge writeback
AnthonyTornetta 46d266a
Merge collider
AnthonyTornetta 2b5ec29
Merge rigid_body
AnthonyTornetta 70d0f8d
Merge mod
AnthonyTornetta 197fd34
Merge world
AnthonyTornetta f744377
Clippy fix
AnthonyTornetta 5bcb4d3
Reworked world syncing to be more reliable
AnthonyTornetta f2ddf29
Fixed ambiguous system ordering that could cause issues
AnthonyTornetta 0b66c3f
Added gravity builder method to make creation of worlds easier
AnthonyTornetta 643f8b3
Added missing scale multiply
AnthonyTornetta File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
use bevy::prelude::*; | ||
use bevy_rapier3d::prelude::*; | ||
|
||
const N_WORLDS: usize = 5; | ||
const WORLD_CHANGE_DELAY_SEC: f32 = 3.0; | ||
|
||
#[derive(Component)] | ||
/// Denotes which object(s) to change the world of | ||
struct ChangeWorld; | ||
|
||
fn main() { | ||
App::new() | ||
.insert_resource(ClearColor(Color::rgb( | ||
0xF9 as f32 / 255.0, | ||
0xF9 as f32 / 255.0, | ||
0xFF as f32 / 255.0, | ||
))) | ||
.add_plugins(( | ||
DefaultPlugins, | ||
RapierPhysicsPlugin::<NoUserData>::default(), | ||
RapierDebugRenderPlugin::default(), | ||
)) | ||
.add_systems(Startup, (setup_graphics, setup_physics)) | ||
.add_systems(Update, change_world) | ||
.run(); | ||
} | ||
|
||
fn change_world(mut query: Query<&mut PhysicsWorld, With<ChangeWorld>>, time: Res<Time>) { | ||
for mut bw in query.iter_mut() { | ||
if time.elapsed_seconds() > (bw.world_id.0 as f32 + 1.0) * WORLD_CHANGE_DELAY_SEC { | ||
let new_world_id = bw.world_id.0 + 1; | ||
|
||
if new_world_id != N_WORLDS { | ||
println!("Changing world to {new_world_id}."); | ||
bw.world_id = WorldId::new(new_world_id); | ||
} | ||
} | ||
} | ||
} | ||
|
||
fn setup_graphics(mut commands: Commands) { | ||
commands.spawn(Camera3dBundle { | ||
transform: Transform::from_xyz(0.0, 3.0, -10.0) | ||
.looking_at(Vec3::new(0.0, 0.0, 0.0), Vec3::Y), | ||
..Default::default() | ||
}); | ||
} | ||
|
||
pub fn setup_physics(mut context: ResMut<RapierContext>, mut commands: Commands) { | ||
for _ in 1..N_WORLDS { | ||
context.add_world(RapierWorld::default()); | ||
} | ||
|
||
for world_id in 0..N_WORLDS { | ||
let color = [ | ||
Color::hsl(220.0, 1.0, 0.3), | ||
Color::hsl(180.0, 1.0, 0.3), | ||
Color::hsl(260.0, 1.0, 0.7), | ||
][world_id % 3]; | ||
|
||
/* | ||
* Ground | ||
*/ | ||
let ground_size = 5.1; | ||
let ground_height = 0.1; | ||
|
||
commands.spawn(( | ||
TransformBundle::from(Transform::from_xyz( | ||
0.0, | ||
(world_id as f32) * -0.5 - ground_height, | ||
0.0, | ||
)), | ||
Collider::cuboid(ground_size, ground_height, ground_size), | ||
ColliderDebugColor(color), | ||
RigidBody::Fixed, | ||
PhysicsWorld { | ||
world_id: WorldId::new(world_id), | ||
}, | ||
)); | ||
} | ||
|
||
/* | ||
* Create the cube | ||
* | ||
* The child is just there to show that physics world changes will also change the children. | ||
*/ | ||
commands | ||
.spawn(( | ||
TransformBundle::from(Transform::from_xyz(0.0, 3.0, 0.0)), | ||
RigidBody::Dynamic, | ||
PhysicsWorld { | ||
world_id: DEFAULT_WORLD_ID, | ||
}, | ||
ChangeWorld, | ||
)) | ||
.with_children(|p| { | ||
p.spawn(( | ||
TransformBundle::from_transform(Transform::from_xyz(0.0, 0.0, 0.0)), | ||
Collider::cuboid(0.5, 0.5, 0.5), | ||
ColliderDebugColor(Color::hsl(260.0, 1.0, 0.7)), | ||
)); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
use bevy::prelude::*; | ||
use bevy_rapier3d::prelude::*; | ||
|
||
const N_WORLDS: usize = 5; | ||
|
||
fn main() { | ||
App::new() | ||
.insert_resource(ClearColor(Color::rgb( | ||
0xF9 as f32 / 255.0, | ||
0xF9 as f32 / 255.0, | ||
0xFF as f32 / 255.0, | ||
))) | ||
.add_plugins(( | ||
DefaultPlugins, | ||
RapierPhysicsPlugin::<NoUserData>::default(), | ||
RapierDebugRenderPlugin::default(), | ||
)) | ||
.add_systems(Startup, (setup_physics, setup_graphics)) | ||
.add_systems(Update, move_middle_world) | ||
// .add_systems(Update, change_world) | ||
// .add_systems(Update, despawn_last) | ||
.run(); | ||
} | ||
|
||
fn setup_graphics(mut commands: Commands) { | ||
commands.spawn(Camera3dBundle { | ||
transform: Transform::from_xyz(0.0, 3.0, -10.0) | ||
.looking_at(Vec3::new(0.0, 0.0, 0.0), Vec3::Y), | ||
..Default::default() | ||
}); | ||
} | ||
|
||
#[derive(Component)] | ||
struct Platform { | ||
starting_y: f32, | ||
} | ||
|
||
fn move_middle_world( | ||
time: Res<Time>, | ||
mut query: Query<(&mut Transform, &PhysicsWorld, &Platform)>, | ||
) { | ||
for (mut transform, world, platform) in query.iter_mut() { | ||
if world.world_id.0 == N_WORLDS / 2 { | ||
transform.translation.y = platform.starting_y + -time.elapsed_seconds().sin(); | ||
} | ||
} | ||
} | ||
|
||
/// Demonstrates despawning an entity removing it from its world | ||
// fn despawn_last(query: Query<(&PhysicsWorld, Entity)>, mut commands: Commands) { | ||
// for (bw, entity) in query.iter() { | ||
// if bw.world_id == N_WORLDS - 1 { | ||
// commands.entity(entity).despawn_recursive(); | ||
// } | ||
// } | ||
// } | ||
|
||
/// Demonstrates how easy it is to move one entity to another world. | ||
// fn change_world(mut query: Query<&mut PhysicsWorld>) { | ||
// for mut bw in query.iter_mut() { | ||
// if bw.world_id == 1 { | ||
// bw.world_id = 0; | ||
// } | ||
// } | ||
// } | ||
|
||
pub fn setup_physics(mut context: ResMut<RapierContext>, mut commands: Commands) { | ||
for _ in 1..N_WORLDS { | ||
context.add_world(RapierWorld::default()); | ||
} | ||
|
||
for world_id in 0..N_WORLDS { | ||
let world_id = WorldId::new(world_id); | ||
|
||
let color = [ | ||
Color::hsl(220.0, 1.0, 0.3), | ||
Color::hsl(180.0, 1.0, 0.3), | ||
Color::hsl(260.0, 1.0, 0.7), | ||
][world_id.0 % 3]; | ||
|
||
/* | ||
* Ground | ||
*/ | ||
let ground_size = 5.1; | ||
let ground_height = 0.1; | ||
|
||
let starting_y = (world_id.0 as f32) * -0.5 - ground_height; | ||
|
||
commands.spawn(( | ||
TransformBundle::from(Transform::from_xyz(0.0, starting_y, 0.0)), | ||
Collider::cuboid(ground_size, ground_height, ground_size), | ||
ColliderDebugColor(color), | ||
Platform { starting_y }, | ||
PhysicsWorld { world_id }, | ||
)); | ||
|
||
/* | ||
* Create the cube | ||
*/ | ||
|
||
commands.spawn(( | ||
TransformBundle::from(Transform::from_xyz(0.0, 1.0 + world_id.0 as f32 * 5.0, 0.0)), | ||
RigidBody::Dynamic, | ||
Collider::cuboid(0.5, 0.5, 0.5), | ||
ColliderDebugColor(color), | ||
PhysicsWorld { world_id }, | ||
)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This user facing API change is unfortunate, I'd like to discuss if alternatives could be achievable, more details in main PR comment feed.