-
Notifications
You must be signed in to change notification settings - Fork 43
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 Generic instances for Component, Elem, Expl[Get|Set|Destroy|Members] #102
Comments
I would like to require I can reasonably want to have a Generic instance for my own purposes and retain the type being opaque. data PlayerVehicle = PV { origin, destination :: Position, fuel :: Fuel }
cmap \(PV{origin, destination}, Position current) -> -- ... 3 (!) components have a type of `Position` Other than this, I'm with you here, this would be a nice thing to have (: |
Forgive me, but I'm not sure how this really differs from my original design, which required an explicit instance declaration for The implementation I was going with would in fact probably not allow the implementation for To reiterate: One would declare Components as one normally does now. The only change here is that instead of manipulating [nested] tuples, you could use data structures of existing Components and they would transparently populate themselves using the underlying |
Ah, I think I get it now. I thought the proposal is to give a default To check, the |
They would not. |
I'm still confused.. So, the instance line in the original message is not required?
|
If you omit the instance declaration |
Looks reasonable 👍 I hope the performance would be retained. |
I hope to come back to this in the coming weeks; have had to deal with some "real-life" issues. |
Keep in mind there's a PR for v1.0 that's (to my understanding) stalled because of performance: #72 (comment) I mention it here for two reasons:
|
This is tangentially related, but I implemented a kind of "fallback component store", where anything can be shoved into using |
I am in the midst of trying to add Generic instances for the above classes.
Rationale
It is my understanding that in order to currently use the library, things such as the following must be written:
I would prefer to write instead something like the following:
Notice that adding a new field to
PlayerVehicle
does not change the implementation ofmySystem
.Performance
apecs
appears to be heavily performance focused, and I do not wish to introduce runtime overhead when unnecessary.The proposed changes have some obvious (and probably not so obvious) performance implications, but I believe these are entirely opt-in; benchmarks would need to be performed before I could commit to this statement unqualified.
However, assuming the above point, this change would allow us to design our systems using components that are plain Haskell datatypes, instead of a mess of tuples of length < 9. If we find through benchmarking that some systems need to be optimized, so be it, switch those systems to tuples! But if they don't, then I believe this to be much better than the status quo, in terms of code maintainability and readability.
Work
I am already in the middle of performing the work, and will likely open a PR in the future with the necessary changes (adding G[Component,Elem,Expl[Get,Set,Destroy,Members]] classes/families and instances, and the default signature to the original non-G version of those classes/families). I thought this would be useful outside of my specific case however, and therefore am offering to do the necessary work to include it in apecs proper.
The text was updated successfully, but these errors were encountered: