Skip to content
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

0.9.0 #218

Merged
merged 66 commits into from
Apr 22, 2023
Merged

0.9.0 #218

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
0bb0ab9
Merge pull request #203 from Anders429/master
Anders429 Apr 3, 2023
c103bec
Reduce number of index parameters for resource::ContainsViews.
Anders429 Apr 6, 2023
8411702
Rename inner trait to Expanded.
Anders429 Apr 6, 2023
d01f2fa
Remove World::insert() bound on Entity.
Anders429 Apr 6, 2023
8c715a1
Update changelog.
Anders429 Apr 6, 2023
f96c8b8
Reduce the indices parameters down to a single parameter for registry…
Anders429 Apr 6, 2023
4334392
Remove bound on entities.
Anders429 Apr 6, 2023
850c743
Reduce to a single indices parameter for registry::ContainsEntities.
Anders429 Apr 6, 2023
f2dd5d8
Remove bounds on Filter trait.
Anders429 Apr 6, 2023
bc34808
Only require one index parameter for registry::ContainsQuery. Also re…
Anders429 Apr 7, 2023
da5b700
Only require one index parameter for registry::ContainsParQuery. Also…
Anders429 Apr 8, 2023
3d60484
Reduce generic parameters in registry::ContainsViews.
Anders429 Apr 11, 2023
2fb4c22
Reduce the number of generic parameters on Disjoint.
Anders429 Apr 11, 2023
0024e86
Fix intradoc link to Filter.
Anders429 Apr 11, 2023
81db4d7
Reduce the number of generic parameters on Schedule.
Anders429 Apr 11, 2023
5bd04e5
Update trybuild tests.
Anders429 Apr 12, 2023
9dee20e
Update README examples.
Anders429 Apr 12, 2023
d38b432
Merge pull request #206 from Anders429/index
Anders429 Apr 12, 2023
76895f1
Update serde_assert requirement from 0.2.0 to 0.4.0
dependabot[bot] Apr 12, 2023
f1fa17c
Remove unnecessary calls setting self_describing to false.
Anders429 Apr 12, 2023
65e1d95
Merge pull request #205 from Anders429/dependabot/cargo/dev/serde_ass…
Anders429 Apr 12, 2023
ddcaebc
Require components viewed in Schedule to implement Sync.
Anders429 Apr 14, 2023
cb3a526
Merge pull request #207 from Anders429/sync
Anders429 Apr 14, 2023
bfb0cb0
Exclude trait methods in schedule tests from code coverage.
Anders429 Apr 15, 2023
f8bc560
Enable no_coverage feature when code coverage is run.
Anders429 Apr 15, 2023
dc391f7
Merge pull request #209 from Anders429/cov
Anders429 Apr 15, 2023
06fc34f
Define generic Get trait.
Anders429 Apr 16, 2023
5666295
Add note about index elision.
Anders429 Apr 16, 2023
ae573d5
Replace entity::Get with hlist::Get.
Anders429 Apr 16, 2023
66c2235
Replace query::result::Get with hlist::Get.
Anders429 Apr 16, 2023
4290711
Replace query::view::Get with hlist::Get.
Anders429 Apr 16, 2023
3c65c55
Replace registry::Get with hlist::Get.
Anders429 Apr 16, 2023
2c20375
Replace entities::Get with hlist::Get.
Anders429 Apr 16, 2023
ce2679d
Replace claim::get::registry::Get with hlist::Get.
Anders429 Apr 16, 2023
ecb3fa1
Replace claim::get::view::Get with hlist::Get.
Anders429 Apr 16, 2023
75f7fa4
Rename query::view::subset::Get to SubViewable.
Anders429 Apr 16, 2023
567b985
Merge pull request #210 from Anders429/get
Anders429 Apr 16, 2023
325fff1
Define generic Reshape trait.
Anders429 Apr 17, 2023
419d432
Replace query::result::Reshape with hlist::Reshape.
Anders429 Apr 17, 2023
2de9fe2
Remove old reshape file.
Anders429 Apr 17, 2023
ead3472
Replace query::view::Reshape with hlist::Reshape.
Anders429 Apr 17, 2023
e3688fa
Merge pull request #211 from Anders429/reshape
Anders429 Apr 17, 2023
63f6cd3
Require all views in schedules to be Send.
Anders429 Apr 17, 2023
5c8411f
Merge pull request #212 from Anders429/reshape
Anders429 Apr 17, 2023
7cd50c8
Rename R generic parameter to Registry.
Anders429 Apr 17, 2023
b0e943a
Rename S generic parameter to System and ParSystem.
Anders429 Apr 17, 2023
a393619
Rename S generic parameter to Schedule.
Anders429 Apr 17, 2023
aedc0a9
Rename R to Registry in trait implementations on World.
Anders429 Apr 17, 2023
f5cdd79
Rename R to Registry in Entry implementations.
Anders429 Apr 17, 2023
366619a
Rename C and I to Component and Index in Entry methods.
Anders429 Apr 17, 2023
74447bd
Rename E to Entities in entities::Batch.
Anders429 Apr 17, 2023
3c845a1
Rename generics in Entity and Entities implementations.
Anders429 Apr 18, 2023
0cf81c1
Rename C to Component.
Anders429 Apr 18, 2023
f15083f
Rename generic parameters on filters.
Anders429 Apr 18, 2023
c497dbc
Rename generic parameters for view implementations.
Anders429 Apr 18, 2023
879595c
Rename generic parameters in Registry traits.
Anders429 Apr 18, 2023
8556d4c
Rename Schedule generic parameter to Registry.
Anders429 Apr 18, 2023
ffabf5f
Rename task generic parameters.
Anders429 Apr 18, 2023
0e4bf12
Fix intradoc link to Component.
Anders429 Apr 18, 2023
6589f5d
Merge pull request #213 from Anders429/name
Anders429 Apr 18, 2023
689ed51
Minimal failing example for entry API multiple shape change issue.
Anders429 Apr 22, 2023
dd1a830
Correct the test to check that the entity is filtered out.
Anders429 Apr 22, 2023
93df5a5
Update the location within the entry when the entity's shape changes.
Anders429 Apr 22, 2023
b62606a
Document fix in changelog.
Anders429 Apr 22, 2023
f5ea542
Merge pull request #217 from Anders429/entry
Anders429 Apr 22, 2023
5165f84
Cut version 0.9.0.
Anders429 Apr 22, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,37 @@

## Unreleased

## 0.9.0 - 2023-04-22
### Changed
- `resource::ContainsViews` now only requires a single generic parameter for indices.
- `World::view_resources()` now only requires a single generic parameter for indices.
- `registry::ContainsEntity` now only requires a single generic parameter for indices.
- `World::insert()` now only requires a single generic parameter for indices.
- `registry::ContainsEntities` now only requires a single generic parameter for indices.
- `World::extend()` now only requires a single generic parameter for indices.
- `World::insert()` no longer requires `E` to implement `Entity`.
- `World::extend()` no longer requires `E` to implement `Entities`.
- `World::query()` and `World::par_query()` both no longer require `V` and `F` to implement `Filter`.
- `registry::ContainsQuery` now only requires a single generic parameter for indices.
- `registry::ContainsParQuery` now only requires a single generic parameter for indices.
- `registry::ContainsViews` now only requires a single generic parameter for indices.
- `World::query()` now only requires a single parameter for query indices.
- `Entry::query()` now only requires a single parameter for query indices.
- `World::run_system()` now only requires a single parameter for query indices.
- `World::run_par_system()` now only requires a single parameter for query indices.
- `World::run_schedule()` now only requires a single parameter for query indices.
- `query::view::Disjoint` now only requires a single parameter for indices.
- `System::run()` now takes the results iterator as a generic parameter `I` to simplify the interface.
- `ParSystem::run()` now takes the results parallel iterator as a generic parameter `I` to simplify the interface.
- `System` and `ParSystem` both no longer require `Filter` and `Views` to implement `Filter`.
- `result::Iter` no longer requires `V` and `F` to implement `Filter`.
- `Entry::query()` no longer requires `V` and `F` to implement `Filter`.
- `system::schedule::Schedule` now only requires a single parameter for indices.
- `World::run_system()` now only requires a single parameter for schedule indices.
### Fixed
- `Schedule`s can now no longer access non-`Sync` components and resources.
- Multiple calls to `Entry::add()` or `Entry::remove()` that change the shape of the entity now no longer accesses the wrong internal entity row, preventing potential undefined behavior.

## 0.8.2 - 2023-04-02
### Fixed
- `Entry::query()` now requires a less-strict lifetime.
Expand Down
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "brood"
version = "0.8.2"
version = "0.9.0"
authors = ["Anders Evensen"]
edition = "2021"
rust-version = "1.65.0"
Expand All @@ -27,7 +27,7 @@ serde = {version = "1.0.148", default-features = false, features = ["alloc"], op
[dev-dependencies]
claims = "0.7.1"
rustversion = "1.0.9"
serde_assert = "0.2.0"
serde_assert = "0.4.0"
serde_derive = "1.0.148"
trybuild = "1.0.72"

Expand Down
35 changes: 20 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ Note that entities stored in `world` above can be made up of any subset of the `
To operate on the entities stored in a `World`, a `System` must be used. `System`s are defined to operate on any entities containing a specified set of components, reading and modifying those components. An example system could be defined and run as follows:

``` rust
use brood::{query::{filter, result, Views}, registry::ContainsQuery, system::System};
use brood::{query::{filter, result, Views}, registry, system::System};

struct UpdatePosition;

Expand All @@ -85,11 +85,12 @@ impl System for UpdatePosition {
type ResourceViews: Views!();
type EntryViews: Views!();

fn run<'a, R, S, FI, VI, P, I, Q, EP, EI, EQ>(
fn run<'a, R, S, I, E>(
&mut self,
query_results: Result<R, S, result::Iter<'a, R, Self::Filter, FI, Self::Views<'a>, VI, P, I, Q>, Self::ResourceViews<'a>, Self::EntryViews<'a>, (EP, EI, EQ)>,
query_results: Result<R, S, I, Self::ResourceViews<'a>, Self::EntryViews<'a>, E>,
) where
R: ContainsQuery<Self::Filter, FI, Self::Views<'a>, VI, P, I, Q>,
R: registry::Registry,
I: Iterator<Item = Self::Views<'a>>,
{
for result!(position, velocity) in query_results.iter {
position.x += velocity.x;
Expand Down Expand Up @@ -160,7 +161,8 @@ Note that there are two modes for serialization, depending on whether the serial
To parallelize system operations on entities (commonly referred to as inner-parallelism), a `ParSystem` can be used instead of a standard `System`. This will allow the `ParSystem`'s operations to be spread across multiple CPUs. For example, a `ParSystem` can be defined as follows:

``` rust
use brood::{entity, query::{filter, result, Views}, Registry, registry::ContainsParQuery, World, system::ParSystem};
use brood::{entity, query::{filter, result, Views}, Registry, registry, World, system::ParSystem};
use rayon::iter::ParallelIterator;

struct Position {
x: f32,
Expand Down Expand Up @@ -195,11 +197,12 @@ impl ParSystem for UpdatePosition {
type ResourceViews: Views!();
type EntryViews: Views!();

fn run<'a, R, S, FI, VI, P, I, Q, EP, EI, EQ>(
fn run<'a, R, S, I, E>(
&mut self,
query_results: Result<R, S, result::ParIter<'a, R, Self::Filter, FI, Self::Views<'a>, VI, P, I, Q>, Self::ResourceViews<'a>, Self::EntryViews<'a>, (EP, EI, EQ)>,
query_results: Result<R, S, I, Self::ResourceViews<'a>, Self::EntryViews<'a>, E>,
) where
R: ContainsParQuery<'a, Self::Filter, FI, Self::Views<'a>, VI, P, I, Q>,
R: registry::Registry,
I: ParallelIterator<Item = Self::Views<'a>>,
{
query_results.iter.for_each(|result!(position, velocity)| {
position.x += velocity.x;
Expand All @@ -219,7 +222,7 @@ Multiple `System`s and `ParSystem`s can be run in parallel as well by defining a
Define and run a `Schedule` that contains multiple `System`s as follows:

``` rust
use brood::{entity, query::{filter, result, Views}, Registry, registry::ContainsQuery, World, system::{schedule, schedule::task, System}};
use brood::{entity, query::{filter, result, Views}, Registry, registry, World, system::{schedule, schedule::task, System}};

struct Position {
x: f32,
Expand Down Expand Up @@ -256,11 +259,12 @@ impl System for UpdatePosition {
type ResourceViews: Views!();
type EntryViews: Views!();

fn run<'a, R, S, FI, VI, P, I, Q, EP, EI, EQ>(
fn run<'a, R, S, I, E>(
&mut self,
query_results: Result<R, S, result::Iter<'a, R, Self::Filter, FI, Self::Views<'a>, VI, P, I, Q>, Self::ResourceViews<'a>, Self::EntryViews<'a>, (EP, EI, EQ)>,
query_results: Result<R, S, I, Self::ResourceViews<'a>, Self::EntryViews<'a>, E>,
) where
R: ContainsQuery<'a, Self::Filter, FI, Self::Views<'a>, VI, P, I, Q>,
R: registry::Registry,
I: Iterator<Item = Self::Views<'a>>,
{
for result!(position, velocity) in query_results.iter {
position.x += velocity.x;
Expand All @@ -277,11 +281,12 @@ impl System for UpdateIsMoving {
type ResourceViews: Views!();
type EntryViews: Views!();

fn run<'a, R, S, FI, VI, P, I, Q, EP, EI, EQ>(
fn run<'a, R, S, I, E>(
&mut self,
query_results: Result<R, S, result::ParIter<'a, R, Self::Filter, FI, Self::Views<'a>, VI, P, I, Q>, Self::ResourceViews<'a>, Self::EntryViews<'a>, (EP, EI, EQ)>,
query_results: Result<R, S, I, Self::ResourceViews<'a>, Self::EntryViews<'a>, E>,
) where
R: ContainsQuery<'a, Self::Filter, FI, Self::Views<'a>, VI, P, I, Q>,
R: registry::Registry,
I: Iterator<Item = Self::Views<'a>>,
{
for result!(velocity, is_moving) in query_results.iter {
is_moving.0 = velocity.x != 0.0 || velocity.y != 0.0;
Expand Down
20 changes: 1 addition & 19 deletions src/archetype/impl_serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -948,7 +948,6 @@ mod tests {
let mut deserializer = Deserializer::builder()
.tokens(tokens)
.is_human_readable(false)
.self_describing(false)
.build();
assert_ok_eq!(
Archetype::<Registry>::deserialize(&mut deserializer),
Expand Down Expand Up @@ -986,7 +985,6 @@ mod tests {
Token::TupleEnd,
]))
.is_human_readable(false)
.self_describing(false)
.build();

assert_err_eq!(
Expand Down Expand Up @@ -1062,7 +1060,6 @@ mod tests {
Token::TupleEnd,
]))
.is_human_readable(false)
.self_describing(false)
.build();

assert_err_eq!(
Expand All @@ -1089,7 +1086,6 @@ mod tests {
Token::TupleEnd,
]))
.is_human_readable(false)
.self_describing(false)
.build();

assert_err_eq!(
Expand Down Expand Up @@ -1163,7 +1159,6 @@ mod tests {
Token::TupleEnd,
]))
.is_human_readable(false)
.self_describing(false)
.build();

assert_err_eq!(
Expand All @@ -1189,7 +1184,6 @@ mod tests {
Token::TupleEnd,
]))
.is_human_readable(false)
.self_describing(false)
.build();

assert_err_eq!(
Expand All @@ -1211,7 +1205,6 @@ mod tests {
Token::TupleEnd,
]))
.is_human_readable(false)
.self_describing(false)
.build();

assert_err_eq!(
Expand All @@ -1235,7 +1228,6 @@ mod tests {
Token::TupleEnd,
]))
.is_human_readable(false)
.self_describing(false)
.build();

assert_err_eq!(
Expand Down Expand Up @@ -1320,10 +1312,7 @@ mod tests {
Token::TupleEnd,
])
);
let mut deserializer = Deserializer::builder()
.tokens(tokens)
.self_describing(false)
.build();
let mut deserializer = Deserializer::builder().tokens(tokens).build();
assert_ok_eq!(
Archetype::<Registry>::deserialize(&mut deserializer),
archetype
Expand All @@ -1350,7 +1339,6 @@ mod tests {
Token::TupleEnd,
Token::TupleEnd,
]))
.self_describing(false)
.build();

assert_err_eq!(
Expand Down Expand Up @@ -1398,7 +1386,6 @@ mod tests {
Token::TupleEnd,
Token::TupleEnd,
]))
.self_describing(false)
.build();

assert_err_eq!(
Expand Down Expand Up @@ -1432,7 +1419,6 @@ mod tests {
Token::TupleEnd,
Token::TupleEnd,
]))
.self_describing(false)
.build();

assert_err_eq!(
Expand Down Expand Up @@ -1482,7 +1468,6 @@ mod tests {
Token::TupleEnd,
Token::TupleEnd,
]))
.self_describing(false)
.build();

assert_err_eq!(
Expand All @@ -1507,7 +1492,6 @@ mod tests {
Token::Tuple { len: 0 },
Token::TupleEnd,
]))
.self_describing(false)
.build();

assert_err_eq!(
Expand All @@ -1528,7 +1512,6 @@ mod tests {
Token::TupleEnd,
Token::TupleEnd,
]))
.self_describing(false)
.build();

assert_err_eq!(
Expand All @@ -1551,7 +1534,6 @@ mod tests {
Token::U64(3),
Token::TupleEnd,
]))
.self_describing(false)
.build();

assert_err_eq!(
Expand Down
58 changes: 26 additions & 32 deletions src/archetype/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ use crate::{
},
Entity,
},
query::view::{
Views,
ViewsSealed,
query::{
view,
view::ViewsSealed,
},
registry,
registry::{
Expand Down Expand Up @@ -238,18 +238,18 @@ where

/// # Safety
/// Each component viewed by `V` must also be identified by this archetype's `Identifier`.
pub(crate) unsafe fn view<'a, V, P, I, Q>(
pub(crate) unsafe fn view<'a, Views, Indices>(
&mut self,
) -> <<<R as ContainsViewsSealed<'a, V, P, I, Q>>::Viewable as ContainsViewsOuter<
) -> <<<R as ContainsViewsSealed<'a, Views, Indices>>::Viewable as ContainsViewsOuter<
'a,
V,
P,
I,
Q,
Views,
<R as ContainsViewsSealed<'a, Views, Indices>>::Containments,
<R as ContainsViewsSealed<'a, Views, Indices>>::Indices,
<R as ContainsViewsSealed<'a, Views, Indices>>::ReshapeIndices,
>>::Canonical as ViewsSealed<'a>>::Results
where
V: Views<'a>,
R: ContainsViews<'a, V, P, I, Q>,
Views: view::Views<'a>,
R: ContainsViews<'a, Views, Indices>,
{
// SAFETY: `self.components` contains the raw parts for `Vec<C>`s of size `self.length`
// for each component `C` identified in `self.identifier` in the canonical order defined by
Expand All @@ -258,7 +258,7 @@ where
// `self.entity_identifiers` also contains the raw parts for a valid
// `Vec<entity::Identifier>` of size `self.length`.
unsafe {
<R as ContainsViewsSealed<'a, V, P, I, Q>>::Viewable::view(
<R as ContainsViewsSealed<'a, Views, Indices>>::Viewable::view(
&self.components,
self.entity_identifiers,
self.length,
Expand Down Expand Up @@ -309,19 +309,19 @@ where
/// Each component viewed by `V` must also be identified by this archetype's `Identifier`.
///
/// The index `index` must be a valid index into this archetype.
pub(crate) unsafe fn view_row_unchecked<'a, V, P, I, Q>(
pub(crate) unsafe fn view_row_unchecked<'a, Views, Indices>(
&mut self,
index: usize,
) -> <<R as ContainsViewsSealed<'a, V, P, I, Q>>::Viewable as ContainsViewsOuter<
) -> <<R as ContainsViewsSealed<'a, Views, Indices>>::Viewable as ContainsViewsOuter<
'a,
V,
P,
I,
Q,
Views,
<R as ContainsViewsSealed<'a, Views, Indices>>::Containments,
<R as ContainsViewsSealed<'a, Views, Indices>>::Indices,
<R as ContainsViewsSealed<'a, Views, Indices>>::ReshapeIndices,
>>::Canonical
where
V: Views<'a>,
R: ContainsViews<'a, V, P, I, Q>,
Views: view::Views<'a>,
R: ContainsViews<'a, Views, Indices>,
{
// SAFETY: `self.components` contains the raw parts for `Vec<C>`s of size `self.length`
// for each component `C` identified in `self.identifier` in the canonical order defined by
Expand All @@ -334,7 +334,7 @@ where
// this archetype, and therefore within the bounds of each column and the entity
// identifiers of this archetype.
unsafe {
<R as ContainsViewsSealed<'a, V, P, I, Q>>::Viewable::view_one(
<R as ContainsViewsSealed<'a, Views, Indices>>::Viewable::view_one(
index,
&self.components,
self.entity_identifiers,
Expand All @@ -346,19 +346,13 @@ where

/// # Safety
/// The index `index` must be a valid index into this archetype.
pub(crate) unsafe fn view_row_maybe_uninit_unchecked<'a, V, P, I, Q>(
pub(crate) unsafe fn view_row_maybe_uninit_unchecked<'a, Views, Indices>(
&mut self,
index: usize,
) -> <<<R as ContainsViewsSealed<'a, V, P, I, Q>>::Viewable as ContainsViewsOuter<
'a,
V,
P,
I,
Q,
>>::Canonical as ViewsSealed<'a>>::MaybeUninit
) -> Views::MaybeUninit
where
V: Views<'a>,
R: ContainsViews<'a, V, P, I, Q>,
Views: view::Views<'a>,
R: ContainsViews<'a, Views, Indices>,
{
// SAFETY: `self.components` contains the raw parts for `Vec<C>`s of size `self.length`
// for each component `C` identified in `self.identifier` in the canonical order defined by
Expand All @@ -371,7 +365,7 @@ where
// this archetype, and therefore within the bounds of each column and the entity
// identifiers of this archetype.
unsafe {
<R as ContainsViewsSealed<'a, V, P, I, Q>>::Viewable::view_one_maybe_uninit(
<R as ContainsViewsSealed<'a, Views, Indices>>::Viewable::view_one_maybe_uninit(
index,
&self.components,
self.entity_identifiers,
Expand Down
Loading