Skip to content

Commit

Permalink
Export the SGPropertyChangeListener for DLLs and document the `Time…
Browse files Browse the repository at this point in the history
…r` class.
  • Loading branch information
bcoconni committed Dec 21, 2024
1 parent f7e576d commit 7e86b90
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
19 changes: 14 additions & 5 deletions src/JSBSim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,15 +183,24 @@ class XMLFile : public FGXMLFileRead {
}
};

/** The Timer class measures the elapsed real time and can be paused and resumed.
It inherits from SGPropertyChangeListener to restart the timer whenever a
property change is detected. */
class Timer : public SGPropertyChangeListener {
public:
Timer() : SGPropertyChangeListener(), isPaused(false) { initialize(); }
void initialize(void) { initial_seconds = getcurrentseconds(); }
Timer() : SGPropertyChangeListener(), isPaused(false) { start(); }
void start(void) { initial_seconds = getcurrentseconds(); }

/// Restart the timer when the listened property is modified.
void valueChanged(SGPropertyNode* prop) override {
initialize();
start();
if (isPaused) pause_start_seconds = initial_seconds;
}
/// Get the elapsed real time in seconds since the timer was started.
double getElapsedTime(void) { return getcurrentseconds() - initial_seconds; }

/** Pause the timer if the `paused` parameter is true and resume it if the
`paused` parameter is false. */
void pause(bool paused) {
if (paused) {
if (!isPaused) {
Expand All @@ -202,7 +211,7 @@ class Timer : public SGPropertyChangeListener {
if (isPaused) {
isPaused = false;
double pause_duration = getcurrentseconds() - pause_start_seconds;
initial_seconds += pause_duration;
initial_seconds += pause_duration; // Shift the initial time to account for the pause duration.
}
}
}
Expand Down Expand Up @@ -567,7 +576,7 @@ int real_main(int argc, char* argv[])
else sleep_nseconds = (sleep_period )*1e9; // 0.01 seconds

tzset();
timer.initialize();
timer.start();

// *** CYCLIC EXECUTION LOOP, AND MESSAGE READING *** //
while (result && FDMExec->GetSimTime() <= end_time) {
Expand Down
14 changes: 7 additions & 7 deletions src/simgear/props/props.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ public:
*/
virtual simgear::props::Type getType() const = 0;
virtual ~SGRaw() {}

/**
* Create a new deep copy of this raw value.
*
Expand All @@ -244,7 +244,7 @@ public:
class SGRawExtended : public SGRaw
{
public:
/**
/**
* Make an SGRawValueContainer from the SGRawValue.
*
* This is a virtual function of SGRawExtended so that
Expand Down Expand Up @@ -723,7 +723,7 @@ typedef std::vector<SGPropertyNode_ptr> PropertyList;
* <p>Any class that needs to listen for property changes must implement
* this interface.</p>
*/
class SGPropertyChangeListener
class JSBSIM_API SGPropertyChangeListener
{
public:
virtual ~SGPropertyChangeListener ();
Expand Down Expand Up @@ -1150,7 +1150,7 @@ public:
* Set all of the mode attributes for the property node.
*/
void setAttributes (int attr) { _attr = attr; }


//
// Leaf Value (primitive).
Expand Down Expand Up @@ -1284,7 +1284,7 @@ public:
{
return setValue(&val[0]);
}

/**
* Set relative node to given value and afterwards make read only.
*
Expand Down Expand Up @@ -1344,7 +1344,7 @@ public:
* Print the value of the property to a stream.
*/
std::ostream& printOn(std::ostream& stream) const;

//
// Data binding.
//
Expand Down Expand Up @@ -2136,4 +2136,4 @@ private:

#endif // __PROPS_HXX

// end of props.hxx
// end of props.hxx

0 comments on commit 7e86b90

Please sign in to comment.