1
0
Fork 0

- simplify number/name handling

- consistent member naming
- coding style fixes in clock.*
This commit is contained in:
mfranz 2006-10-26 15:06:12 +00:00
parent 19f3ae5133
commit e63b8b3351
4 changed files with 24 additions and 64 deletions

View file

@ -51,7 +51,6 @@ class ADF : public SGSubsystem
public: public:
ADF ( SGPropertyNode *node ); ADF ( SGPropertyNode *node );
ADF ();
virtual ~ADF (); virtual ~ADF ();
virtual void init (); virtual void init ();

View file

@ -15,47 +15,19 @@
#include <Main/util.hxx> #include <Main/util.hxx>
Clock::Clock ( SGPropertyNode *node ) Clock::Clock(SGPropertyNode *node) :
: _is_serviceable(true), _name(node->getStringValue("name", "clock")),
_num(node->getIntValue("number", 0)),
_is_serviceable(true),
_gmt_time_sec(0), _gmt_time_sec(0),
_offset_sec(0), _offset_sec(0),
_indicated_sec(0), _indicated_sec(0),
_indicated_min(0), _indicated_min(0),
_indicated_hour(0), _indicated_hour(0),
_local_hour(0), _local_hour(0),
_standstill_offset(0),
name("clock"),
num(0)
{
_indicated_string[0] = '\0';
int i;
for ( i = 0; i < node->nChildren(); ++i ) {
SGPropertyNode *child = node->getChild(i);
string cname = child->getName();
string cval = child->getStringValue();
if ( cname == "name" ) {
name = cval;
} else if ( cname == "number" ) {
num = child->getIntValue();
} else {
SG_LOG( SG_INSTR, SG_WARN, "Error in clock config logic" );
if ( name.length() ) {
SG_LOG( SG_INSTR, SG_WARN, "Section = " << name );
}
}
}
}
Clock::Clock ()
: _is_serviceable(true),
_gmt_time_sec(0),
_offset_sec(0),
_indicated_sec(0),
_standstill_offset(0) _standstill_offset(0)
{ {
_indicated_string[0] = '\0'; _indicated_string[0] = '\0';
_indicated_short_string[0] = '\0';
} }
Clock::~Clock () Clock::~Clock ()
@ -66,9 +38,9 @@ void
Clock::init () Clock::init ()
{ {
string branch; string branch;
branch = "/instrumentation/" + name; branch = "/instrumentation/" + _name;
SGPropertyNode *node = fgGetNode(branch.c_str(), num, true ); SGPropertyNode *node = fgGetNode(branch.c_str(), _num, true );
_serviceable_node = node->getChild("serviceable", 0, true); _serviceable_node = node->getChild("serviceable", 0, true);
_offset_node = node->getChild("offset-sec", 0, true); _offset_node = node->getChild("offset-sec", 0, true);
_sec_node = node->getChild("indicated-sec", 0, true); _sec_node = node->getChild("indicated-sec", 0, true);
@ -99,8 +71,10 @@ Clock::update (double delta_time_sec)
// compute local time zone hour // compute local time zone hour
int tzoffset_hours = globals->get_time_params()->get_local_offset() / 3600; int tzoffset_hours = globals->get_time_params()->get_local_offset() / 3600;
int lhour = hour + tzoffset_hours; int lhour = hour + tzoffset_hours;
if ( lhour < 0 ) { lhour += 24; } if (lhour < 0)
if ( lhour >= 24 ) { lhour -= 24; } lhour += 24;
if (lhour >= 24)
lhour -= 24;
long gmt = (hour * 60 + min) * 60 + sec; long gmt = (hour * 60 + min) * 60 + sec;
int offset = _offset_node->getLongValue(); int offset = _offset_node->getLongValue();
@ -152,8 +126,6 @@ Clock::update (double delta_time_sec)
_hour_node->setLongValue(_indicated_hour); _hour_node->setLongValue(_indicated_hour);
_local_hour = lhour; _local_hour = lhour;
_lhour_node->setLongValue(_local_hour); _lhour_node->setLongValue(_local_hour);
} }

View file

@ -9,10 +9,6 @@
#ifndef __INSTRUMENTS_CLOCK_HXX #ifndef __INSTRUMENTS_CLOCK_HXX
#define __INSTRUMENTS_CLOCK_HXX 1 #define __INSTRUMENTS_CLOCK_HXX 1
#ifndef __cplusplus
# error This library requires C++
#endif
#include <simgear/props/props.hxx> #include <simgear/props/props.hxx>
#include <simgear/structure/subsystem_mgr.hxx> #include <simgear/structure/subsystem_mgr.hxx>
@ -30,19 +26,17 @@
* /instrumentation/clock/indicated-sec * /instrumentation/clock/indicated-sec
* /instrumentation/clock/indicated-string * /instrumentation/clock/indicated-string
*/ */
class Clock : public SGSubsystem class Clock : public SGSubsystem {
{
public: public:
Clock(SGPropertyNode *node);
virtual ~Clock();
Clock ( SGPropertyNode *node ); virtual void init();
Clock (); virtual void update(double dt);
virtual ~Clock ();
virtual void init ();
virtual void update (double dt);
private: private:
string _name;
unsigned int _num;
bool _is_serviceable; bool _is_serviceable;
long _gmt_time_sec; long _gmt_time_sec;
@ -56,9 +50,6 @@ private:
char _local_short_string[16]; char _local_short_string[16];
long _standstill_offset; long _standstill_offset;
string name;
int num;
SGPropertyNode_ptr _serviceable_node; SGPropertyNode_ptr _serviceable_node;
SGPropertyNode_ptr _offset_node; SGPropertyNode_ptr _offset_node;
SGPropertyNode_ptr _sec_node; SGPropertyNode_ptr _sec_node;
@ -68,7 +59,6 @@ private:
SGPropertyNode_ptr _string_node; SGPropertyNode_ptr _string_node;
SGPropertyNode_ptr _string_node1; SGPropertyNode_ptr _string_node1;
SGPropertyNode_ptr _string_node2; SGPropertyNode_ptr _string_node2;
}; };
#endif // __INSTRUMENTS_CLOCK_HXX #endif // __INSTRUMENTS_CLOCK_HXX

View file

@ -42,7 +42,6 @@ class TACAN : public SGSubsystem, public SGPropertyChangeListener
public: public:
TACAN ( SGPropertyNode *node ); TACAN ( SGPropertyNode *node );
TACAN ();
virtual ~TACAN (); virtual ~TACAN ();
virtual void init (); virtual void init ();