I am writing for a simulation that uses an old 3D model file format (Carbon Graphics' GEO, if you're interested), and the way the OpenSceneGraph plugin for this model format updates its internal variables is by you registering a callback method for the model to call when it's time to update its values. The callback has the simulation time, the variable name, and its current value. You are to return back the new value for that variable.
So, in my code, I set the callback as follows:
headerNode->setUserUpdate(&FlightDriver::updateGeoVariable);
The class headerNode belongs to has the following variable:
double (* uvarupdate)(const double t, const double val, const std::string name);
Every interval, it will call uvarupdate
which I have set to:
updateGeoVariable(const double time, const double val, const std::string name)
{
return flightData->getValue(name);
}
for each variable inside the model, one at a time. I can't make the method or the flightData
member static, as they need to be unique per instance.
I have a hunch that this callback is possibly being called from C code, because when I break, it seems to have no knowledge that it is inside a class, and if I change the signature, the same three values get passed and shoehorned into whatever parameters are first.
However, I really need access to the members of the class, to avoid a really dirty kludge. Since the class itself is what drives a model in the 3D world, having 2 or more of these means that I get callbacks that say: "234, pitch, 90" and I have no way of knowing which model's variable that data belongs to.
I could possibly recompile the DLL (as it is an OSG plugin) to take additionally a pointer to that instance, or an id, or something, and return it in the callback, but I'd really like to avoid that if possible.
I've read about thunking, but it looks like that and most other ideas require access to the code that creates the callback. Any ideas?