Inheritance and extensibility

Jul 7, 2009 at 12:20 AM

Hi all,

I've been adding some changes to PhysicsSimulator and some other classes, that are somewhat specific to my game. Today I decided that in order to keep my code compatible with future versions of farseer, it'd be best to put my changes in derived classes, rather than modifying the farseer code directly. The only problem is a lot of functions are private rather than protected, and there's not a lot of virtual functions either so it's hard to derive from Farseer to expand on it.

I'm not very good with the whole versioning system, so I'm not sure whether it's a good idea to make these changes myself and try to submit them. All that needs doing is that a bunch of the "private" functions should become protected, and possibly virtual. At the moment I'm finding that I need to copy-paste the code for the private functions into my inherited class, which obviously means that when I update my farseer version I need to check them all to make sure they haven't changed, and keep them updated manually...

I'm not saying you HAVE to implement this though, as I imagine extending Farseer in this way isn't really top on many peoples' list of priorities, but it's something to think about, right?

What do you think?

Jul 7, 2009 at 12:41 AM

The thing is that virtual members are really slow compared to native managed calls. We try to keep the virtual members at a minimum and we try to have as little inheritance as possible. It is all to get better optimizations (especially on Xbox360).

I'm not sure, but I think that the partial keyword is compile-time only. We could insert the partial keyword in most files. This would ensure that you can extend the functionality of a class, but you can't override functionality.
If I remember correctly, no CLR optimizations are based on the visibility of a member, so it would not hurt performance in any way to have protected members instead of private. I'll keep this in mind for FPE 3.0

Jul 7, 2009 at 1:15 AM

That would be a big help :)

Do you happen to know if using the "new" keyword to override a function in a base class (eg private new void Func()) is also slow on the Xbox 360? You don't need the functions to be virtual in this case but it might do similar stuff internally... I can't find the information anywhere because however I search I find loads of stuff on using "new" for allocation.

Jul 7, 2009 at 3:31 AM

To my knowledge, it does not slow down. It simply exchanges the implementation at compile time and does no evaluation at runtime. I could be wrong tho.