-
Notifications
You must be signed in to change notification settings - Fork 46
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
Introducing ViewHolder macro and Visibility attribute #211
Comments
This is all already available, and more. The relevant derives are #[derive(Borrow, BorrowInfo)]
struct CommandProvider<'v> {
device: UniqueViewMut<'v, Device>,
queue: UniqueViewMut<'v, Queue>,
shaders: ViewMut<'v, Shader>,
}
impl CommandProvider<'_> {
fn createSprite(&mut self) {
// provide custom logic to abstract directly using device and queue structs
}
//other custom logic
} You can use regular privacy syntax, both on the custom view itself and its fields. Non view fields are allowed as long as they implement #[derive(Borrow, BorrowInfo)]
struct CommandProvider<'v> {
device: UniqueViewMut<'v, Device>,
queue: UniqueViewMut<'v, Queue>,
shaders: ViewMut<'v, Shader>,
#[shipyard(default)]
created_sprites: u32,
} You can also easily derive an iterator from it. (It's a bit ridiculous on this example but this just to show the syntax) fn main() {
let world = World::new();
world.run(|mut commands: CommandProvider| {
let sprite = commands.createSprite(); // custom abstraction for example
for command in commands.iter() {
command.shader;
}
})
}
#[derive(Borrow, BorrowInfo, IntoIter)]
struct CommandProvider<'v> {
#[shipyard(item_field_skip)]
device: UniqueViewMut<'v, Device>,
#[shipyard(item_field_skip)]
queue: UniqueViewMut<'v, Queue>,
#[shipyard(item_field_name = "shader")]
shaders: ViewMut<'v, Shader>,
#[shipyard(item_field_skip)]
#[shipyard(default)]
created_sprites: u32,
} |
ah thats really good !! |
You can use regular visibility syntax, both on the custom view itself and its fields. |
can you give a small example on it |
#[derive(Borrow, BorrowInfo)]
pub struct CommandProvider<'v> {
pub(super) device: UniqueViewMut<'v, Device>,
pub(crate) queue: UniqueViewMut<'v, Queue>,
shaders: ViewMut<'v, Shader>,
} |
fair enought |
it would be realy helpfull if there is an initialize function like this to querry and then filter the results on creation without doing that on the systems : trait BorrowInit
{
fn initialise(world:&mut World)->Self;
} is this what you were refering to here ? |
What do you mean by "filter the results"? I was referring to something like this, like serde: #[derive(Borrow, BorrowInfo)]
struct CommandProvider<'v> {
device: UniqueViewMut<'v, Device>,
queue: UniqueViewMut<'v, Queue>,
shaders: ViewMut<'v, Shader>,
#[shipyard(default = non_default_type_init_fn)]
created_sprites: NonDefaultType,
}
fn non_default_type_init_fn() -> NonDefaultType {} |
in bevy there is querry filters (i am talking about |
Query filters don't really make sense for shipyard. Bevy's default storage are archetypes, which can filter component "combinations" without looking in the storage. Because components are stored separately from the start. Now for shipyard, the default storage is sparse set. It cannot filter without looking in the storage. Like everything, it's a trade-off. With shipyard there is no conflicts possible on queries. Arguably it makes things simpler, at the cost of potential parallelism. Technically, you can also run some filtering in GroupsIn theory, one day, shipyard will have groups again. Which are basically archetypes and could benefit from query filters. |
1. ViewHolder
In order to make the shipyard crate more general porpuse and easly programable without going into source code, we can introduce :
ViewHolder : a derive macro that can be applied to structs containing only views and UniqueViews as their members
Use example :
then you can just do :
2. Visibility
#[derive(Component(Visible/Private))]
Benefits
Validation
The text was updated successfully, but these errors were encountered: