-
-
Notifications
You must be signed in to change notification settings - Fork 865
/
Copy pathLandscapeMgr.cpp
2199 lines (1944 loc) · 76.2 KB
/
LandscapeMgr.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
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Stellarium
* Copyright (C) 2006 Fabien Chereau
* Copyright (C) 2010 Bogdan Marinov (add/remove landscapes feature)
* Copyright (C) 2011 Alexander Wolf
* Copyright (C) 2012 Timothy Reaves
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
*/
#include "StelActionMgr.hpp"
#include "LandscapeMgr.hpp"
#include "Landscape.hpp"
#include "AtmospherePreetham.hpp"
#include "AtmosphereShowMySky.hpp"
#include "StelApp.hpp"
#include "SolarSystem.hpp"
#include "StelCore.hpp"
#include "StelLocaleMgr.hpp"
#include "StelModuleMgr.hpp"
#include "StelFileMgr.hpp"
#include "Planet.hpp"
#include "StelIniParser.hpp"
#include "StelSkyDrawer.hpp"
#include "StelPainter.hpp"
#include "StelPropertyMgr.hpp"
#include "StelUtils.hpp"
#include <private/qzipreader_p.h>
#include <QTimer>
#include <QDebug>
#include <QSettings>
#include <QString>
#include <QDir>
#include <QDirIterator>
#include <QFile>
#include <QTemporaryFile>
#include <QMouseEvent>
#include <QPainter>
#include <QElapsedTimer>
#include <QOpenGLPaintDevice>
#include <stdexcept>
namespace
{
constexpr char ATMOSPHERE_MODEL_CONFIG_KEY[]="landscape/atmosphere_model";
constexpr char ATMOSPHERE_MODEL_PATH_CONFIG_KEY[]="landscape/atmosphere_model_path";
constexpr char ATMOSPHERE_ECLIPSE_SIM_QUALITY_CONFIG_KEY[]="landscape/atmosphere_eclipse_simulation_quality";
constexpr char ATMOSPHERE_MODEL_CONF_VAL_PREETHAM[]="preetham";
constexpr char ATMOSPHERE_MODEL_CONF_VAL_SHOWMYSKY[]="showmysky";
constexpr char ATMOSPHERE_MODEL_CONF_VAL_DEFAULT[]="preetham";
}
Cardinals::Cardinals()
: color(0.6f,0.2f,0.2f)
{
QSettings* conf = StelApp::getInstance().getSettings();
Q_ASSERT(conf);
screenFontSize = StelApp::getInstance().getScreenFontSize();
propMgr = StelApp::getInstance().getStelPropertyManager();
// Default font size is 24
font4WCR.setPixelSize(conf->value("viewing/cardinal_font_size", screenFontSize+11).toInt());
// Default font size is 18
font8WCR.setPixelSize(conf->value("viewing/ordinal_font_size", screenFontSize+5).toInt());
// Draw the principal wind points even smaller.
font16WCR.setPixelSize(conf->value("viewing/16wcr_font_size", screenFontSize+2).toInt());
font32WCR.setPixelSize(conf->value("viewing/32wcr_font_size", screenFontSize).toInt());
// English names for cardinals
labels = {
{ dN, "N" }, { dS, "S" }, { dE, "E" }, { dW, "W" },
{ dNE, "NE" }, { dSE, "SE" }, { dSW, "SW" }, { dNW, "NW" },
{ dNNE,"NNE" }, { dENE,"ENE" }, { dESE,"ESE" }, { dSSE,"SSE" },
{ dSSW,"SSW" }, { dWSW,"WSW" }, { dWNW,"WNW" }, { dNNW,"NNW" },
{ dNbE,"NbE" }, {dNEbN,"NEbN"}, {dNEbE,"NEbE"}, { dEbN,"EbN" },
{ dEbS,"EbS" }, {dSEbE,"SEbE"}, {dSEbS,"SEbS"}, { dSbE,"SbE" },
{ dSbW,"SbW" }, {dSWbS,"SWbS"}, {dSWbW,"SWbW"}, { dWbS,"WbS" },
{ dWbN,"WbN" }, {dNWbW,"NWbW"}, {dNWbN,"NWbN"}, { dNbW,"NbW" }
};
}
Cardinals::~Cardinals()
{
}
const float Cardinals::sp8 = sin(M_PIf/8.f); // dimension for intercardinals
const float Cardinals::cp8 = cos(M_PIf/8.f); // dimension for intercardinals
const float Cardinals::s1p16 = sin(M_PIf/16.f); // dimension for rose32
const float Cardinals::c1p16 = cos(M_PIf/16.f); // dimension for rose32
const float Cardinals::s3p16 = sin(3.f*M_PIf/16.f); // dimension for rose32
const float Cardinals::c3p16 = cos(3.f*M_PIf/16.f); // dimension for rose32
const QMap<Cardinals::CompassDirection, Vec3f> Cardinals::rose4winds = {
{ Cardinals::dN, Vec3f(-1.f, 0.f, 0.f) }, { Cardinals::dS, Vec3f(1.f, 0.f, 0.f) },
{ Cardinals::dE, Vec3f( 0.f, 1.f, 0.f) }, { Cardinals::dW, Vec3f(0.f, -1.f, 0.f) }
};
const QMap<Cardinals::CompassDirection, Vec3f> Cardinals::rose8winds = {
{ Cardinals::dNE, Vec3f(-q8, q8, 0.f) }, { Cardinals::dSE, Vec3f( q8, q8, 0.f) },
{ Cardinals::dSW, Vec3f( q8, -q8, 0.f) }, { Cardinals::dNW, Vec3f(-q8, -q8, 0.f) }
};
const QMap<Cardinals::CompassDirection, Vec3f> Cardinals::rose16winds = {
{ Cardinals::dNNE, Vec3f(-cp8, sp8, 0.f) }, { Cardinals::dENE, Vec3f(-sp8, cp8, 0.f) },
{ Cardinals::dESE, Vec3f( sp8, cp8, 0.f) }, { Cardinals::dSSE, Vec3f( cp8, sp8, 0.f) },
{ Cardinals::dSSW, Vec3f( cp8, -sp8, 0.f) }, { Cardinals::dWSW, Vec3f( sp8, -cp8, 0.f) },
{ Cardinals::dWNW, Vec3f(-sp8, -cp8, 0.f) }, { Cardinals::dNNW, Vec3f(-cp8, -sp8, 0.f) }
};
const QMap<Cardinals::CompassDirection, Vec3f> Cardinals::rose32winds = {
{ Cardinals::dNbE, Vec3f(-c1p16, s1p16, 0.f) }, { Cardinals::dNbW, Vec3f(-c1p16, -s1p16, 0.f) },
{ Cardinals::dSbE, Vec3f( c1p16, s1p16, 0.f) }, { Cardinals::dSbW, Vec3f( c1p16, -s1p16, 0.f) },
{ Cardinals::dEbS, Vec3f( s1p16, c1p16, 0.f) }, { Cardinals::dEbN, Vec3f(-s1p16, c1p16, 0.f) },
{ Cardinals::dWbN, Vec3f(-s1p16,-c1p16, 0.f) }, { Cardinals::dWbS, Vec3f( s1p16, -c1p16, 0.f) },
{ Cardinals::dNEbN, Vec3f(-c3p16, s3p16, 0.f) }, { Cardinals::dNWbN, Vec3f(-c3p16, -s3p16, 0.f) },
{ Cardinals::dSEbS, Vec3f( c3p16, s3p16, 0.f) }, { Cardinals::dSWbS, Vec3f( c3p16, -s3p16, 0.f) },
{ Cardinals::dSEbE, Vec3f( s3p16, c3p16, 0.f) }, { Cardinals::dNEbE, Vec3f(-s3p16, c3p16, 0.f) },
{ Cardinals::dNWbW, Vec3f(-s3p16,-c3p16, 0.f) }, { Cardinals::dSWbW, Vec3f( s3p16, -c3p16, 0.f) }
};
void Cardinals::update(double deltaTime)
{
fader4WCR.update(static_cast<int>(deltaTime*1000));
fader8WCR.update(static_cast<int>(deltaTime*1000));
fader16WCR.update(static_cast<int>(deltaTime*1000));
fader32WCR.update(static_cast<int>(deltaTime*1000));
}
void Cardinals::setFadeDuration(float duration)
{
fader4WCR.setDuration(static_cast<int>(duration*1000.f));
fader8WCR.setDuration(static_cast<int>(duration*1000.f));
fader16WCR.setDuration(static_cast<int>(duration*1000.f));
fader32WCR.setDuration(static_cast<int>(duration*1000.f));
}
// Draw the cardinals points : N S E W and the subcardinal and sub-subcardinal.
// Handles special cases at poles
void Cardinals::draw(const StelCore* core, double latitude) const
{
// fun polar special cases: no cardinals!
if ((fabs(latitude - 90.0) < 1e-10) || (fabs(latitude + 90.0) < 1e-10))
return;
if (fader4WCR.getInterstate()>0.f)
{
const StelProjectorP prj = core->getProjection(StelCore::FrameAltAz, StelCore::RefractionOff);
const float ppx = static_cast<float>(core->getCurrentStelProjectorParams().devicePixelsPerPixel);
StelPainter sPainter(prj);
sPainter.setFont(font4WCR);
float sshift=0.f, bshift=0.f, cshift=0.f, dshift=0.f, vshift=1.f;
bool flagMask = (core->getProjection(StelCore::FrameJ2000)->getMaskType() != StelProjector::MaskDisk);
if (propMgr->getProperty("SpecialMarkersMgr.compassMarksDisplayed")->getValue().toBool())
vshift = static_cast<float>(screenFontSize + 12)*ppx;
Vec3f xy;
sPainter.setColor(color, fader4WCR.getInterstate());
sPainter.setBlending(true);
QMapIterator<Cardinals::CompassDirection, Vec3f> it4w(rose4winds);
while(it4w.hasNext())
{
it4w.next();
QString directionLabel = labels.value(it4w.key(), "");
if (flagMask)
sshift = ppx*static_cast<float>(sPainter.getFontMetrics().boundingRect(directionLabel).width())*0.5f;
if (prj->project(it4w.value(), xy))
{
Vec3f up(it4w.value()[0], it4w.value()[1], 1.f*M_PI_180f);
Vec3f upPrj;
prj->project(up, upPrj);
float dx=upPrj[0]-xy[0];
float dy=upPrj[1]-xy[1];
float textAngle=atan2(dx, dy);
sPainter.drawText(xy[0], xy[1], directionLabel, -textAngle*M_180_PIf, -sshift, vshift, true);
}
}
if (fader8WCR.getInterstate()>0.f)
{
float minFader = qMin(fader4WCR.getInterstate(), fader8WCR.getInterstate());
sPainter.setColor(color, minFader);
sPainter.setFont(font8WCR);
QMapIterator<Cardinals::CompassDirection, Vec3f> it8w(rose8winds);
while(it8w.hasNext())
{
it8w.next();
QString directionLabel = labels.value(it8w.key(), "");
if (flagMask)
bshift = ppx*static_cast<float>(sPainter.getFontMetrics().boundingRect(directionLabel).width())*0.5f;
if (prj->project(it8w.value(), xy))
{
Vec3f up(it8w.value()[0], it8w.value()[1], 1.f*M_PI_180f);
Vec3f upPrj;
prj->project(up, upPrj);
float dx=upPrj[0]-xy[0];
float dy=upPrj[1]-xy[1];
float textAngle=atan2(dx, dy);
sPainter.drawText(xy[0], xy[1], directionLabel, -textAngle*M_180_PIf, -bshift, vshift, true);
}
}
if (fader16WCR.getInterstate()>0.f)
{
sPainter.setColor(color, qMin(minFader, fader16WCR.getInterstate()));
sPainter.setFont(font16WCR);
QMapIterator<Cardinals::CompassDirection, Vec3f> it16w(rose16winds);
while(it16w.hasNext())
{
it16w.next();
QString directionLabel = labels.value(it16w.key(), "");
if (flagMask)
cshift = ppx*static_cast<float>(sPainter.getFontMetrics().boundingRect(directionLabel).width())*0.5f;
if (prj->project(it16w.value(), xy))
{
Vec3f up(it16w.value()[0], it16w.value()[1], 1.f*M_PI_180f);
Vec3f upPrj;
prj->project(up, upPrj);
float dx=upPrj[0]-xy[0];
float dy=upPrj[1]-xy[1];
float textAngle=atan2(dx, dy);
sPainter.drawText(xy[0], xy[1], directionLabel, -textAngle*M_180_PIf, -cshift, vshift, true);
}
}
if (fader32WCR.getInterstate()>0.f)
{
sPainter.setColor(color, qMin(minFader, fader32WCR.getInterstate()));
sPainter.setFont(font32WCR);
QMapIterator<Cardinals::CompassDirection, Vec3f> it32w(rose32winds);
while(it32w.hasNext())
{
it32w.next();
QString directionLabel = labels.value(it32w.key(), "");
if (flagMask)
dshift = ppx*static_cast<float>(sPainter.getFontMetrics().boundingRect(directionLabel).width())*0.5f;
if (prj->project(it32w.value(), xy))
{
Vec3f up(it32w.value()[0], it32w.value()[1], 1.f*M_PI_180f);
Vec3f upPrj;
prj->project(up, upPrj);
float dx=upPrj[0]-xy[0];
float dy=upPrj[1]-xy[1];
float textAngle=atan2(dx, dy);
sPainter.drawText(xy[0], xy[1], directionLabel, -textAngle*M_180_PIf, -dshift, vshift, true);
}
}
}
}
}
}
}
// Translate cardinal labels with gettext to current sky language and update font for the language
void Cardinals::updateI18n()
{
labels = {
// TRANSLATORS: North
{ dN, qc_("N", "compass direction") },
// TRANSLATORS: South
{ dS, qc_("S", "compass direction") },
// TRANSLATORS: East
{ dE, qc_("E", "compass direction") },
// TRANSLATORS: West
{ dW, qc_("W", "compass direction") },
// TRANSLATORS: Northeast
{ dNE, qc_("NE", "compass direction") },
// TRANSLATORS: Southeast
{ dSE, qc_("SE", "compass direction") },
// TRANSLATORS: Southwest
{ dSW, qc_("SW", "compass direction") },
// TRANSLATORS: Northwest
{ dNW, qc_("NW", "compass direction") },
// TRANSLATORS: North-northeast
{ dNNE, qc_("NNE", "compass direction") },
// TRANSLATORS: East-northeast
{ dENE, qc_("ENE", "compass direction") },
// TRANSLATORS: East-southeast
{ dESE, qc_("ESE", "compass direction") },
// TRANSLATORS: South-southeast
{ dSSE, qc_("SSE", "compass direction") },
// TRANSLATORS: South-southwest
{ dSSW, qc_("SSW", "compass direction") },
// TRANSLATORS: West-southwest
{ dWSW, qc_("WSW", "compass direction") },
// TRANSLATORS: West-northwest
{ dWNW, qc_("WNW", "compass direction") },
// TRANSLATORS: North-northwest
{ dNNW, qc_("NNW", "compass direction") },
// TRANSLATORS: North by east
{ dNbE, qc_("NbE", "compass direction") },
// TRANSLATORS: Northeast by north
{dNEbN, qc_("NEbN","compass direction") },
// TRANSLATORS: Northeast by east
{dNEbE, qc_("NEbE","compass direction") },
// TRANSLATORS: East by north
{ dEbN, qc_("EbN", "compass direction") },
// TRANSLATORS: East by south
{ dEbS, qc_("EbS", "compass direction") },
// TRANSLATORS: Southeast by east
{dSEbE, qc_("SEbE","compass direction") },
// TRANSLATORS: Southeast by south
{dSEbS, qc_("SEbS","compass direction") },
// TRANSLATORS: South by east
{ dSbE, qc_("SbE", "compass direction") },
// TRANSLATORS: South by west
{ dSbW, qc_("SbW", "compass direction") },
// TRANSLATORS: Southwest by south
{dSWbS, qc_("SWbS","compass direction") },
// TRANSLATORS: Southwest by west
{dSWbW, qc_("SWbW","compass direction") },
// TRANSLATORS: West by south
{ dWbS, qc_("WbS", "compass direction") },
// TRANSLATORS: West by north
{ dWbN, qc_("WbN", "compass direction") },
// TRANSLATORS: Northwest by west
{dNWbW, qc_("NWbW","compass direction") },
// TRANSLATORS: Northwest by north
{dNWbN, qc_("NWbN","compass direction") },
// TRANSLATORS: North by west
{ dNbW, qc_("NbW", "compass direction") }
};
}
LandscapeMgr::LandscapeMgr()
: StelModule()
, atmosphere(Q_NULLPTR)
, cardinalPoints(Q_NULLPTR)
, landscape(Q_NULLPTR)
, oldLandscape(Q_NULLPTR)
, messageTimer(new QTimer(this))
, flagLandscapeSetsLocation(false)
, flagLandscapeAutoSelection(false)
, flagLightPollutionFromDatabase(false)
, atmosphereNoScatter(false)
, flagPolyLineDisplayedOnly(false)
, polyLineThickness(1)
, flagLandscapeUseMinimalBrightness(false)
, defaultMinimalBrightness(0.01)
, flagLandscapeSetsMinimalBrightness(false)
, flagEnvironmentAutoEnabling(false)
, flagLandscapeUseTransparency(false)
, landscapeTransparency(0.)
{
setObjectName("LandscapeMgr"); // should be done by StelModule's constructor.
//Note: The first entry in the list is used as the default 'default landscape' in removeLandscape().
packagedLandscapeIDs = (QStringList() << "guereins");
QDirIterator directories(StelFileMgr::getInstallationDir()+"/landscapes/", QDir::Dirs | QDir::NoSymLinks | QDir::NoDotAndDotDot, QDirIterator::Subdirectories);
while(directories.hasNext())
{
directories.next();
packagedLandscapeIDs << directories.fileName();
}
packagedLandscapeIDs.removeDuplicates();
landscapeCache.clear();
messageTimer->setInterval(5000);
messageTimer->setSingleShot(true);
connect(messageTimer, &QTimer::timeout, this, &LandscapeMgr::clearMessage);
}
LandscapeMgr::~LandscapeMgr()
{
delete cardinalPoints;
if (oldLandscape)
{
delete oldLandscape;
oldLandscape=Q_NULLPTR;
}
delete landscape;
landscape = Q_NULLPTR;
qDebug() << "LandscapeMgr: Clearing cache of" << landscapeCache.size() << "landscapes totalling about " << landscapeCache.totalCost() << "MB.";
landscapeCache.clear(); // deletes all objects within.
}
/*************************************************************************
Reimplementation of the getCallOrder method
*************************************************************************/
double LandscapeMgr::getCallOrder(StelModuleActionName actionName) const
{
if (actionName==StelModule::ActionDraw)
return StelApp::getInstance().getModuleMgr().getModule("SporadicMeteorMgr")->getCallOrder(actionName)+20;
if (actionName==StelModule::ActionUpdate)
return StelApp::getInstance().getModuleMgr().getModule("SolarSystem")->getCallOrder(actionName)+10;
// GZ The next 2 lines are only required to test landscape transparency. They should be commented away for releases.
if (actionName==StelModule::ActionHandleMouseClicks)
return StelApp::getInstance().getModuleMgr().getModule("StelMovementMgr")->getCallOrder(actionName)-1;
return 0.;
}
void LandscapeMgr::update(double deltaTime)
{
if(needToRecreateAtmosphere && !loadingAtmosphere)
createAtmosphere();
const auto core = StelApp::getInstance().getCore();
const auto drawer = core->getSkyDrawer();
if(loadingAtmosphere && loadingAtmosphere->isLoading())
{
try
{
// Use no more than 1/60th of a second for this batch of loading
QElapsedTimer timer;
timer.start();
Atmosphere::LoadingStatus status={1,1};
while(loadingAtmosphere->isLoading() && timer.elapsed() < 1000/60)
status = loadingAtmosphere->stepDataLoading();
if(loadingAtmosphere->isLoading())
{
setAtmosphereShowMySkyStoppedWithError(false);
const auto percentDone = std::lround(100.*status.stepsDone/status.stepsToDo);
setAtmosphereShowMySkyStatusText(QString("%1 %2% %3").arg(q_("Loading..."), QString::number(percentDone), qc_("done","percentage of done")));
qDebug() << "Finished this batch of loading at" << percentDone << "%, will continue in the next frame";
}
else
{
setAtmosphereShowMySkyStatusText(q_("Switching models..."));
}
}
catch(Atmosphere::InitFailure const& error)
{
qWarning() << "ERROR: Failed to load atmosphere model data:" << error.what();
qWarning() << "WARNING: Falling back to the Preetham's model";
setAtmosphereShowMySkyStoppedWithError(true);
setAtmosphereShowMySkyStatusText(error.what());
loadingAtmosphere.reset();
}
}
if(loadingAtmosphere && loadingAtmosphere->isReadyToRender())
{
bool loaded = false;
if(drawer->getFlagHasAtmosphere())
{
// Fade out current atmosphere, then fade in the new one
if(atmosphere->getFlagShow())
{
atmosphere->setFlagShow(false);
}
else if(atmosphere->getFadeIntensity() == 0)
{
loadingAtmosphere->setFlagShow(true);
loadingAtmosphere->setFadeDuration(atmosphere->getFadeDuration());
loadingAtmosphere->setLightPollutionLuminance(atmosphere->getLightPollutionLuminance());
loaded = true;
}
}
else
{
loaded = true;
}
if(loaded)
{
atmosphere = std::move(loadingAtmosphere);
#ifdef ENABLE_SHOWMYSKY
if(dynamic_cast<AtmosphereShowMySky*>(atmosphere.get()))
setAtmosphereShowMySkyStatusText(q_("Loaded successfully"));
#endif
emit atmosphereModelChanged(getAtmosphereModel());
}
}
atmosphere->update(deltaTime);
if (oldLandscape)
{
// This is only when transitioning to newly loaded landscape. We must draw the old one until the new one is faded in completely.
oldLandscape->update(deltaTime);
if (getIsLandscapeFullyVisible())
{
oldLandscape->setFlagShow(false);
if (oldLandscape->getEffectiveLandFadeValue()< 0.01f)
{
// new logic: try to put old landscape to cache.
//qDebug() << "LandscapeMgr::update: moving oldLandscape " << oldLandscape->getId() << "to Cache. Cost:" << oldLandscape->getMemorySize()/(1024*1024)+1;
landscapeCache.insert(oldLandscape->getId(), oldLandscape, oldLandscape->getMemorySize()/(1024*1024)+1);
//qDebug() << "--> LandscapeMgr::update(): cache now contains " << landscapeCache.size() << "landscapes totalling about " << landscapeCache.totalCost() << "MB.";
oldLandscape=Q_NULLPTR;
}
}
}
landscape->update(deltaTime);
cardinalPoints->update(deltaTime);
// Compute the atmosphere color and intensity
// Compute the sun position in local coordinate
SolarSystem* ssystem = static_cast<SolarSystem*>(StelApp::getInstance().getModuleMgr().getModule("SolarSystem"));
// Compute the moon position in local coordinate
const auto sun = ssystem->getSun();
const auto moon = ssystem->getMoon();
const auto earth = ssystem->getEarth();
const auto currentPlanet = core->getCurrentPlanet();
const bool currentIsEarth = currentPlanet->getID() == earth->getID();
// First parameter in next call is used for particularly earth-bound computations in Schaefer's sky brightness model. Difference DeltaT makes no difference here.
// Temperature = 15°C, relative humidity = 40%
try
{
atmosphere->computeColor(core, core->getJDE(), *currentPlanet, *sun,
currentIsEarth ? moon.data() : nullptr, core->getCurrentLocation(),
15.f, 40.f, static_cast<float>(drawer->getExtinctionCoefficient()), atmosphereNoScatter);
}
catch(Atmosphere::InitFailure const& error)
{
qWarning().noquote() << "ShowMySky atmosphere model crashed:" << error.what();
qWarning() << "Loading Preetham model";
showMessage(q_("ShowMySky atmosphere model crashed. Loading Preetham model as a fallback."));
resetToFallbackAtmosphere();
}
core->getSkyDrawer()->reportLuminanceInFov(3.75f+atmosphere->getAverageLuminance()*3.5f, true);
// NOTE: Simple workaround for brightness of landscape when observing from the Sun.
if (currentPlanet->getID() == sun->getID())
{
landscape->setBrightness(1.0, 1.0);
return;
}
// Compute the ground luminance based on every planets around
// TBD: Reactivate and verify this code!? Source, reference?
// float groundLuminance = 0;
// const vector<Planet*>& allPlanets = ssystem->getAllPlanets();
// for (auto i=allPlanets.begin();i!=allPlanets.end();++i)
// {
// Vec3d pos = (*i)->getAltAzPos(core);
// pos.normalize();
// if (pos[2] <= 0)
// {
// // No need to take this body into the landscape illumination computation
// // because it is under the horizon
// }
// else
// {
// // Compute the Illuminance E of the ground caused by the planet in lux = lumen/m^2
// float E = pow10(((*i)->get_mag(core)+13.988)/-2.5);
// //qDebug() << "mag=" << (*i)->get_mag(core) << " illum=" << E;
// // Luminance in cd/m^2
// groundLuminance += E/0.44*pos[2]*pos[2]; // 1m^2 from 1.5 m above the ground is 0.44 sr.
// }
// }
// groundLuminance*=atmosphere->getFadeIntensity();
// groundLuminance=atmosphere->getAverageLuminance()/50;
// qDebug() << "Atmosphere lum=" << atmosphere->getAverageLuminance() << " ground lum=" << groundLuminance;
// qDebug() << "Adapted Atmosphere lum=" << eye->adaptLuminance(atmosphere->getAverageLuminance()) << " Adapted ground lum=" << eye->adaptLuminance(groundLuminance);
// compute global ground brightness in a simplistic way, directly in RGB
double landscapeBrightness=0.0;
if (getFlagLandscapeUseMinimalBrightness())
{
// Setting from landscape.ini has priority if enabled
if (getFlagLandscapeSetsMinimalBrightness() && landscape->getLandscapeMinimalBrightness()>=0)
landscapeBrightness = landscape->getLandscapeMinimalBrightness();
else
landscapeBrightness = getDefaultMinimalBrightness();
}
Vec3d sunPos = sun->getAltAzPosAuto(core);
sunPos.normalize();
Vec3d moonPos = moon->getAltAzPosAuto(core);
moonPos.normalize();
// With atmosphere on, we define the solar brightness contribution zero when the sun is 8 degrees below the horizon.
// The multiplier of 1.5 just looks better, it somehow represents illumination by scattered sunlight.
// Else, we should account for sun's diameter but else just apply Lambertian Cos-rule and check with landscape opacity.
double sinSunAngle = 0.0;
if(atmosphere->getFlagShow())
{
sinSunAngle=sin(qMin(M_PI_2, asin(sunPos[2])+8.*M_PI/180.));
if(sinSunAngle > -0.1/1.5 )
landscapeBrightness += 1.5*(sinSunAngle+0.1/1.5);
}
else
{
// In case we have exceptionally deep horizons ("Little Prince planet"), the sun will rise somehow over that line and demand light on the landscape.
sinSunAngle=sin(qMin(M_PI_2, asin(qBound(-1.0, sunPos[2]-landscape->getSinMinAltitudeLimit(), 1.0) ) + (0.25 *M_PI_180)));
if(sinSunAngle > 0.0)
landscapeBrightness += (1.0-static_cast<double>(landscape->getOpacity(sunPos)))*sinSunAngle;
}
// GZ: 2013-09-25 Take light pollution into account!
const float nelm = StelCore::luminanceToNELM(drawer->getLightPollutionLuminance());
float pollutionAddonBrightness=(15.5f-2*nelm)*0.025f; // 0..8, so we assume empirical linear brightening 0..0.02
float lunarAddonBrightness=0.f;
if (currentIsEarth && moonPos[2] > -0.1/1.5)
lunarAddonBrightness = qMax(0.2f/-12.f*moon->getVMagnitudeWithExtinction(core),0.f)*static_cast<float>(moonPos[2]);
landscapeBrightness += static_cast<double>(qMax(lunarAddonBrightness, pollutionAddonBrightness));
// TODO make this more generic for non-atmosphere planets
if(atmosphere->getFadeIntensity() > 0.99999f )
{
// If the atmosphere is on, a solar eclipse might darken the sky
// otherwise we just use the sun position calculation above
landscapeBrightness *= static_cast<double>(atmosphere->getRealDisplayIntensityFactor()+0.1f);
}
// TODO: should calculate dimming with solar eclipse even without atmosphere on
// Brightness can't be over 1.f (see https://bugs.launchpad.net/stellarium/+bug/1115364)
if (landscapeBrightness>0.95)
landscapeBrightness = 0.95;
// GZ's rules and intentions for lightscape brightness:
// lightscapeBrightness >0 makes sense only for sun below horizon.
// If atmosphere on, we mix it in with darkening twilight. If atmosphere off, we can switch on more apruptly.
// Note however that lightscape rendering does not per se depend on atmosphere on/off.
// This allows for illuminated windows or light panels on spaceships. If a landscape's lightscape
// contains light smog of a city, it should also be shown if atmosphere is switched off.
// (Configure another landscape without light smog to avoid, or just switch off lightscape.)
double lightscapeBrightness=0.0;
const double sinSunAlt = sunPos[2];
if (atmosphere->getFlagShow())
{
// light pollution layer is mixed in at -3...-8 degrees.
if (sinSunAlt<-0.14)
lightscapeBrightness=1.0;
else if (sinSunAlt<-0.05)
lightscapeBrightness = 1.0-(sinSunAlt+0.14)/(-0.05+0.14);
}
else
{
// If we have no atmosphere, we can assume windows and panels on spaceships etc. are switched on whenever the sun does not shine, i.e. when sun is blocked by landscape.
lightscapeBrightness= static_cast<double>(landscape->getOpacity(sunPos));
}
landscape->setBrightness(landscapeBrightness, lightscapeBrightness);
if (getFlagLandscapeUseTransparency())
landscape->setTransparency(landscapeTransparency);
messageFader.update(static_cast<int>(deltaTime*1000));
}
void LandscapeMgr::draw(StelCore* core)
{
// For observers we never draw anything of landscape, atmosphere, cardinals.
if (core->getCurrentPlanet()->getPlanetType()==Planet::isObserver)
return;
StelSkyDrawer* drawer=core->getSkyDrawer();
// Draw the atmosphere
if (!getFlagAtmosphereNoScatter() && core->getFlagClearSky())
atmosphere->draw(core);
// GZ 2016-01: When we draw the atmosphere with a low sun, it is possible that the glaring red ball is overpainted and thus invisible.
// Attempt to draw the sun only here while not having drawn it by SolarSystem:
//if (atmosphere->getFlagShow())
if (drawer->getFlagDrawSunAfterAtmosphere())
{
SolarSystem* ssys = GETSTELMODULE(SolarSystem);
PlanetP sun=ssys->getSun();
QFont font;
font.setPixelSize(StelApp::getInstance().getScreenFontSize());
sun->draw(core, 0, font);
}
// Draw the landscape
if (oldLandscape)
oldLandscape->draw(core, flagPolyLineDisplayedOnly);
landscape->draw(core, flagPolyLineDisplayedOnly);
// Draw the cardinal points
cardinalPoints->draw(core, static_cast<double>(StelApp::getInstance().getCore()->getCurrentLocation().getLatitude()));
if(messageFader.getInterstate())
{
const StelProjectorP prj = core->getProjection(StelCore::FrameEquinoxEqu);
StelPainter painter(prj);
QFont font;
font.setPixelSize(16);
painter.setFont(font);
painter.setColor(1, 0, 0, messageFader.getInterstate());
painter.drawText(83, 70, messageToShow);
}
}
// Some element in drawing order behind LandscapeMgr can call this at the end of its own draw() to overdraw with the polygon line and gazetteer.
void LandscapeMgr::drawPolylineOnly(StelCore* core)
{
// For observers we never draw anything of landscape, atmosphere, cardinals.
if (core->getCurrentPlanet()->getPlanetType()==Planet::isObserver)
return;
// Draw the landscape
if (oldLandscape && oldLandscape->hasLandscapePolygon())
oldLandscape->draw(core, true);
if (landscape->hasLandscapePolygon())
landscape->draw(core, true);
// Draw the cardinal points
cardinalPoints->draw(core, static_cast<double>(StelApp::getInstance().getCore()->getCurrentLocation().getLatitude()));
}
void LandscapeMgr::createAtmosphere()
{
const auto modelName=getAtmosphereModel();
const auto modelConfig=modelName.toLower();
bool needResetConfig=false;
if(modelConfig==ATMOSPHERE_MODEL_CONF_VAL_PREETHAM)
{
loadingAtmosphere.reset(new AtmospherePreetham(skylight));
}
#ifdef ENABLE_SHOWMYSKY
else if(modelConfig==ATMOSPHERE_MODEL_CONF_VAL_SHOWMYSKY)
{
try
{
// Clear status so that if a repeated error happens, we do emit a signal that will update the GUI.
setAtmosphereShowMySkyStatusText("");
setAtmosphereShowMySkyStoppedWithError(false);
const auto core = StelApp::getInstance().getCore();
loadingAtmosphere.reset(new AtmosphereShowMySky(core->getCurrentLocation().altitude));
if(!atmosphere)
{
// We're just loading the first atmosphere in the run of Stellarium. Initialize it synchronously.
while(loadingAtmosphere->isLoading())
loadingAtmosphere->stepDataLoading();
setAtmosphereShowMySkyStoppedWithError(false);
setAtmosphereShowMySkyStatusText(q_("Loaded successfully"));
}
else
{
setAtmosphereShowMySkyStoppedWithError(false);
setAtmosphereShowMySkyStatusText(QString("%1 0% %2").arg(q_("Loading..."), qc_("done","percentage of done")));
}
}
catch(Atmosphere::InitFailure const& error)
{
qWarning() << "ERROR: Failed to initialize ShowMySky atmosphere model:" << error.what();
qWarning() << "WARNING: Falling back to the Preetham's model";
loadingAtmosphere.reset(new AtmospherePreetham(skylight));
needResetConfig=true;
setAtmosphereShowMySkyStoppedWithError(true);
setAtmosphereShowMySkyStatusText(error.what());
}
}
#endif
else
{
qWarning() << "Unsupported atmosphere model" << modelName;
loadingAtmosphere.reset(new AtmospherePreetham(skylight));
needResetConfig=true;
}
if(!atmosphere)
{
// We're just loading the first atmosphere in the run of Stellarium. The atmosphere is fully loaded by this point.
atmosphere = std::move(loadingAtmosphere);
const auto conf=StelApp::getInstance().getSettings();
setFlagAtmosphere(conf->value("landscape/flag_atmosphere", true).toBool());
setAtmosphereFadeDuration(conf->value("landscape/atmosphere_fade_duration",0.5).toFloat());
const auto drawer = StelApp::getInstance().getCore()->getSkyDrawer();
setAtmosphereLightPollutionLuminance(drawer->getLightPollutionLuminance());
}
if(needResetConfig)
{
// We've failed to apply the setting, so reset to the fallback value
const auto conf=StelApp::getInstance().getSettings();
conf->setValue(ATMOSPHERE_MODEL_CONFIG_KEY, ATMOSPHERE_MODEL_CONF_VAL_PREETHAM);
}
needToRecreateAtmosphere=false;
}
void LandscapeMgr::resetToFallbackAtmosphere()
{
StelApp::getInstance().getSettings()->setValue(ATMOSPHERE_MODEL_CONFIG_KEY, ATMOSPHERE_MODEL_CONF_VAL_PREETHAM);
atmosphere.reset();
createAtmosphere();
}
void LandscapeMgr::init()
{
QSettings* conf = StelApp::getInstance().getSettings();
Q_ASSERT(conf);
StelApp *app = &StelApp::getInstance();
Q_ASSERT(app);
landscapeCache.setMaxCost(conf->value("landscape/cache_size_mb", 100).toInt());
qDebug() << "LandscapeMgr: initialized Cache for" << landscapeCache.maxCost() << "MB.";
// SET SIMPLE PROPERTIES FIRST, before loading the landscape (Loading may already make use of them! GH#1237)
setFlagLandscapeSetsLocation(conf->value("landscape/flag_landscape_sets_location",false).toBool());
setFlagLandscapeAutoSelection(conf->value("viewing/flag_landscape_autoselection", false).toBool());
setFlagEnvironmentAutoEnable(conf->value("viewing/flag_environment_auto_enable",true).toBool());
// Set minimal brightness for landscape. This feature has been added for folks which say "landscape is super dark, please add light". --AW
setDefaultMinimalBrightness(conf->value("landscape/minimal_brightness", 0.01).toDouble());
setFlagLandscapeUseMinimalBrightness(conf->value("landscape/flag_minimal_brightness", false).toBool());
setFlagLandscapeSetsMinimalBrightness(conf->value("landscape/flag_landscape_sets_minimal_brightness",false).toBool());
const auto var = conf->value(ATMOSPHERE_MODEL_PATH_CONFIG_KEY);
if(!var.isValid())
conf->setValue(ATMOSPHERE_MODEL_PATH_CONFIG_KEY, getDefaultAtmosphereModelPath());
createAtmosphere();
// Put the atmosphere's Skylight under the StelProperty system (simpler and more consistent GUI)
StelApp::getInstance().getStelPropertyManager()->registerObject(&skylight);
defaultLandscapeID = conf->value("init_location/landscape_name").toString();
// We must make sure to allow auto location or command-line location even if landscape usually should set location.
StelCore *core = StelApp::getInstance().getCore();
const bool setLocationFromIPorCLI=((conf->value("init_location/location", "auto").toString() == "auto") || (core->getCurrentLocation().state=="CLI"));
const bool shouldThenSetLocation=getFlagLandscapeSetsLocation();
if (setLocationFromIPorCLI) setFlagLandscapeSetsLocation(false);
setCurrentLandscapeID(defaultLandscapeID);
setFlagLandscapeSetsLocation(shouldThenSetLocation);
setFlagUseLightPollutionFromDatabase(conf->value("viewing/flag_light_pollution_database", false).toBool());
setFlagLandscape(conf->value("landscape/flag_landscape", conf->value("landscape/flag_ground", true).toBool()).toBool());
setFlagFog(conf->value("landscape/flag_fog",true).toBool());
setFlagIllumination(conf->value("landscape/flag_enable_illumination_layer", true).toBool());
setFlagLabels(conf->value("landscape/flag_enable_labels", true).toBool());
setFlagPolyLineDisplayed(conf->value("landscape/flag_polyline_only", false).toBool());
setPolyLineThickness(conf->value("landscape/polyline_thickness", 1).toInt());
setLabelFontSize(conf->value("landscape/label_font_size", 18).toInt());
setLabelColor(Vec3f(conf->value("landscape/label_color", "0.2,0.8,0.2").toString()));
setFlagLandscapeUseTransparency(conf->value("landscape/flag_transparency", false).toBool());
setLandscapeTransparency(conf->value("landscape/transparency", 0.5).toDouble());
cardinalPoints = new Cardinals();
cardinalPoints->setFlagShow4WCRLabels(conf->value("viewing/flag_cardinal_points", true).toBool());
cardinalPoints->setFlagShow8WCRLabels(conf->value("viewing/flag_ordinal_points", true).toBool());
cardinalPoints->setFlagShow16WCRLabels(conf->value("viewing/flag_16wcr_points", false).toBool());
cardinalPoints->setFlagShow32WCRLabels(conf->value("viewing/flag_32wcr_points", false).toBool());
// Load colors from config file
QString defaultColor = conf->value("color/default_color").toString();
setColorCardinalPoints(Vec3f(conf->value("color/cardinal_color", defaultColor).toString()));
currentPlanetName = app->getCore()->getCurrentLocation().planetName;
//Bortle scale is managed by SkyDrawer
StelSkyDrawer* drawer = app->getCore()->getSkyDrawer();
Q_ASSERT(drawer);
setAtmosphereLightPollutionLuminance(drawer->getLightPollutionLuminance());
connect(app->getCore(), SIGNAL(locationChanged(StelLocation)), this, SLOT(onLocationChanged(StelLocation)));
connect(app->getCore(), SIGNAL(targetLocationChanged(const StelLocation&, const QString&)), this, SLOT(onTargetLocationChanged(const StelLocation&, const QString&)));
connect(drawer, &StelSkyDrawer::lightPollutionLuminanceChanged, this, &LandscapeMgr::setAtmosphereLightPollutionLuminance);
connect(app, SIGNAL(languageChanged()), this, SLOT(updateI18n()));
QString displayGroup = N_("Display Options");
addAction("actionShow_Atmosphere", displayGroup, N_("Atmosphere"), "atmosphereDisplayed", "A");
addAction("actionShow_Fog", displayGroup, N_("Fog"), "fogDisplayed", "F");
addAction("actionShow_Cardinal_Points", displayGroup, N_("Cardinal points"), "cardinalPointsDisplayed", "Q");
addAction("actionShow_Intercardinal_Points", displayGroup, N_("Ordinal (Intercardinal) points"), "ordinalPointsDisplayed");
addAction("actionShow_Secondary_Intercardinal_Points", displayGroup, N_("Secondary Intercardinal points"), "ordinal16WRPointsDisplayed");
addAction("actionShow_Tertiary_Intercardinal_Points", displayGroup, N_("Tertiary Intercardinal points"), "ordinal32WRPointsDisplayed");
addAction("actionShow_Ground", displayGroup, N_("Ground"), "landscapeDisplayed", "G");
addAction("actionShow_LandscapeIllumination", displayGroup, N_("Landscape illumination"), "illuminationDisplayed", "Shift+G");
addAction("actionShow_LandscapeLabels", displayGroup, N_("Landscape labels"), "labelsDisplayed", "Ctrl+Shift+G");
addAction("actionShow_LightPollutionFromDatabase", displayGroup, N_("Light pollution data from locations database"), "flagUseLightPollutionFromDatabase");
// Details: https://github.com/Stellarium/stellarium/issues/171
addAction("actionShow_LightPollutionIncrease", displayGroup, N_("Increase light pollution"), "increaseLightPollution()");
addAction("actionShow_LightPollutionReduce", displayGroup, N_("Reduce light pollution"), "reduceLightPollution()");
addAction("actionShow_LightPollutionCyclicChange", displayGroup, N_("Cyclic change in light pollution"), "cyclicChangeLightPollution()");
}
bool LandscapeMgr::setCurrentLandscapeID(const QString& id, const double changeLocationDuration)
{
if (id.isEmpty())
return false;
//prevent unnecessary changes/file access
if(id==currentLandscapeID)
return false;
if (!getAllLandscapeIDs().contains(id))
{
qDebug() << "LandscapeMgr::setCurrentLandscapeID: unknown landscape" << id << ", using 'zero'";
return setCurrentLandscapeID("zero", changeLocationDuration);
}
Landscape* newLandscape;
// There is a slight chance that we switch back to oldLandscape while oldLandscape is still fading away.
// in this case it is not yet stored in cache, but obviously available. So we just swap places.
if (oldLandscape && oldLandscape->getId()==id)
{
newLandscape=oldLandscape;
}
else
{
// We want to lookup the landscape ID (dir) from the name.
newLandscape= landscapeCache.take(id);
if (newLandscape)
{
#ifndef NDEBUG
qDebug() << "LandscapeMgr::setCurrentLandscapeID():: taken " << id << "from cache...";
qDebug() << ".-->LandscapeMgr::setCurrentLandscapeID(): cache contains " << landscapeCache.size() << "landscapes totalling about " << landscapeCache.totalCost() << "MB.";
#endif
}
else
{
#ifndef NDEBUG
qDebug() << "LandscapeMgr::setCurrentLandscapeID: Loading from file:" << id ;
#endif
newLandscape = createFromFile(StelFileMgr::findFile("landscapes/" + id + "/landscape.ini"), id);
}
if (!newLandscape)
{
qWarning() << "ERROR while loading landscape " << "landscapes/" + id + "/landscape.ini";
return false;
}
}
// Keep current landscape for a while, while new landscape fades in!
// This prevents subhorizon sun or grid becoming briefly visible.
if (landscape)
{
// Copy display parameters from previous landscape to new one
newLandscape->setFlagShow(landscape->getFlagShow());
newLandscape->setFlagShowFog(landscape->getFlagShowFog());
newLandscape->setFlagShowIllumination(landscape->getFlagShowIllumination());
newLandscape->setFlagShowLabels(landscape->getFlagShowLabels());
newLandscape->setLabelFontSize(landscape->getLabelFontSize());
newLandscape->setLabelColor(landscape->getLabelColor());
// If we have an oldLandscape that is not just swapped back, put that into cache.
if (oldLandscape && oldLandscape!=newLandscape)
{
#ifndef NDEBUG
qDebug() << "LandscapeMgr::setCurrent: moving oldLandscape " << oldLandscape->getId() << "to Cache. Cost:" << oldLandscape->getMemorySize()/(1024*1024)+1;
#endif
landscapeCache.insert(oldLandscape->getId(), oldLandscape, oldLandscape->getMemorySize()/(1024*1024)+1);
#ifndef NDEBUG
qDebug() << "-->LandscapeMgr::setCurrentLandscapeId(): cache contains " << landscapeCache.size() << "landscapes totalling about " << landscapeCache.totalCost() << "MB.";
#endif
}
oldLandscape = landscape; // keep old while transitioning!
}
landscape=newLandscape;
currentLandscapeID = id;
if (getFlagLandscapeSetsLocation() && landscape->hasLocation())
{
StelCore *core = StelApp::getInstance().getCore();
core->moveObserverTo(landscape->getLocation(), changeLocationDuration, changeLocationDuration, id);
StelSkyDrawer* drawer=core->getSkyDrawer();
if (landscape->getLocation().ianaTimeZone.length())
{
core->setCurrentTimeZone(landscape->getLocation().ianaTimeZone);
}
if (landscape->getDefaultFogSetting() >-1)
{
setFlagFog(static_cast<bool>(landscape->getDefaultFogSetting()));
landscape->setFlagShowFog(static_cast<bool>(landscape->getDefaultFogSetting()));
}
if (landscape->getDefaultLightPollutionLuminance().isValid())
{
drawer->setLightPollutionLuminance(landscape->getDefaultLightPollutionLuminance().toFloat());
}
if (landscape->getDefaultAtmosphericExtinction() >= 0.0)
{
drawer->setExtinctionCoefficient(landscape->getDefaultAtmosphericExtinction());
}
if (landscape->getDefaultAtmosphericTemperature() > -273.15)
{
drawer->setAtmosphereTemperature(landscape->getDefaultAtmosphericTemperature());
}
if (landscape->getDefaultAtmosphericPressure() >= 0.0)
{
drawer->setAtmospherePressure(landscape->getDefaultAtmosphericPressure());
}
else if (landscape->getDefaultAtmosphericPressure() < 0.0)
{
// compute standard pressure for standard atmosphere in given altitude if landscape.ini coded as atmospheric_pressure=-1
// International altitude formula found in Wikipedia.
double alt=landscape->getLocation().altitude;