1 /*******************************************************************************
6 Purpose: Schedules and runs the model routines.
9 ------------- Copyright (C) 1999 Jon S. Berndt (jsb@hal-pc.org) -------------
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
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
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.
25 Further information about the GNU General Public License can also be found on
26 the world wide web at http://www.gnu.org.
28 FUNCTIONAL DESCRIPTION
29 --------------------------------------------------------------------------------
31 This class wraps up the simulation scheduling routines.
34 --------------------------------------------------------------------------------
37 ********************************************************************************
39 *******************************************************************************/
46 #include "FGFDMExec.h"
49 #include "FGAtmosphere.h"
51 #include "FGAircraft.h"
52 #include "FGTranslation.h"
53 #include "FGRotation.h"
54 #include "FGPosition.h"
55 #include "FGAuxiliary.h"
58 /*******************************************************************************
59 ************************************ CODE **************************************
60 *******************************************************************************/
65 FGFDMExec::FGFDMExec(void)
79 // Instantiate this FDM Executive's Models
81 Atmosphere = new FGAtmosphere(this);
82 FCS = new FGFCS(this);
83 Aircraft = new FGAircraft(this);
84 Translation = new FGTranslation(this);
85 Rotation = new FGRotation(this);
86 Position = new FGPosition(this);
87 Auxiliary = new FGAuxiliary(this);
88 Output = new FGOutput(this);
90 State = new FGState(this);
92 // Initialize models so they can communicate with each other
94 if (!Atmosphere->InitModel()) {cerr << "Atmosphere model init failed"; Error+=1;}
95 if (!FCS->InitModel()) {cerr << "FCS model init failed"; Error+=2;}
96 if (!Aircraft->InitModel()) {cerr << "Aircraft model init failed"; Error+=4;}
97 if (!Translation->InitModel()){cerr << "Translation model init failed"; Error+=8;}
98 if (!Rotation->InitModel()) {cerr << "Rotation model init failed"; Error+=16;}
99 if (!Position->InitModel()) {cerr << "Position model init failed"; Error+=32;}
100 if (!Auxiliary->InitModel()) {cerr << "Auxiliary model init failed"; Error+=64;}
101 if (!Output->InitModel()) {cerr << "Output model init failed"; Error+=128;}
103 Schedule(Atmosphere, 5);
105 Schedule(Aircraft, 1);
106 Schedule(Rotation, 1);
107 Schedule(Translation, 1);
108 Schedule(Position, 1);
109 Schedule(Auxiliary, 1);
117 FGFDMExec::~FGFDMExec(void)
122 int FGFDMExec::Schedule(FGModel* model, int rate)
124 FGModel* model_iterator;
126 model_iterator = FirstModel;
128 if (model_iterator == 0L) { // this is the first model
131 FirstModel->NextModel = 0L;
132 FirstModel->SetRate(rate);
134 } else { // subsequent model
136 while (model_iterator->NextModel != 0L) {
137 model_iterator = model_iterator->NextModel;
139 model_iterator->NextModel = model;
140 model_iterator->NextModel->SetRate(rate);
147 bool FGFDMExec::Run(void)
149 FGModel* model_iterator;
151 if (frozen) return true;
153 model_iterator = FirstModel;
154 if (model_iterator == 0L) return false;
156 while (!model_iterator->Run())
158 model_iterator = model_iterator->NextModel;
159 if (model_iterator == 0L) break;