You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
publicinterfaceIEventsHandler{// ...}// a struct for compiler optimizationpublicstructNullEventsHandler:IEventsHandler{// empty implementations with aggressively inlined methods}// World with generic TEventsHandler, which would have nicely optimized calls for NullEventsHandlerpublicclassWorld<TEventsHandler>whereTA:IEventsHandler{// ...}publicstaticclassWorld{publicWorld<NullEventsHandler>Create(){/* ... */}publicWorld<TEventsHandler>Create(TEventsHandlerhandler)whereTEventsHandler:IEventsHandler{/* ... */}}
The only issue is that a generic World is returned. If that's a problem, an interface of IWorld could be created and returned instead. If an only one class exists for such interface, that would be optimized too (devirtualization).
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 ^^
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: