-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Components as entities #23988
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
Draft
Trashtalk217
wants to merge
23
commits into
bevyengine:main
Choose a base branch
from
Trashtalk217:components-as-entities
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Components as entities #23988
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
67092dd
make RequiredComponentConstructor Send and Sync
Trashtalk217 361525e
made RelationshipAccessorInitializer Sync and Send
Trashtalk217 ba5d095
derive Component for ComponentInfo
Trashtalk217 382d79d
made ComponentId(usize) into ComponentId(Entity)
Trashtalk217 064e481
Revert "derive Component for ComponentInfo"
Trashtalk217 b246b70
removed ResourceEntities
Trashtalk217 505dec4
fixed some tests
Trashtalk217 ddcf786
Merge branch 'main' of https://github.com/bevyengine/bevy into compon…
Trashtalk217 1a33441
fix more tests and other crates
Trashtalk217 e85625a
fix review comments
Trashtalk217 9238025
fixed clippy mistakes
Trashtalk217 d686995
fix other crates
Trashtalk217 46cd5bd
renamed .entity() to .id() for ComponentId
Trashtalk217 f93a9b8
changed access to use HashSets
Trashtalk217 8694591
made ComponentId::from_u32 public
Trashtalk217 6448e4d
fix doc tests and benches
Trashtalk217 6fcb4d8
fix doc comment
Trashtalk217 d072251
add ComponentIdMap as a hybrid map
Trashtalk217 023893f
changed ComponentIdSet
Trashtalk217 e4c9182
cargo clippy
Trashtalk217 baec7eb
fix doc test
Trashtalk217 155b998
add benchmark
Trashtalk217 569112d
changed over to SparseSet
Trashtalk217 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 hidden or 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 hidden or 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 hidden or 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,69 @@ | ||
| use std::{alloc::Layout, hint::black_box, ptr::NonNull}; | ||
|
|
||
| use benches::bench; | ||
| use bevy_ecs::{ | ||
| change_detection::MaybeLocation, | ||
| component::{ComponentCloneBehavior, ComponentDescriptor, StorageType}, | ||
| prelude::*, | ||
| ptr::OwningPtr, | ||
| }; | ||
| use criterion::{criterion_group, Criterion}; | ||
|
|
||
| criterion_group!(benches, get, get_mut, insert_remove); | ||
|
|
||
| fn create_world() -> World { | ||
| let mut world = World::new(); | ||
| for _ in 0..500 { | ||
| // SAFETY: Uses zero-sized value, never drops | ||
| unsafe { | ||
| let resource_id = | ||
| world.register_component_with_descriptor(ComponentDescriptor::new_with_layout( | ||
| "", | ||
| StorageType::SparseSet, | ||
| Layout::new::<()>(), | ||
| None, | ||
| true, | ||
| ComponentCloneBehavior::Default, | ||
| None, | ||
| )); | ||
| world.insert_resource_by_id( | ||
| resource_id, | ||
| OwningPtr::new(NonNull::dangling()), | ||
| MaybeLocation::caller(), | ||
| ); | ||
| } | ||
| } | ||
| world | ||
| } | ||
|
|
||
| #[derive(Resource)] | ||
| struct R; | ||
|
|
||
| pub fn get(criterion: &mut Criterion) { | ||
| let mut world = create_world(); | ||
| world.insert_resource(R); | ||
| criterion.bench_function(bench!("get"), |bencher| { | ||
| bencher.iter(|| world.get_resource::<R>()); | ||
| }); | ||
| } | ||
|
|
||
| pub fn get_mut(criterion: &mut Criterion) { | ||
| let mut world = create_world(); | ||
| world.insert_resource(R); | ||
| criterion.bench_function(bench!("get_mut"), |bencher| { | ||
| bencher.iter(|| { | ||
| black_box(world.get_resource_mut::<R>()); | ||
| }); | ||
| }); | ||
| } | ||
|
|
||
| pub fn insert_remove(criterion: &mut Criterion) { | ||
| let mut world = create_world(); | ||
| criterion.bench_function(bench!("insert_remove"), |bencher| { | ||
| bencher.iter(|| { | ||
| world.insert_resource(R); | ||
| black_box(&mut world); | ||
| world.remove_resource::<R>() | ||
| }); | ||
| }); | ||
| } |
This file contains hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,14 +1,14 @@ | ||
| //! Constant components included in every world. | ||
|
|
||
| /// `usize` for the [`Add`](crate::lifecycle::Add) component used in lifecycle observers. | ||
| pub const ADD: usize = 0; | ||
| /// `usize` for the [`Insert`](crate::lifecycle::Insert) component used in lifecycle observers. | ||
| pub const INSERT: usize = 1; | ||
| /// `usize` for the [`Discard`](crate::lifecycle::Discard) component used in lifecycle observers. | ||
| pub const DISCARD: usize = 2; | ||
| /// `usize` for the [`Remove`](crate::lifecycle::Remove) component used in lifecycle observers. | ||
| pub const REMOVE: usize = 3; | ||
| /// `usize` for [`Despawn`](crate::lifecycle::Despawn) component used in lifecycle observers. | ||
| pub const DESPAWN: usize = 4; | ||
| /// `usize` of the [`IsResource`](crate::resource::IsResource) component used to mark entities with resources. | ||
| pub const IS_RESOURCE: usize = 5; | ||
| /// `u32` for the [`Add`](crate::lifecycle::Add) component used in lifecycle observers. | ||
| pub const ADD: u32 = 0; | ||
| /// `u32` for the [`Insert`](crate::lifecycle::Insert) component used in lifecycle observers. | ||
| pub const INSERT: u32 = 1; | ||
| /// `u32` for the [`Discard`](crate::lifecycle::Discard) component used in lifecycle observers. | ||
| pub const DISCARD: u32 = 2; | ||
| /// `u32` for the [`Remove`](crate::lifecycle::Remove) component used in lifecycle observers. | ||
| pub const REMOVE: u32 = 3; | ||
| /// `u32` for [`Despawn`](crate::lifecycle::Despawn) component used in lifecycle observers. | ||
| pub const DESPAWN: u32 = 4; | ||
| /// `u32` of the [`IsResource`](crate::resource::IsResource) component used to mark entities with resources. | ||
| pub const IS_RESOURCE: u32 = 5; |
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.
Uh oh!
There was an error while loading. Please reload this page.