Skip to content

Commit acc752e

Browse files
authored
Merge pull request #2 from BenchmarkSims/dev
update to functions
2 parents d5c7cc2 + 283430c commit acc752e

File tree

9 files changed

+49
-102
lines changed

9 files changed

+49
-102
lines changed

01_KTO_Interactive_Map/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1616,7 +1616,7 @@
16161616
<!-- Connectivity TAB -->
16171617
<div id="Connections" class="tabcontent">
16181618
<b>Collaboration</b><hr>
1619-
<input type="checkbox" id="imcs-secure" value="on" onchange="changedIMCS(this);"><label for="secure">&nbspSecure Connection</label><br><br>
1619+
<input type="checkbox" id="imcs-secure" value="on" onchange="changedIMCS(this);"><label for="imcs-secure">&nbspSecure Connection</label><br><br>
16201620
<table width="95%">
16211621
<tr><td align="right">Callsign</td><td><input type="text" id="imcs-callsign" name="callsign" onchange="changedIMCS(this);" style="width:130px"></td></tr>
16221622
<tr><td align="right">Session</td><td><input type="text" id="imcs-session" name="session" onchange="changedIMCS(this);" style="width:130px"></td></tr>

02_Balkans_Interactive_Map/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2103,7 +2103,7 @@
21032103
<!-- Connectivity TAB -->
21042104
<div id="Connections" class="tabcontent">
21052105
<b>Collaboration</b><hr>
2106-
<input type="checkbox" id="imcs-secure" value="on" onchange="changedIMCS(this);"><label for="secure">&nbspSecure Connection</label><br><br>
2106+
<input type="checkbox" id="imcs-secure" value="on" onchange="changedIMCS(this);"><label for="imcs-secure">&nbspSecure Connection</label><br><br>
21072107
<table width="95%">
21082108
<tr><td align="right">Callsign</td><td><input type="text" id="imcs-callsign" name="callsign" onchange="changedIMCS(this);" style="width:130px"></td></tr>
21092109
<tr><td align="right">Session</td><td><input type="text" id="imcs-session" name="session" onchange="changedIMCS(this);" style="width:130px"></td></tr>

03_ITO_Interactive_Map/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1897,7 +1897,7 @@
18971897
<!-- Connectivity TAB -->
18981898
<div id="Connections" class="tabcontent">
18991899
<b>Collaboration</b><hr>
1900-
<input type="checkbox" id="imcs-secure" value="on" onchange="changedIMCS(this);"><label for="secure">&nbspSecure Connection</label><br><br>
1900+
<input type="checkbox" id="imcs-secure" value="on" onchange="changedIMCS(this);"><label for="imcs-secure">&nbspSecure Connection</label><br><br>
19011901
<table width="95%">
19021902
<tr><td align="right">Callsign</td><td><input type="text" id="imcs-callsign" name="callsign" onchange="changedIMCS(this);" style="width:130px"></td></tr>
19031903
<tr><td align="right">Session</td><td><input type="text" id="imcs-session" name="session" onchange="changedIMCS(this);" style="width:130px"></td></tr>

common/scripts/map_actions.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1618,9 +1618,6 @@ window.onload = function(e) {
16181618
this.addEventListener('mousemove', pointer_drag);
16191619
this.addEventListener('mouseup', pointer_end);
16201620

1621-
// Install the File handler
1622-
reader.addEventListener('load', processFile);
1623-
16241621
// Trigger a Render
16251622
updateToolbar();
16261623

common/scripts/map_draw.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ function getDopplerColor(scan) {
356356
// Draw the Radar from the fmap
357357
function drawDopplerRadar(ctx) {
358358
// Guard
359-
if (fmap.radar.length == 0) return;
359+
if (fmap.type.length == 0) return;
360360

361361
// Set Transparency
362362
ctx.globalAlpha = 0.6;
@@ -374,8 +374,8 @@ function drawDopplerRadar(ctx) {
374374
var y = ((point.y + 1920) / 65) >> 0 ;
375375
if (x > 58) x = 58;
376376
if (y > 58) y = 58;
377-
//console.log(x,y);
378-
var scan = fmap.radar[y][x];
377+
378+
var scan = dopplerSense(x,y);
379379
var occluded = ((Math.random() * 15) >> 0) > 13;
380380
if (scan != 0 && !occluded) {
381381
ctx.beginPath();

common/scripts/map_files.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
// This file will process Mission.ini and Pilot.ini files.
55
// TODO: Process .fmap files for weather layer
66

7-
var reader = new FileReader();
87
var filename = "";
98

109
function processWhiteboard(data) {
@@ -30,31 +29,31 @@ function processWhiteboard(data) {
3029
// BMS fmap weather or Mission.ini and Pilot.ini can be dropped
3130
function processFile(e) {
3231

33-
if (typeof(reader.result) == "string") {
32+
if (typeof(e.target.result) == "string") {
3433

3534
// Process .ini file
3635
if (filename.endsWith(".ini")) {
37-
processDataCartridge(reader.result);
36+
processDataCartridge(e.target.result);
3837
refreshCanvas();
3938
return;
4039
}
4140
// Process .png file
4241
if (filename.endsWith(".png")) {
43-
processWhiteboard(reader.result);
42+
processWhiteboard(e.target.result);
4443
return;
4544
}
4645
}
47-
if (typeof(reader.result) == "object") {
46+
if (typeof(e.target.result) == "object") {
4847

4948
// Process .fmap file
5049
if (filename.endsWith(".fmap")) {
51-
processWeather(reader.result);
50+
processWeather(e.target.result);
5251
refreshCanvas();
5352
return;
5453
}
5554
// Process GRIB2 file
5655
if (filename.startsWith("gfs.")) {
57-
ProcessGrib2(reader.result);
56+
ProcessGrib2(e.target.result);
5857
refreshCanvas();
5958
return;
6059
}
@@ -74,19 +73,22 @@ function allowDrop(ev) {
7473
// The .ini is for mission files
7574
// The .fmap is for the weather data
7675
// The .png is for restoring the Whiteboard
76+
// The gfs. is for importing GFS grib2 data
7777
function dropHandler(ev) {
78-
7978
ev.preventDefault();
8079

8180
if (ev.dataTransfer.items) {
81+
// Initialize the File handler
82+
var reader = new FileReader();
83+
reader.addEventListener('load', processFile);
8284

8385
// Use DataTransferItemList interface for Modern Browers
8486
for (let i = 0; i < ev.dataTransfer.items.length; i++) {
8587

8688
// If dropped items aren't files, reject them
8789
if (ev.dataTransfer.items[i].kind === 'file') {
8890
const file = ev.dataTransfer.items[i].getAsFile();
89-
filename = file.name;
91+
filename = file.name.repeat(1);
9092
if (filename.endsWith(".ini")) reader.readAsText(file);
9193
if (filename.endsWith(".fmap")) reader.readAsArrayBuffer(file);
9294
if (filename.endsWith(".png")) reader.readAsDataURL(file);

common/scripts/map_gfs.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -823,23 +823,27 @@ function gfsProcessGrib2Msg() {
823823
if (gfs_msg.s4.def.surface1_value != 0) return;
824824
gfsDecodeMsg('PRMSL', gfs.prmsl);
825825
gfsTranscodeMsg('PRMSL',gfs.prmsl, fmap.pressure);
826+
gfs.prmsl.data = [];
826827
break;
827828

828829
case gfsMsgType.VIS:
829830
if (gfs_msg.s4.def.surface1_value != 0) return;
830831
gfsDecodeMsg('VIS', gfs.vis);
831832
gfsTranscodeMsg('VIS', gfs.vis, fmap.visibility);
833+
gfs.vis.data = [];
832834
break;
833835

834836
case gfsMsgType.TMP:
835837
if (gfs_msg.s4.def.surface1_value != 2) return;
836838
gfsDecodeMsg('TMP', gfs.tmp);
837839
gfsTranscodeMsg('TMP', gfs.tmp, fmap.temperature);
840+
gfs.tmp.data = [];
838841
break;
839842

840843
case gfsMsgType.TCDC:
841844
gfsDecodeMsg('TCDC', gfs.tcdc);
842845
gfsTranscodeCloudCoverage();
846+
gfs.tcdc.data = [];
843847
break;
844848

845849
case gfsMsgType.UGRD:
@@ -849,25 +853,31 @@ function gfsProcessGrib2Msg() {
849853
case gfsMsgType.VGRD:
850854
gfsDecodeMsg('VGRD', gfs.vgrd);
851855
gfsTranscodeWinds(); // UGRD and VGRD come in pairs
856+
gfs.ugrd.data = [];
857+
gfs.vgrd.data = [];
852858
break;
853859

854860
case gfsMsgType.PRES:
855861
gfsDecodeMsg('PRES', gfs.pres);
856862
gfsTranscodeCloudBase();
857863
gfsTranscodeFogAltitude();
864+
gfs.pres.data = [];
858865
break;
859866

860867
case gfsMsgType.PRATE:
861868
gfsDecodeMsg('PRATE', gfs.prate);
862869
gfsTranscodeShowers();
870+
gfs.prate.data = [];
863871
break;
864872

865873
case gfsMsgType.APCP:
866874
gfsDecodeMsg('APCP', gfs.apcp);
875+
gfs.apcp.data = [];
867876
break;
868877

869878
case gfsMsgType.ACPCP:
870879
gfsDecodeMsg('ACPCP', gfs.acpcp);
880+
gfs.acpcp.data = [];
871881
break;
872882
default:
873883
console.log("Warning: Unknown Message");
@@ -925,7 +935,6 @@ function ProcessGrib2(buffer){
925935
gfs_file.msg_cnt = 0;
926936

927937
while (gfs_file.offset < gfs_file.bytes.length) {
928-
//while (gfs_file.offset < gfs_file.bytes.length && gfs_file.msg_cnt < 55) {
929938
gfs_file.msg_cnt++;
930939
gfsReadGrib2Msg();
931940
gfsProcessGrib2Msg();
@@ -936,8 +945,8 @@ function ProcessGrib2(buffer){
936945
gfsAirmassDirSpd();
937946
gfsForecastTime();
938947

939-
// Generate the Doppler Radar and METARs
940-
dopplerScan();
948+
// Update Airport METAR
941949
updateAirportTitles();
942950
fmap.changed = true;
951+
gfs_file.bytes = [];
943952
}

common/scripts/map_mission.js

Lines changed: 6 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -58,36 +58,6 @@ var mission = {
5858
}
5959
};
6060

61-
// List of Mission Text Abbreviations
62-
// This is used to keep the Objectives list remain within max 2 lines per
63-
// objective
64-
function abbreviate(text){
65-
// Add as many abbreviations as needed
66-
// This will keep the text within a line if possible
67-
text = text.replace("Air Defense", "AD");
68-
text = text.replace("Airbase", "AB");
69-
text = text.replace("Depot", "Dep");
70-
text = text.replace("Runway", "Rwy");
71-
text = text.replace("Complex", "Cmplx");
72-
text = text.replace("Tower", "Twr");
73-
text = text.replace("Control", "Ctrl");
74-
text = text.replace("Center", "Ctr");
75-
text = text.replace("Factory", "Fac");
76-
text = text.replace("Section", "Sec");
77-
text = text.replace("Warehouse", "Wrhs");
78-
text = text.replace("Maintenance", "Maint.");
79-
text = text.replace("Hangar", "Hngr");
80-
text = text.replace("Battalion", "BN");
81-
text = text.replace("Brigade", "BDE");
82-
text = text.replace("Defense", "Def.");
83-
text = text.replace("Manufacturer", "Mfr.");
84-
text = text.replace("Bridge Bridge", "Bridge");
85-
text = text.replace("Village", "Vill.");
86-
text = text.replace("Transport", "Tpt.");
87-
text = text.replace("Station", "Sta.");
88-
return text;
89-
}
90-
9161
// MISSION DATA PROCESSING
9262
function clearMissionData() {
9363
mission.ppts = [];
@@ -127,10 +97,7 @@ function isTargetWaypoint(index) {
12797
}
12898

12999
function getSteerpointType(index) {
130-
if (isTargetWaypoint(index)) {
131-
return "TGT";
132-
}
133-
return "STPT";
100+
return (isTargetWaypoint(index))?"TGT":"STPT";
134101
}
135102

136103
// Parse and create ppt object
@@ -244,31 +211,24 @@ function getMissionTime() {
244211

245212
function getTankerIndex() {
246213
for (var i = 0; i < mission.targets.length; i++) {
247-
if (mission.targets[i].action == Action.Refuel) {
248-
return i;
249-
}
214+
if (mission.targets[i].action == Action.Refuel) return i;
250215
}
251216
return -1;
252217
}
253218

254219
function getHomePlateIndex() {
255220
for (var i = 0; i < mission.targets.length; i++) {
256-
if (mission.targets[i].action == Action.Land) {
257-
return i;
258-
}
221+
if (mission.targets[i].action == Action.Land) return i;
259222
}
260223
return -1;
261224
}
262225

263226
function getAlternateIndex() {
264227
var index = getHomePlateIndex();
265228
for (var i = (index + 1); i < mission.targets.length; i++) {
266-
if (mission.targets[i].action == Action.Land) {
267-
index = i;
268-
break;
269-
}
229+
if (mission.targets[i].action == Action.Land) return i;
270230
}
271-
return index;
231+
return -1;
272232
}
273233

274234
function getEstimatedFuelUntil(index) {
@@ -317,9 +277,7 @@ function getMaxHomePlateDistance() {
317277
function getMissionDistance() {
318278
var distance = 0;
319279
for (var i = 0; i < mission.route.length; i++) {
320-
if (mission.targets[i].action == Action.Land) {
321-
break;
322-
}
280+
if (mission.targets[i].action == Action.Land) break;
323281
distance += mission.route[i].dist;
324282
}
325283
return(distance);

common/scripts/map_weather.js

Lines changed: 14 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ var fmap = {
2424
turbulence: {top: 31000, bottom: 28000},
2525
contrail: [34000,28000,25000,2000],
2626
cells: 0, // Total cells
27-
type: [], // [y][x] 1: Sunny, 1: Fair, 2: Poor, 3: Inclement
27+
type: [], // [y][x] 1: Sunny, 2: Fair, 3: Poor, 4: Inclement
2828
pressure: [], // [y][x] hPa
2929
temperature: [], // [y][x] C
3030
wind: [], // [y][x][alt] Direction and Speed in Kts at Altitudes (10 levels)
@@ -38,9 +38,6 @@ var fmap = {
3838
visibility: [], // 0 .. 60 km
3939
fog: [], // 0 .. 10000 ft
4040

41-
// Simulated Doppler Radar using Weather Type, Pressure and Temperature
42-
radar: [],
43-
4441
// Analytics done on the data
4542
analytics: {
4643
pressure_min: 1060,
@@ -67,32 +64,22 @@ function isIMC(x,y){
6764
//
6865
// Frontal zones are based on 10C delta per 20NM
6966
// Tornado is 15% pressure drop with neighbors (Not Implemented)
70-
7167
// Snow is determined by looking at the surface temperature being at or below 0C.
72-
//
73-
function dopplerScan() {
74-
75-
// Setup Doppler Radar Data
76-
for (var y=0;y < fmap.dimension.y; y++) {
77-
var scan = Array(fmap.dimension.x).fill(0);
78-
fmap.radar.push(scan);
79-
for (var x = 0;x < fmap.dimension.x; x++) {
80-
var wx = 0;
81-
// Initialize Rain and add extra scores
82-
if (fmap.type[y][x] == 4 || fmap.shower == 1) {
83-
wx++;
84-
if (fmap.pressure[y][x] < 1004) wx++;
85-
if (fmap.wind[x][y][0] > 20 ) wx++;
86-
if (fmap.cloud.type == 1 && fmap.cloud.size < 2) wx=+2;
87-
}
68+
function dopplerSense(x,y) {
69+
var wx = 0;
70+
71+
if (fmap.type[y][x] == 4 || fmap.shower == 1) {
72+
wx++;
73+
if (fmap.pressure[y][x] < 1004) wx++;
74+
if (fmap.wind[x][y][0] > 20 ) wx++;
75+
if (fmap.cloud.type == 1 && fmap.cloud.size < 2) wx=+2;
76+
}
8877

89-
// Check if is below zero C
90-
if (fmap.temperature[y][x] <= 0) wx = -wx;
78+
// Check if is below zero C
79+
if (fmap.temperature[y][x] <= 0) wx = -wx;
9180

92-
// Assign Weather to Radar
93-
fmap.radar[y][x] = wx;
94-
}
95-
}
81+
// Assign Weather to Radar
82+
return wx;
9683
}
9784

9885
//
@@ -129,7 +116,6 @@ function clearWeather() {
129116
fmap.shower = [];
130117
fmap.visibility = [];
131118
fmap.fog = [];
132-
fmap.radar = [];
133119
fmap.analytics = {
134120
pressure_min: 1060,
135121
pressure_max: 950,
@@ -158,8 +144,6 @@ function readMapInfo(buffer) {
158144

159145
// Read the BMS Weather Type (1:Sunny, 2: Fair, 3: Poor, 4: Inclement)
160146
function readWeatherType(buffer) {
161-
let view = new Uint32Array(buffer);
162-
163147
const offset = 11;
164148
let type = new Int32Array(buffer);
165149

@@ -635,9 +619,6 @@ function processWeather(buffer) {
635619

636620
updateAirportTitles();
637621

638-
// Create Doppler Radar Scan
639-
dopplerScan();
640-
641622
// Tell the action layer weather has changed so it will redener the main canvas
642623
fmap.changed = true;
643624
}

0 commit comments

Comments
 (0)