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

An easier way to register multiple components' storage at once #1794

Closed
piedoom opened this issue Apr 1, 2021 · 5 comments
Closed

An easier way to register multiple components' storage at once #1794

piedoom opened this issue Apr 1, 2021 · 5 comments
Labels
A-ECS Entities, components, systems, and events C-Usability A targeted quality-of-life change that makes Bevy easier to use D-Trivial Nice and easy! A great choice to get started with Bevy

Comments

@piedoom
Copy link

piedoom commented Apr 1, 2021

What problem does this solve or what need does it fill?

Registering many components as SparseSet at once is not ergonomic, as it requires a lot of repetition.

For my specific context, I am creating a state machine that uses a wrapper with different types to represent the current state. This also means I'd like to register these all as SparseSet as they will be added/removed frequently. For the following examples, I have a lot of CombatState<_> component types representing a state.

What solution would you like?

@alice-i-cecile proposed a register_bundle name. I'm not exactly sure what that might look like, but I would guess it could look like

world.register_bundle::<(CombatState<Peaceful>, CombatState<Searching>, CombatState<Chasing>)>(component_descriptor)

But I don't think that works 100%...

What alternative(s) have you considered?

Currently, I am manually registering these components, which is not ideal.

world
    .register_component(ComponentDescriptor::new::<CombatState<Peaceful>>(
        StorageType::SparseSet,
    ))
    .unwrap();
world
    .register_component(ComponentDescriptor::new::<CombatState<Chasing>>(
        StorageType::SparseSet,
    ))
    .unwrap();
world
    .register_component(ComponentDescriptor::new::<CombatState<Searching>>(
        StorageType::SparseSet,
    ))
    .unwrap();
world
    .register_component(ComponentDescriptor::new::<CombatState<Evading>>(
    // ... etc.

It's also possible that this request is also related to changing the storage type in general. Will users generally want to access the entire ComponentDescriptor struct? In my case, I think something like .register_component_storage::<TargetComponent>(StorageType::SparseSet) may be worth investigating, but I haven't given it more thought than that.

Additionally, it's further possible that this exists and I just missed it!

@alice-i-cecile alice-i-cecile added A-ECS Entities, components, systems, and events C-Usability A targeted quality-of-life change that makes Bevy easier to use D-Trivial Nice and easy! A great choice to get started with Bevy labels Apr 1, 2021
@mockersf
Copy link
Member

mockersf commented Apr 3, 2021

not sure I like the name register_bundle, as a bundle of components here doesn't have the same meaning as the bundle of components added to an entity

@alice-i-cecile
Copy link
Member

Yeah, that's a sensible point. register_components would be another obvious choice, and I don't mind the similarity.

@ahmedcharles
Copy link
Contributor

There was an attempt at merging this which didn't succeed, so is this still relevant? If so, what alternative solution is desired?

@alice-i-cecile
Copy link
Member

#2254 should improve the matter dramatically, if I understand correctly :)

@alice-i-cecile
Copy link
Member

Resolved with the new derive(Component) changes in #2254.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ECS Entities, components, systems, and events C-Usability A targeted quality-of-life change that makes Bevy easier to use D-Trivial Nice and easy! A great choice to get started with Bevy
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants