One issue I have is how to store a weak pointer in a Newton object? Ideally I want something like this:
- Code: Select all
void NewtonApplyForceAndTorque(const NewtonBody* body, dFloat timestep, int threadIndex)
{
void* data = NewtonBodyGetUserData(body);
if (data != nullptr)
{
auto ptr = ((weak_ptr<PhysicsNode>)*)data;
auto node = ptr->lock();
if (node != nullptr)
{
// Do some stuff here...
}
}
}
Of course I do not want to use new to create a weak pointer! I guess I could create a global map but that seems bad to me:
- Code: Select all
std::map<NewtonBody*, weak_ptr<PhysicsNode> > physicsnodes;
void NewtonApplyForceAndTorque(const NewtonBody* body, dFloat timestep, int threadIndex)
{
auto node = physicsnodes[body].lock();
if (node != nullptr)
{
// Do some stuff here...
}
}
Any suggestions on how to handle this?