-
-
Notifications
You must be signed in to change notification settings - Fork 82
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
Event handling via generics instead of conditional compilation #201
Comments
I've just realized that public class World: World<NullEventsHandler>
{
// shadows World<NullEventsHandler>.Create
public static World Create(/*...*/)
{
// ...
}
} So, if anyone wants to use events, they may simply use |
This is definitely worth considering. This could simplify some things and it has the advantage that the performance remains stable. Unfortunately I'm currently working on some other features, but that would also be worth considering ^^ |
How would you then listen for individual component changes? That doesn't really make sense to me right now. E.g. So how would this generic world variant implement this? |
I think that there is a better approach to optionally handle events than conditional compilation. .NET does some smart optimizations based on generics and struct generic argument, for example:
The only issue is that a generic
World
is returned. If that's a problem, an interface ofIWorld
could be created and returned instead. If an only one class exists for such interface, that would be optimized too (devirtualization).The approach with generics has been successfully utilized in pebuphysics2:
https://github.com/bepu/bepuphysics2/blob/a763813/Demos/Demos/SimpleSelfContainedDemo.cs
Specifically it's described here:
https://github.com/bepu/bepuphysics2/blob/a763813/Demos/Demos/SimpleSelfContainedDemo.cs#L20
The text was updated successfully, but these errors were encountered: