Original Post
I have this issue with NxActor. I want to have this structure to my logic system:
The problem is, the NxActor * becomes null at some point that the NxScene decides upon. I want the entity classes (Thing, Vehicle, Character etc) to delegate functionality such as getPosition() and isSleeping() to their appropriate NxActor. I do not want to be scanning through the contents of the NxScene to figure out what is happening, since this means I need my World class to be aware of api specific stuff in PhysX. I'm "spawning" the Thing like this: But when I do stuff like this, I get a crash: Is there any other way of implementing this design? Or perhaps my design is flawed and I should abandon it.
The problem is, the NxActor * becomes null at some point that the NxScene decides upon. I want the entity classes (Thing, Vehicle, Character etc) to delegate functionality such as getPosition() and isSleeping() to their appropriate NxActor. I do not want to be scanning through the contents of the NxScene to figure out what is happening, since this means I need my World class to be aware of api specific stuff in PhysX. I'm "spawning" the Thing like this:
void World::spawnThing(const std::string& name, VectorMaths::Mat44<float>& pos)
{
ThingEntity * e = (ThingEntity *)things.instance(name);
physics.addThing(e,pos);
queue.push(new ThingSpawnEvent(t,e->getObjectID(),e->getModelName()));
}
void Physics::addThing(ThingEntity *& thing, VectorMaths::Mat44<float>& pos)
{
NxActor * newActor = mScene->createActor(thing->getNxActorDesc());
thing->spawn(pos,newActor);
actors.push_back(newActor);
// newActor is currently valid.
}
void ThingEntity::spawn(VectorMaths::Mat44<float> pos, NxActor * actor)
{
position = pos;
actor = actor;
mode = ESpawned;
}
bool ThingEntity::isActive()
{
if(mode == ESpawned)
return (!actor->isSleeping()); // crash here, since actor is now mysteriously NULL
else
return false;
}