-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathopenSAM.cpp
696 lines (567 loc) · 20.8 KB
/
openSAM.cpp
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
/*
openSAM: open source SAM emulator for X Plane
Copyright (C) 2024 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
*/
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <fstream>
#include "openSAM.h"
#include "plane.h"
#include "os_dgs.h"
#include "samjw.h"
#include "jwctrl.h"
#include "os_anim.h"
#include "plane.h"
#include "mpadapter.h"
#include "XPLMPlugin.h"
#include "XPLMProcessing.h"
//
// C++ style:
// This is largely moved over code from C to C++.
// Whenever something is refactored or added it should be formatted according to
// Google's style: https://google.github.io/styleguide/cppguide.html
//
//------------------------------------------------------------------------------------
//
// On the various coordinate systems and angles:
//
// Objects are drawn in a +x east , -z true north, +y up system.
// Headings (hdgt) are measured from -z (=true north) right turning
//
// Imagine looking from below to the sky you have the more traditional 'math' view
// +x right, +z up, angles left turning from the +x axis to the +z axis.
//
// So if alpha is a 'math' angle we have
//
// hdgt = 90° + alpha.
//
// If we have a coordinate system that is rotated by an angle of psi we have
//
// hdgt\rot = hdgt - psi
//
// When it comes to object rotations or longitudes we use relative angles in (-180, +180]
// This is done by RA().
//
// So first of all we rotate and shift everything into the 'door' frame i.e.
// acf nose pointing up to -z, door at (0,0), jetways to the left somewhere at -x and some z.
//
// These values are kept in the "active_jw".
//
// Then we do our math in the door frame and transform everything back to the jetway frame
// to get the rotation angles.
//
// The datarefs for jetway animation are:
// rotation1 tunnel relative to the placed object
// rotation2 cabin relative to the tunnel
// rotation3 tunnel relative to horizontal (= x-z plane)
// wheelrotatec wheel base relative to tunnel around the y-axis
// wheelrotater right wheel
// wheelrotatel left wheel
// wheel delta height in m of tunnel over wheelbase relative to horizontal
//
// Likewise for DGS we xform everything into the stand frame and go from there.
//
///
// no multiplayer processing if y_agl > limit
constexpr float kMultiPlayerHeightLimit = 1000.0f;
static int init_fail;
std::string xp_dir;
static std::string pref_path;
static XPLMMenuID os_menu, seasons_menu;
static int toggle_mp_item, auto_item, season_item[4];
static const char* toggle_mp_support_txt = "Toggle Multiplayer Support";
static int auto_season;
static int airport_loaded;
static int nh; // on northern hemisphere
static int season; // 0-3
static const char *dr_name[] = {"sam/season/winter", "sam/season/spring",
"sam/season/summer", "sam/season/autumn"};
static int sam_library_installed;
static XPLMDataRef date_day_dr;
XPLMDataRef lat_ref_dr, lon_ref_dr,
draw_object_x_dr, draw_object_y_dr, draw_object_z_dr, draw_object_psi_dr,
gear_fnrml_dr,
total_running_time_sec_dr,
vr_enabled_dr;
float lat_ref{-1000}, lon_ref{-1000};
unsigned int ref_gen{1};
static int pref_auto_mode;
float now; // current timestamp
std::string base_dir; // base directory of openSAM
static std::unique_ptr<MpAdapter> mp_adapter;
std::unordered_map<std::string, DoorInfo> door_info_map;
std::unordered_map<std::string, DoorInfo> csl_door_info_map;
std::unordered_map<std::string, std::string> acf_generic_type_map;
unsigned long long stat_sc_far_skip, stat_near_skip,
stat_acc_called, stat_jw_match, stat_dgs_acc,
stat_anim_acc_called, stat_auto_drf_called,
stat_jw_cache_hit;
XPLMProbeInfo_t probeinfo;
XPLMProbeRef probe_ref;
XPLMMenuID anim_menu;
static void
save_pref()
{
FILE *f = fopen(pref_path.c_str(), "w");
if (NULL == f)
return;
pref_auto_mode = my_plane.auto_mode();
// encode southern hemisphere with negative season
int s = nh ? season : -season;
fprintf(f, "%d,%d,%d", auto_season, s, pref_auto_mode);
fclose(f);
log_msg("Saving pref auto_season: %d, season: %d, auto_select_jws: %d", auto_season, s, pref_auto_mode);
}
static void
load_pref()
{
// set some reasonable default values in case there is no pref file
nh = 1;
auto_season = 1;
season = 1;
pref_auto_mode = 1;
FILE *f = fopen(pref_path.c_str(), "r");
if (NULL == f)
return;
[[maybe_unused]]int n = fscanf(f, "%i,%i,%i", &auto_season, &season, &pref_auto_mode);
log_msg("From pref: auto_season: %d, seasons: %d, auto_select_jws: %d",
auto_season, season, pref_auto_mode);
fclose(f);
if (season < 0) {
nh = 0;
season = -season;
}
}
// Accessor for the "opensam/SAM_Library_installed" dataref
static int
sam_lib_installed_acc([[maybe_unused]]void *ref)
{
return sam_library_installed;
}
// Accessor for the "sam/season/*" datarefs
static int
read_season_acc(void *ref)
{
int s = (long long)ref;
int val = (s == season);
//log_msg("accessor %s called, returns %d", dr_name[s], val);
return val;
}
static int
cmd_activate_cb([[maybe_unused]] XPLMCommandRef cmdr,
XPLMCommandPhase phase, [[maybe_unused]] void *ref)
{
if (xplm_CommandBegin != phase)
return 0;
log_msg("cmd manually_activate");
dgs_set_active();
return 0;
}
static int
cmd_toggle_ui_cb([[maybe_unused]] XPLMCommandRef cmdr,
XPLMCommandPhase phase, [[maybe_unused]] void *ref)
{
if (xplm_CommandBegin != phase)
return 0;
log_msg("cmd toggle_ui");
toggle_ui();
return 0;
}
// multiplayer activation
static int
cmd_toggle_mp_cb([[maybe_unused]]XPLMCommandRef cmdr,
XPLMCommandPhase phase, [[maybe_unused]] void *ref)
{
if (xplm_CommandBegin != phase)
return 0;
log_msg("cmd toggle_mp");
if (mp_adapter) {
mp_adapter = nullptr;
} else {
mp_adapter = MpAdapter_factory();
}
if (mp_adapter) {
std::string menu_txt{toggle_mp_support_txt};
menu_txt += " (";
menu_txt += mp_adapter->personality();
menu_txt += ")";
XPLMSetMenuItemName(os_menu, toggle_mp_item, menu_txt.c_str(), 0);
} else
XPLMSetMenuItemName(os_menu, toggle_mp_item, toggle_mp_support_txt, 0);
XPLMCheckMenuItem(os_menu, toggle_mp_item,
mp_adapter ? xplm_Menu_Checked : xplm_Menu_Unchecked);
return 0;
}
static float
flight_loop_cb([[maybe_unused]] float inElapsedSinceLastCall,
[[maybe_unused]] float inElapsedTimeSinceLastFlightLoop, [[maybe_unused]] int inCounter,
[[maybe_unused]] void *inRefcon)
{
static float jw_next_ts, dgs_next_ts, anim_next_ts, mp_update_next_ts;
now = XPLMGetDataf(total_running_time_sec_dr);
bool on_ground_prev = my_plane.on_ground();
my_plane.update();
bool on_ground = my_plane.on_ground();
// check for transition
if (on_ground != on_ground_prev) {
if (on_ground)
dgs_set_active();
else
dgs_set_inactive();
}
float jw_loop_delay = jw_next_ts - now;
float dgs_loop_delay = dgs_next_ts - now;
float anim_loop_delay = anim_next_ts - now;
float mp_update_delay = mp_update_next_ts - now;
float my_y_agl = my_plane.y_agl();
if (my_y_agl < kMultiPlayerHeightLimit
&& mp_adapter && mp_update_delay <= 0.0f)
mp_update_next_ts = now + mp_adapter->update();
if (! my_plane.is_helicopter_) {
if (jw_loop_delay <= 0.0f) {
jw_loop_delay = my_plane.jw_state_machine();
if (my_y_agl < kMultiPlayerHeightLimit && mp_adapter)
jw_loop_delay = std::min(jw_loop_delay,
mp_adapter->jw_state_machine());
jw_next_ts = now + jw_loop_delay;
}
if (dgs_loop_delay <= 0.0f) {
dgs_loop_delay = dgs_state_machine();
dgs_next_ts = now + dgs_loop_delay;
}
}
if (anim_loop_delay <= 0.0f) {
anim_loop_delay = anim_state_machine();
anim_next_ts = now + anim_loop_delay;
}
//log_msg("jw_loop_delay: %0.2f", jw_loop_delay);
return std::min(anim_loop_delay, std::min(jw_loop_delay, dgs_loop_delay));
}
// set season according to date
static void
set_season_auto()
{
if (! auto_season)
return;
int day = XPLMGetDatai(date_day_dr);
if (nh) {
if (day <= 80) {
season = 0;
} else if (day <= 172) {
season = 1;
} else if (day <= 264) {
season = 2;
} else if (day <= 355) {
season = 3;
} else if (day) {
season = 0;
}
} else {
if (day <= 80) {
season = 2;
} else if (day <= 172) {
season = 3;
} else if (day <= 264) {
season = 0;
} else if (day <= 355) {
season = 1;
} else if (day) {
season = 2;
}
}
log_msg("nh: %d, day: %d, season: %d", nh, day, season);
}
// emulate a kind of radio buttons
static void
set_menu()
{
XPLMCheckMenuItem(seasons_menu, auto_item,
auto_season ? xplm_Menu_Checked : xplm_Menu_Unchecked);
XPLMCheckMenuItem(seasons_menu, season_item[season], xplm_Menu_Checked);
for (int i = 0; i < 4; i++)
if (i != season)
XPLMCheckMenuItem(seasons_menu, season_item[i], xplm_Menu_Unchecked);
}
static void
menu_cb([[maybe_unused]] void *menu_ref, void *item_ref)
{
int entry = (long long)item_ref;
if (entry == 4) {
auto_season = !auto_season;
set_season_auto();
} else {
season = entry;
auto_season = 0; // selecting a season always goes to manual mode
}
set_menu();
save_pref();
}
// dock/undock command
static int
cmd_dock_jw_cb([[maybe_unused]] XPLMCommandRef cmdr, XPLMCommandPhase phase, void *ref)
{
if (xplm_CommandBegin != phase)
return 0;
log_msg("cmd_dock_jw_cb called");
if (ref == NULL)
my_plane.request_dock();
else if (ref == (void *)1)
my_plane.request_undock();
else if (ref == (void *)2)
my_plane.request_toggle();
return 0;
}
// intercept XP12's standard cmd
static int
cmd_xp12_dock_jw_cb([[maybe_unused]] XPLMCommandRef cmdr, XPLMCommandPhase phase,
[[maybe_unused]] void *ref)
{
if (xplm_CommandBegin != phase)
return 1;
log_msg("cmd_xp12_dock_jw_cb called");
my_plane.request_toggle();
return 1; // pass on to XP12, likely there is no XP12 jw here 8-)
}
static void
load_door_info(const std::string& fn, std::unordered_map<std::string, DoorInfo>& di_map)
{
std::ifstream f(fn);
if (!f.is_open())
throw OsEx("Error loading " + fn);
log_msg("Building door_info_map from %s", fn.c_str());
std::string line;
while (std::getline(f, line)) {
size_t i = line.find('\r');
if (i != std::string::npos)
line.resize(i);
char icao[5];
int d;
float x, y, z;
if (5 == sscanf(line.c_str(), "%4s %d %f %f %f", icao, &d, &x, &y, &z)) {
if (icao[0] == '#')
continue;
if (d < 1 || d > kMaxDoor) {
log_msg("invalid entry: '%s'", line.c_str());
continue;
}
char c = d + '0';
DoorInfo d{x, y, z};
di_map[std::string(icao) + c] = d;
}
}
log_msg("%d mappings loaded", (int)di_map.size());
}
static void
load_acf_generic_type(const std::string& fn)
{
std::ifstream f(fn);
if (!f.is_open())
throw OsEx("Error loading " + fn);
log_msg("Building acf_generic_type_map from %s", fn.c_str());
std::string line;
while (std::getline(f, line)) {
size_t i = line.find('\r');
if (i != std::string::npos)
line.resize(i);
char code[5];
char icao[5];
if (2 == sscanf(line.c_str(), "%4s %4s", code, icao)) {
if (code[0] == '#')
continue;
acf_generic_type_map[std::string(code)] = std::string(icao);
}
}
log_msg("%d mappings loaded", (int)acf_generic_type_map.size());
}
// =========================== plugin entry points ===============================================
PLUGIN_API int
XPluginStart(char *out_name, char *out_sig, char *out_desc)
{
log_msg("Startup " VERSION);
probeinfo.structSize = sizeof(XPLMProbeInfo_t);
strcpy(out_name, "openSAM " VERSION);
strcpy(out_sig, "openSAM.hotbso");
strcpy(out_desc, "A plugin that emulates SAM");
// Always use Unix-native paths on the Mac!
XPLMEnableFeature("XPLM_USE_NATIVE_PATHS", 1);
XPLMEnableFeature("XPLM_USE_NATIVE_WIDGET_WINDOWS", 1);
char buffer[2048];
XPLMGetSystemPath(buffer);
xp_dir = std::string(buffer);
// set pref path
XPLMGetPrefsPath(buffer);
XPLMExtractFileAndPath(buffer);
pref_path = std::string(buffer) + "/openSAM.prf";
// set plugin's base dir
base_dir = xp_dir + "Resources/plugins/openSAM/";
// collect all config and *.xml files
try {
load_door_info(base_dir + "acf_door_position.txt", door_info_map);
load_door_info(base_dir + "csl_door_position.txt", csl_door_info_map);
load_acf_generic_type(base_dir + "acf_generic_type.txt");
SceneryPacks scp(xp_dir);
sam_library_installed = scp.SAM_Library_path.size() > 0;
collect_sam_xml(scp);
log_msg("%d sceneries with sam jetways found", (int)sceneries.size());
JwCtrl::sound_init();
} catch (const OsEx& ex) {
log_msg("fatal error: '%s', bye!", ex.what());
return 0; // bye
}
date_day_dr = XPLMFindDataRef("sim/time/local_date_days");
lat_ref_dr = XPLMFindDataRef("sim/flightmodel/position/lat_ref");
lon_ref_dr = XPLMFindDataRef("sim/flightmodel/position/lon_ref");
draw_object_x_dr = XPLMFindDataRef("sim/graphics/animation/draw_object_x");
draw_object_y_dr = XPLMFindDataRef("sim/graphics/animation/draw_object_y");
draw_object_z_dr = XPLMFindDataRef("sim/graphics/animation/draw_object_z");
draw_object_psi_dr = XPLMFindDataRef("sim/graphics/animation/draw_object_psi");
total_running_time_sec_dr = XPLMFindDataRef("sim/time/total_running_time_sec");
vr_enabled_dr = XPLMFindDataRef("sim/graphics/VR/enabled");
load_pref();
// If commands or dataref accessors are already registered it's to late to
// fail XPluginStart as the dll is unloaded and X-Plane crashes.
// So from here on we are doomed to succeed.
XPLMRegisterDataAccessor("opensam/SAM_Library_installed", xplmType_Int, 0, sam_lib_installed_acc,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL);
// create the seasons datarefs
for (int i = 0; i < 4; i++)
XPLMRegisterDataAccessor(dr_name[i], xplmType_Int, 0, read_season_acc,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, (void *)(long long)i, NULL);
MyPlane::init();
my_plane.auto_mode_set(pref_auto_mode);
JwInit();
JwCtrl::init();
dgs_init();
anim_init();
// own commands
XPLMCommandRef activate_cmdr = XPLMCreateCommand("openSAM/activate", "Manually activate searching for DGS");
XPLMRegisterCommandHandler(activate_cmdr, cmd_activate_cb, 0, NULL);
XPLMCommandRef toggle_ui_cmdr = XPLMCreateCommand("openSAM/toggle_ui", "Toggle UI");
XPLMRegisterCommandHandler(toggle_ui_cmdr, cmd_toggle_ui_cb, 0, NULL);
XPLMCommandRef dock_cmdr = XPLMCreateCommand("openSAM/dock_jwy", "Dock jetway");
XPLMRegisterCommandHandler(dock_cmdr, cmd_dock_jw_cb, 0, (void *)0);
XPLMCommandRef undock_cmdr = XPLMCreateCommand("openSAM/undock_jwy", "Undock jetway");
XPLMRegisterCommandHandler(undock_cmdr, cmd_dock_jw_cb, 0, (void *)1);
XPLMCommandRef toggle_cmdr = XPLMCreateCommand("openSAM/toggle_jwy", "Toggle jetway");
XPLMRegisterCommandHandler(toggle_cmdr, cmd_dock_jw_cb, 0, (void *)2);
XPLMCommandRef toggle_mp_cmdr = XPLMCreateCommand("openSAM/toggle_multiplayer", "Toggle Multiplayer Support");
XPLMRegisterCommandHandler(toggle_mp_cmdr, cmd_toggle_mp_cb, 0, NULL);
// augment XP12's standard cmd
XPLMCommandRef xp12_toggle_cmdr = XPLMFindCommand("sim/ground_ops/jetway");
if (xp12_toggle_cmdr)
XPLMRegisterCommandHandler(xp12_toggle_cmdr, cmd_xp12_dock_jw_cb, 1, NULL);
// build menues
XPLMMenuID menu = XPLMFindPluginsMenu();
os_menu = XPLMCreateMenu("openSAM", menu,
XPLMAppendMenuItem(menu, "openSAM", NULL, 0),
NULL, NULL);
// openSAM
XPLMAppendMenuItemWithCommand(os_menu, "Dock Jetway", dock_cmdr);
XPLMAppendMenuItemWithCommand(os_menu, "Undock Jetway", undock_cmdr);
XPLMAppendMenuItemWithCommand(os_menu, "Toggle UI", toggle_ui_cmdr);
XPLMAppendMenuSeparator(os_menu);
// openSAM -> Remote control
int rc_menu_item = XPLMAppendMenuItem(os_menu, "Remote Control", NULL, 0);
anim_menu = XPLMCreateMenu("Remote Control", os_menu, rc_menu_item, anim_menu_cb, NULL);
XPLMAppendMenuSeparator(os_menu);
XPLMAppendMenuItemWithCommand(os_menu, "Manually activate searching for DGS", activate_cmdr);
XPLMAppendMenuSeparator(os_menu);
toggle_mp_item = XPLMAppendMenuItemWithCommand(os_menu, toggle_mp_support_txt, toggle_mp_cmdr);
XPLMAppendMenuSeparator(os_menu);
// openSAM -> Seasons
int seasons_menu_item = XPLMAppendMenuItem(os_menu, "Seasons", NULL, 0);
seasons_menu = XPLMCreateMenu("Seasons", os_menu, seasons_menu_item, menu_cb, NULL);
auto_item = XPLMAppendMenuItem(seasons_menu, "Automatic", (void *)4, 0);
XPLMAppendMenuSeparator(seasons_menu);
season_item[0] = XPLMAppendMenuItem(seasons_menu, "Winter", (void *)0, 0);
season_item[1] = XPLMAppendMenuItem(seasons_menu, "Spring", (void *)1, 0);
season_item[2] = XPLMAppendMenuItem(seasons_menu, "Summer", (void *)2, 0);
season_item[3] = XPLMAppendMenuItem(seasons_menu, "Autumn", (void *)3, 0);
// ---------------------
set_menu();
// ... and off we go
XPLMRegisterFlightLoopCallback(flight_loop_cb, 2.0, NULL);
return 1;
#if 0
// keep in case we need it later
fail:
log_msg("init failure, can't enable openSAM");
init_fail = 1;
return 1;
#endif
}
PLUGIN_API void
XPluginStop(void)
{
}
PLUGIN_API void
XPluginDisable(void)
{
if (probe_ref) {
XPLMDestroyProbe(probe_ref);
probe_ref = NULL;
}
save_pref();
log_msg("acc called: %9llu", stat_acc_called);
log_msg("scenery far skip: %9llu", stat_sc_far_skip);
log_msg("near skip: %9llu", stat_near_skip);
log_msg("stat_jw_cache_hit %9llu", stat_jw_cache_hit);
log_msg("cache hit rate: %9.2f %%", 100.0f * stat_jw_cache_hit / stat_acc_called);
log_msg("dgs acc called: %9llu", stat_dgs_acc);
log_msg("stat_anim_acc_called: %9llu", stat_anim_acc_called);
log_msg("stat_auto_drf_called: %9llu", stat_auto_drf_called);
}
PLUGIN_API int
XPluginEnable(void)
{
if (init_fail) // once and for all
return 0;
probe_ref = XPLMCreateProbe(xplm_ProbeY);
if (NULL == probe_ref) {
log_msg("Can't create terrain probe");
return 0;
}
stat_sc_far_skip = stat_near_skip = stat_acc_called
= stat_jw_match = stat_dgs_acc = stat_anim_acc_called = stat_auto_drf_called
= stat_jw_cache_hit = 0;
return 1;
}
PLUGIN_API void
XPluginReceiveMessage([[maybe_unused]] XPLMPluginID in_from, long in_msg, void *in_param)
{
// Everything before XPLM_MSG_AIRPORT_LOADED has bogus datarefs.
// Anyway it's too late for the current scenery.
if ((in_msg == XPLM_MSG_AIRPORT_LOADED) ||
(airport_loaded && (in_msg == XPLM_MSG_SCENERY_LOADED))) {
airport_loaded = 1;
nh = (my_plane.lat() >= 0.0);
set_season_auto();
return;
}
// my plane loaded
if (in_msg == XPLM_MSG_PLANE_LOADED && in_param == 0) {
my_plane.plane_loaded();
return;
}
// livery loaded
if (in_msg == XPLM_MSG_LIVERY_LOADED && in_param == 0) {
my_plane.livery_loaded();
return;
}
}