.dll Question clbkPreStep doesn't get called

cristiapi

New member
Joined
May 26, 2014
Messages
222
Reaction score
0
Points
0
Location
Ancona
It seems that opcPreStep() doesn't get called from a dll for an atmosphere module. Then I tried with oapi::Module::clbkPreStep(), but it's the same; this is the code:

Code:
class MODU : public oapi::Module
{
public:
	MODU(HINSTANCE hDLL);
	void clbkPreStep(double simt, double simdt, double mjd);
};

MODU::MODU(HINSTANCE hDLL) : oapi::Module(hDLL) { }

void MODU::clbkPreStep(double simt, double simdt, double mjd)
{
	char tmp[99]; sprintf(tmp, "PreStep %.9g", simdt); oapiWriteLog(tmp);
}

DLLCLBK void InitModule(HINSTANCE hModule)
{
   oapiRegisterModule(new MODU(hModule));
}

Is that correct?
 

meson800

Addon Developer
Addon Developer
Donator
Joined
Aug 6, 2011
Messages
405
Reaction score
2
Points
18
That seems correct :shrug:
 

meson800

Addon Developer
Addon Developer
Donator
Joined
Aug 6, 2011
Messages
405
Reaction score
2
Points
18
Yes, I have used a DLL that implements that.

Here's the relevant code. I have strikethroughed the specific stuff for my dll
Code:
class SimpitManager : public oapi::Module
{
public:
	SimpitManager(HINSTANCE hDLL);
	void handleEvent(Event ev);
	void clbkSimulationStart(RenderMode mode);
	void clbkSimulationEnd();
	void clbkFocusChanged(OBJHANDLE old_focus, OBJHANDLE new_focus);
	void clbkPreStep(double simt, double simdt, double mjd);
	void clbkPostStep(double simt, double simdt, double mjd);

[s]
private:
	vector<IO *> modules;[/s]

};

SimpitManager::SimpitManager(HINSTANCE hDLL) : Module(hDLL)
{
	[s]ModuleFactory::createModules(modules, hDLL);[/s]

}

void SimpitManager::clbkPreStep(double simt, double simdt, double mjd)
{
	[s]for (unsigned int i = 0; i < modules.size(); i++)
	{
		modules[i]->PreStep(simt,simdt,mjd);
	}[/s]
}
In the main file:
Code:
#define STRICT 1
#define ORBITER_MODULE
#include "Orbitersdk.h"

#include "SimpitManager.h"

DLLCLBK void InitModule (HINSTANCE hModule)
{
	 
	[s]//start logging
	Log::initLogging();

	HINSTANCE hDLL = hModule;
	g_hInst = hDLL; // remember the instance handle
	
	//init the MFD stuff
	InitMFD(hDLL);[/s]

	//set the manager up so stuff can hook
	SimpitManager * manager = new SimpitManager(hDLL);
	[s]SimpitObserver::setUpManager(manager);[/s]
	//register module
	oapiRegisterModule(manager);

}

As a stab at the solution, do you have the required module define in your main file?
Code:
#define ORBITER_MODULE
 

cristiapi

New member
Joined
May 26, 2014
Messages
222
Reaction score
0
Points
0
Location
Ancona
Yes, I have used a DLL that implements that.

Here's the relevant code. I have strikethroughed the specific stuff for my dll
[...]

Thank you, but it doesn't work.

As a stab at the solution, do you have the required module define in your main file?
Code:
#define ORBITER_MODULE

Yes.
Probably an atmosphere module doesn't support clbkPreStep(); does that make any sense?
 

cristiapi

New member
Joined
May 26, 2014
Messages
222
Reaction score
0
Points
0
Location
Ancona
I can confirm that if I put the class MODU in a MFD dll it works, while if I put that class in an atmosphere module it doesn't work.
Here is the whole code:

Code:
#define STRICT
#define ORBITER_MODULE
#include <OrbiterAPI.h>
#include <CelbodyAPI.h>
#include <OrbiterSDK.h> 


static double T0       = 288.0;  // ground level temperature [K] 
static double p0       = 101325; // ground level pressure [Pa] 
static double rho0     = 1.2250; // ground level density [kg/m^3] 
static double R        = 286.91; // gas constant 
static double gamma    = 1.4;    // ratio of specific heats 
static double altlimit = 200e3;  // cutoff altitude 
static double C        = rho0/p0; 


class DLLEXPORT ATMO: public ATMOSPHERE
{
public:
  ATMO(CELBODY2 *body);
  const char *clbkName () const;
  bool clbkConstants (ATMCONST *atmc) const;
  bool clbkParams (const PRM_IN *prm_in, PRM_OUT *prm_out);
};


class MODU : public oapi::Module
{
public:
	MODU(HINSTANCE hDLL);
	void clbkPreStep(double simt, double simdt, double mjd);
} *modu;

MODU::MODU(HINSTANCE hDLL) : oapi::Module(hDLL) { }

void MODU::clbkPreStep(double simt, double simdt, double mjd)
{
	char buf[33]; sprintf(buf, "clbkPreStep %g", simt); oapiWriteLog(buf);
}



DLLCLBK void InitModule (HINSTANCE hModule)
{
	oapiRegisterModule(modu= new MODU(hModule));
}

DLLCLBK void ExitModule (HINSTANCE hModule) 
{
  // module cleanup 
}

DLLCLBK ATMOSPHERE *CreateAtmosphere (CELBODY2 *cbody)
{
  return new ATMO(cbody); 
}
 
DLLCLBK void DeleteAtmosphere (ATMOSPHERE *atm) 
{ 
  delete (ATMO*)atm; 
} 

 
ATMO::ATMO(CELBODY2 *body): ATMOSPHERE (body) 
{ 
} 
 
const char *ATMO::clbkName () const 
{ 
  static char *name = "Cristiano's atmosphere"; 
  return name; 
} 
 
bool ATMO::clbkConstants(ATMCONST *atmc) const 
{ 
  atmc->p0       = p0; 
  atmc->rho0     = rho0; 
  atmc->R        = R; 
  atmc->gamma    = gamma; 
  atmc->altlimit = altlimit; 
  return true;
} 
 
bool ATMO::clbkParams (const PRM_IN *prm_in, PRM_OUT *prm_out) 
{
	const double z = (prm_in->flag & PRM_ALT ? prm_in->alt : 0.0);
	if (z < 200e3) {
		double scale = exp (-C*z);
		prm_out->T = 123 + 100 * sin(oapiGetSimMJD() * 860); // <-- T= f(time)
		prm_out->rho = rho0 * scale;
		prm_out->p   = p0   * scale;
		return true;
	}

	prm_out->T   = 0;
	prm_out->rho = 0;
	prm_out->p   = 0;
	return false;
}


// ------------------------------------------------------------------------------

DLLCLBK char *ModelName ()
{
  static char *name = "Cristiano's atmosphere";
  return name;
}

DLLCLBK char *ModelDesc ()
{ 
  static char *desc = "Cristiano's custom atmosphere model"; 
  return desc;
}
 
Top