Skip to content

Commit

Permalink
Replace query::view::Reshape with hlist::Reshape.
Browse files Browse the repository at this point in the history
  • Loading branch information
Anders429 committed Apr 17, 2023
1 parent 2de9fe2 commit ead3472
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 138 deletions.
8 changes: 1 addition & 7 deletions src/archetype/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -349,13 +349,7 @@ where
pub(crate) unsafe fn view_row_maybe_uninit_unchecked<'a, Views, Indices>(
&mut self,
index: usize,
) -> <<<R as ContainsViewsSealed<'a, Views, Indices>>::Viewable as ContainsViewsOuter<
'a,
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>>::MaybeUninit
) -> Views::MaybeUninit
where
Views: view::Views<'a>,
R: ContainsViews<'a, Views, Indices>,
Expand Down
34 changes: 10 additions & 24 deletions src/query/entries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@ use crate::{
query::{
filter::And,
view,
view::{
Reshape,
SubSet,
},
view::SubSet,
},
registry,
registry::contains::views::{
Expand Down Expand Up @@ -88,26 +85,15 @@ where
// viewable by every possible `SubViews` (for example, in a `System` where the
// `Registry` is generic). Therefore, we instead prove that the `Views` can be viewed
// by the `SubViews`.
let super_views = <<Registry as ContainsViewsSealed<
Views,
Indices,
>>::Viewable as ContainsViewsOuter<
Views,
Registry::Containments,
Registry::Indices,
Registry::ReshapeIndices
>>::Canonical::reshape_maybe_uninit(
// SAFETY: `self.location.index` is a valid
// index into this archetype, as guaranteed
// by the entity allocator.
unsafe {
(*self.entries.world).archetypes
.get_mut(self.location.identifier)?
.view_row_maybe_uninit_unchecked::<
Views,
Indices,
>(self.location.index)
});

// SAFETY: `self.location.index` is a valid index into this archetype, as guaranteed by
// the entity allocator.
let super_views = unsafe {
(*self.entries.world)
.archetypes
.get_mut(self.location.identifier)?
.view_row_maybe_uninit_unchecked::<Views, Indices>(self.location.index)
};

// SAFETY: `super_views` is viewed on the archetype identified by
// `self.location.identifier`. The `indices` also correspond to the registry the
Expand Down
2 changes: 0 additions & 2 deletions src/query/view/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ mod disjoint;
mod merge;
#[cfg(feature = "rayon")]
mod par;
mod reshape;
mod sealed;
mod subset;

Expand All @@ -82,7 +81,6 @@ pub(crate) use par::{
ParViewsSeal,
RepeatNone,
};
pub(crate) use reshape::Reshape;
pub(crate) use sealed::ViewsSealed;

use crate::{
Expand Down
82 changes: 0 additions & 82 deletions src/query/view/reshape.rs

This file was deleted.

55 changes: 33 additions & 22 deletions src/registry/contains/views/sealed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use crate::{
query::{
view,
view::{
Reshape as _,
Views,
ViewsSealed,
},
Expand Down Expand Up @@ -88,7 +87,7 @@ where
/// The canonical form of the views `V`.
type Canonical: Views<'a>
+ ViewsSealed<'a, Results = Self::CanonicalResults>
+ view::Reshape<'a, V, Q>;
+ Reshape<V, Q, view::Null>;
/// The canonical form of the results of the views `V`. Equivalent to
/// `Self::Canonical::Results`.
type CanonicalResults: Reshape<V::Results, Q, iter::Take<iter::Repeat<view::Null>>>;
Expand Down Expand Up @@ -134,7 +133,7 @@ where
entity_identifiers: (*mut entity::Identifier, usize),
length: usize,
archetype_identifier: archetype::identifier::Iter<R>,
) -> <Self::Canonical as ViewsSealed<'a>>::MaybeUninit
) -> V::MaybeUninit
where
R: Registry;

Expand Down Expand Up @@ -178,7 +177,7 @@ where
P,
IS,
>>::Canonical,
): view::Reshape<'a, V, Q>
): Reshape<V, Q, view::Null>
+ ViewsSealed<
'a,
Results = (
Expand Down Expand Up @@ -209,6 +208,24 @@ where
>>::Canonical as ViewsSealed<'a>>::MaybeUninit,
),
>,
<(
entity::Identifier,
<R as ContainsViewsInner<
'a,
<V as Get<entity::Identifier, I>>::Remainder,
P,
IS,
>>::Canonical,
) as ViewsSealed<'a>>::Indices: Reshape<V::Indices, Q, view::Null>,
<(
entity::Identifier,
<R as ContainsViewsInner<
'a,
<V as Get<entity::Identifier, I>>::Remainder,
P,
IS,
>>::Canonical,
) as ViewsSealed<'a>>::MaybeUninit: Reshape<V::MaybeUninit, Q, view::Null>,
{
type Registry = R;
type Canonical = (
Expand Down Expand Up @@ -277,7 +294,7 @@ where
entity_identifiers: (*mut entity::Identifier, usize),
length: usize,
archetype_identifier: archetype::identifier::Iter<R_>,
) -> <Self::Canonical as ViewsSealed<'a>>::MaybeUninit
) -> V::MaybeUninit
where
R_: Registry,
{
Expand All @@ -293,7 +310,7 @@ where
// `Vec<C>`s of length `length` for each of the components identified by
// `archetype_identifier`. `index` is guaranteed to be less than `length`.
unsafe { R::view_one_maybe_uninit(index, columns, length, archetype_identifier) },
)
).reshape()
}

#[cfg(feature = "rayon")]
Expand All @@ -303,7 +320,7 @@ where
}

fn indices() -> V::Indices {
let canonical_indices = (
(
view::Null,
<R as CanonicalViews<
'a,
Expand All @@ -315,16 +332,7 @@ where
>>::Canonical,
P,
>>::indices::<R>(),
);
<(
entity::Identifier,
<R as ContainsViewsInner<
'a,
<V as Get<entity::Identifier, I>>::Remainder,
P,
IS,
>>::Canonical,
)>::reshape_indices(canonical_indices)
).reshape()
}
}

Expand All @@ -335,7 +343,11 @@ where
+ ContainsViewsInner<'a, V, P, I>,
<<R as ContainsViewsInner<'a, V, P, I>>::Canonical as ViewsSealed<'a>>::Results:
Reshape<<V as ViewsSealed<'a>>::Results, Q, iter::Take<iter::Repeat<view::Null>>>,
<R as ContainsViewsInner<'a, V, P, I>>::Canonical: view::Reshape<'a, V, Q>,
<R as ContainsViewsInner<'a, V, P, I>>::Canonical: Reshape<V, Q, view::Null>,
<<R as ContainsViewsInner<'a, V, P, I>>::Canonical as ViewsSealed<'a>>::Indices:
Reshape<V::Indices, Q, view::Null>,
<<R as ContainsViewsInner<'a, V, P, I>>::Canonical as ViewsSealed<'a>>::MaybeUninit:
Reshape<V::MaybeUninit, Q, view::Null>,
V: Views<'a>,
{
type Registry = R;
Expand Down Expand Up @@ -379,12 +391,12 @@ where
_entity_identifiers: (*mut entity::Identifier, usize),
length: usize,
archetype_identifier: archetype::identifier::Iter<R_>,
) -> <Self::Canonical as ViewsSealed<'a>>::MaybeUninit
) -> V::MaybeUninit
where
R_: Registry,
{
// SAFETY: The safety contract of this function applies to this function call.
unsafe { R::view_one_maybe_uninit(index, columns, length, archetype_identifier) }
unsafe { R::view_one_maybe_uninit(index, columns, length, archetype_identifier) }.reshape()
}

#[cfg(feature = "rayon")]
Expand All @@ -394,8 +406,7 @@ where
}

fn indices() -> V::Indices {
let canonical_indices = R::indices::<R>();
Self::Canonical::reshape_indices(canonical_indices)
R::indices::<R>().reshape()
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/world/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ use crate::{
archetype,
component::Component,
entity::allocator::Location,
hlist::Reshape,
query::{
filter::And,
view,
view::Reshape,
Query,
},
registry,
Expand Down

0 comments on commit ead3472

Please sign in to comment.