-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathSimulationModel.cpp
More file actions
2126 lines (1692 loc) · 69.2 KB
/
SimulationModel.cpp
File metadata and controls
2126 lines (1692 loc) · 69.2 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
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
/* Bridge Command 5.0 Ship Simulator
Copyright (C) 2014 James Packer
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License version 2 as
published by the Free Software Foundation
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, Fifth Floor, Boston, MA 02110-1301 USA. */
#include "SimulationModel.hpp"
#include "ScenarioDataStructure.hpp"
#include "GUIMain.hpp"
#include "Terrain.hpp"
#include "Sky.hpp"
#include "Buoys.hpp"
#include "Sound.hpp"
#include "IniFile.hpp"
#include "Constants.hpp"
#include "Utilities.hpp"
#include <cmath>
#include <fstream>
#ifdef WITH_PROFILING
#include "iprof.hpp"
#else
#define IPROF(a) //intentionally empty placeholder
#endif
//#include <ctime>
//using namespace irr;
SimulationModel::SimulationModel(irr::IrrlichtDevice* dev,
irr::scene::ISceneManager* scene,
GUIMain* gui,
Sound* sound,
ScenarioData scenarioData,
ModelParameters modelParameters):
manOverboard(irr::core::vector3df(0,0,0),scene,dev,this) //Initialise MOB
{
//get reference to scene manager
device = dev;
smgr = scene;
driver = scene->getVideoDriver();
guiMain = gui;
this->sound = sound;
isMouseDown = false;
moveViewWithPrimary = true;
//Store a serialised form of the scenario loaded, as we may want to send this over the network
serialisedScenarioData = scenarioData.serialise(false);
scenarioName = scenarioData.scenarioName;
// Store model parameters
this->modelParameters = modelParameters;
//Set loop number to zero
loopNumber = 0;
worldName = scenarioData.worldName;
irr::f32 startTime = scenarioData.startTime;
irr::u32 startDay=scenarioData.startDay;
irr::u32 startMonth=scenarioData.startMonth;
irr::u32 startYear=scenarioData.startYear;
//load the sun times
irr::f32 sunRise = scenarioData.sunRise;
irr::f32 sunSet = scenarioData.sunSet;
if(sunRise==0.0) {sunRise=6;}
if(sunSet==0.0) {sunSet=18;}
//load the weather:
//Fixme: add in wind direction etc
weather = scenarioData.weather;
rainIntensity = scenarioData.rainIntensity;
visibilityRange = scenarioData.visibilityRange;
if (visibilityRange <= 0) {visibilityRange = 5*M_IN_NM;} //TODO: Check units
windDirection = scenarioData.windDirection;
windSpeed = scenarioData.windSpeed;
//std::cout << "Wind direction: " << windDirection << " Wind speed: " << windSpeed << std::endl;
//Fixme: Think about time zone handling
//Fixme: Note that if the time_t isn't long enough, 2038 problem exists
scenarioOffsetTime = Utilities::dmyToTimestamp(startDay,startMonth,startYear);//Time in seconds to start of scenario day (unix timestamp for 0000h on day scenario starts)
//set internal scenario time to start
scenarioTime = startTime * SECONDS_IN_HOUR;
//Set initial tide height to zero
tideHeight = 0;
if (worldName == "") {
//Could not load world name from scenario, so end here
std::cerr << "World model name not defined" << std::endl;
exit(EXIT_FAILURE);
}
//construct path to world model
std::string worldPath = "World/";
worldPath.append(worldName);
//Check if this world model exists in the user dir.
std::string userFolder = Utilities::getUserDir();
if (Utilities::pathExists(userFolder + worldPath)) {
worldPath = userFolder + worldPath;
}
// Store world model readme.txt file contents here if available
std::string worldReadmePath = worldPath + "/readme.txt";
worldModelReadmeText = "";
if (Utilities::pathExists(worldReadmePath)) {
std::ifstream file(worldReadmePath.c_str());
if (file.is_open()) {
std::string line;
while (std::getline(file, line)) {
worldModelReadmeText.append(line);
worldModelReadmeText.append("\n");
}
}
}
//Add terrain: Needs to happen first, so the terrain parameters are available
terrain.load(worldPath, smgr, device, modelParameters.limitTerrainResolution);
//sky box/dome
Sky sky (smgr);
//Load own ship model.
// TODO: It would be better to pass in modelParameters directly
ownShip.load(scenarioData.ownShipData,
modelParameters.numberOfContactPoints,
modelParameters.minContactPointSpacing,
modelParameters.contactStiffnessFactor,
modelParameters.contactDampingFactor,
modelParameters.frictionCoefficient,
modelParameters.tanhFrictionFactor,
smgr,
this,
&terrain,
device);
if(modelParameters.mode == OperatingMode::Secondary) {
ownShip.setSpeed(0); //Don't start moving if in secondary mode
}
//add water
bool waterReflection = true;
if (modelParameters.vrMode == true) {
waterReflection = false;
}
water.load(smgr,ownShip.getSceneNode(),weather,modelParameters.disableShaders,waterReflection,modelParameters.waterSegments);
/* To be replaced by getting information and passing into gui load method.
//Tell gui to hide the second engine scroll bar if we have a single engine
if (ownShip.isSingleEngine()) {
gui->setSingleEngine();
}
//Tell gui to hide all ship controls if in secondary mode
if (mode == OperatingMode::Secondary) {
gui->hideEngineAndRudder();
// TODO gui->hideWheel();
// DEE_NOV22 todo hide schottels engine indicators etc
}
//Tell the GUI what instruments to display - currently GPS and depth sounder
gui->setInstruments(ownShip.hasDepthSounder(),ownShip.getMaxSounderDepth(),ownShip.hasGPS());
*/
//Load the radar with config parameters
radarCalculation.load(ownShip.getRadarConfigFile(),device);
//set camera zoom to 1
currentZoom = 1.0;
zoomLevel = 7.0; //Default zoom of 7x
//make a camera, setting parent and offset
std::vector<irr::core::vector3df> views = ownShip.getCameraViews(); //Get the initial camera offset from the own ship model
std::vector<bool> isHighView = ownShip.getCameraIsHighView(); //Are these special 'looking down' views
irr::f32 angleCorrection = ownShip.getAngleCorrection();
camera.load(smgr,device->getLogger(),ownShip.getSceneNode(),views, isHighView,irr::core::degToRad(modelParameters.viewAngle),modelParameters.lookAngle,angleCorrection);
camera.setNearValue(modelParameters.cameraMinDistance);
camera.setFarValue(modelParameters.cameraMaxDistance);
//make ambient light
light.load(smgr,sunRise,sunSet, camera.getSceneNode());
//Load other ships
otherShips.load(scenarioData.otherShipsData,scenarioTime,modelParameters.mode,smgr,this,device);
//Load buoys
buoys.load(worldPath, smgr, this,device);
//Load land objects
landObjects.load(worldPath, smgr, this, &terrain, device);
//Load land lights
landLights.load(worldPath, smgr, this, terrain);
//Load tidal information
tide.load(worldPath, scenarioData);
//Load rain
rain.load(smgr, camera.getSceneNode(), device);
//Set up 3d engine/wheel controls/visualisation
if (isAzimuthDrive()) {
portEngineVisual.load(smgr, ownShip.getSceneNode(), ownShip.getPortEngineControlPosition(), 1.0 / ownShip.getScaleFactor(), 1, 2); // 2=schottel base
stbdEngineVisual.load(smgr, ownShip.getSceneNode(), ownShip.getStbdEngineControlPosition(), 1.0 / ownShip.getScaleFactor(), 1, 2);
portAzimuthThrottleVisual.load(smgr, portEngineVisual.getSceneNode(), irr::core::vector3df(0,0,0), 1.0, 0, 3); // 3 = schottel lever
stbdAzimuthThrottleVisual.load(smgr, stbdEngineVisual.getSceneNode(), irr::core::vector3df(0,0,0), 1.0, 0, 3);
} else {
portEngineVisual.load(smgr, ownShip.getSceneNode(), ownShip.getPortEngineControlPosition(), 1.0 / ownShip.getScaleFactor(), 0, 0); // 0 = regular throttle
stbdEngineVisual.load(smgr, ownShip.getSceneNode(), ownShip.getStbdEngineControlPosition(), 1.0 / ownShip.getScaleFactor(), 0, 0);
wheelVisual.load(smgr, ownShip.getSceneNode(), ownShip.getWheelControlPosition(), ownShip.getWheelControlScale() / ownShip.getScaleFactor(), 2, 1); // 1 = wheel
}
//make a radar screen, setting parent and offset from own ship
radarScreen.load(smgr,ownShip.getSceneNode(), ownShip.getScreenDisplayPosition(), ownShip.getScreenDisplaySize(), ownShip.getScreenDisplayTilt());
//make radar image - one for the background render, and one with any 2d drawing on top
//Make as big as the maximum screen display size (next power of 2), and then only use as much as is needed to get 1:1 image to screen pixel mapping
irr::u32 radarTextureSize = driver->getScreenSize().Height*0.4; // Optimised for the small radar screen (Where 0.6*screen height is used for the 3d view). We should have a higher resolution for full radar view
irr::u32 largeRadarTextureSize = driver->getScreenSize().Height; // Optimised for the large radar screen
//Find next power of 2 size
radarTextureSize = std::pow(2,std::ceil(std::log2(radarTextureSize)));
largeRadarTextureSize = std::pow(2,std::ceil(std::log2(largeRadarTextureSize)));
//In simulationModel, keep track of the used size, and pass this to gui etc.
radarImage = driver->createImage (irr::video::ECF_A8R8G8B8, irr::core::dimension2d<irr::u32>(radarTextureSize, radarTextureSize)); //Create image for radar calculation to work on
radarImageOverlaid = driver->createImage (irr::video::ECF_A8R8G8B8, irr::core::dimension2d<irr::u32>(radarTextureSize, radarTextureSize)); //Create image for radar calculation to work on
radarImageLarge = driver->createImage (irr::video::ECF_A8R8G8B8, irr::core::dimension2d<irr::u32>(largeRadarTextureSize, largeRadarTextureSize)); //Create image for radar calculation to work on
radarImageOverlaidLarge = driver->createImage (irr::video::ECF_A8R8G8B8, irr::core::dimension2d<irr::u32>(largeRadarTextureSize, largeRadarTextureSize)); //Create image for radar calculation to work on
//Images will be filled with background colour in RadarCalculation
//make radar camera
std::vector<irr::core::vector3df> radarViews; //Get the initial camera offset from the radar screen
std::vector<bool> radarViewsLookDown; //Not needed for the radar camera, but needed for compatability
irr::f32 screenTilt = ownShip.getScreenDisplayTilt();
radarViews.push_back(ownShip.getScreenDisplayPosition() + irr::core::vector3df(0,0.5*sin(irr::core::DEGTORAD*screenTilt)*ownShip.getScreenDisplaySize(),-0.5*cos(irr::core::DEGTORAD*screenTilt)*ownShip.getScreenDisplaySize()));
radarViewsLookDown.push_back(false);
radarCamera.load(smgr, device->getLogger(),ownShip.getSceneNode(),radarViews,radarViewsLookDown,irr::core::PI/2.0,0,0);
radarCamera.setLookUp(-1.0 * screenTilt); //FIXME: Why doesn't simply -1.0*screenTilt work?
radarCamera.updateViewport(1.0);
radarCamera.setNearValue(0.8*0.5*ownShip.getScreenDisplaySize());
radarCamera.setFarValue(1.2*0.5*ownShip.getScreenDisplaySize());
//Hide the man overboard model
manOverboard.setVisible(false);
//initialise offset
offsetPosition = irr::core::vector3d<int64_t>(0,0,0);
//store time
previousTime = device->getTimer()->getTime();
guiData = new GUIData;
// Initialise as paused to start with
guiData->paused = true;
} //end of SimulationModel constructor
SimulationModel::~SimulationModel()
{
radarImage->drop(); //We created this with 'create', so drop it when we're finished
radarImageOverlaid->drop(); //We created this with 'create', so drop it when we're finished
radarImageLarge->drop(); //We created this with 'create', so drop it when we're finished
radarImageOverlaidLarge->drop(); //We created this with 'create', so drop it when we're finished
delete guiData;
}
irr::f32 SimulationModel::longToX(irr::f32 longitude) const
{
return terrain.longToX(longitude); //Cascade to terrain
}
irr::f32 SimulationModel::latToZ(irr::f32 latitude) const
{
return terrain.latToZ(latitude); //Cascade to terrain
}
void SimulationModel::setSpeed(irr::f32 spd)
{
ownShip.setSpeed(spd);
}
irr::f32 SimulationModel::getLat() const{
return terrain.zToLat(ownShip.getPosition().Z + offsetPosition.Z);
}
irr::f32 SimulationModel::getLong() const{
return terrain.xToLong(ownShip.getPosition().X + offsetPosition.X);
}
irr::f32 SimulationModel::getPosX() const{
return ownShip.getPosition().X + offsetPosition.X;
}
irr::f32 SimulationModel::getPosZ() const{
return ownShip.getPosition().Z + offsetPosition.Z;
}
irr::f32 SimulationModel::getCOG() const{
return ownShip.getCOG();
}
irr::f32 SimulationModel::getSOG() const{
return ownShip.getSOG();
}
irr::f32 SimulationModel::getDepth() const{
return ownShip.getDepth();
}
irr::f32 SimulationModel::getWaveHeight(irr::f32 posX, irr::f32 posZ) const {
return water.getWaveHeight(posX,posZ);
}
irr::core::vector2df SimulationModel::getLocalNormals(irr::f32 relPosX, irr::f32 relPosZ) const {
return water.getLocalNormals(relPosX,relPosZ);
}
irr::core::vector2df SimulationModel::getTidalStream(irr::f32 longitude, irr::f32 latitude, uint64_t requestTime) const {
if (streamOverride) {
irr::core::vector2df overrideStream;
overrideStream.X = sin(streamOverrideDirection*irr::core::DEGTORAD)*streamOverrideSpeed*KTS_TO_MPS;
overrideStream.Y = cos(streamOverrideDirection*irr::core::DEGTORAD)*streamOverrideSpeed*KTS_TO_MPS;
return overrideStream;
} else {
return tide.getTidalStream(longitude,latitude,requestTime);
}
}
// void SimulationModel::getTime(irr::u8& hour, irr::u8& min, irr::u8& sec) const{
// //FIXME: Complete
// }
//void SimulationModel::getDate(irr::u8& day, irr::u8& month, irr::u16& year) const{
// //FIXME: Complete
//}
uint64_t SimulationModel::getTimestamp() const{
return absoluteTime;
}
uint64_t SimulationModel::getTimeOffset() const { //The timestamp at the start of the first day of the scenario
return scenarioOffsetTime;
}
void SimulationModel::setTimeDelta(irr::f32 scenarioTime) {
this->scenarioTime = scenarioTime;
}
irr::f32 SimulationModel::getTimeDelta() const { //The change in time (s) since the start of the start day of the scenario
return scenarioTime;
}
irr::u32 SimulationModel::getNumberOfOtherShips() const {
return otherShips.getNumber();
}
irr::u32 SimulationModel::getNumberOfBuoys() const {
return buoys.getNumber();
}
std::string SimulationModel::getOtherShipName(int number) const{
return otherShips.getName(number);
}
irr::f32 SimulationModel::getOtherShipPosX(int number) const{
return otherShips.getPosition(number).X + offsetPosition.X;
}
irr::f32 SimulationModel::getOtherShipPosZ(int number) const{
return otherShips.getPosition(number).Z + offsetPosition.Z;
}
irr::f32 SimulationModel::getOtherShipLong(int number) const{
return terrain.xToLong(getOtherShipPosX(number));
}
irr::f32 SimulationModel::getOtherShipLat(int number) const{
return terrain.zToLat(getOtherShipPosZ(number));
}
irr::f32 SimulationModel::getOtherShipHeading(int number) const{
return otherShips.getHeading(number);
}
irr::f32 SimulationModel::getOtherShipSpeed(int number) const{
return otherShips.getSpeed(number);
}
irr::u32 SimulationModel::getOtherShipMMSI(int number) const{
return otherShips.getMMSI(number);
}
void SimulationModel::setOtherShipMMSI(int number, irr::u32 mmsi) {
otherShips.setMMSI(number,mmsi);
}
void SimulationModel::setOtherShipHeading(int number, irr::f32 hdg){
otherShips.setHeading(number, hdg);
}
void SimulationModel::setOtherShipSpeed(int number, irr::f32 speed){
otherShips.setSpeed(number, speed);
}
void SimulationModel::setOtherShipPos(int number, irr::f32 positionX, irr::f32 positionZ){
otherShips.setPos(number, positionX - offsetPosition.X, positionZ - offsetPosition.Z);
}
void SimulationModel::setOtherShipRateOfTurn(int number, irr::f32 rateOfTurn) {
otherShips.setRateOfTurn(number, rateOfTurn);
}
std::vector<Leg> SimulationModel::getOtherShipLegs(int number) const{
return otherShips.getLegs(number);
}
irr::f32 SimulationModel::getBuoyPosX(int number) const{
return buoys.getPosition(number).X + offsetPosition.X;
}
irr::f32 SimulationModel::getBuoyPosZ(int number) const{
return buoys.getPosition(number).Z + offsetPosition.Z;
}
void SimulationModel::changeOtherShipLeg(int shipNumber, int legNumber, irr::f32 bearing, irr::f32 speed, irr::f32 distance) {
otherShips.changeLeg(shipNumber, legNumber, bearing, speed, distance, scenarioTime);
}
void SimulationModel::addOtherShipLeg(int shipNumber, int afterLegNumber, irr::f32 bearing, irr::f32 speed, irr::f32 distance) {
otherShips.addLeg(shipNumber, afterLegNumber, bearing, speed, distance, scenarioTime);
}
void SimulationModel::deleteOtherShipLeg(int shipNumber, int legNumber) {
otherShips.deleteLeg(shipNumber, legNumber, scenarioTime);
}
void SimulationModel::resetOtherShipLegs(int shipNumber, irr::f32 course, irr::f32 speedKts, irr::f32 distanceNm) {
otherShips.resetLegs(shipNumber, course, speedKts, distanceNm, scenarioTime);
}
std::string SimulationModel::getOwnShipEngineSound() const {
//Check existence of sound file in base path, and if not fall back to default.
std::string soundPath = ownShip.getBasePath();
{ //Create local scope for file
soundPath.append("/Engine.wav");
std::ifstream file(soundPath.c_str());
if (file.good()) {
return soundPath;
}
}
//Check for lower case version
{
soundPath = ownShip.getBasePath();
soundPath.append("/engine.wav");
std::ifstream file(soundPath.c_str());
if (file.good()) {
return soundPath;
}
}
//Fall back to default, again checking both upper and lower case
{
soundPath = "Sounds/Engine.wav";
std::ifstream file(soundPath.c_str());
if (file.good()) {
return soundPath;
}
}
{
soundPath = "Sounds/engine.wav";
std::ifstream file(soundPath.c_str());
if (file.good()) {
return soundPath;
}
}
//In case nothing found
return "";
}
std::string SimulationModel::getOwnShipWaveSound() const {
//Check existence of sound file in base path, and if not fall back to default.
std::string soundPath = ownShip.getBasePath();
{ //Create local scope for file
soundPath.append("/Bwave.wav");
std::ifstream file(soundPath.c_str());
if (file.good()) {
return soundPath;
}
}
//Check for lower case version
{
soundPath = ownShip.getBasePath();
soundPath.append("/bwave.wav");
std::ifstream file(soundPath.c_str());
if (file.good()) {
return soundPath;
}
}
//Fall back to default, again checking both upper and lower case
{
soundPath = "Sounds/Bwave.wav";
std::ifstream file(soundPath.c_str());
if (file.good()) {
return soundPath;
}
}
{
soundPath = "Sounds/bwave.wav";
std::ifstream file(soundPath.c_str());
if (file.good()) {
return soundPath;
}
}
//In case nothing found
return "";
}
std::string SimulationModel::getOwnShipHornSound() const {
//Check existence of sound file in base path, and if not fall back to default.
std::string soundPath = ownShip.getBasePath();
{ //Create local scope for file
soundPath.append("/Horn.wav");
std::ifstream file(soundPath.c_str());
if (file.good()) {
return soundPath;
}
}
//Check for lower case version
{
soundPath = ownShip.getBasePath();
soundPath.append("/horn.wav");
std::ifstream file(soundPath.c_str());
if (file.good()) {
return soundPath;
}
}
//Fall back to default, again checking both upper and lower case
{
soundPath = "Sounds/Horn.wav";
std::ifstream file(soundPath.c_str());
if (file.good()) {
return soundPath;
}
}
{
soundPath = "Sounds/horn.wav";
std::ifstream file(soundPath.c_str());
if (file.good()) {
return soundPath;
}
}
//In case nothing found
return "";
}
std::string SimulationModel::getOwnShipAlarmSound() const {
//Check existence of sound file in base path, and if not fall back to default.
std::string soundPath = ownShip.getBasePath();
{ //Create local scope for file
soundPath.append("/Alarm.wav");
std::ifstream file(soundPath.c_str());
if (file.good()) {
return soundPath;
}
}
//Check for lower case version
{
soundPath = ownShip.getBasePath();
soundPath.append("/alarm.wav");
std::ifstream file(soundPath.c_str());
if (file.good()) {
return soundPath;
}
}
//Fall back to default, again checking both upper and lower case
{
soundPath = "Sounds/Alarm.wav";
std::ifstream file(soundPath.c_str());
if (file.good()) {
return soundPath;
}
}
{
soundPath = "Sounds/alarm.wav";
std::ifstream file(soundPath.c_str());
if (file.good()) {
return soundPath;
}
}
//In case nothing found
return "";
}
void SimulationModel::setHeading(irr::f32 hdg)
{
ownShip.setHeading(hdg);
}
irr::f32 SimulationModel::getRateOfTurn() const
{
return ownShip.getRateOfTurn();
}
void SimulationModel::setRateOfTurn(irr::f32 rateOfTurn)
{
ownShip.setRateOfTurn(rateOfTurn);
}
void SimulationModel::setPos(irr::f32 positionX, irr::f32 positionZ)
{
ownShip.setPosition(positionX - offsetPosition.X, positionZ - offsetPosition.Z );
}
irr::f32 SimulationModel::getHeading() const
{
return(ownShip.getHeading());
}
void SimulationModel::setRudder(irr::f32 rudder)
{
//Set the rudder (-ve is port, +ve is stbd)
ownShip.setRudder(rudder);
}
irr::f32 SimulationModel::getRudder() const
{
return ownShip.getRudder();
}
// DEE vvvvvvvvvvv
void SimulationModel::setWheel(irr::f32 wheel, bool force)
{
//Set the wheel (-ve is port, +ve is stbd)
ownShip.setWheel(wheel, force);
}
irr::f32 SimulationModel::getWheel() const
{
return ownShip.getWheel();
}
// DEE ^^^^^^^^^^^
void SimulationModel::setAzimuth1Master(bool isMaster)
{ // Set if azimuth 1 should also control azimuth 2
ownShip.setAzimuth1Master(isMaster);
}
void SimulationModel::setAzimuth2Master(bool isMaster)
{ // Set if azimuth 2 should also control azimuth 1
ownShip.setAzimuth2Master(isMaster);
}
bool SimulationModel::getAzimuth1Master() const
{
return ownShip.getAzimuth1Master();
}
bool SimulationModel::getAzimuth2Master() const
{
return ownShip.getAzimuth2Master();
}
// DEE_NOV22 vvvv Azimuth Drive follow up code
// Schottels
void SimulationModel::setPortSchottel(irr::f32 portAngle)
{ // Set the Port Schottel control angle in degrees (-ve is anticlockwise, +ve is clockwise)
ownShip.setPortSchottel(portAngle);
}
void SimulationModel::setStbdSchottel(irr::f32 stbdAngle)
{ // Set the Stbd Schottel control angle in degrees (-ve is anticlockwise, +ve is clockwise)
ownShip.setStbdSchottel(stbdAngle);
}
irr::f32 SimulationModel::getPortSchottel()
{ // Gets the Port Schottel angle, (-ve is anticlockwise, +ve is clockwise)
return ownShip.getPortSchottel();
}
irr::f32 SimulationModel::getStbdSchottel()
{ // Gets the Stbd Schottel angle, (-ve is anticlockwise, +ve is clockwise)
return ownShip.getStbdSchottel();
}
// DEE_NOV22 btn control of shcottels ... this is for when you dont use a mouse of control console,
// however it is also close enough to emergency steering mode of azimuth drives for all
// practical playability purposes.
void SimulationModel::btnIncrementPortSchottel()
{
ownShip.btnIncrementPortSchottel(); // DEE_NOV22 stbd schottel clockwise
}
void SimulationModel::btnDecrementPortSchottel()
{
ownShip.btnDecrementPortSchottel(); // DEE_NOV22 port schottel anticlockwise
}
void SimulationModel::btnIncrementStbdSchottel()
{
ownShip.btnIncrementStbdSchottel(); // DEE_NOV22 stbd shcottel clockwise in response to KEY_KEY_L
}
void SimulationModel::btnDecrementStbdSchottel()
{
ownShip.btnDecrementStbdSchottel(); // DEE_NOV22 port schottel anticlockwise in response to KEY_KEY_J
}
// Thrust levers
void SimulationModel::setPortAzimuthThrustLever(irr::f32 portThrustLever)
{
ownShip.setPortAzimuthThrustLever(portThrustLever);
// ownShip.setPortThrustLever(irr::f32 portThrustLever);
}
void SimulationModel::setStbdAzimuthThrustLever(irr::f32 stbdThrustLever)
{
// ownShip.setStbdThrustLever(irr::f32 stbdThrustLever);
ownShip.setStbdAzimuthThrustLever(stbdThrustLever);
}
irr::f32 SimulationModel::getPortAzimuthThrustLever()
{
return ownShip.getPortAzimuthThrustLever();
}
irr::f32 SimulationModel::getStbdAzimuthThrustLever()
{
return ownShip.getStbdAzimuthThrustLever();
}
// DEE_NOV22 below in response to keyboard presses
// todo implement an emergency steering mode
// respond to physical control's buttons emergency mode
// other code for follow up response to physical controls
void SimulationModel::btnIncrementPortThrustLever()
{
ownShip.btnIncrementPortThrustLever();
}
void SimulationModel::btnDecrementPortThrustLever()
{
ownShip.btnDecrementPortThrustLever();
}
void SimulationModel::btnIncrementStbdThrustLever()
{
ownShip.btnIncrementStbdThrustLever();
}
void SimulationModel::btnDecrementStbdThrustLever()
{
ownShip.btnDecrementStbdThrustLever();
}
// DEE_NOV22 Clutches , in normal operation these would be automatic, however in emergency (non follow up) mode they are manual
// DEE_NOV22 in future perhaps model engine stall for when clutch engaged at too low a revs and prop shaft snap if clutch
// DEE_NOV22 is engaged at too high a revs
void SimulationModel::setPortClutch(bool portClutch)
{
ownShip.setPortClutch(portClutch);
}
void SimulationModel::setStbdClutch(bool stbdClutch)
{
ownShip.setStbdClutch(stbdClutch);
}
bool SimulationModel::getPortClutch()
{
return ownShip.getPortClutch();
}
bool SimulationModel::getStbdClutch()
{
return ownShip.getStbdClutch();
}
// DEE_NOV22 todo need to assign keys to this is emergency steering mode where there is no automatic clutch
// I think we could use the follow up / non follow up flag to determine if it is in normal or
// emergency steering mode.
// todo is it better to use SimulationModel::setXXXXClutch(xxxx) for this
void SimulationModel::engagePortClutch()
{
ownShip.setPortClutch(true);
}
void SimulationModel::disengagePortClutch()
{
ownShip.setPortClutch(false);
}
void SimulationModel::engageStbdClutch()
{
ownShip.setStbdClutch(true);
}
void SimulationModel::disengageStbdClutch()
{
ownShip.setStbdClutch(false);
}
// DEE_NOV22 ^^^^ Azimuth Drive follow up code
void SimulationModel::setPortAzimuthAngle(irr::f32 angle)
{// Set the azimuth angle, in degrees (-ve is port, +ve is stbd)
ownShip.setPortAzimuthAngle(angle);
}
void SimulationModel::setStbdAzimuthAngle(irr::f32 angle)
{// Set the azimuth angle, in degrees (-ve is port, +ve is stbd)
ownShip.setStbdAzimuthAngle(angle);
}
void SimulationModel::setPortEngine(irr::f32 port)
{
//Set the engine, (-ve astern, +ve ahead)
ownShip.setPortEngine(port); //This method limits the range applied
//Set engine sound level
// DEE_NOV22 unless this is a controllable pitch propellor,
// where the engine turns at a constant rpm
// where with increased power then the sound of the engine
// results in the same frequency engine noise, only louder.
// Vessels where engine rpm controls power then the frequency
// of the engine noise should change with engine rpm
if (ownShip.isSingleEngine()) {
sound->setVolumeEngine(fabs(getPortEngine())*0.5);
}
else {
sound->setVolumeEngine((fabs(getPortEngine()) + fabs(getStbdEngine()))*0.5);
}
}
void SimulationModel::setStbdEngine(irr::f32 stbd)
{
//Set the engine, (-ve astern, +ve ahead)
ownShip.setStbdEngine(stbd); //This method limits the range applied
//Set engine sound level
// DEE_NOV22 same comment as for port engine
if (ownShip.isSingleEngine()) {
sound->setVolumeEngine(fabs(getPortEngine())*0.5);
}
else {
sound->setVolumeEngine((fabs(getPortEngine()) + fabs(getStbdEngine()))*0.5);
}
}
irr::f32 SimulationModel::getPortEngine() const
{
return ownShip.getPortEngine();
}
irr::f32 SimulationModel::getStbdEngine() const
{
return ownShip.getStbdEngine();
}
irr::f32 SimulationModel::getPortEngineRPM() const
{
return ownShip.getPortEngineRPM();
}
irr::f32 SimulationModel::getStbdEngineRPM() const
{
return ownShip.getStbdEngineRPM();
}
void SimulationModel::setBowThruster(irr::f32 proportion)
{
ownShip.setBowThruster(proportion);
}
void SimulationModel::setSternThruster(irr::f32 proportion)
{
ownShip.setSternThruster(proportion);
}
void SimulationModel::setBowThrusterRate(irr::f32 bowThrusterRate){
//Sets the rate of increase of bow thruster, used for joystick button control
ownShip.setBowThrusterRate(bowThrusterRate);
}
void SimulationModel::setSternThrusterRate(irr::f32 sternThrusterRate){
//Sets the rate of increase of bow thruster, used for joystick button control
ownShip.setSternThrusterRate(sternThrusterRate);
}
irr::f32 SimulationModel::getBowThruster() const
{
return ownShip.getBowThruster();
}
irr::f32 SimulationModel::getSternThruster() const
{
return ownShip.getSternThruster();
}
void SimulationModel::setRudderPumpState(int whichPump, bool rudderPumpState) {
ownShip.setRudderPumpState(whichPump, rudderPumpState);
}
bool SimulationModel::getRudderPumpState(int whichPump) const
{
return ownShip.getRudderPumpState(whichPump);
}
void SimulationModel::setFollowUpRudderWorking(bool followUpRudderWorking) {
ownShip.setFollowUpRudderWorking(followUpRudderWorking);
}
void SimulationModel::setAccelerator(irr::f32 accelerator)
{
device->getTimer()->setSpeed(accelerator);
}
irr::f32 SimulationModel::getAccelerator() const
{
return device->getTimer()->getSpeed();
}
void SimulationModel::setWeather(irr::f32 weather)
{
this->weather = weather;