1
0
Fork 0

Portability fix - use SimGear when available

This commit is contained in:
fredb 2006-02-11 14:43:48 +00:00
parent 3894dc75a7
commit 852c98aadd
2 changed files with 11 additions and 15 deletions

View file

@ -46,6 +46,8 @@
* *
******************************************************************/ ******************************************************************/
#include <simgear/timing/timestamp.hxx>
#include "mpplayer.hxx" #include "mpplayer.hxx"
#include <stdlib.h> #include <stdlib.h>
@ -192,15 +194,13 @@ MPPlayer::Close(void)
bool MPPlayer::CheckTime(int time, int timeusec) bool MPPlayer::CheckTime(int time, int timeusec)
{ {
double curOffset; double curOffset;
// set the offset
struct timeval tv;
int toff, utoff; int toff, utoff;
gettimeofday(&tv, NULL);
SGTimeStamp now;
// calculate the offset // calculate the offset
toff = ((int) tv.tv_sec) - time; toff = ((int) now.get_seconds()) - time;
utoff = ((int) tv.tv_usec) - timeusec; utoff = ((int) now.get_usec()) - timeusec;
while (utoff < 0) { while (utoff < 0) {
toff--; toff--;
utoff += 1000000; utoff += 1000000;
@ -256,8 +256,6 @@ MPPlayer::SetPosition
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 // Save the position matrix and update time
if (m_Initialised) if (m_Initialised)
{ {
@ -357,7 +355,7 @@ void MPPlayer::SetProperty(string property, SGPropertyNode::Type type, double va
// set the property // set the property
switch (type) { switch (type) {
case 2: case 2:
node->setBoolValue((bool) val); node->setBoolValue( val != 0.0 );
break; break;
case 3: case 3:
node->setIntValue((int) val); node->setIntValue((int) val);
@ -491,14 +489,13 @@ MPPlayer::FillPosMsg
T_PositionMsg *PosMsg T_PositionMsg *PosMsg
) )
{ {
struct timeval tv; SGTimeStamp now;
gettimeofday(&tv, NULL);
FillMsgHdr(MsgHdr, POS_DATA_ID); FillMsgHdr(MsgHdr, POS_DATA_ID);
strncpy(PosMsg->Model, m_ModelName.c_str(), MAX_MODEL_NAME_LEN); strncpy(PosMsg->Model, m_ModelName.c_str(), MAX_MODEL_NAME_LEN);
PosMsg->Model[MAX_MODEL_NAME_LEN - 1] = '\0'; PosMsg->Model[MAX_MODEL_NAME_LEN - 1] = '\0';
PosMsg->time = XDR_encode_uint32 (tv.tv_sec); PosMsg->time = XDR_encode_uint32 (now.get_seconds());
PosMsg->timeusec = XDR_encode_uint32 (tv.tv_usec); PosMsg->timeusec = XDR_encode_uint32 (now.get_usec());
PosMsg->lat = XDR_encode_double (m_lat); PosMsg->lat = XDR_encode_double (m_lat);
PosMsg->lon = XDR_encode_double (m_lon); PosMsg->lon = XDR_encode_double (m_lon);
PosMsg->alt = XDR_encode_double (m_alt); PosMsg->alt = XDR_encode_double (m_alt);

View file

@ -46,7 +46,6 @@
#include <simgear/io/sg_socket_udp.hxx> #include <simgear/io/sg_socket_udp.hxx>
#include <simgear/props/props.hxx> #include <simgear/props/props.hxx>
#include <time.h> #include <time.h>
#include <sys/time.h>
#include STL_STRING #include STL_STRING
SG_USING_STD(string); SG_USING_STD(string);