Game Development Community

Deriving from what Base ?

by Jendrik Posche · in Torque Game Engine · 04/28/2008 (1:33 am) · 4 replies

Hi all,

Im tring to extend the engine with a new type of 3d object, where i can have my own oncollision processticks methods defined.

From which class should i derive?

My initial thoughts were ShapeBase or StaticShape, but they don't offer a virtual destructor, so i reckon these shouldn't be derived.

Any ideas?

#1
04/28/2008 (3:44 am)
Quote:
My initial thoughts were ShapeBase or StaticShape, but they don't offer a virtual destructor, so i reckon these shouldn't be derived.

Why not? I can't argument against your point about the importance of a virtual destructor, but many classes are already derived from ShapeBase and they work. Player, Vehicle and Camera being three examples.
#2
04/28/2008 (4:05 am)
Memory leakage ? ~Shapebase does the following:

ShapeBase::~ShapeBase()
{
delete mConvexList;
mConvexList = NULL;

AssertFatal(mMount.link == 0,"ShapeBase::~ShapeBase: An object is still mounted");
if( mShapeInstance && (mShapeInstance->getDebrisRefCount() == 0) )
{
delete mShapeInstance;
}

CollisionTimeout* ptr = mTimeoutList;
while (ptr) {
CollisionTimeout* cur = ptr;
ptr = ptr->next;
cur->next = sFreeTimeoutList;
sFreeTimeoutList = cur;
}
}

how can you assure that it will be cleanup if that destructor is not virtual and i derive my class from this?
#3
04/28/2008 (4:14 am)
Quote:
how can you assure that it will be cleanup if that destructor is not virtual and i derive my class from this?

It strikes me as odd, as well. You're right that ShapeBase has a deconstructor, which is non-virtual, and Player has a deconstructor which is empty, which would cause a memory leak.
#4
04/28/2008 (5:51 am)
Whether the destructor is virtual or not is determined by the true root class. The inheriting classes don't need to explicitly declare it virtual. In TGE, the root class for ShapeBase and others is ConsoleObject and it declares a virtual destructor.