-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSimShip.cpp
More file actions
6756 lines (5915 loc) · 287 KB
/
SimShip.cpp
File metadata and controls
6756 lines (5915 loc) · 287 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
#include "SimShip.h"
int RENDER_SKY = 2;
int RENDER_OCEAN = 3; // 0 = wireframe, 1 = one mesh, 2 = lod, 3 = lod with wake
int IMGUI_STYLE = 4;
extern pair<string, uint64_t> OceanTimeStamps[5];
/*
RENDER PASS 0 : g_RenderPassShadow (1x)
├── 1 ATTACHMENT : g_TexShadowDepth (1x) → Texture for Ocean Shader & Model shader
└── 1 FRAMEBUFFER : g_ShadowFramebuffer
RENDER PASS 1 : g_RenderPassWake (1x)
├── 1 ATTACHMENT : g_TexWake (1x) → Texture for Ocean Shader
└── 1 FRAMEBUFFER : g_WakeFramebuffer
RENDER PASS 2 : g_RenderPassReflection (1x)
├── 2 ATTACHMENTS : g_TexReflectionColor (1x) → Texture for Ocean Shader
│ : g_TexReflectionDepth (1x) → Depth pour reflection
└── 1 FRAMEBUFFER : g_ReflectionFramebuffer
ATMOSPHERE : Compute shaders (hors render pass)
├── Compute 3 LUTs (Bruneton/Sakmary)
├── Compute Sky → g_SkyImage[g_iCurrentFrame]
├── Compute Clouds → Texture
└── Assemble sky+clouds → g_Clouds PostProcess Texture
RENDER PASS 3 : g_RenderPassScene (5 ATTACHMENTS, 1 SUBPASS)
├── ATTACHMENT 0 : g_ColorImageView (MSAA 8x) → Rendu COLOR MSAA
├── ATTACHMENT 1 : g_vSwapChainImageViews[i] (1x) → Resolve COLOR (temporaire)
├── ATTACHMENT 2 : g_DepthImageView (MSAA 8x) → Rendu DEPTH MSAA
├── ATTACHMENT 3 : g_DepthViewResolve (1x) → Resolve DEPTH (ScreenQuad)
└── ATTACHMENT 4 : g_ColorViewResolve (1x) → ScreenQuad COLOR input
└── 2 FRAMEBUFFERS : g_vFramebuffersSwapChain[0..1]
RENDER PASS 4 : g_RenderPassPostProcess (1x)
├── 1 ATTACHMENT : g_vSwapChainImageViews[i] (1x) → LOAD/STORE final
└── 2 FRAMEBUFFERS : g_vFramebuffersPostProcess[0..1]
RENDER PASS 5 : g_RenderPassImGui (1x)
├── 1 ATTACHMENT : g_vSwapChainImageViews[i] (1x) → LOAD/STORE (over post-process)
└── 2 FRAMEBUFFERS : g_vFramebuffersPostProcess[0..1] (réutilisés)
*/
void SwitchToFullScreen()
{
vkDeviceWaitIdle(g_Device->device);
static uint32_t oldWindowX;
static uint32_t oldWindowY;
static uint32_t oldWindowW;
static uint32_t oldWindowH;
if (!g_IsFullscreen) // -> Switch to fullscreen
{
// Storing the window position BEFORE fullscreen, glfwGetWindowPos returns the top-left corner of the client area
int wx, wy;
glfwGetWindowPos(g_hWindow, &wx, &wy);
oldWindowX = wx;
oldWindowY = wy;
oldWindowW = g_WindowW;
oldWindowH = g_WindowH;
GLFWmonitor* targetMonitor = get_current_monitor(g_hWindow);
const GLFWvidmode* mode = glfwGetVideoMode(targetMonitor);
glfwSetWindowMonitor(g_hWindow, targetMonitor, 0, 0, mode->width, mode->height, mode->refreshRate);
}
else
{
// Restoring directly with the saved coordinates without adjustment by GetWindowFrameSize (unreliable post-fullscreen)
glfwSetWindowMonitor(g_hWindow, nullptr, oldWindowX, oldWindowY, oldWindowW, oldWindowH, 0);
}
g_IsFullscreen = !g_IsFullscreen;
}
void framebuffer_size_callback(GLFWwindow* window, int width, int height)
{
// Callback function for window resizing
if (width == 0 || height == 0) return;
if (g_IsRecreating) return;
g_WindowW = width;
g_WindowH = height;
g_WindowW_2 = width / 2;
g_WindowH_2 = height / 2;
g_Camera.SetViewportSize(g_WindowW, g_WindowH);
g_IsRecreating = true;
PartialRecreate();
g_IsRecreating = false;
}
void CursorPosCallback(GLFWwindow* window, double xposIn, double yposIn)
{
g_Camera.MousePosUpdate(xposIn, yposIn);
}
void MouseButtonCallback(GLFWwindow* window, int button, int action, int mods)
{
double xpos, ypos;
glfwGetCursorPos(window, &xpos, &ypos);
vec2 mouse = vec2(int(xpos), int(ypos));
if (button == 0 && action == GLFW_PRESS)
{
if (IsInRect(g_CtrlSound, mouse))
{
g_SoundMgr->bSound = !g_SoundMgr->bSound;
}
if (IsInRect(g_CtrlTimer, mouse))
{
g_ChronoStep++;
if (g_ChronoStep > 2) g_ChronoStep = 0;
switch (g_ChronoStep)
{
case 0: g_bChrono = true; g_Chrono.restart(); break;
case 1: g_Chrono.stop(); break;
case 2: g_bChrono = false; break;
}
}
if (IsInRect(g_CtrlMto0, mouse)) // Random
SetMeteo(0);
if (IsInRect(g_CtrlMto1, mouse)) // Clear
SetMeteo(1);
if (IsInRect(g_CtrlMto2, mouse)) // Cloudy
SetMeteo(2);
if (IsInRect(g_CtrlMto3, mouse)) // Foggy
SetMeteo(3);
if (IsInRect(g_CtrlThrottle1, mouse))
{
float valeur = 1 - (mouse.y - g_CtrlThrottleHigh1) / (g_CtrlThrottleLow1 - g_CtrlThrottleHigh1);
g_Ship->PowerCurrentStep1 = (valeur - 0.5f) * (2.0f * g_Ship->ship.PowerStepMax);
}
if (IsInRect(g_CtrlThrottle2, mouse))
{
float valeur = 1 - (mouse.y - g_CtrlThrottleHigh2) / (g_CtrlThrottleLow2 - g_CtrlThrottleHigh2);
g_Ship->PowerCurrentStep2 = (valeur - 0.5f) * (2.0f * g_Ship->ship.PowerStepMax);
}
if (IsInRect(g_CtrlBowThruster, mouse))
{
float valeur = (mouse.x - g_CtrlBowThrusterLeft) / (g_CtrlBowThrusterRight - g_CtrlBowThrusterLeft);
g_Ship->BowThrusterCurrentStep = (valeur - 0.5f) * (2.0f * g_Ship->ship.BowThrusterStepMax);
}
if (IsInRect(g_CtrlSternThruster, mouse))
{
float valeur = (mouse.x - g_CtrlSternThrusterLeft) / (g_CtrlSternThrusterRight - g_CtrlSternThrusterLeft);
g_Ship->SternThrusterCurrentStep = (valeur - 0.5f) * (2.0f * g_Ship->ship.SternThrusterStepMax);
}
if (IsInRect(g_CtrlRudder, mouse))
{
float valeur = 1 - (mouse.x - g_CtrlRudderLeft) / (g_CtrlRudderRight - g_CtrlRudderLeft);
g_Ship->RudderCurrentStep = (valeur - 0.5f) * (2.0f * g_Ship->ship.RudderStepMax);
}
if (IsInRect(g_CtrlNow, mouse))
{
g_Sky->SetNow();
}
if (IsInRect(g_CtrlAutopilotCMD, mouse))
{
g_Ship->bAutopilot = !g_Ship->bAutopilot;
return;
}
if (IsInRect(g_CtrlAutopilotM1, mouse))
{
g_Ship->HDGInstruction--;
if (g_Ship->HDGInstruction < 0)
g_Ship->HDGInstruction += 360;
return;
}
if (IsInRect(g_CtrlAutopilotP1, mouse))
{
g_Ship->HDGInstruction++;
if (g_Ship->HDGInstruction > 360)
g_Ship->HDGInstruction -= 360;
return;
}
if (IsInRect(g_CtrlAutopilotM10, mouse))
{
g_Ship->HDGInstruction -= 10;
if (g_Ship->HDGInstruction < 0)
g_Ship->HDGInstruction += 360;
return;
}
if (IsInRect(g_CtrlAutopilotP10, mouse))
{
g_Ship->HDGInstruction += 10;
if (g_Ship->HDGInstruction > 360)
g_Ship->HDGInstruction -= 360;
return;
}
}
if (button == 1 && action == GLFW_PRESS)
g_bBinoculars = !g_bBinoculars;
if (!ImGui::GetIO().WantCaptureMouse)
g_Camera.MouseButtonUpdate(button, action, mods);
}
void ScrollCallback(GLFWwindow* window, double xoffset, double yoffset)
{
double mouseX, mouseY;
glfwGetCursorPos(window, &mouseX, &mouseY);
vec2 mouse(mouseX, mouseY);
if (IsInRect(g_CtrlPanel, mouse))
{
if (IsInRect(g_CtrlThrottle1, mouse))
{
if (yoffset > 0)
{
g_Ship->PowerCurrentStep1++;
if (g_Ship->PowerCurrentStep1 > g_Ship->ship.PowerStepMax)
g_Ship->PowerCurrentStep1 = g_Ship->ship.PowerStepMax;
}
else
{
g_Ship->PowerCurrentStep1--;
if (g_Ship->PowerCurrentStep1 < -g_Ship->ship.PowerStepMax)
g_Ship->PowerCurrentStep1 = -g_Ship->ship.PowerStepMax;
}
return;
}
else if (IsInRect(g_CtrlThrottle2, mouse))
{
if (yoffset > 0)
{
g_Ship->PowerCurrentStep2++;
if (g_Ship->PowerCurrentStep2 > g_Ship->ship.PowerStepMax)
g_Ship->PowerCurrentStep2 = g_Ship->ship.PowerStepMax;
}
else
{
g_Ship->PowerCurrentStep2--;
if (g_Ship->PowerCurrentStep2 < -g_Ship->ship.PowerStepMax)
g_Ship->PowerCurrentStep2 = -g_Ship->ship.PowerStepMax;
}
return;
}
else if (IsInRect(g_CtrlThrottle12, mouse))
{
int average = (g_Ship->PowerCurrentStep1 + g_Ship->PowerCurrentStep2) / 2;
if (yoffset > 0)
{
g_Ship->PowerCurrentStep1 = average + 1;
g_Ship->PowerCurrentStep2 = average + 1;
if (g_Ship->PowerCurrentStep1 > g_Ship->ship.PowerStepMax)
g_Ship->PowerCurrentStep1 = g_Ship->ship.PowerStepMax;
if (g_Ship->PowerCurrentStep2 > g_Ship->ship.PowerStepMax)
g_Ship->PowerCurrentStep2 = g_Ship->ship.PowerStepMax;
}
else
{
g_Ship->PowerCurrentStep1 = average - 1;
g_Ship->PowerCurrentStep2 = average - 1;
if (g_Ship->PowerCurrentStep1 < -g_Ship->ship.PowerStepMax)
g_Ship->PowerCurrentStep1 = -g_Ship->ship.PowerStepMax;
if (g_Ship->PowerCurrentStep2 < -g_Ship->ship.PowerStepMax)
g_Ship->PowerCurrentStep2 = -g_Ship->ship.PowerStepMax;
}
return;
}
else if (IsInRect(g_CtrlRudder, mouse))
{
if (yoffset < 0)
{
if (g_Ship->bAutopilot) g_Ship->bAutopilot = false;
g_Ship->RudderCurrentStep++;
if (g_Ship->RudderCurrentStep > g_Ship->ship.RudderStepMax)
g_Ship->RudderCurrentStep = g_Ship->ship.RudderStepMax;
}
else
{
if (g_Ship->bAutopilot) g_Ship->bAutopilot = false;
g_Ship->RudderCurrentStep--;
if (g_Ship->RudderCurrentStep < -g_Ship->ship.RudderStepMax)
g_Ship->RudderCurrentStep = -g_Ship->ship.RudderStepMax;
}
return;
}
else if (IsInRect(g_CtrlBowThruster, mouse))
{
if (yoffset > 0)
{
if (g_Ship->bAutopilot) g_Ship->bAutopilot = false;
g_Ship->BowThrusterCurrentStep++;
if (g_Ship->BowThrusterCurrentStep > g_Ship->ship.BowThrusterStepMax)
g_Ship->BowThrusterCurrentStep = g_Ship->ship.BowThrusterStepMax;
}
else
{
if (g_Ship->bAutopilot) g_Ship->bAutopilot = false;
g_Ship->BowThrusterCurrentStep--;
if (g_Ship->BowThrusterCurrentStep < -g_Ship->ship.BowThrusterStepMax)
g_Ship->BowThrusterCurrentStep = -g_Ship->ship.BowThrusterStepMax;
}
return;
}
else if (IsInRect(g_CtrlSternThruster, mouse))
{
if (yoffset > 0)
{
if (g_Ship->bAutopilot) g_Ship->bAutopilot = false;
g_Ship->SternThrusterCurrentStep++;
if (g_Ship->SternThrusterCurrentStep > g_Ship->ship.SternThrusterStepMax)
g_Ship->SternThrusterCurrentStep = g_Ship->ship.SternThrusterStepMax;
}
else
{
if (g_Ship->bAutopilot) g_Ship->bAutopilot = false;
g_Ship->SternThrusterCurrentStep--;
if (g_Ship->SternThrusterCurrentStep < -g_Ship->ship.SternThrusterStepMax)
g_Ship->SternThrusterCurrentStep = -g_Ship->ship.SternThrusterStepMax;
}
return;
}
else if (IsInRect(g_CtrlTimeHour, mouse))
{
sHM hm = g_Sky->GetTime();
if (yoffset < 0)
{
hm.hour--;
if (hm.hour < 0.0f)
hm.hour = 0.0f;
}
else
{
hm.hour++;
if (hm.hour > 23.0f)
hm.hour = 23.0f;
}
g_Sky->SetTime(hm.hour, hm.minute);
g_Ship->bLights = g_Sky->SunPosition.y < 0.0f ? true : false;
g_Traffics->bLights = g_Ship->bLights;
return;
}
else if (IsInRect(g_CtrlTimeMinute, mouse))
{
sHM hm = g_Sky->GetTime();
if (yoffset < 0)
{
hm.minute--;
if (hm.minute < 0)
{
if (hm.hour > 0)
{
hm.minute = 59;
hm.hour--;
}
else
hm.minute = 0;
}
}
else
{
hm.minute++;
if (hm.minute > 59)
{
if (hm.hour < 23)
{
hm.minute = 0;
hm.hour++;
}
else
hm.minute = 59;
}
}
g_Sky->SetTime(hm.hour, hm.minute);
g_Ship->bLights = g_Sky->SunPosition.y < 0.0f ? true : false;
g_Traffics->bLights = g_Ship->bLights;
return;
}
else if (IsInRect(g_CtrlWind, mouse))
{
if (yoffset < 0)
g_TWS_Kt--;
else
g_TWS_Kt++;
g_TWS_Kt = glm::clamp(g_TWS_Kt, 0.1f, 30.0f);
g_Wind = wind_from_speeddir(g_TWS_Deg, g_TWS_Kt);
g_Ocean->SetWind(g_Wind);
g_Ocean->InitFrequencies();
g_Clouds->SetCloudSpeed(g_TWS_Kt);
return;
}
else if (IsInRect(g_CtrlAutopilotM1, mouse))
{
if (yoffset < 0)
{
g_Ship->HDGInstruction--;
if (g_Ship->HDGInstruction < 0)
g_Ship->HDGInstruction += 360;
}
if (yoffset > 0)
{
g_Ship->HDGInstruction++;
if (g_Ship->HDGInstruction > 360)
g_Ship->HDGInstruction -= 360;
}
return;
}
if (IsInRect(g_CtrlAutopilotP1, mouse))
{
if (yoffset < 0)
{
g_Ship->HDGInstruction--;
if (g_Ship->HDGInstruction < 0)
g_Ship->HDGInstruction += 360;
}
if (yoffset > 0)
{
g_Ship->HDGInstruction++;
if (g_Ship->HDGInstruction > 360)
g_Ship->HDGInstruction -= 360;
}
return;
}
if (IsInRect(g_CtrlAutopilotM10, mouse))
{
if (yoffset < 0)
{
g_Ship->HDGInstruction -= 10;
if (g_Ship->HDGInstruction < 0)
g_Ship->HDGInstruction += 360;
}
if (yoffset > 0)
{
g_Ship->HDGInstruction += 10;
if (g_Ship->HDGInstruction > 360)
g_Ship->HDGInstruction -= 360;
}
return;
}
if (IsInRect(g_CtrlAutopilotP10, mouse))
{
if (yoffset < 0)
{
g_Ship->HDGInstruction -= 10;
if (g_Ship->HDGInstruction < 0)
g_Ship->HDGInstruction += 360;
}
if (yoffset > 0)
{
g_Ship->HDGInstruction += 10;
if (g_Ship->HDGInstruction > 360)
g_Ship->HDGInstruction -= 360;
}
return;
}
}
else if (!ImGui::GetIO().WantCaptureMouse)
{
if (g_Camera.GetMode() == eCameraMode::ORBITAL)
g_Camera.AdjustOrbitRadius(-yoffset * 0.1f * g_Camera.GetOrbitRadius());
}
}
void KeyCallback(GLFWwindow* window, int key, int scancode, int action, int mods)
{
g_Camera.KeyboardUpdate(key, scancode, action, mods);
if (action == GLFW_PRESS || action == GLFW_REPEAT)
{
switch (key)
{
case GLFW_KEY_ESCAPE:
glfwSetWindowShouldClose(window, true);
break;
// Pause
case GLFW_KEY_SPACE:
g_bPause = !g_bPause;
if (g_bPause) g_TimerScene.stop();
else g_TimerScene.start();
break;
case GLFW_KEY_1:
SetShip(0);
break;
case GLFW_KEY_2:
SetShip(1);
break;
case GLFW_KEY_3:
SetShip(2);
break;
case GLFW_KEY_4:
SetShip(3);
break;
case GLFW_KEY_5:
SetShip(4);
break;
case GLFW_KEY_6:
SetShip(5);
break;
case GLFW_KEY_7:
SetShip(6);
break;
case GLFW_KEY_8:
SetShip(7);
break;
case GLFW_KEY_9:
SetShip(8);
break;
case GLFW_KEY_0:
SetShip(9);
break;
case GLFW_KEY_A:
if (g_Camera.GetMode() != eCameraMode::FPS)
{
g_eBridgeView = eBridgeView::LEFT;
g_Camera.KeyboardUpdate(GLFW_KEY_B, scancode, action, mods);
}
break;
case GLFW_KEY_D:
if (g_Camera.GetMode() != eCameraMode::FPS)
{
g_eBridgeView = eBridgeView::RIGHT;
g_Camera.KeyboardUpdate(GLFW_KEY_B, scancode, action, mods);
}
break;
case GLFW_KEY_G:
IMGUI_STYLE++;
ApplyTheme();
break;
case GLFW_KEY_H: // Horn
if (g_SoundMgr->bSound && g_Ship->bSound)
g_SoundHorn->play();
break;
case GLFW_KEY_I: // Cycle the interpolation function to the next type
{
int current = static_cast<int>(g_Camera.GetInterpolation());
int next = (current + 1) % static_cast<int>(eInterpolation::COUNT);
g_Camera.SetInterpolation(static_cast<eInterpolation>(next));
}
break;
case GLFW_KEY_L:
g_Ship->bLights = !g_Ship->bLights;
g_Traffics->bLights = g_Ship->bLights;
break;
case GLFW_KEY_SEMICOLON: // M for Manoeuver
g_Ship->PowerCurrentStep1 = g_Ship->ship.PowerStepMax * 7 / 10;
g_Ship->PropRpm1 = g_Ship->ship.PropRpmMax * 7 / 10;
if (g_Ship->ship.nPropeller == 2)
{
g_Ship->PowerCurrentStep2 = g_Ship->ship.PowerStepMax * 7 / 10;
g_Ship->PropRpm2 = g_Ship->ship.PropRpmMax * 7 / 10;
}
g_Ship->SurgeVelocity = knot_to_ms(g_Ship->ship.SpeedEcoKt);
g_Ship->RudderCurrentStep = -g_Ship->ship.RudderStepMax;
break;
case GLFW_KEY_N:
g_bNightVision = !g_bNightVision;
break;
case GLFW_KEY_O: // Color ocean
g_Ocean->iOceanColor++;
if (g_Ocean->iOceanColor >= g_Ocean->vOceanColors.size())
g_Ocean->iOceanColor = 0;
g_Ocean->OceanColor = g_Ocean->vOceanColors[g_Ocean->iOceanColor];
break;
case GLFW_KEY_P:
RENDER_OCEAN++;
if (RENDER_OCEAN == 4)
RENDER_OCEAN = 0;
break;
case GLFW_KEY_S:
if (g_Camera.GetMode() != eCameraMode::FPS)
{
g_eBridgeView = eBridgeView::WHEEL;
g_Camera.KeyboardUpdate(GLFW_KEY_B, scancode, action, mods);
}
break;
case GLFW_KEY_T: // Textures
g_bShowTextures = !g_bShowTextures;
break;
case GLFW_KEY_W:
if (g_Camera.GetMode() != eCameraMode::FPS)
{
g_eBridgeView = eBridgeView::BOW;
g_Camera.KeyboardUpdate(GLFW_KEY_B, scancode, action, mods);
}
break;
case GLFW_KEY_X:
if (g_Camera.GetMode() != eCameraMode::FPS)
{
g_eBridgeView = eBridgeView::STERN;
g_Camera.KeyboardUpdate(GLFW_KEY_B, scancode, action, mods);
}
break;
case GLFW_KEY_KP_SUBTRACT: // 1 kt
g_Ship->SurgeVelocity -= 0.5144f;
break;
case GLFW_KEY_KP_ADD: // 1 kt
g_Ship->SurgeVelocity += 0.5144f;
break;
case GLFW_KEY_KP_DIVIDE: // Engine at 7/10
g_Ship->PowerCurrentStep1 = g_Ship->ship.PowerStepMax * 7 / 10;
g_Ship->PropRpm1 = g_Ship->ship.PropRpmMax * 7 / 10;
g_Ship->PowerCurrentStep2 = g_Ship->ship.PowerStepMax * 7 / 10;
g_Ship->PropRpm2 = g_Ship->ship.PropRpmMax * 7 / 10;
break;
case GLFW_KEY_KP_MULTIPLY: // Service speed
g_Ship->SurgeVelocity = knot_to_ms(g_Ship->ship.SpeedEcoKt);
break;
case GLFW_KEY_LEFT: // Rudder
if (g_Ship->bAutopilot) g_Ship->bAutopilot = false;
g_Ship->RudderCurrentStep++;
if (g_Ship->RudderCurrentStep > g_Ship->ship.RudderStepMax)
g_Ship->RudderCurrentStep = g_Ship->ship.RudderStepMax;
break;
case GLFW_KEY_DOWN:
if (g_Ship->bAutopilot) g_Ship->bAutopilot = false;
g_Ship->RudderCurrentStep = 0;
break;
case GLFW_KEY_RIGHT:
if (g_Ship->bAutopilot) g_Ship->bAutopilot = false;
g_Ship->RudderCurrentStep--;
if (g_Ship->RudderCurrentStep < -g_Ship->ship.RudderStepMax)
g_Ship->RudderCurrentStep = -g_Ship->ship.RudderStepMax;
break;
case GLFW_KEY_KP_7: // Power LEFT
if (g_Ship->ship.nPropeller == 2)
{
g_Ship->PowerCurrentStep1++;
if (g_Ship->PowerCurrentStep1 > g_Ship->ship.PowerStepMax)
g_Ship->PowerCurrentStep1 = g_Ship->ship.PowerStepMax;
}
break;
case GLFW_KEY_KP_4:
if (g_Ship->ship.nPropeller == 2)
{
g_Ship->PowerCurrentStep1 = 0;
}
break;
case GLFW_KEY_KP_1:
if (g_Ship->ship.nPropeller == 2)
{
g_Ship->PowerCurrentStep1--;
if (g_Ship->PowerCurrentStep1 < -g_Ship->ship.PowerStepMax)
g_Ship->PowerCurrentStep1 = -g_Ship->ship.PowerStepMax;
}
break;
case GLFW_KEY_KP_9: // Power RIGHT
if (g_Ship->ship.nPropeller == 2)
{
g_Ship->PowerCurrentStep2++;
if (g_Ship->PowerCurrentStep2 > g_Ship->ship.PowerStepMax)
g_Ship->PowerCurrentStep2 = g_Ship->ship.PowerStepMax;
}
break;
case GLFW_KEY_KP_6:
if (g_Ship->ship.nPropeller == 2)
{
g_Ship->PowerCurrentStep2 = 0;
}
break;
case GLFW_KEY_KP_3:
if (g_Ship->ship.nPropeller == 2)
{
g_Ship->PowerCurrentStep2--;
if (g_Ship->PowerCurrentStep2 < -g_Ship->ship.PowerStepMax)
g_Ship->PowerCurrentStep2 = -g_Ship->ship.PowerStepMax;
}
break;
case GLFW_KEY_KP_8: // Power ALL or single prop
if (g_Ship->ship.nPropeller == 2)
{
int average = (g_Ship->PowerCurrentStep1 + g_Ship->PowerCurrentStep2) / 2;
g_Ship->PowerCurrentStep1 = average + 1;
if (g_Ship->PowerCurrentStep1 > g_Ship->ship.PowerStepMax)
g_Ship->PowerCurrentStep1 = g_Ship->ship.PowerStepMax;
g_Ship->PowerCurrentStep2 = average + 1;
if (g_Ship->PowerCurrentStep2 > g_Ship->ship.PowerStepMax)
g_Ship->PowerCurrentStep2 = g_Ship->ship.PowerStepMax;
}
else
{
g_Ship->PowerCurrentStep1++;
if (g_Ship->PowerCurrentStep1 > g_Ship->ship.PowerStepMax)
g_Ship->PowerCurrentStep1 = g_Ship->ship.PowerStepMax;
}
break;
case GLFW_KEY_KP_5:
g_Ship->PowerCurrentStep1 = 0;
g_Ship->PowerCurrentStep2 = 0;
break;
case GLFW_KEY_KP_2:
if (g_Ship->ship.nPropeller == 2)
{
int average = (g_Ship->PowerCurrentStep1 + g_Ship->PowerCurrentStep2) / 2;
g_Ship->PowerCurrentStep1 = average - 1;
if (g_Ship->PowerCurrentStep1 < -g_Ship->ship.PowerStepMax)
g_Ship->PowerCurrentStep1 = -g_Ship->ship.PowerStepMax;
g_Ship->PowerCurrentStep2 = average - 1;
if (g_Ship->PowerCurrentStep2 < -g_Ship->ship.PowerStepMax)
g_Ship->PowerCurrentStep2 = -g_Ship->ship.PowerStepMax;
}
else
{
g_Ship->PowerCurrentStep1--;
if (g_Ship->PowerCurrentStep1 < -g_Ship->ship.PowerStepMax)
g_Ship->PowerCurrentStep1 = -g_Ship->ship.PowerStepMax;
}
break;
case GLFW_KEY_INSERT: // Bow Thruster
if (g_Ship->ship.HasBowThruster)
{
g_Ship->BowThrusterCurrentStep--;
if (g_Ship->BowThrusterCurrentStep < -g_Ship->ship.BowThrusterStepMax)
g_Ship->BowThrusterCurrentStep = -g_Ship->ship.BowThrusterStepMax;
}
break;
case GLFW_KEY_HOME:
if (g_Ship->ship.HasBowThruster)
{
g_Ship->BowThrusterCurrentStep = 0;
}
break;
case GLFW_KEY_PAGE_UP:
if (g_Ship->ship.HasBowThruster)
{
g_Ship->BowThrusterCurrentStep++;
if (g_Ship->BowThrusterCurrentStep > g_Ship->ship.BowThrusterStepMax)
g_Ship->BowThrusterCurrentStep = g_Ship->ship.BowThrusterStepMax;
}
break;
case GLFW_KEY_DELETE: // Stern Thruster
if (g_Ship->ship.HasSternThruster)
{
g_Ship->SternThrusterCurrentStep--;
if (g_Ship->SternThrusterCurrentStep < -g_Ship->ship.SternThrusterStepMax)
g_Ship->SternThrusterCurrentStep = -g_Ship->ship.SternThrusterStepMax;
}
break;
case GLFW_KEY_END:
if (g_Ship->ship.HasSternThruster)
{
g_Ship->SternThrusterCurrentStep = 0;
}
break;
case GLFW_KEY_PAGE_DOWN:
if (g_Ship->ship.HasSternThruster)
{
g_Ship->SternThrusterCurrentStep++;
if (g_Ship->SternThrusterCurrentStep > g_Ship->ship.SternThrusterStepMax)
g_Ship->SternThrusterCurrentStep = g_Ship->ship.SternThrusterStepMax;
}
break;
case GLFW_KEY_F1:
g_bShowShortcuts = !g_bShowShortcuts;
break;
case GLFW_KEY_F2:
g_bShowSceneWindow = !g_bShowSceneWindow;
break;
case GLFW_KEY_F3:
g_bShowShipWindow = !g_bShowShipWindow;
break;
case GLFW_KEY_F4:
g_bShowStatusBar = !g_bShowStatusBar;
break;
case GLFW_KEY_F5:
g_bShowAutopilotWindow = !g_bShowAutopilotWindow;
break;
case GLFW_KEY_F6:
g_bShowShipForcesWindows = !g_bShowShipForcesWindows;
break;
case GLFW_KEY_F7:
g_bShowChronoWindow = !g_bShowChronoWindow;
break;
case GLFW_KEY_F8:
{
HWND hWnd = glfwGetWin32Window(g_hWindow);
g_CaptureName = SaveClientArea(hWnd);
g_CaptureDisplayTime = g_CaptureMaxTime;
}
break;
case GLFW_KEY_F11:
g_PendingFullscreen = true;
break;
}
}
else if (action == GLFW_RELEASE)
{
// A key has just been released
}
}
ImVec2 GetLeftAlignedTextPos(const char* text, ImVec2 box_left, float padding_x, float padding_y, ImFont* font)
{
ImGui::PushFont(font);
// Calculate text size
ImVec2 text_size = ImGui::CalcTextSize(text);
// Text position: left edge of the box + padding (left-aligned)
ImVec2 text_pos = ImVec2(box_left.x + padding_x, box_left.y - text_size.y * 0.5f);
ImGui::PopFont();
return text_pos;
}
ImVec2 GetCenteredTextPos(const char* text, ImVec2 box_center, float padding_x, float padding_y, ImFont* font)
{
ImGui::PushFont(font);
// Calculate text size
ImVec2 text_size = ImGui::CalcTextSize(text);
// Text position: center of the box - half text size
ImVec2 text_pos = ImVec2( box_center.x - text_size.x * 0.5f, box_center.y - text_size.y * 0.5f );
ImGui::PopFont();
return text_pos;
}
ImVec2 GetRightAlignedTextPos(const char* text, ImVec2 box_right, float padding_x, float padding_y, ImFont* font)
{
ImGui::PushFont(font);
// Calculate text size
ImVec2 text_size = ImGui::CalcTextSize(text);
// Text position: right edge of the box - text size (right-aligned)
ImVec2 text_pos = ImVec2(box_right.x - text_size.x - padding_x, box_right.y - text_size.y * 0.5f);
ImGui::PopFont();
return text_pos;
}
// Imgui
void TestCtrlZone(ImDrawList* draw_list, vec4 ctrl)
{
draw_list->AddRect(ImVec2(ctrl.x, ctrl.y), ImVec2(ctrl.x + ctrl.z, ctrl.y + ctrl.w), g_ColorMagenta, 1.0f);
}
void RenderEnv(float x, float y)
{
ImGui::PushFont(g_FontArial16);
float w = 80;
float h = 136;
float buttonWidth = 72;
float buttonHeight = 28;
float gap = 5;
ImDrawList* draw_list = ImGui::GetBackgroundDrawList();
ImVec2 pos = ImVec2(x, y);
// Rounded frame
draw_list->AddRectFilled(pos, ImVec2(pos.x + w, pos.y + h), g_ColorSimShip4, 10.0f);
draw_list->AddRect(pos, ImVec2(pos.x + w, pos.y + h), g_ColorWhite, 10.0f, 0, 1.0f);
// Camera mode button
float currentY = y + 5;
ImU32 color = g_ColorAmbre;
switch (g_Camera.GetMode())
{
case eCameraMode::ORBITAL: color = g_ColorAmbre; break;
case eCameraMode::BRIDGE: color = g_ColorRed; break;
case eCameraMode::FPS: color = g_ColorGreen; break;
}
string mode;
switch (g_Camera.GetMode())
{
case eCameraMode::ORBITAL: mode = "ORBITAL"; break;
case eCameraMode::BRIDGE:
switch (g_eBridgeView)
{
case eBridgeView::WHEEL: mode = "BRIDGE"; break;
case eBridgeView::LEFT: mode = "LEFT"; break;
case eBridgeView::RIGHT: mode = "RIGHT"; break;
case eBridgeView::BOW: mode = "BOW"; break;
case eBridgeView::STERN: mode = "STERN"; break;
}
break;
case eCameraMode::FPS: mode = "FPS"; break;
}
ImVec2 btn_pos = ImVec2(x + (w - buttonWidth) / 2, currentY);
draw_list->AddRectFilled(btn_pos, ImVec2(btn_pos.x + buttonWidth, btn_pos.y + buttonHeight), color, 5.0f);
ImVec2 textPos = GetCenteredTextPos(mode.c_str(), ImVec2(btn_pos.x + buttonWidth / 2, btn_pos.y + buttonHeight / 2), 0, 0, g_FontArial16);
draw_list->AddText(textPos, g_ColorWhite, mode.c_str());
// Lookat angle
buttonWidth = 60; buttonHeight = 18;
char lookat[16];
snprintf(lookat, sizeof(lookat), "%03d\xC2\xB0", (int)g_Camera.GetNorthAngleDEG());
ImVec2 look_pos = ImVec2(x + (w - buttonWidth) / 2, y + 38);
draw_list->AddRectFilled(look_pos, ImVec2(look_pos.x + buttonWidth, look_pos.y + buttonHeight), g_ColorSimShip1, 3.0f);
ImVec2 text_pos = GetCenteredTextPos(lookat, ImVec2(look_pos.x + buttonWidth / 2, look_pos.y + buttonHeight / 2), 0, 0, g_FontArial16);
draw_list->AddText(text_pos, g_ColorCyan, lookat);
// FPS
char fps[16];
snprintf(fps, sizeof(fps), "%d i/s", g_nFps);
ImVec2 fps_pos = ImVec2(x + (w - buttonWidth) / 2, y + 61);
draw_list->AddRectFilled(fps_pos, ImVec2(fps_pos.x + buttonWidth, fps_pos.y + buttonHeight), g_ColorSimShip1, 3.0f);
text_pos = GetCenteredTextPos(fps, ImVec2(fps_pos.x + buttonWidth / 2, fps_pos.y + buttonHeight / 2), 0, 0, g_FontArial16);
draw_list->AddText(text_pos, g_ColorCyan, fps);
// Icon Sound
ImVec2 icon_pos = ImVec2(x + 5, y + 88);
VkDescriptorSet* tex_sound = g_SoundMgr->bSound ? (VkDescriptorSet*)g_ImgSoundUp->GetImGuiDescriptorSet() : (VkDescriptorSet*)g_ImgSoundOff->GetImGuiDescriptorSet();
draw_list->AddRectFilled(icon_pos, ImVec2(icon_pos.x + 20, icon_pos.y + 20), g_ColorSimShip3, 5.0f);
draw_list->AddImage((ImTextureID)tex_sound, icon_pos, ImVec2(icon_pos.x + 20, icon_pos.y + 20));
g_CtrlSound = vec4(x + 5, 88, 20.0f, 20.0f);
// Icon Timer
ImVec2 timer_pos = ImVec2(x + 30, y + 88);
draw_list->AddRectFilled(timer_pos, ImVec2(timer_pos.x + 20, timer_pos.y + 20), g_ColorSimShip3, 5.0f);
draw_list->AddImage((ImTextureID)(VkDescriptorSet*)g_ImgTimer->GetImGuiDescriptorSet(), timer_pos, ImVec2(timer_pos.x + 20, timer_pos.y + 20));
g_CtrlTimer = vec4(x + 30, 88, 20.0f, 20.0f);
// Icons Meteo
ImVec2 mto0_pos = ImVec2(x + 55, y + 88);
draw_list->AddRectFilled(mto0_pos, ImVec2(mto0_pos.x + 20, mto0_pos.y + 20), g_ColorSimShip2, 5.0f);
draw_list->AddImage((ImTextureID)(VkDescriptorSet*)g_ImgMto0->GetImGuiDescriptorSet(), mto0_pos, ImVec2(mto0_pos.x + 20, mto0_pos.y + 20));
g_CtrlMto0 = vec4(x + 55, 88, 20.0f, 20.0f);
ImVec2 mto1_pos = ImVec2(x + 5, y + 112);
draw_list->AddRectFilled(mto1_pos, ImVec2(mto1_pos.x + 20, mto1_pos.y + 20), g_ColorSimShip2, 5.0f);
draw_list->AddImage((ImTextureID)(VkDescriptorSet*)g_ImgMto1->GetImGuiDescriptorSet(), mto1_pos, ImVec2(mto1_pos.x + 20, mto1_pos.y + 20));
g_CtrlMto1 = vec4(x + 5, 112, 20.0f, 20.0f);
ImVec2 mto2_pos = ImVec2(x + 30, y + 112);
draw_list->AddRectFilled(mto2_pos, ImVec2(mto2_pos.x + 20, mto2_pos.y + 20), g_ColorSimShip2, 5.0f);
draw_list->AddImage((ImTextureID)(VkDescriptorSet*)g_ImgMto2->GetImGuiDescriptorSet(), mto2_pos, ImVec2(mto2_pos.x + 20, mto2_pos.y + 20));
g_CtrlMto2 = vec4(x + 30, 112, 20.0f, 20.0f);
ImVec2 mto3_pos = ImVec2(x + 55, y + 112);
draw_list->AddRectFilled(mto3_pos, ImVec2(mto3_pos.x + 20, mto3_pos.y + 20), g_ColorSimShip2, 5.0f);
draw_list->AddImage((ImTextureID)(VkDescriptorSet*)g_ImgMto3->GetImGuiDescriptorSet(), mto3_pos, ImVec2(mto3_pos.x + 20, mto3_pos.y + 20));
g_CtrlMto3 = vec4(x + 55, 112, 20.0f, 20.0f);
// Overlay night
if (g_Sky->SunPosition.y < 0.0f)
draw_list->AddRectFilled(pos, ImVec2(pos.x + w, pos.y + h), IM_COL32(0, 0, 0, 128), 10.0f);
ImGui::PopFont();
}
void RenderControlFrame(float x, float y, float w, float h)
{
ImDrawList* draw_list = ImGui::GetBackgroundDrawList();
ImVec2 pos = ImVec2(x, y);
// Rounded frame with white border (equivalent to NanoVG)
draw_list->AddRectFilled(pos, ImVec2(pos.x + w, pos.y + h), g_ColorSimShip4, 10.0f);
draw_list->AddRect(pos, ImVec2(pos.x + w, pos.y + h), g_ColorWhite, 10.0f, 0, 1.0f);
// TWS text (kt) - Red
ImGui::PushFont(g_FontArial08);
char twsLabel[32];
snprintf(twsLabel, sizeof(twsLabel), "TWS (kt)");
draw_list->AddText(ImVec2(x + 5, y + 5), IM_COL32(255, 0, 0, 255), twsLabel);
ImGui::PopFont();
ImGui::PushFont(g_FontArial20);
char windText[32];
snprintf(windText, sizeof(windText), "%.0f", g_TWS_Kt);
draw_list->AddText(ImVec2(x + 5, y + 15), IM_COL32(255, 0, 0, 255), windText); // Rouge pour la valeur
ImGui::PopFont();
g_CtrlWind = vec4(x + 5, y + 15, 20, 20);
// AWS text (kt) - Blue
ImGui::PushFont(g_FontArial08);
snprintf(windText, sizeof(windText), "AWS (kt)");
draw_list->AddText(ImVec2(x + 5, y + h - 15), IM_COL32(0, 0, 255, 255), windText);
ImGui::PopFont();
ImGui::PushFont(g_FontArial20);
snprintf(windText, sizeof(windText), "%.1f", ms_to_knot(g_Ship->AWS));
draw_list->AddText(ImVec2(x + 5, y + h - 35), IM_COL32(0, 0, 255, 255), windText); // Bleu pour la valeur
ImGui::PopFont();
}
void RenderCompass(float x, float y, float radius)
{
ImGui::PushFont(g_FontArial16);
ImDrawList* draw_list = ImGui::GetBackgroundDrawList();
ImVec2 center = ImVec2(x, y);
// Settings
float thicknessCircle = 2.0f;
float lengthGraduation = 5.0f;
float sizeTriangle = 15.0f;
float sizeTexDisplay = 8.0f;
float sizeNumDisplay = 22.0f;
float spacing = 18.0f;
// Circle
draw_list->AddCircleFilled(center, radius, g_ColorSimShip1, 0);
// Graduations and cardinal points (every 10°)
for (int i = 0; i < 360; i += 10)
{
float angle = i * M_PI / 180.0f;
ImVec2 outer = ImVec2(x + cosf(angle) * radius, y + sinf(angle) * radius);
ImVec2 inner = ImVec2(x + cosf(angle) * (radius - lengthGraduation), y + sinf(angle) * (radius - lengthGraduation));
draw_list->AddLine(outer, inner, g_ColorWhite, 1.0f);
}
// HDG Triangle cyan
float angleTriangle = (g_Ship->HDG - 90.0f) * M_PI / 180.0f;
float baseTriangle = 10.0f;
float heightTriangle = 17.0f;