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

Add ECS bundle concept #364

Merged
merged 6 commits into from Sep 19, 2017

Conversation

Projects
None yet
5 participants
@Rhuagh
Member

Rhuagh commented Sep 17, 2017

Opening this early to get feedback. Is this a viable concept or should I trash it immediately?

Rhuagh added some commits Sep 17, 2017

@jojolepro

This comment has been minimized.

Show comment
Hide comment
@jojolepro

jojolepro Sep 17, 2017

Collaborator

@Rhuagh Basically they are code wrappers to make the code less heavy and reduce the boiler plate?
I'd like to know how that handles conflicts between dependencies and component registration too.

Collaborator

jojolepro commented Sep 17, 2017

@Rhuagh Basically they are code wrappers to make the code less heavy and reduce the boiler plate?
I'd like to know how that handles conflicts between dependencies and component registration too.

@Rhuagh

This comment has been minimized.

Show comment
Hide comment
@Rhuagh

Rhuagh Sep 18, 2017

Member

Well, they're a generification of with_renderer in the ApplicationBuilder, so instead of adding functions there for every single concept (with_audio, with_transform), we can add bundles instead.

Conflicts are handled by specs for the most part. Resources are overridden, component registration is essentially a NOP for any duplicate registration. System registration is a panic if the name given already exists. When it comes to dependencies and system names, each bundle handles that on it's own. Look at the TransformBundle for example, it has support for dependencies.

Member

Rhuagh commented Sep 18, 2017

Well, they're a generification of with_renderer in the ApplicationBuilder, so instead of adding functions there for every single concept (with_audio, with_transform), we can add bundles instead.

Conflicts are handled by specs for the most part. Resources are overridden, component registration is essentially a NOP for any duplicate registration. System registration is a panic if the name given already exists. When it comes to dependencies and system names, each bundle handles that on it's own. Look at the TransformBundle for example, it has support for dependencies.

@Rhuagh

This comment has been minimized.

Show comment
Hide comment
@Rhuagh

Rhuagh Sep 18, 2017

Member

An alternative would be to have the build() function take the ApplicationBuilder as argument and return it wrapped in a Result.

Member

Rhuagh commented Sep 18, 2017

An alternative would be to have the build() function take the ApplicationBuilder as argument and return it wrapped in a Result.

src/app.rs
+ ///
+ pub fn with_bundle<B>(mut self, bundle: B) -> Result<Self>
+ where
+ B: for<'c> ECSBundle<'a, 'b, (&'c EventsLoop)>,

This comment has been minimized.

@omni-viral

omni-viral Sep 18, 2017

Member

RenderSystem is special as it the only one that need access to EventsLoop during building.
What should we do if there will be new bundle that will require some other data from Application to build?

@omni-viral

omni-viral Sep 18, 2017

Member

RenderSystem is special as it the only one that need access to EventsLoop during building.
What should we do if there will be new bundle that will require some other data from Application to build?

This comment has been minimized.

@Rhuagh

Rhuagh Sep 18, 2017

Member

Yeah, it's not perfect, but I haven't figured out a good solution to that yet.

@Rhuagh

Rhuagh Sep 18, 2017

Member

Yeah, it's not perfect, but I haven't figured out a good solution to that yet.

This comment has been minimized.

@Rhuagh

Rhuagh Sep 18, 2017

Member

Updated, the bundle trait now works on the ApplicationBuilder directly.

@Rhuagh

Rhuagh Sep 18, 2017

Member

Updated, the bundle trait now works on the ApplicationBuilder directly.

src/app.rs
+ ///
+ pub fn with_bundle<B>(mut self, bundle: B) -> Result<Self>
+ where
+ B: for<'c> ECSBundle<'a, 'b, (&'c EventsLoop)>,

This comment has been minimized.

@omni-viral

omni-viral Sep 18, 2017

Member

Parentheses are unnecessary. If you want to make a tuple with single element you need to make it like this (A,)

@omni-viral

omni-viral Sep 18, 2017

Member

Parentheses are unnecessary. If you want to make a tuple with single element you need to make it like this (A,)

@Rhuagh

This comment has been minimized.

Show comment
Hide comment
@Rhuagh

Rhuagh Sep 18, 2017

Member

Refactored to use ApplicationBuilder directly.

Member

Rhuagh commented Sep 18, 2017

Refactored to use ApplicationBuilder directly.

src/ecs/mod.rs
- where
- Self: Sized;
+/// Describes a bundle of ECS components, resources and systems
+pub trait ECSBundle<'a, 'b, T: ::state::State + 'a> {

This comment has been minimized.

@omni-viral

omni-viral Sep 18, 2017

Member

This bound shouldn't be here. Please, remove it from ApplicationBuilder's functions where T: State is not required so that it's not enforced everywhere. I believe the only function that requires T: State is ApplicationBuilder::build

@omni-viral

omni-viral Sep 18, 2017

Member

This bound shouldn't be here. Please, remove it from ApplicationBuilder's functions where T: State is not required so that it's not enforced everywhere. I believe the only function that requires T: State is ApplicationBuilder::build

This comment has been minimized.

@Rhuagh

Rhuagh Sep 18, 2017

Member

Well, ApplicationBuilder requires it at the moment, and that's a separate change from this PR imho.

@Rhuagh

Rhuagh Sep 18, 2017

Member

Well, ApplicationBuilder requires it at the moment, and that's a separate change from this PR imho.

This comment has been minimized.

@Rhuagh

Rhuagh Sep 18, 2017

Member

I fixed it.

@Rhuagh

Rhuagh Sep 18, 2017

Member

I fixed it.

@omni-viral omni-viral self-assigned this Sep 18, 2017

@omni-viral

I like it

@Xaeroxe

This comment has been minimized.

Show comment
Hide comment
@Xaeroxe

Xaeroxe Sep 18, 2017

Member

Looks good so far! What would you consider the remaining tasks on this PR?

Member

Xaeroxe commented Sep 18, 2017

Looks good so far! What would you consider the remaining tasks on this PR?

@Rhuagh

This comment has been minimized.

Show comment
Hide comment
@Rhuagh

Rhuagh Sep 18, 2017

Member

A bit of cleanup, and making a bundle for the pong stuff. And more documentation

Member

Rhuagh commented Sep 18, 2017

A bit of cleanup, and making a bundle for the pong stuff. And more documentation

@Rhuagh Rhuagh changed the title from [WIP] Add ECS bundle concept to Add ECS bundle concept Sep 18, 2017

@Rhuagh

This comment has been minimized.

Show comment
Hide comment
@Rhuagh

Rhuagh Sep 18, 2017

Member

Ready to go after rereview.

Member

Rhuagh commented Sep 18, 2017

Ready to go after rereview.

@Xaeroxe

bors r+

Thanks @Rhuagh !

bors bot added a commit that referenced this pull request Sep 18, 2017

Merge #364
364: Add ECS bundle concept r=Xaeroxe a=Rhuagh

Opening this early to get feedback. Is this a viable concept or should I trash it immediately?
@bors

This comment has been minimized.

Show comment
Hide comment
@bors

bors bot Sep 19, 2017

Contributor

Timed out

Contributor

bors bot commented Sep 19, 2017

Timed out

@Xaeroxe

This comment has been minimized.

Show comment
Hide comment
@Xaeroxe

Xaeroxe Sep 19, 2017

Member

Override.

Member

Xaeroxe commented Sep 19, 2017

Override.

@Xaeroxe Xaeroxe merged commit 60107f5 into amethyst:develop Sep 19, 2017

1 of 3 checks passed

bors Timed out
continuous-integration/travis-ci/pr The Travis CI build is in progress
Details
continuous-integration/appveyor/pr AppVeyor build succeeded
Details

@Rhuagh Rhuagh deleted the Rhuagh:bundles branch Sep 19, 2017

- .register_texture_asset()
- .register_material_not_yet_asset(),
- )
+ pub fn with_bundle<B>(self, bundle: B) -> Result<Self>

This comment has been minimized.

@torkleyy

torkleyy Sep 19, 2017

Member

If a bundle offers multiple systems, how would one manage dependencies? Should maybe the documentation list the system names it adds?

@torkleyy

torkleyy Sep 19, 2017

Member

If a bundle offers multiple systems, how would one manage dependencies? Should maybe the documentation list the system names it adds?

This comment has been minimized.

@Rhuagh

Rhuagh Sep 19, 2017

Member

I'd put all the information that the user could need in the documentation for each bundle.

@Rhuagh

Rhuagh Sep 19, 2017

Member

I'd put all the information that the user could need in the documentation for each bundle.

+ ResourceId::new::<Option<Output>>(),
+ )
+ {
+ builder = builder.with_resource(default_output());

This comment has been minimized.

@torkleyy

torkleyy Sep 19, 2017

Member

We should really have an entry API here.

@torkleyy

torkleyy Sep 19, 2017

Member

We should really have an entry API here.

This comment has been minimized.

@Rhuagh

Rhuagh Sep 19, 2017

Member

Yes.

+ builder = builder.with_resource(default_output());
+ }
+
+ let dj = match *builder.world.read_resource::<Option<Output>>() {

This comment has been minimized.

@torkleyy

torkleyy Sep 19, 2017

Member

Should use map.

@torkleyy

torkleyy Sep 19, 2017

Member

Should use map.

This comment has been minimized.

@Rhuagh

Rhuagh Sep 19, 2017

Member

Not sure I follow.

@Rhuagh

Rhuagh Sep 19, 2017

Member

Not sure I follow.

This comment has been minimized.

@Rhuagh

Rhuagh Sep 19, 2017

Member

Got it now.

@Rhuagh

Rhuagh Sep 19, 2017

Member

Got it now.

+ };
+
+ if let Some(dj) = dj {
+ builder = builder.with_resource(dj).with(

This comment has been minimized.

@torkleyy

torkleyy Sep 19, 2017

Member

That's where we need add_*.

@torkleyy

torkleyy Sep 19, 2017

Member

That's where we need add_*.

This comment has been minimized.

@Rhuagh

Rhuagh Sep 19, 2017

Member

Yep.

+
+/// Bundle for adding the InputHandler and input bindings
+///
+/// # Errors

This comment has been minimized.

@torkleyy

torkleyy Sep 19, 2017

Member

Should be ## Errors

@torkleyy

torkleyy Sep 19, 2017

Member

Should be ## Errors

This comment has been minimized.

@Rhuagh

Rhuagh Sep 19, 2017

Member

I just followed what @csherratt has done with the ApplicationBuilder etc.

@Rhuagh

Rhuagh Sep 19, 2017

Member

I just followed what @csherratt has done with the ApplicationBuilder etc.

@@ -1,9 +1,11 @@
//! `amethyst` rendering ecs module
+pub use self::bundle::RenderBundle;

This comment has been minimized.

@torkleyy

torkleyy Sep 19, 2017

Member

I think we should decide on whether we want to have a public module or reexported items. Given these bundles all have the same postfix, a conflict is impossible. I just see this inconsistency existed before the PR 😟

@torkleyy

torkleyy Sep 19, 2017

Member

I think we should decide on whether we want to have a public module or reexported items. Given these bundles all have the same postfix, a conflict is impossible. I just see this inconsistency existed before the PR 😟

+/// Will register transform components, and the TransformSystem.
+/// TransformSystem will be registered with name "transform_system".
+///
+/// # Errors

This comment has been minimized.

@torkleyy

torkleyy Sep 19, 2017

Member

Same as above

@torkleyy

torkleyy Sep 19, 2017

Member

Same as above

+///
+/// No errors will be returned by this bundle.
+///
+/// # Panics

This comment has been minimized.

@torkleyy

torkleyy Sep 19, 2017

Member

Should be ## Panics

@torkleyy

torkleyy Sep 19, 2017

Member

Should be ## Panics

+///
+/// # Panics
+///
+/// Panics in TransformSystem registration if the bundle is applied twice in the same dispatcher.

This comment has been minimized.

@torkleyy

torkleyy Sep 19, 2017

Member

TransformSystem

@torkleyy

torkleyy Sep 19, 2017

Member

TransformSystem

This comment has been minimized.

@Xaeroxe

Xaeroxe Sep 19, 2017

Member

That's what he wrote?

@Xaeroxe

Xaeroxe Sep 19, 2017

Member

That's what he wrote?

This comment has been minimized.

@torkleyy

torkleyy Sep 19, 2017

Member

Yep, just without backticks.

@torkleyy

torkleyy Sep 19, 2017

Member

Yep, just without backticks.

+ }
+
+ /// Set dependencies for the TransformSystem
+ pub fn with_dep(mut self, dep: &'a [&'a str]) -> Self {

This comment has been minimized.

@torkleyy

torkleyy Sep 19, 2017

Member

This is something that makes the new bundle system more complex and gives the user less control. Also see my comment above. But well, let's see how it works out.

@torkleyy

torkleyy Sep 19, 2017

Member

This is something that makes the new bundle system more complex and gives the user less control. Also see my comment above. But well, let's see how it works out.

This comment has been minimized.

@Rhuagh

Rhuagh Sep 19, 2017

Member

You are not forced to use the bundle system, you can do all it does on your own, and the code is open so you can see what goes on inside.
I feel this is a way of lowering the threshold to start using the engine, without giving anything up really.

@Rhuagh

Rhuagh Sep 19, 2017

Member

You are not forced to use the bundle system, you can do all it does on your own, and the code is open so you can see what goes on inside.
I feel this is a way of lowering the threshold to start using the engine, without giving anything up really.

Aceeri added a commit to Aceeri/amethyst that referenced this pull request Oct 18, 2017

Add ECS bundle concept (#364)
* Add ECS bundle concept

* Adding bundles for Audio and Transform, and updating examples to use the bundles.

* Removing SystemExt

* Changed ECSBundle to use ApplicationBuilder directly

* Moving trait bound to the only place it is used.

* Adding a bundle for Input. Adding a bundle to the Pong example. Adding docs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment