]> git.mxchange.org Git - flightgear.git/blob - JSBsim/FGFDMExec.cpp
877656ec7ef47f4891e651126496f77b37432e4d
[flightgear.git] / JSBsim / FGFDMExec.cpp
1 /*******************************************************************************
2
3  Module:       FGFDMExec.cpp
4  Author:       Jon S. Berndt
5  Date started: 11/17/98
6  Purpose:      Schedules and runs the model routines.
7  Called by:    The GUI.
8
9  ------------- Copyright (C) 1999  Jon S. Berndt (jsb@hal-pc.org) -------------
10
11  This program is free software; you can redistribute it and/or modify it under
12  the terms of the GNU General Public License as published by the Free Software
13  Foundation; either version 2 of the License, or (at your option) any later
14  version.
15
16  This program is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18  FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
19  details.
20
21  You should have received a copy of the GNU General Public License along with
22  this program; if not, write to the Free Software Foundation, Inc., 59 Temple
23  Place - Suite 330, Boston, MA  02111-1307, USA.
24
25  Further information about the GNU General Public License can also be found on
26  the world wide web at http://www.gnu.org.
27
28 FUNCTIONAL DESCRIPTION
29 --------------------------------------------------------------------------------
30
31 This class wraps up the simulation scheduling routines.
32
33
34 ARGUMENTS
35 --------------------------------------------------------------------------------
36
37
38 HISTORY
39 --------------------------------------------------------------------------------
40 11/17/98   JSB   Created
41
42 ********************************************************************************
43 INCLUDES
44 *******************************************************************************/
45
46 #include "FGFDMExec.h"
47 #include <stdio.h>
48 #include <stdlib.h>
49 #include <iostream.h>
50 #include <time.h>
51
52 /*******************************************************************************
53 ************************************ CODE **************************************
54 *******************************************************************************/
55
56
57 // Constructor
58
59 FGFDMExec::FGFDMExec(void)
60 {
61   FirstModel = 0L;
62
63   State       = new FGState();
64   Atmosphere  = new FGAtmosphere();
65   FCS         = new FGFCS();
66   Aircraft    = new FGAircraft();
67   Translation = new FGTranslation();
68   Rotation    = new FGRotation();
69   Position    = new FGPosition();
70   Auxiliary   = new FGAuxiliary();
71   Output      = new FGOutput();
72
73   Schedule(Atmosphere,  5);
74   Schedule(FCS,         1);
75   Schedule(Aircraft,    1);
76   Schedule(Rotation,    1);
77   Schedule(Translation, 1);
78   Schedule(Position,    1);
79   Schedule(Auxiliary,   1);
80   Schedule(Output,      5);
81
82   terminate = false;
83   freeze = false;
84 }
85
86
87 FGFDMExec::~FGFDMExec(void)
88 {
89 }
90
91
92 int FGFDMExec::Schedule(FGModel* model, int rate)
93 {
94   FGModel* model_iterator;
95
96   model_iterator = FirstModel;
97
98   if (model_iterator == 0L) {                  // this is the first model
99
100     FirstModel = model;
101     FirstModel->NextModel = 0L;
102     FirstModel->SetRate(rate);
103
104   } else {                                     // subsequent model
105
106     while (model_iterator->NextModel != 0L) {
107       model_iterator = model_iterator->NextModel;
108     }
109     model_iterator->NextModel = model;
110     model_iterator->NextModel->SetRate(rate);
111
112   }
113   return 0;
114 }
115
116
117 bool FGFDMExec::Run(void)
118 {
119   FGModel* model_iterator;
120
121   model_iterator = FirstModel;
122   if (model_iterator == 0L) return false;
123
124   while (!model_iterator->Run())
125   {
126     model_iterator = model_iterator->NextModel;
127     if (model_iterator == 0L) break;
128   }
129
130   return true;
131 }
132