]> git.mxchange.org Git - flightgear.git/blobdiff - src/FDM/JSBSim/input_output/FGScript.h
Merge branch 'next' of gitorious.org:fg/flightgear into next
[flightgear.git] / src / FDM / JSBSim / input_output / FGScript.h
index 903057a1de69d41b8366f2e3b6b8c2b8388097d6..9f8d3ef8e84984bab04bd7857f64fa9ec717ee6d 100644 (file)
@@ -3,7 +3,7 @@
  Author:       Jon Berndt
  Date started: 12/21/2001
 
- ------------- Copyright (C) 2001  Jon S. Berndt (jsb@hal-pc.org) -------------
+ ------------- Copyright (C) 2001  Jon S. Berndt (jon@jsbsim.org) -------------
 
  This program is free software; you can redistribute it and/or modify it under
  the terms of the GNU Lesser General Public License as published by the Free Software
@@ -38,16 +38,17 @@ INCLUDES
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
 
 #include "FGJSBBase.h"
-#include "FGState.h"
 #include "FGFDMExec.h"
-#include <math/FGCondition.h>
+#include "math/FGFunction.h"
+#include "math/FGCondition.h"
 #include <vector>
+#include "input_output/FGXMLFileRead.h"
 
 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 DEFINITIONS
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
 
-#define ID_FGSCRIPT "$Id$"
+#define ID_FGSCRIPT "$Id: FGScript.h,v 1.18 2010/04/11 13:44:42 jberndt Exp $"
 
 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 FORWARD DECLARATIONS
@@ -68,13 +69,14 @@ CLASS DOCUMENTATION
     format. A test condition (or conditions) can be set up in an event in a
     script and when the condition evaluates to true, the specified
     action[s] is/are taken. An event can be <em>persistent</em>,
-    meaning that at all times when the test condition evaluates to true
-    the specified <em>set</em> actions take place. When the set of
-    tests evaluates to true for a given
+    meaning that at every time the test condition first evaluates to true
+    (toggling from false to true) then the specified <em>set</em> actions take
+    place. An event can also be defined to execute or evaluate continuously
+    while the condition is true. When the set of tests evaluates to true for a given
     condition, an item may be set to another value. This value may
     be a value, or a delta value, and the change from the
-    current value to the new value can be either via a step function,
-    a ramp, or an exponential approach. The speed of a ramp or
+    current value to the new value can be either via a step action,
+    a ramp, or an exponential approach. The speed of a ramp or exponential
     approach is specified via the time constant. Here is an example
     illustrating the format of the script file:
 
@@ -155,14 +157,14 @@ CLASS DOCUMENTATION
     comes the &quot;run&quot; section, where the conditions are
     described in &quot;event&quot; clauses.</p>
     @author Jon S. Berndt
-    @version "$Id$"
+    @version "$Id: FGScript.h,v 1.18 2010/04/11 13:44:42 jberndt Exp $"
 */
 
 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 CLASS DECLARATION
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
 
-class FGScript : public FGJSBBase
+class FGScript : public FGJSBBase, public FGXMLFileRead
 {
 public:
   /// Default constructor
@@ -172,16 +174,23 @@ public:
   ~FGScript();
 
   /** Loads a script to drive JSBSim (usually in standalone mode).
-      The language is the Script Directives for JSBSim.
+      The language is the Script Directives for JSBSim. If a simulation step size
+      has been supplied on the command line, it will be override the script-
+      specified simulation step size.
       @param script the filename (including path name, if any) for the script.
+      @param deltaT a simulation step size from the command line
       @return true if successful */
-  bool LoadScript( string script );
+  bool LoadScript(string script, double deltaT);
 
   /** This function is called each pass through the executive Run() method IF
       scripting is enabled.
       @return false if script should exit (i.e. if time limits are violated */
   bool RunScript(void);
 
+  void ResetEvents(void) {
+    for (unsigned int i=0; i<Events.size(); i++) Events[i].reset();
+  }
+
 private:
   enum eAction {
     FG_RAMP  = 1,
@@ -198,9 +207,10 @@ private:
   struct event {
     FGCondition     *Condition;
     bool             Persistent;
+    bool             Continuous;
     bool             Triggered;
-    bool             PrevTriggered;
     bool             Notify;
+    bool             Notified;
     double           Delay;
     double           StartTime;
     double           TimeSpan;
@@ -215,24 +225,31 @@ private:
     vector <double>  OriginalValue;
     vector <double>  ValueSpan;
     vector <bool>    Transiting;
+    vector <FGFunction*> Functions;
 
     event() {
       Triggered = false;
-      PrevTriggered = false;
       Persistent = false;
+      Continuous = false;
       Delay = 0.0;
-      Notify = false;
+      Notify = Notified = false;
       Name = "";
       StartTime = 0.0;
       TimeSpan = 0.0;
     }
+
+    void reset(void) {
+      Triggered = false;
+      Notified = false;
+      StartTime = 0.0;
+    }
   };
 
   struct LocalProps {
     double *value;
     string title;
-    LocalProps() {
-      value = new double(0.0);
+    LocalProps(double initial_value=0) {
+      value = new double(initial_value);
       title = "";
     }
   };
@@ -244,7 +261,6 @@ private:
   vector <LocalProps*> local_properties;
 
   FGFDMExec* FDMExec;
-  FGState* State;
   FGPropertyManager* PropertyManager;
   void Debug(int from);
 };