-
Notifications
You must be signed in to change notification settings - Fork 3
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
Grouped component #13
Conversation
I suppose for |
This is quite nice! I like the idea of not doing the duplication check in SharedComponent for certain cases. Couple of questions:
|
We can. This pretty much just changes what
That could work too, though with just the entity you wouldn't be able to tell if the parent has a parent and which entity that might be. I also think that inheritance should be more of a per component (and entity) thing than a per entity thing. Otherwise you can't do "inherit a, b, c from X and d, e from Y"...
Ok. I think this could be merged relatively easily with
Maybe we could have a wrapper type for entity to signal that it should adjust the group. E.g. |
I adjusted things to work how I wanted them to work:
That required some checks on whether a group index is unique, which decreased performance. I assume that can be fixed in a memory vs performance trade of.
Yup, with
|
Sorry for my very delayed response, I like this approach a lot, thank you! I will have a look at some things and play around with it to evaluate it and come back to you! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is super nice work I like it a lot! Thanks for your effort.
If I understand it correctly, the root "parent" in this case is really just the data value itself, not any given particular entity. All entities that have that datavalue can be used as parents to a new Entity equally validly.
If I understood that correctly, I think this is almost like a better version of SharedComponent
, where you'd get the latter's functionality upon calling make_unique!
if you so please.
Do you think the current SharedComponent
still has a place? If not I think I'd prefer also that naming over GroupedComponent, because I somehow still think that a component group should signify components with identical entity orders and datalayout.
Anyway, as far as I can see except for those couple of @inbounds, this is pretty much ready to be merged, thanks again!
src/component.jl
Outdated
deleteat!(c.data, idx) | ||
deleteat!(c.group_size, idx) | ||
for i in eachindex(c.group) | ||
c.group[i] = c.group[i] - (c.group[i] > eg) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cool, I did not know this - Bool turns into - 0 or 1 :D
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea, you can skip branching with that sometimes
Oh Before I forget, I added some benchmarks etc to the master, along with that new iteration scheme, could you rebase your branch on that if it's not too much of a hassle? |
It's been quite a while since I worked on this so I'm not sure what exactly I did here. But I think the way it's set up every entity belonging to the same group can act as parent to that group. And the group is just an index pointing to some datavalue.
I think that was my original goal with this. Make a SharedComponent with better
I think the way I build this it can do everything a SharedComponent does with a manual
Ok, I'll try to update things now |
I did a bit of performance checking and noticed that
SharedComponent
is comparable toComponent
in terms of speed when getting values but much slower when setting. I assumed this is mostly because the duplication check, so I tried making another component that does not do this.So basically
GroupedComponent
isSharedComponent
but without any check for duplication. The normal syntax ofcomponent[entity] = value
will always store a new value and generate a new group. You can add an entity to that group viacomponent[entity] = parent_entity
, which is somewhat like inheritance. However there is no "parent" - removing an entity will only remove that entity and only clear the value if it's the last entity in its group.I also added an
Entity(::AbstractLedger, parent::Entity, components...)
method which "inherits" all components fromparent
, with passed components taking priority. (I.e. if you pass aColor
the new entity will have that color, not the one from the parent.)My hope is that this will be helpful for entity collections with shared attributes. In the context of Makie, for example, transforming
scatter(rand(Point3f0, 1000), color = :red)
into 1000 entities, without duplicating the color 1000 times.Performance test I ran:
https://gist.github.com/ffreyer/0b56242048b6ca18bde0caa206e24847
This probably needs some more changes... For example
color[e] = GroupedColor(rand(RGBA{Float32}))
should create new groups but it adjusts the grouped value instead...