[Opensim-dev] physics architecture

Tleiades Hax tleiades at gmail.com
Sat Nov 3 07:53:19 UTC 2007


>
> This may be all wrong in C#-land, but in my wee little C++ brain I would
> do
> something like this:
>
> SceneObjectGroup should be subclassed as SceneObjectGroupPhysical for any
> object that interacts physically.  This way, constructors and destructors
> can do the right thing wrt allocating & cleaning up physics-engine stuff.
>

This may be the ramblings of a mad man, since I haven't studied the physics
code, I am focussing on the differences between C# and C++, so please
forgive me, if I state the obvious.

Sub-classing sounds like a good strategy, but you cannot rely on the
destructor to assist you in cleaning up. In .NET/Mono destructors are being
called when ever the garbage collector feels like it. I think you'll need
the IDisposable pattern.

The IDisposable pattern is designed to handle situations where you
needdeterministic deconstruction of your class. Unfortunately the
IDisposable
pattern has some drawbacks.

1) I is a little complex, when ever you inherit from a "Disposable" class,
you need to set up code, which overrides the Disposable methods correctly
(The good news is that there are 10 gazillion articles out there explaining
how it works.)

2) Just as with resource leaks in C/C++ and similar unmnanaged languages,
people tend to forget to implement stuff in: "using(object) { ..... }" or
executing the Dispose method. Only matters are even worse, because some new
commers to .NET/Mono thinks that the garbage collector will solve all their
problems.

I would suggest creating an IPhysicalObject interface, which inherits from
IDisposable. Then I would add that interface to SceneObjectGroupPhysical,
and make sure that the physics engine only operates on the IPhysicalObject
interface.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://opensimulator.org/pipermail/opensim-dev/attachments/20071103/d21d5944/attachment-0001.html>


More information about the Opensim-dev mailing list