- Joined
- Aug 5, 2011
- Messages
- 1,667
- Reaction score
- 3
- Points
- 38
I'm doing some work on Glideslope 2, and I would like to update the opcPreStep to use oapi::Module::clbkPreStep instead. I am looking for a generic how-to on how this is meant to work.
Current implementation code snippet for ... opcDLLInit, opsDLLExit, opcPreStep, opcDeleteVessel, MsgProc:
The Glideslope MFD is the ephemeral class that gets destroyed as usual - e.g. on an F8 press. There's a GlideslopeCore instantiated one per vessel, which the opcPreStep() calls. And things work pretty much as you'd expect.
OK - so I figured that I would have a single generic class instantiated from opcDLLInit - say like this:
.. and then Orbiter would call these callbacks (plus then add more clbk's), and I could remove the opcPreStep deprecated function. Only ... these don't get called, regardless of whether the opcPreStep is also commented out.
So ... what am I doing wrong? Should the oapi::Module inheritance be on the ephemeral MFD class, or the persistent Vessel core class, or as a single root instance linked to the opcDLLInit?
In the meantime ... I'll revert to the old deprecated way.
Current implementation code snippet for ... opcDLLInit, opsDLLExit, opcPreStep, opcDeleteVessel, MsgProc:
Code:
DLLCLBK void opcDLLInit (HINSTANCE hDLL) {
static char *name = "Glideslope 2"; // MFD mode name .. enhancing the original awesome Glideslope into Glideslope 2
MFDMODESPEC spec;
spec.name = name;
spec.key = OAPI_KEY_W; // MFD mode selection key
spec.msgproc = Glideslope::MsgProc; // MFD mode callback function
// Register the new MFD mode with Orbiter
g_MFDmode = oapiRegisterMFDMode (spec);
nGutsUsed=0;
}
DLLCLBK void opcDLLExit (HINSTANCE hDLL) {
// Unregister the custom MFD mode when the module is unloaded
oapiUnregisterMFDMode (g_MFDmode);
}
DLLCLBK void opcPreStep(double SimT,double SimDT,double mjd) {
for(int i=0;i<nGutsUsed;i++) {
if(GCoreData[i]->isInit)GCoreData[i]->MinorCycle(SimT);
}
}
DLLCLBK void opcDeleteVessel (OBJHANDLE hVessel) {
for(int i=0;i<nGutsUsed;i++) {
if (GCoreVessel[i]==hVessel) {
delete GCoreData[i];
for (int j=i; j<nGutsUsed-1; j++) {
GCoreVessel[j] = GCoreVessel[j+1];
GCoreData[j] = GCoreData[j+1];
}
nGutsUsed--;
break;
}
}
}
int Glideslope::MsgProc (UINT msg, UINT mfd, WPARAM wparam, LPARAM lparam) {
switch (msg) {
case OAPI_MSG_MFD_OPENED:
// Our new MFD mode has been selected, so we create the MFD and
// return a pointer to it.
return (int)(new Glideslope (LOWORD(wparam), HIWORD(wparam), (VESSEL*)lparam, mfd));
}
return 0;
}
The Glideslope MFD is the ephemeral class that gets destroyed as usual - e.g. on an F8 press. There's a GlideslopeCore instantiated one per vessel, which the opcPreStep() calls. And things work pretty much as you'd expect.
OK - so I figured that I would have a single generic class instantiated from opcDLLInit - say like this:
Code:
header:
class GlideslopeModule : public oapi::Module {
public:
GlideslopeModule(HINSTANCE hDLL);
~GlideslopeModule();
void clbkSimulationStart(RenderMode mode);
void clbkSimulationEnd();
};
and code:
//
// ==============================================================
// Orbiter oapi::Module API interface
// ==============================================================
//
//
GlideslopeModule::GlideslopeModule(HINSTANCE hDLL) : oapi::Module( hDLL ) {
return;
}
GlideslopeModule::~GlideslopeModule() {
return;
};
void GlideslopeModule::clbkSimulationStart(RenderMode mode) {
return;
};
void GlideslopeModule::clbkSimulationEnd() {
return;
}
.. and then Orbiter would call these callbacks (plus then add more clbk's), and I could remove the opcPreStep deprecated function. Only ... these don't get called, regardless of whether the opcPreStep is also commented out.
So ... what am I doing wrong? Should the oapi::Module inheritance be on the ephemeral MFD class, or the persistent Vessel core class, or as a single root instance linked to the opcDLLInit?
In the meantime ... I'll revert to the old deprecated way.