I don't think my program is flawed
I am using Box2D library, in which I have to store pointer as void pointer...
I mean the collision detection use callback function
something like this
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
void PostSolve(b2Contact *contact, const b2ContactImpulse *impulse ){
void *DataA = contact->GetFixtureA()->GetUserData();
void *DataB = contact->GetFixtureB()->GetUserData();
if( DataA && DataB ){
base* bodyA = static_cast<base*>( DataA );
base* bodyB = static_cast<base*>( DataB );
if( isHero( bodyA ) ){
// deal with it
}
else if( isHero( bodyB ) ){
// deal with it
}
}
}
|
this "isHero" function and serveral other seems to need typeid
although the template solution works, I think the define is still better
I think about other solution that need to declare
1 2 3 4
|
class base {
public:
virtual Type getType() = 0;
}
|
but it'll become a hassle as the class grew in number
because I have to store everything in a void pointer
I need a God Object which is not very good design either
I just can't come up with a better solution...
Any suggestion is ok...
it's likely that I will change my design to prevent too much coupling and bad design ...