*
******************************************************************/
-#include "mpplayer.hxx"
+#include <simgear/timing/timestamp.hxx>
+#include "mpplayer.hxx"
#include <stdlib.h>
#if !(defined(_MSC_VER) || defined(__MINGW32__))
bool MPPlayer::CheckTime(int time, int timeusec)
{
double curOffset;
-
- // set the offset
- struct timeval tv;
int toff, utoff;
- gettimeofday(&tv, NULL);
+
+ SGTimeStamp now;
// calculate the offset
- toff = ((int) tv.tv_sec) - time;
- utoff = ((int) tv.tv_usec) - timeusec;
+ toff = ((int) now.get_seconds()) - time;
+ utoff = ((int) now.get_usec()) - timeusec;
while (utoff < 0) {
toff--;
utoff += 1000000;
const double left_aileron, const double right_aileron, const double elevator, const double rudder,
//const double rpms[6],
const double rateH, const double rateR, const double rateP,
- const double accN, const double accE, const double accD
+ const double accN, const double accE, const double accD
)
{
- int toff, utoff;
-
// Save the position matrix and update time
if (m_Initialised)
{
m_speedN = speedN;
m_speedE = speedE;
m_speedD = speedD;
- m_accN = accN;
- m_accE = accE;
- m_accD = accD;
+ m_accN = accN;
+ m_accE = accE;
+ m_accD = accD;
m_left_aileron = left_aileron;
- m_right_aileron = right_aileron;
+ m_right_aileron = right_aileron;
m_elevator = elevator;
- m_rudder = rudder;
+ m_rudder = rudder;
/*for (int i = 0; i < 6; i++) {
m_rpms[i] = rpms[i];
// set properties
SGPropertyNode *root = m_AIModel->getProps();
root->getNode("surface-positions/left-aileron-pos-norm", true)->setDoubleValue(m_left_aileron);
- root->getNode("surface-positions/right-aileron-pos-norm", true)->setDoubleValue(m_right_aileron);
+ root->getNode("surface-positions/right-aileron-pos-norm", true)->setDoubleValue(m_right_aileron);
root->getNode("surface-positions/elevator-pos-norm", true)->setDoubleValue(m_elevator);
root->getNode("surface-positions/rudder-pos-norm", true)->setDoubleValue(m_rudder);
/*root->getNode("engines/engine/rpm", true)->setDoubleValue(m_rpms[0]);
// Adjust by the last offset
//cout << "OFFSET: " << (m_LastOffset - m_TimeOffset) << endl;
- //m_AIModel->timewarp(m_LastOffset - m_TimeOffset);
+ //m_AIModel->timewarp(m_LastOffset - m_TimeOffset);
- // set the timestamp for the data update (sim elapsed time (secs))
- m_AIModel->setTimeStamp();
+ // set the timestamp for the data update (sim elapsed time (secs))
+ m_AIModel->setTimeStamp();
}
time(&m_LastUpdate);
// set the property
switch (type) {
case 2:
- node->setBoolValue((bool) val);
+ node->setBoolValue( val != 0.0 );
break;
case 3:
node->setIntValue((int) val);
void
MPPlayer::LoadAI(void)
{
- // set up the model info
- FGAIModelEntity aiModel;
- aiModel.m_type = "aircraft";
- aiModel.path = m_ModelName;
- aiModel.acType = "Multiplayer";
- aiModel.company = m_Callsign;
-
// then get the model manager
FGAIManager *aiModelMgr = (FGAIManager *) globals->get_subsystem("ai_model");
if (!aiModelMgr) {
// then get the model
fgSetBool("/sim/freeze/clock", true);
- m_AIModel = (FGAIMultiplayer *) aiModelMgr->createMultiplayer(&aiModel);
+ m_AIModel = new FGAIMultiplayer;
+ m_AIModel->setAcType("Multiplayer");
+ m_AIModel->setCompany(m_Callsign);
+ m_AIModel->setPath(m_ModelName.c_str());
+ aiModelMgr->attach(m_AIModel);
fgSetBool("/sim/freeze/clock", false);
}
T_PositionMsg *PosMsg
)
{
- struct timeval tv;
- gettimeofday(&tv, NULL);
-
+ SGTimeStamp now;
+
FillMsgHdr(MsgHdr, POS_DATA_ID);
strncpy(PosMsg->Model, m_ModelName.c_str(), MAX_MODEL_NAME_LEN);
PosMsg->Model[MAX_MODEL_NAME_LEN - 1] = '\0';
- PosMsg->time = XDR_encode_uint32 (tv.tv_sec);
- PosMsg->timeusec = XDR_encode_uint32 (tv.tv_usec);
+ PosMsg->time = XDR_encode_uint32 (now.get_seconds());
+ PosMsg->timeusec = XDR_encode_uint32 (now.get_usec());
PosMsg->lat = XDR_encode_double (m_lat);
PosMsg->lon = XDR_encode_double (m_lon);
PosMsg->alt = XDR_encode_double (m_alt);
PosMsg->rateH = XDR_encode_float ((float) m_rateH);
PosMsg->rateR = XDR_encode_float ((float) m_rateR);
PosMsg->rateP = XDR_encode_float ((float) m_rateP);
- PosMsg->accN = XDR_encode_float ((float) m_accN);
+ PosMsg->accN = XDR_encode_float ((float) m_accN);
PosMsg->accE = XDR_encode_float ((float) m_accE);
PosMsg->accD = XDR_encode_float ((float) m_accD);
}