-
Notifications
You must be signed in to change notification settings - Fork 6
/
main.cpp
9864 lines (7376 loc) · 394 KB
/
main.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
#include <cstdio>
#include <iomanip>
#include <sstream>
#include <iostream>
#include <cmath>
#include <fstream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <chrono>
#include <atomic>
#include <thread>
#include <queue>
#include <stdint.h>
#include "raylib.h"
#include "raymath.h"
#include "rcamera.h"
//#include <glm.hpp>
//#include <gtx\\string_cast.hpp>
//#define RLIGHTS_IMPLEMENTATION
//#include "rlights.h"
#if defined(PLATFORM_DESKTOP)
#define GLSL_VERSION 330
#else // PLATFORM_ANDROID, PLATFORM_WEB
#define GLSL_VERSION 100
#endif
#include "imgui.h"
#include "rlImGui.h"
#include "rlImGuiColors.h"
//#include "ImGuiFileDialog.h"
#include "classes.hpp"
#include "planet.hpp"
#include "region.hpp"
#include "functions.hpp"
#define getURL URLOpenBlockingStreamA
// nodiscard attribute
#pragma warning (disable: 4834)
#define REGIONALCREATIONSTEPS 84
#define GLOBALTERRAINCREATIONSTEPS1 26
#define GLOBALTERRAINCREATIONSTEPS2 31
#define GLOBALCLIMATECREATIONSTEPS 28
#define REGIONALTILEWIDTH 32
#define REGIONALTILEHEIGHT 32
#define DISPLAYMAPSIZEX 1024
#define DISPLAYMAPSIZEY 512
//MATERIAL_MAP_ROUGHNESS
using namespace std;
// Random number generator. From https://stackoverflow.com/questions/26237419/faster-than-rand
// It uses a global variable.
static long g_seed = 1;
// Used to seed the generator.
void fast_srand(long seed)
{
g_seed = seed;
}
// Compute a pseudorandom integer.
// Output value in range [0, 32767]
int fast_rand(void)
{
g_seed = (214013 * g_seed + 2531011);
return (g_seed >> 16) & 0x7FFF;
}
int main()
{
SetTraceLogLevel(7);
float currentversion = 1.0f;
float latestversion = getlatestversion();
string currentversionstring = "Current version: " + to_string(currentversion);
string latestversionstring = "Latest version: " + to_string(latestversion);
//updatereport(currentversionstring.c_str());
//updatereport(latestversionstring.c_str());
string degree = "\xC2\xB0"; // 0xC2 0xB0 (c2b0) °
string cube = "\xC2\xB3"; // 0xC2 0xB3 (c2b3) ³
// Set up the window.
int scwidth = 1920; // 1224;
int scheight = 1080; // 700; // 768;
SetConfigFlags(FLAG_WINDOW_RESIZABLE | FLAG_WINDOW_HIGHDPI);
//InitWindow(scwidth, scheight, "Undiscovered Worlds");
InitWindow(0, 0, "Undiscovered Worlds"); // Uses maximum screen dimensions automatically.
scwidth = GetScreenWidth();
scheight = GetScreenHeight();
ImVec2 focusedwindowpos = ImVec2(200,100); // The position of the focused window. (Because if the focus changes the window ID will change, but we want it to stay in the same position if the user has moved it.)
// Set up ImGui.
ImGui::CreateContext();
ImGuiIO& io = ImGui::GetIO(); (void)io;
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls
// Set up Dear ImGUI style.
// A rough imitation of Nanogui.
ImGuiStyle& Style = ImGui::GetStyle();
Style.WindowMinSize = ImVec2(160, 20);
Style.WindowPadding = ImVec2(9, 2);
Style.FramePadding = ImVec2(4, 2);
Style.ItemSpacing = ImVec2(9, 12);
Style.Alpha = 0.95f;
Style.WindowRounding = 4.0f;
Style.FrameRounding = 4.0f;
Style.IndentSpacing = 6.0f;
Style.ItemInnerSpacing = ImVec2(7, 4);
Style.ColumnsMinSpacing = 50.0f;
Style.GrabMinSize = 8.0f;
Style.GrabRounding = 16.0f;
Style.ScrollbarSize = 12.0f;
Style.ScrollbarRounding = 16.0f;
Style.AntiAliasedLinesUseTex = 0.0f;
Style.TabBorderSize = 0.0f;
Style.TabBarBorderSize = 0.0f;
//Style.FancyThickness = 1.5f; // 2.0f;
//Style.FancyTabIndent = 30;
//Style.FancyTabBorder = 20;
//Style.FancyButtonGradient = 0.15f; // 0.15f;
//Style.FancyTitleGradient = 0.15f; // 0.1f;
//Style.FancyTitlePadding = 10.0f;
//Style.FancyProgressGradient = 0.2f; // 0.2f;
//Style.FancyProgressBandWidth = 100.0f; // 60.0f;
float highlight1 = 0.40f;
float highlight2 = 0.40f;
float highlight3 = 0.40f;
Style.Colors[ImGuiCol_Text] = ImVec4(0.69f, 0.69f, 0.69f, 1.0f);
Style.Colors[ImGuiCol_TextDisabled] = ImVec4(0.86f, 0.93f, 0.89f, 0.28f);
Style.Colors[ImGuiCol_WindowBg] = ImVec4(0.18f, 0.18f, 0.18f, 1.0f); // 0.18
Style.Colors[ImGuiCol_ChildBg] = ImVec4(highlight1, highlight2, highlight3, 1.00f); // new
Style.Colors[ImGuiCol_PopupBg] = ImVec4(highlight1, highlight2, highlight3, 1.00f); // new
Style.Colors[ImGuiCol_Border] = ImVec4(0.1f, 0.1f, 0.1f, 0.2f); // frame around each window
Style.Colors[ImGuiCol_BorderShadow] = ImVec4(0.00f, 0.00f, 0.00f, 0.2f);
Style.Colors[ImGuiCol_FrameBg] = ImVec4(0.14f, 0.14f, 0.14f, 1.0f);
Style.Colors[ImGuiCol_FrameBgHovered] = ImVec4(0.20f, 0.22f, 0.27f, 1.0f);
Style.Colors[ImGuiCol_FrameBgActive] = ImVec4(0.20f, 0.22f, 0.27f, 1.0f);
Style.Colors[ImGuiCol_TitleBg] = ImVec4(0.26f, 0.26f, 0.26f, 1.0f); // 25
Style.Colors[ImGuiCol_TitleBgCollapsed] = ImVec4(0.28f, 0.28f, 0.28f, 1.0f);
Style.Colors[ImGuiCol_TitleBgActive] = ImVec4(0.28f, 0.28f, 0.28f, 1.0f);
Style.Colors[ImGuiCol_MenuBarBg] = ImVec4(0.157f, 0.157f, 0.157f, 1.0f);
Style.Colors[ImGuiCol_ScrollbarBg] = ImVec4(0.157f, 0.157f, 0.157f, 1.0f);
Style.Colors[ImGuiCol_ScrollbarGrab] = ImVec4(0.2f, 0.2f, 0.2f, 1.00f);
Style.Colors[ImGuiCol_ScrollbarGrabHovered] = ImVec4(0.29f, 0.18f, 0.92f, 0.78f);
Style.Colors[ImGuiCol_ScrollbarGrabActive] = ImVec4(highlight1, highlight2, highlight3, 1.00f);
Style.Colors[ImGuiCol_CheckMark] = ImVec4(0.86f, 0.93f, 0.89f, 0.78f);
Style.Colors[ImGuiCol_SliderGrab] = ImVec4(0.3f, 0.3f, 0.3f, 1.0f);
Style.Colors[ImGuiCol_SliderGrabActive] = ImVec4(highlight1, highlight2, highlight3, 1.00f);
Style.Colors[ImGuiCol_Button] = ImVec4(0.25f, 0.25f, 0.25f, 1.0f);
Style.Colors[ImGuiCol_ButtonHovered] = ImVec4(highlight1, highlight2, highlight3, 0.86f);
Style.Colors[ImGuiCol_ButtonActive] = ImVec4(highlight1, highlight2, highlight3, 1.00f);
Style.Colors[ImGuiCol_Header] = ImVec4(highlight1, highlight2, highlight3, 0.76f);
Style.Colors[ImGuiCol_HeaderHovered] = ImVec4(highlight1, highlight2, highlight3, 0.86f);
Style.Colors[ImGuiCol_HeaderActive] = ImVec4(highlight1, highlight2, highlight3, 1.00f);
Style.Colors[ImGuiCol_Separator] = ImVec4(1.0f, 1.0f, 1.0f, 1.00f); //ImVec4(0.14f, 0.16f, 0.19f, 1.00f);
Style.Colors[ImGuiCol_SeparatorHovered] = ImVec4(highlight1, highlight2, highlight3, 0.78f);
Style.Colors[ImGuiCol_SeparatorActive] = ImVec4(highlight1, highlight2, highlight3, 1.0f);
Style.Colors[ImGuiCol_PlotLines] = ImVec4(0.86f, 0.93f, 0.89f, 0.63f);
Style.Colors[ImGuiCol_PlotLinesHovered] = ImVec4(highlight1, highlight2, highlight3, 1.0f);
Style.Colors[ImGuiCol_PlotHistogram] = ImVec4(0.25f, 0.25f, 0.25f, 1.0f);
Style.Colors[ImGuiCol_PlotHistogramHovered] = ImVec4(highlight1, highlight2, highlight3, 1.0f);
Style.Colors[ImGuiCol_PopupBg] = ImVec4(0.157f, 0.157f, 0.157f, 1.0f);
Style.Colors[ImGuiCol_TextSelectedBg] = ImVec4(0.157f, 0.157f, 0.157f, 1.0f);
Style.Colors[ImGuiCol_Tab] = ImVec4(0.11f, 0.11f, 0.11f, 1.0f);
Style.Colors[ImGuiCol_TabHovered] = ImVec4(highlight1, highlight2, highlight3, 0.86f);
Style.Colors[ImGuiCol_TabActive] = Style.Colors[ImGuiCol_WindowBg];
Style.Colors[ImGuiCol_TabUnfocused] = ImVec4(0.11f, 0.11f, 0.11f, 1.0f);
Style.Colors[ImGuiCol_TabUnfocusedActive] = ImVec4(highlight1, highlight2, highlight3, 0.86f);
// These ones are used for our custom highlighting/shading around buttons etc.
Style.Colors[ImGuiCol_ResizeGrip] = ImVec4(0.377f, 0.377f, 0.377f, 1.0f); // Top highlight.
Style.Colors[ImGuiCol_ResizeGripHovered] = ImVec4(0.259f, 0.259f, 0.259f, 1.0f); // Bottom highlight
Style.Colors[ImGuiCol_ResizeGripActive] = ImVec4(0.137f, 0.137f, 0.137f, 1.0f); // Shade
ImFont* font1 = io.Fonts->AddFontFromFileTTF("fonts\\Roboto-Medium.ttf", 20.0f); // 18.0f
io.Fonts->Build();
IM_ASSERT(font1 != NULL);
ImGuiWindowFlags window_flags = 0;
window_flags |= ImGuiWindowFlags_NoCollapse;
//window_flags |= ImGuiWindowFlags_NoResize;
ImGui_ImplRaylib_Init();
float buttonheight = 30.0f; // 30
float buttonwidth = 120.0f; // 140
float buttongap = 40.0f; // To space buttons vertically.
float topmargin = 30.0f; // Margin to add just to the top of windows.
bool* closeflag = new bool(true); // For when we want a close button on windows.
// Now create the main world object and initialise its basic variables.
planet* world = new planet;
initialiseworld(*world);
initialisemapcolours(*world);
initialisespacesettings(*world);
int edge = world->edge();
bool drawface[6];
for (int n = 0; n < 6; n++)
drawface[n] = 1;
bool drawstarface[6];
for (int n = 0; n < 6; n++)
drawstarface[n] = 1;
// Now we need to load the template images for various kinds of terrain creation.
boolshapetemplate landshape[12]; // Basic land shape
createlandshapetemplates(landshape);
boolshapetemplate chainland[2]; // Mountain chain land shapes.
createchainlandtemplates(chainland);
boolshapetemplate smalllake[12]; // Small lake shapes
createsmalllaketemplates(smalllake);
boolshapetemplate largelake[10]; // Large lake shapes
createlargelaketemplates(largelake);
boolshapetemplate island[12]; // Small island shapes
createislandtemplates(island);
byteshapetemplate smudge[6]; // Smudge shapes
createsmudgetemplates(smudge);
byteshapetemplate smallsmudge[6]; // Small smudge shapes
createsmallsmudgetemplates(smallsmudge);
peaktemplate* peaks = new peaktemplate; // Peak shapes.
loadpeaktemplates(*peaks);
// Other bits
fast_srand((long)time(0));
bool brandnew = 1; // This means the program has just started and it's the first world to be generated.
bool loadingworld = 0; // This would mean that we're trying to load in a new world.
bool savingworld = 0; // This would mean that we're trying to save a world.
bool loadingsettings = 0; // This would mean that we're trying to load appearance settings.
bool savingsettings = 0; // This would mean that we're trying to save appearance settings.
bool exportingworldmaps = 0;
bool exportingregionalmaps = 0;
bool exportingareamaps = 0;
bool importinglandmap = 0;
bool importingseamap = 0;
bool importingmountainsmap = 0;
bool importingvolcanoesmap = 0;
string month[12];
month[0] = "Jan";
month[1] = "Feb";
month[2] = "Mar";
month[3] = "Apr";
month[4] = "May";
month[5] = "Jun";
month[6] = "Jul";
month[7] = "Aug";
month[8] = "Sep";
month[9] = "Oct";
month[10] = "Nov";
month[11] = "Dec";
vector<int> squareroot((MAXCRATERRADIUS * MAXCRATERRADIUS + MAXCRATERRADIUS + 1) * 24);
for (int n = 0; n <= ((MAXCRATERRADIUS * MAXCRATERRADIUS + MAXCRATERRADIUS) * 24); n++)
squareroot[n] = (int)sqrt(n);
screenmodeenum screenmode = createworldscreen; // This is used to keep track of which screen mode we're in.
screenmodeenum oldscreenmode = createworldscreen;
mapviewenum mapview = space; // This is used to keep track of which kind of information we want the map to show.
int seedentry = 0; // The value currently entered into the seed box in the create world screen.
bool *focused = new bool (false); // This will track whether we're focusing on one point or not.
globepoint poi; // Coordinates of the point of interest.
bool globalmapimagecreated[GLOBALMAPTYPES] = {}; // This will keep track of which global map images have actually been created.
bool newworld = 0; // Whether to show the new world message.
bool *showcolouroptions = new bool(false); // If this is 1 then we display the appearance preferences options.
bool *showworldproperties = new bool (false); // If this is 1 then we display the properties of the current world.
bool *showmovementoptions = new bool(false); // If this is 1 then we display the movement preferences options.
bool *showglobaltemperaturechart = new bool(false); // If this is 1 then we show monthly temperatures for the selected point.
bool *showglobalrainfallchart = new bool(false); // If this is 1 then we show monthly rainfall for the selected point.
bool *showglobalriverchart = new bool(false); // If this is 1 then we show monthly river flow for the selected point.
bool showregionaltemperaturechart = 0; // If this is 1 then we show monthly temperatures for the selected point.
bool showregionalrainfallchart = 0; // If this is 1 then we show monthly rainfall for the selected point.
bool showsetsize = 0; // If this is 1 then a window is show to set the size for the custom world.
bool showtectonicchooser = 0; // If this is 1 then we show the panel for creating tectonic-based custom world terrain.
bool shownontectonicchooser = 0; // If this is 1 then we show the panel for creating non-tectonic-based custom world terrain.
bool showworldeditproperties = 0; // If this is 1 then we show the panel for editing custom world properties.
bool showareawarning = 0; // If this is 1 then we show a warning about too-large areas.
bool showabout = 0; // If this is 1 then we display information about the program.
bool showui = 1; // If this is 1 then we show the UI.
// And some for the movement controls.
float camerazoomspeed = 0.0f;
float camerarotatespeed = 0.0f;
bool cameralock = 0;
float planetrotatespeed = 0.0f;
float monthspeed = 0.0f;
bool monthrotate = 0;
initialisemovementsettings(camerazoomspeed, camerarotatespeed, planetrotatespeed, monthspeed, cameralock, monthrotate);
vector<string> keycodes(350, "");
createkeycodelist(keycodes);
int keybindingsno = 12;
vector<int> keybindings(12, 0);
loadcontrols(keybindings, keybindingsno, camerazoomspeed, camerarotatespeed, planetrotatespeed, monthspeed, cameralock, monthrotate, "bindings.txt");
int gettingkeybinding = 0; // If this is > 0 then we are waiting for a key to be pressed to set a binding.
for (int n = 0; n < GLOBALMAPTYPES; n++)
globalmapimagecreated[n] = 0;
bool colourschanged = 0; // If this is 1 then the colours have been changed and the maps need to be redrawn.
bool othermonthsneedupdating = 0; // If this is 1 then we need to redo all the space images upon closing the colour changing window.
float linespace = 8.0f; // Gap between groups of buttons.
string filepathname = "";
string filepath = "";
short completingimportpass = 0; // Tracks which pass we're on for this section, to ensure that widgets are correctly displayed.
short loadingworldpass = 0; // Tracks which pass we're on for this section, to ensure that widgets are correctly displayed.
short savingworldpass = 0; // Tracks which pass we're on for this section, to ensure that widgets are correctly displayed.
short exportingareapass = 0; // Tracks which pass we're on for this section, to ensure that widgets are correctly displayed.
short generatingregionpass = 0; // Tracks which pass we're on for this section, to ensure that widgets are correctly displayed.
short generatingtectonicpass = 0; // Tracks which pass we're on for this section, to ensure that widgets are correctly displayed.
short generatingnontectonicpass = 0; // Tracks which pass we're on for this section, to ensure that widgets are correctly displayed.
int landmass = 5; // Rough amount of land coverage, for custom worlds.
int mergefactor = 15; // Amount continents will be removed by merging with the fractal map, for custom worlds.-----------------
int iterations = 4; // Number of terrain iterations for worlds of terrain type 4.
int sealeveleditable = 5; // Sea level (0-10) for worlds of terrain type 4.
// Now world property variables that can be directly manipulated in the world settings edit panel.
int currentsize = world->size();
float currentgravity = world->gravity();
float currentlunar = world->lunar();
float currenteccentricity = world->eccentricity();
int currentperihelion = world->perihelion();
int currentrotation = world->rotation();
float currenttilt = world->tilt();
float currenttempdecrease = world->tempdecrease();
int currentnorthpolaradjust = world->northpolaradjust();
int currentsouthpolaradjust = world->southpolaradjust();
int currentaveragetemp = world->averagetemp();
float currentwaterpickup = world->waterpickup();
int currentglacialtemp = world->glacialtemp();
bool currentrivers = 1; // This one controls whether or not rivers will be calculated for the custom world.
bool currentlakes = 1; // This one controls whether or not lakes will be calculated for the custom world.
bool currentdeltas = 1; // This one controls whether or not river deltas will be calculated for the custom world.
// Prepare look-up tables for longitude and latitude. (As they take too long to calculate on the fly.)
vector<float> longitude(6 * 512 * 512);
vector<float> latitude(6 * 512 * 512);
for (int face = 0; face < 6; face++)
{
int vface = face * 512 * 512;
for (int i = 0; i < 512; i++)
{
int vi = vface + i * 512;
for (int j = 0; j < 512; j++)
{
int index = vi + j;
getlonglat(512, face, (float)i, (float)j, longitude[index], latitude[index]);
}
}
}
// Now prepare look-up tables for directions. This will store the coordinates of points to the north, east, south, and west of each point.
vector<fourglobepoints> dirpoint(6 * 512 * 512);
createdirectiontable(edge, dirpoint, longitude, latitude);
vector<fourdirs> dircode(6 * 512 * 512);
createdircodetable(edge, dirpoint, dircode);
// Prepare 2D images to be used as textures. There are six images for each category, corresponding to the six faces of the cubesphere.
const int globaltexturesize = 512;
const int globallargetexturesize = 512 * 4;
vector<Image> globalelevationimage(6);
vector<Image> globaltemperatureimage(6);
vector<Image> globalprecipitationimage(6);
vector<Image> globalclimateimage(6);
vector<Image> globalriversimage(6);
vector<Image> globalreliefimage(6);
vector<Image> globalpickingimage(6);
vector<Image> globalnormalimage(6);
vector<Image> globalspaceimage(6 * 12); // 12 of these, for the months
vector<Image> globalspecularimage(6 * 12); // 12 of these, for the months
for (int n = 0; n < 6; n++)
{
globalelevationimage[n] = GenImageColor(globaltexturesize, globaltexturesize, BLACK);
globaltemperatureimage[n] = GenImageColor(globaltexturesize, globaltexturesize, BLACK);
globalprecipitationimage[n] = GenImageColor(globaltexturesize, globaltexturesize, BLACK);
globalclimateimage[n] = GenImageColor(globaltexturesize, globaltexturesize, BLACK);
globalriversimage[n] = GenImageColor(globaltexturesize, globaltexturesize, BLACK);
globalreliefimage[n] = GenImageColor(globaltexturesize, globaltexturesize, BLACK);
globalpickingimage[n] = GenImageColor(globaltexturesize, globaltexturesize, BLACK);
globalnormalimage[n] = GenImageColor(globallargetexturesize, globallargetexturesize, BLACK);
}
for (int n = 0; n < 6; n++)
{
for (int m = 0; m < 12; m++)
{
globalspaceimage[n * 12 + m] = GenImageColor(globallargetexturesize, globallargetexturesize, BLACK);
globalspecularimage[n * 12 + m] = GenImageColor(globallargetexturesize, globallargetexturesize, BLACK);
}
}
vector<Texture2D> globaltexture(6);
vector<Texture2D> globalspeculartexture(6);
vector<Texture2D> globalspacetextureold(6);
vector<Texture2D> globalspeculartextureold(6);
vector<Texture2D> globalnormaltexture(6);
for (int n = 0; n < 6; n++)
{
globaltexture[n] = LoadTextureFromImage(globalnormalimage[n]);
globalspeculartexture[n] = LoadTextureFromImage(globalnormalimage[n]);
globalspacetextureold[n] = LoadTextureFromImage(globalnormalimage[n]);
globalspeculartextureold[n] = LoadTextureFromImage(globalnormalimage[n]);
globalnormaltexture[n] = LoadTextureFromImage(globalnormalimage[n]);
}
//Image testimage = LoadImage("resources\\parrots.png");
drawglobalpickingimage(*world, globaltexturesize, globalpickingimage);
// Now we prepare map colours. We put them into ImVec4 objects, which can be directly manipulated by the colour picker objects.
ImVec4 seacolour;
seacolour.x = (float)world->sea1() / 255.f;
seacolour.y = (float)world->sea2() / 255.f;
seacolour.z = (float)world->sea3() / 255.f;
seacolour.w = 1.f;
ImVec4 oceancolour;
oceancolour.x = (float)world->ocean1() / 255.f;
oceancolour.y = (float)world->ocean2() / 255.f;
oceancolour.z = (float)world->ocean3() / 255.f;
oceancolour.w = 1.f;
ImVec4 deepoceancolour;
deepoceancolour.x = (float)world->deepocean1() / 255.f;
deepoceancolour.y = (float)world->deepocean2() / 255.f;
deepoceancolour.z = (float)world->deepocean3() / 255.f;
deepoceancolour.w = 1.f;
ImVec4 basecolour;
basecolour.x = (float)world->base1() / 255.f;
basecolour.y = (float)world->base2() / 255.f;
basecolour.z = (float)world->base3() / 255.f;
basecolour.w = 1.f;
ImVec4 grasscolour;
grasscolour.x = (float)world->grass1() / 255.f;
grasscolour.y = (float)world->grass2() / 255.f;
grasscolour.z = (float)world->grass3() / 255.f;
grasscolour.w = 1.f;
ImVec4 basetempcolour;
basetempcolour.x = (float)world->basetemp1() / 255.f;
basetempcolour.y = (float)world->basetemp2() / 255.f;
basetempcolour.z = (float)world->basetemp3() / 255.f;
basetempcolour.w = 1.f;
ImVec4 highbasecolour;
highbasecolour.x = (float)world->highbase1() / 255.f;
highbasecolour.y = (float)world->highbase2() / 255.f;
highbasecolour.z = (float)world->highbase3() / 255.f;
highbasecolour.w = 1.f;
ImVec4 desertcolour;
desertcolour.x = (float)world->desert1() / 255.f;
desertcolour.y = (float)world->desert2() / 255.f;
desertcolour.z = (float)world->desert3() / 255.f;
desertcolour.w = 1.f;
ImVec4 highdesertcolour;
highdesertcolour.x = (float)world->highdesert1() / 255.f;
highdesertcolour.y = (float)world->highdesert2() / 255.f;
highdesertcolour.z = (float)world->highdesert3() / 255.f;
highdesertcolour.w = 1.f;
ImVec4 colddesertcolour;
colddesertcolour.x = (float)world->colddesert1() / 255.f;
colddesertcolour.y = (float)world->colddesert2() / 255.f;
colddesertcolour.z = (float)world->colddesert3() / 255.f;
colddesertcolour.w = 1.f;
ImVec4 eqtundracolour;
eqtundracolour.x = (float)world->eqtundra1() / 255.f;
eqtundracolour.y = (float)world->eqtundra2() / 255.f;
eqtundracolour.z = (float)world->eqtundra3() / 255.f;
eqtundracolour.w = 1.f;
ImVec4 tundracolour;
tundracolour.x = (float)world->tundra1() / 255.f;
tundracolour.y = (float)world->tundra2() / 255.f;
tundracolour.z = (float)world->tundra3() / 255.f;
tundracolour.w = 1.f;
ImVec4 coldcolour;
coldcolour.x = (float)world->cold1() / 255.f;
coldcolour.y = (float)world->cold2() / 255.f;
coldcolour.z = (float)world->cold3() / 255.f;
coldcolour.w = 1.f;
ImVec4 seaicecolour;
seaicecolour.x = (float)world->seaice1() / 255.f;
seaicecolour.y = (float)world->seaice2() / 255.f;
seaicecolour.z = (float)world->seaice3() / 255.f;
seaicecolour.w = 1.f;
ImVec4 glaciercolour;
glaciercolour.x = (float)world->glacier1() / 255.f;
glaciercolour.y = (float)world->glacier2() / 255.f;
glaciercolour.z = (float)world->glacier3() / 255.f;
glaciercolour.w = 1.f;
ImVec4 saltpancolour;
saltpancolour.x = (float)world->saltpan1() / 255.f;
saltpancolour.y = (float)world->saltpan2() / 255.f;
saltpancolour.z = (float)world->saltpan3() / 255.f;
saltpancolour.w = 1.f;
ImVec4 ergcolour;
ergcolour.x = (float)world->erg1() / 255.f;
ergcolour.y = (float)world->erg2() / 255.f;
ergcolour.z = (float)world->erg3() / 255.f;
ergcolour.w = 1.f;
ImVec4 wetlandscolour;
wetlandscolour.x = (float)world->wetlands1() / 255.f;
wetlandscolour.y = (float)world->wetlands2() / 255.f;
wetlandscolour.z = (float)world->wetlands3() / 255.f;
wetlandscolour.w = 1.f;
ImVec4 lakecolour;
lakecolour.x = (float)world->lake1() / 255.f;
lakecolour.y = (float)world->lake2() / 255.f;
lakecolour.z = (float)world->lake3() / 255.f;
lakecolour.w = 1.f;
ImVec4 rivercolour;
rivercolour.x = (float)world->river1() / 255.f;
rivercolour.y = (float)world->river2() / 255.f;
rivercolour.z = (float)world->river3() / 255.f;
rivercolour.w = 1.f;
ImVec4 sandcolour;
sandcolour.x = (float)world->sand1() / 255.f;
sandcolour.y = (float)world->sand2() / 255.f;
sandcolour.z = (float)world->sand3() / 255.f;
sandcolour.w = 1.f;
ImVec4 mudcolour;
mudcolour.x = (float)world->mud1() / 255.f;
mudcolour.y = (float)world->mud2() / 255.f;
mudcolour.z = (float)world->mud3() / 255.f;
mudcolour.w = 1.f;
ImVec4 shinglecolour;
shinglecolour.x = (float)world->shingle1() / 255.f;
shinglecolour.y = (float)world->shingle2() / 255.f;
shinglecolour.z = (float)world->shingle3() / 255.f;
shinglecolour.w = 1.f;
ImVec4 mangrovecolour;
mangrovecolour.x = (float)world->mangrove1() / 255.f;
mangrovecolour.y = (float)world->mangrove2() / 255.f;
mangrovecolour.z = (float)world->mangrove3() / 255.f;
mangrovecolour.w = 1.f;
ImVec4 highlightcolour;
highlightcolour.x = (float)world->highlight1() / 255.f;
highlightcolour.y = (float)world->highlight2() / 255.f;
highlightcolour.z = (float)world->highlight3() / 255.f;
highlightcolour.w = 1.f;
ImVec4 atmoscolour;
atmoscolour.x = (float)world->atmos1() / 255.f;
atmoscolour.y = (float)world->atmos2() / 255.f;
atmoscolour.z = (float)world->atmos3() / 255.f;
atmoscolour.w = 1.f;
ImVec4 duskcolour;
duskcolour.x = (float)world->dusk1() / 255.f;
duskcolour.y = (float)world->dusk2() / 255.f;
duskcolour.z = (float)world->dusk3() / 255.f;
duskcolour.w = 1.f;
ImVec4 suncolour;
suncolour.x = (float)world->sun1() / 255.f;
suncolour.y = (float)world->sun2() / 255.f;
suncolour.z = (float)world->sun3() / 255.f;
suncolour.w = 1.f;
ImVec4 gal1hazecolour;
gal1hazecolour.x = (float)world->gal1haze1() / 255.f;
gal1hazecolour.y = (float)world->gal1haze2() / 255.f;
gal1hazecolour.z = (float)world->gal1haze3() / 255.f;
gal1hazecolour.w = 1.f;
ImVec4 gal2hazecolour;
gal2hazecolour.x = (float)world->gal2haze1() / 255.f;
gal2hazecolour.y = (float)world->gal2haze2() / 255.f;
gal2hazecolour.z = (float)world->gal2haze3() / 255.f;
gal2hazecolour.w = 1.f;
ImVec4 gal1nebulacolour;
gal1nebulacolour.x = (float)world->gal1nebula1() / 255.f;
gal1nebulacolour.y = (float)world->gal1nebula2() / 255.f;
gal1nebulacolour.z = (float)world->gal1nebula3() / 255.f;
gal1nebulacolour.w = 1.f;
ImVec4 gal2nebulacolour;
gal2nebulacolour.x = (float)world->gal2nebula1() / 255.f;
gal2nebulacolour.y = (float)world->gal2nebula2() / 255.f;
gal2nebulacolour.z = (float)world->gal2nebula3() / 255.f;
gal2nebulacolour.w = 1.f;
ImVec4 bloomcolour;
bloomcolour.x = (float)world->bloom1() / 255.f;
bloomcolour.y = (float)world->bloom2() / 255.f;
bloomcolour.z = (float)world->bloom3() / 255.f;
bloomcolour.w = 1.f;
// Prepare some other variables for the appearance controls.
int rainpoint = 80; // Areas with less rain than this will have reduced clouds.
float marblingland = world->landmarbling();
float marblinglake = world->lakemarbling();
float marblingsea = world->seamarbling();
int minriverflowglobal = world->minriverflowglobal();
int minriverflowregional = world->minriverflowregional();
int globalriversentry = world->minriverflowglobal();
int regionalriversentry = world->minriverflowregional();
float normal = world->normal();
float ambient = world->ambient();
float gamma = world->gamma();
float haze = world->haze();
float specular = world->specular();
float cloudcover = world->cloudcover();
float bloomdist = world->bloomdist();
float sunglare = world->sunglare();
float sunlens = world->sunlens();
int sunrayno = world->sunrayno();
float sunraystrength = world->sunraystrength();
float starbright = world->starbright();
float starcolour = world->starcolour();
float starhaze = world->starhaze();
float starnebula = world->starnebula();
int snowchange = world->snowchange() - 1;
int seaiceappearance = world->seaiceappearance() - 1;
bool colourcliffs = world->colourcliffs();
bool mangroves = world->showmangroves();
bool mouseleftpressed = 0;
// Set up the camera.
float camdist = 4.0f; // Distance of the camera from the centre of the planet.
float camlong = 0.0f; // "Longitude" of the camera position. Measured absolutely, not necessarily corresponding to the planet's long/lat, as that can rotate.
float camlat = 0.0f; // "latitude" of the camera position.
threefloats cameraposition = getcoordinatesfromlatlong(camlat, camlong, camdist);
Vector3 campos = { cameraposition.x, cameraposition.y, cameraposition.z };
Camera camera = { 0 };
camera.position = campos;
camera.target = Vector3{ 0.0f, 0.0f, 0.0f };
camera.up = Vector3{ 0.0f, 1.0f, 0.0f };
camera.fovy = 45.0f;
camera.projection = CAMERA_PERSPECTIVE;
threefloats highlightposition;
highlightposition.x = 0.0f;
highlightposition.y = 0.0f;
highlightposition.x = 0.0f;
float sundistance = 400.0f;
int currentmonth = 0;
float currentsunlong = world->sunlong(currentmonth);
float currentsunlat = world->sunlat(currentmonth);
float currentsundist = world->sundist(currentmonth);
int monthsteps = 100; // The number of frames it takes to shift from one month to another if it's done at maximum slowness.
float thismonthsteps = 0.0f; // The number of frames it takes to shift at the moment.
int currentstep = 0; // If this is > 1 then count it down to shift to the next month.
float movesunlong = 0.0f; // The amount to move the sun (in degrees) every frame, if shifting.
float movesunlat = 0.0f;
float movesundist = 0.0f;
float showcurrentmonth = 1.0f; // If this is 1, just show the image for the current month. If it's < 1.0, merge the current month image with the old month image.
int totalprogress = 0; // How many steps it takes to create the world.
int progressval = 0; // Current step.
string progresstext = "";
// Load shaders
// Basic shader (for the planet when not in "space" view mode)
Shader baseshader = LoadShader(TextFormat("shaders\\base.vs", GLSL_VERSION),
TextFormat("shaders\\base.fs", GLSL_VERSION));
baseshader.locs[SHADER_LOC_VECTOR_VIEW] = GetShaderLocation(baseshader, "viewPos");
// Black shader (for the black version of the planet, when doing the glow for the sun)
Shader blackshader = LoadShader(TextFormat("shaders\\black.vs", GLSL_VERSION),
TextFormat("shaders\\black.fs", GLSL_VERSION));
blackshader.locs[SHADER_LOC_VECTOR_VIEW] = GetShaderLocation(blackshader, "viewPos");
// Shader for the starfield
Shader starshader = LoadShader(TextFormat("shaders\\starfield.vs", GLSL_VERSION),
TextFormat("shaders\\starfield.fs", GLSL_VERSION));
starshader.locs[SHADER_LOC_VECTOR_VIEW] = GetShaderLocation(starshader, "viewPos");
int starbrightLoc = GetShaderLocation(starshader, "starBrightness");
int starcolourLoc = GetShaderLocation(starshader, "starColor");
int starhazeLoc = GetShaderLocation(starshader, "hazeBrightness");
int starnebulaLoc = GetShaderLocation(starshader, "nebulaBrightness");
int galhazecol1Loc = GetShaderLocation(starshader, "hazeColor1");
int galhazecol2Loc = GetShaderLocation(starshader, "hazeColor2");
int galnebcol1Loc = GetShaderLocation(starshader, "nebulaColor1");
int galnebcol2Loc = GetShaderLocation(starshader, "nebulaColor2");
starshader.locs[SHADER_LOC_MAP_OCCLUSION] = GetShaderLocation(starshader, "haze");
// Shader for the sun
Shader sunshader = LoadShader(TextFormat("shaders\\sun.vs", GLSL_VERSION),
TextFormat("shaders\\sun.fs", GLSL_VERSION));
sunshader.locs[SHADER_LOC_VECTOR_VIEW] = GetShaderLocation(sunshader, "viewPos");
// Shader for the bloom effect
Shader bloomshader = LoadShader(TextFormat("shaders\\sunbloom.vs", GLSL_VERSION),
TextFormat("shaders\\sunbloom.fs", GLSL_VERSION));
bloomshader.locs[SHADER_LOC_VECTOR_VIEW] = GetShaderLocation(bloomshader, "viewPos");
int suncolLoc = GetShaderLocation(bloomshader, "sunColor");
int sunpos2dLoc = GetShaderLocation(bloomshader, "sunCentre");
int bloomcolLoc = GetShaderLocation(bloomshader, "bloomColor");
int bloomdistLoc = GetShaderLocation(bloomshader, "bDist");
int sunglareLoc = GetShaderLocation(bloomshader, "glareFactor");
int sunraystrengthLoc = GetShaderLocation(bloomshader, "rayValue");
int sunraynoLoc = GetShaderLocation(bloomshader, "rayNo");
// Shader for the lens flare effect
Shader lensshader = LoadShader(TextFormat("shaders\\sunlens.vs", GLSL_VERSION),
TextFormat("shaders\\sunlens.fs", GLSL_VERSION));
lensshader.locs[SHADER_LOC_VECTOR_VIEW] = GetShaderLocation(bloomshader, "viewPos");
int suncollensLoc = GetShaderLocation(lensshader, "sunColor");
int sunpos2dlensLoc = GetShaderLocation(lensshader, "sunCentre");
int sunlensLoc = GetShaderLocation(lensshader, "lensStrength");
// Shader for the planet object (when in "space" view mode)
Shader planetshader = LoadShader(TextFormat("shaders\\planet.vs", GLSL_VERSION),
TextFormat("shaders\\planet.fs", GLSL_VERSION));
planetshader.locs[SHADER_LOC_VECTOR_VIEW] = GetShaderLocation(planetshader, "viewPos");
int normalLoc = GetShaderLocation(planetshader, "bumpiness");
int ambientLoc = GetShaderLocation(planetshader, "ambient");
int gammaLoc = GetShaderLocation(planetshader, "gamma");
int hazeLoc = GetShaderLocation(planetshader, "haze");
int specularLoc = GetShaderLocation(planetshader, "specularOverall");
int cloudcoverLoc = GetShaderLocation(planetshader, "cloudCover");
int showcurrentmonthLoc = GetShaderLocation(planetshader, "showCurrentMonth");
int atmosLoc = GetShaderLocation(planetshader, "atmosCentreColor");
int duskLoc = GetShaderLocation(planetshader, "duskColor");
int lightcolLoc = GetShaderLocation(planetshader, "lightCol");
int lightposLoc = GetShaderLocation(planetshader, "lightPos");
int lighttargetLoc = GetShaderLocation(planetshader, "lightTarget");
float ambientcol[4] = { ambient, ambient, ambient, 1.0f };
SetShaderValue(planetshader, ambientLoc, ambientcol, SHADER_UNIFORM_VEC4);
float lightpos[3];
threefloats thissunpos = getcoordinatesfromlatlong(world->sunlat(currentmonth), world->sunlong(currentmonth), sundistance * world->sundist(currentmonth));
lightpos[0] = thissunpos.x;
lightpos[1] = thissunpos.y;
lightpos[2] = thissunpos.z;
SetShaderValue(planetshader, lightposLoc, lightpos, SHADER_UNIFORM_VEC3);
float lighttarget[3] = { 0.0f, 0.0f, 0.0f };
SetShaderValue(planetshader, lighttargetLoc, lighttarget, SHADER_UNIFORM_VEC3);
planetshader.locs[SHADER_LOC_MAP_OCCLUSION] = GetShaderLocation(planetshader, "olddiffuse");
planetshader.locs[SHADER_LOC_MAP_EMISSION] = GetShaderLocation(planetshader, "oldspecular");
// Set up the cubesphere.
Vector3 globepos = { 0.0f, 0.0f, 0.0f };
float globerotate = 0.0f;
float globetilt = 0.0f;
float globepitch = 0.0f;
float relativelong = 0.0f;
float relativelat = 0.0f;
int panels = 16; // Each face of the cubesphere consists of panels * panels panels. (Each panel consists of two flat triangles.)
vector<vector<vector<Model>>> spherepanels(6, vector<vector<Model>>(panels, vector<Model>(panels)));
setupspherepanels(spherepanels, panels, 1.0f);
updateshader(spherepanels, planetshader, panels);
// Now three more cubespheres for the regions (for the three planetary sizes). Where regions have been generated, we will show their panels instead of the global sphere panels.
vector<vector<vector<Model>>> regionspherepanels0(6, vector<vector<Model>>(panels, vector<Model>(panels)));
vector<vector<vector<Model>>> regionspherepanels1(6, vector<vector<Model>>(panels, vector<Model>(panels)));
vector<vector<vector<Model>>> regionspherepanels2(6, vector<vector<Model>>(panels, vector<Model>(panels)));
setupregionalspherepanels(regionspherepanels0, panels, 0, 1.0f);
updateshader(regionspherepanels0, planetshader, panels);
setupregionalspherepanels(regionspherepanels1, panels, 1, 1.0f);
updateshader(regionspherepanels1, planetshader, panels);
setupregionalspherepanels(regionspherepanels2, panels, 2, 1.0f);
updateshader(regionspherepanels2, planetshader, panels);
// Now create the skybox. It's a cubesphere as well.
const int skytexturesize = 1012; // 512;
vector<Image> starsimage(6);
vector<Image> starhazeimage(6);
for (int n = 0; n < 6; n++)
{
starsimage[n] = GenImageColor(skytexturesize, skytexturesize, BLACK);
starhazeimage[n] = GenImageColor(skytexturesize, skytexturesize, BLACK);
}
vector<Texture2D> starstexture(6);
vector<Texture2D> starhazetexture(6);
for (int n = 0; n < 6; n++)
{
starstexture[n] = LoadTextureFromImage(starsimage[n]);
starhazetexture[n] = LoadTextureFromImage(starhazeimage[n]);
}
float skyrotate = 0.0f;
float skytilt = 0.0f;
float skypitch = 0.0f;
int spanels = 1; // Fewer panels for this one, as it doesn't need to be as smooth.
vector<vector<vector<Model>>> skypanels(6, vector<vector<Model>>(spanels, vector<Model>(spanels)));
setupspherepanels(skypanels, spanels, -1000.0f);
updateshader(skypanels, starshader, spanels);
float textureypos = -9.0f; // y position of the bloom texture, to make it match the rest of the scene.
// Create a simple planet object. This will be used just for creating planetary textures.
simpleplanet* simpleworld = new simpleplanet;
// Vector to work out value proportions for enhanced detail on space images.
vector<float> proportions(4 * 4 * 4, 0.0f);
createproportionstable(proportions);
// Now we need an enormous vector of region objects.
int maxregions = 8 * 8; // This is the most regions we can hold in memory at once.
vector<region> regions(maxregions); // The actual region objects themselves.
vector<globepoint>regionID(maxregions); // This will specify where each of these regions actually is on the globe.
vector<int>regionloc(16 * 16 * 6, -1); // The reverse of the above: it will specify which region object corresponds to this area of the globe.
for (int n = 0; n < maxregions; n++)
{
regionID[n].face = -1;
regionID[n].x = -1;
regionID[n].y = -1;
}
vector<short> regioncreated(maxregions,0); // 0 == uncreated, 1 == created, 2 == being created.
vector<short>regioncreatedloc(16 * 16 * 6, 0); // As above, but ordered by location.
// We also need textures for the regions.
const int regionaltexturesize = 512;
vector<Image> regionalelevationimage(maxregions);
vector<Image> regionaltemperatureimage(maxregions);
vector<Image> regionalprecipitationimage(maxregions);