-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathjwctrl.h
More file actions
155 lines (117 loc) · 4.38 KB
/
jwctrl.h
File metadata and controls
155 lines (117 loc) · 4.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
//
// openSAM: open source SAM emulator for X Plane
//
// Copyright (C) 2025 Holger Teutsch
//
// This library 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 Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
// USA
//
#ifndef _JWCTRL_H
#define _JWCTRL_H
#include <array>
#include "samjw.h"
#include "XPLMSound.h"
struct Sound {
void *data;
int size;
int num_channels;
int sample_rate;
};
class Plane;
struct Vec2 {
float x, z;
};
// JwCtrl
// The jetway controller is the glue between a plane and its doors and sam jetways.
// It has support functions to find appropriate jetways for a plane and does the animation
// by updating values for the animation datarefs in the corresponding SamJw class.
// *** This must stay a POD *** (or change the code...)
class JwCtrl {
private:
static Sound alert_;
static bool SoundDevInit();
public:
enum JwCtrlState {
PARKED,
TO_AP,
AT_AP,
TO_DOOR,
AT_DOOR,
DOCKED, // sequence for docking
// TO_AP, // sequence for undocking
TO_PARK
};
bool selected_; // nearest jw was selected as an active jw
int door_; // active JwCtrl associated with door #
SamJw* jw_;
JwCtrlState state_;
// everything in plane local coordinates
float x_, y_, z_, psi_;
int soft_match_; // does not really fulfill matching criteria
// parked position of jw
float parked_x_, parked_z_;
// target cabin position with corresponding dref values
// docked_x/z is a cabinLength abeam of the door
float docked_x_, docked_z_, docked_y_, docked_rot1_, docked_rot2_, docked_rot3_, docked_extent_;
float ap_x_, ap_z_; // intermediate alignment point abeam docked_x/z
double cabin_x_, cabin_z_; // current position of cabin
bool wait_wb_rot_; // waiting for wheel base rotation
float wb_rot_; // to this angle
float start_ts_; // actually start operation if now > start_ts_
float last_step_ts_;
float timeout_; // so we don't get stuck
FMOD_CHANNEL* alert_chn_;
void SetupForDoor(const DoorInfo& door_info);
// convert tunnel end at (cabin_x, cabin_z) to dataref values; rot2, rot3 are optional
void XzToSamDref(float cabin_x, float cabin_z, float& rot1, float& extent, float* rot2, float* rot3);
//
// animation
//
private:
void Rotate1Extend();
// rotation 2/3 to angle, return true when done
bool Rotate2(float rot2, float dt);
bool Rotate3(float rot3, float dt);
bool RotateWheelBase(float dt);
void AnimateWheels(float ds);
// sound stuff
void AlertOn();
void AlertOff();
void AlertSetpos();
public:
JwCtrl(const JwCtrl&) = default;
JwCtrl& operator=(const JwCtrl&) = default;
JwCtrl(SamJw* jw, const Plane& plane);
// find nearest jetways, order by z (= door number, hopefully)
static int FindNearestJetways(Plane& plane, std::vector<JwCtrl>& nearest_jws);
// check whether extended nearest njw would crash into parked njw2
bool CollisionCheck(const JwCtrl& njw2);
// setup for operation
void SetupDockUndock(float start_time, bool with_sound);
// drive jetway, return true when done
bool DockDrive();
bool UndockDrive();
void Reset();
friend bool operator<(const JwCtrl&, const JwCtrl&);
// static initialization hooks, call once
static void SoundInit(); // inits device and loads wav
static void Init(); // registers dref accessors
};
static_assert(std::is_trivially_copyable_v<JwCtrl> &&
std::is_standard_layout_v<JwCtrl>,
"JwCtrl must be Trivial and Standard Layout (POD equivalent)");
// from ReadWav.cpp
extern void ReadWav(const std::string& fname, Sound& sound);
#endif