FlightGear next
submodel.hxx
Go to the documentation of this file.
1// submodel.hxx - models a releasable submodel.
2// Written by Dave Culp, started Aug 2004
3//
4// This file is in the Public Domain and comes with no warranty.
5
6#pragma once
7
8#include <string>
9#include <vector>
10
11#include <simgear/math/SGMath.hxx>
12#include <simgear/props/props.hxx>
13#include <simgear/structure/subsystem_mgr.hxx>
14
15#include <simgear/misc/inputvalue.hxx>
16
17class FGAIBase;
18class FGAIManager;
19
20class FGSubmodelMgr : public SGSubsystem,
21 public SGPropertyChangeListener
22{
23public:
24 typedef struct {
25 SGPropertyNode_ptr trigger_node;
26 SGPropertyNode_ptr prop;
27 SGPropertyNode_ptr contents_node;
28 SGPropertyNode_ptr submodel_node;
29 SGPropertyNode_ptr speed_node;
30
31 std::string name;
32 std::string model;
33 double speed;
34 bool slaved;
35 bool repeat;
36 double delay;
37 double timer;
38 int count;
40 simgear::Value_ptr x_offset;
41 simgear::Value_ptr y_offset;
42 simgear::Value_ptr z_offset;
43 simgear::Value_ptr yaw_offset;
44 simgear::Value_ptr pitch_offset;
45 double drag_area;
46 double life;
47 double buoyancy;
48 simgear::Value_ptr azimuth_error;
49 simgear::Value_ptr elevation_error;
50 simgear::Value_ptr cd_randomness;
51 simgear::Value_ptr life_randomness;
52 bool wind;
54 double cd;
55 double weight;
56 double mass;
57 double contents;
59 int id;
60 bool no_roll;
62 bool random;
64 bool expiry;
65 bool impact;
66 std::string impact_report;
67 double fuse_range;
68 std::string submodel;
69 int sub_id;
72 std::string force_path;
73 } submodel;
74
75 typedef struct {
76 double lat;
77 double lon;
78 double alt;
79 double roll;
80 double azimuth;
81 double elevation;
82 double speed;
88 double mass;
89 int id;
90 bool no_roll;
92 } IC_struct;
93
95 virtual ~FGSubmodelMgr() = default;
96
97 // Subsystem API.
98 void bind() override;
99 void init() override;
100 void postinit() override;
101 void shutdown() override;
102 void unbind() override;
103 void update(double dt) override;
104
105 // Subsystem identification.
106 static const char* staticSubsystemClassId() { return "submodel-mgr"; }
107
108 void load();
109
110private:
111 typedef std::vector<submodel*> submodel_vector_type;
112 typedef submodel_vector_type::iterator submodel_vector_iterator;
113
114 submodel_vector_type submodels;
115 submodel_vector_type subsubmodels;
116 submodel_vector_iterator submodel_iterator, subsubmodel_iterator;
117
118 int index{0};
119
120 double x_offset, y_offset, z_offset;
121 double pitch_offset, yaw_offset;
122
123 double _parent_lat{0.0};
124 double _parent_lon{0.0};
125 double _parent_elev{0.0};
126 double _parent_hdg{0.0};
127 double _parent_pitch{0.0};
128 double _parent_roll{0.0};
129 double _parent_speed{0.0};
130
131 double _x_offset{0.0};
132 double _y_offset{0.0};
133 double _z_offset{0.0};
134
135 // Conversion factor
136 static const double lbs_to_slugs;
137
138 double contrail_altitude{0.0};
139
140 bool _impact{false};
141 bool _hit{false};
142 bool _expiry{false};
143 bool _found_sub{false};
144
145 SGPropertyNode_ptr _serviceable_node;
146 SGPropertyNode_ptr _user_lat_node;
147 SGPropertyNode_ptr _user_lon_node;
148 SGPropertyNode_ptr _user_heading_node;
149 SGPropertyNode_ptr _user_alt_node;
150 SGPropertyNode_ptr _user_pitch_node;
151 SGPropertyNode_ptr _user_roll_node;
152 SGPropertyNode_ptr _user_yaw_node;
153 SGPropertyNode_ptr _user_alpha_node;
154 SGPropertyNode_ptr _user_speed_node;
155 SGPropertyNode_ptr _user_wind_from_east_node;
156 SGPropertyNode_ptr _user_wind_from_north_node;
157 SGPropertyNode_ptr _user_speed_down_fps_node;
158 SGPropertyNode_ptr _user_speed_east_fps_node;
159 SGPropertyNode_ptr _user_speed_north_fps_node;
160 SGPropertyNode_ptr _contrail_altitude_node;
161 SGPropertyNode_ptr _contrail_trigger;
162 SGPropertyNode_ptr _count_node;
163 SGPropertyNode_ptr props;
164 SGPropertyNode_ptr _model_added_node;
165 SGPropertyNode_ptr _path_node;
166 SGPropertyNode_ptr _selected_ac;
167
168 IC_struct IC;
169
170 // Helper to retrieve the AI manager, if it currently exists
171 FGAIManager* aiManager();
172
173 void loadAI();
174 void loadSubmodels();
175 void setData(int id, const std::string& path, bool serviceable, const std::string& property_path, submodel_vector_type& models);
176 void valueChanged(SGPropertyNode*);
177 void transform(submodel*);
178 void setParentNode(int parent_id);
179 bool release(submodel*, double dt);
180
181 int _count{0};
182
183 SGGeod userpos;
184 SGGeod offsetpos;
185
186 SGVec3d getCartOffsetPos(submodel* sm) const;
187 void setOffsetPos(submodel* sm);
188};
virtual ~FGSubmodelMgr()=default
void postinit() override
Definition submodel.cxx:87
void init() override
Definition submodel.cxx:53
void unbind() override
Definition submodel.cxx:111
static const char * staticSubsystemClassId()
Definition submodel.hxx:106
void update(double dt) override
Definition submodel.cxx:120
void bind() override
Definition submodel.cxx:107
void shutdown() override
Definition submodel.cxx:101
simgear::Value_ptr azimuth_error
Definition submodel.hxx:48
simgear::Value_ptr life_randomness
Definition submodel.hxx:51
SGPropertyNode_ptr contents_node
Definition submodel.hxx:27
simgear::Value_ptr elevation_error
Definition submodel.hxx:49
simgear::Value_ptr y_offset
Definition submodel.hxx:41
simgear::Value_ptr cd_randomness
Definition submodel.hxx:50
std::string impact_report
Definition submodel.hxx:66
simgear::Value_ptr z_offset
Definition submodel.hxx:42
simgear::Value_ptr pitch_offset
Definition submodel.hxx:44
simgear::Value_ptr yaw_offset
Definition submodel.hxx:43
SGPropertyNode_ptr prop
Definition submodel.hxx:26
SGPropertyNode_ptr trigger_node
Definition submodel.hxx:25
SGPropertyNode_ptr speed_node
Definition submodel.hxx:29
SGPropertyNode_ptr submodel_node
Definition submodel.hxx:28
simgear::Value_ptr x_offset
Definition submodel.hxx:40