add zstddec, thanks github.com/donmccurdy/zstddec

use aircraft.binCraft.zst when available
This commit is contained in:
Matthias Wirth
2022-07-06 08:58:49 +02:00
parent 770b47b884
commit 5639a4bea8
6 changed files with 65 additions and 6 deletions

View File

@@ -22,6 +22,7 @@ let globeIndexGrid = 0;
let globeIndexSpecialTiles;
let dynGlobeRate = false;
let binCraft = false;
let zstd = false;
let dbServer = false;
let l3harris = false;
let heatmap = false;
@@ -470,9 +471,9 @@ if (uuid != null) {
RefreshInterval = data.refresh;
nHistoryItems = (data.history < 2) ? 0 : data.history;
binCraft = data.binCraft ? true : false || data.aircraft_binCraft ? true : false;
zstd = data.zstd ? true : false;
if (usp.has('noglobe') || usp.has('ptracks')) {
data.globeIndexGrid = null; // disable globe on user request
binCraft = data.aircraft_binCraft ? true : false;
}
dbServer = (data.dbServer && data.globeIndexGrid != null) ? true : false;
@@ -790,3 +791,7 @@ function add_kml_overlay(url, name, opacity) {
zIndex: 99,
}));
}
zstddec.decoder = new zstddec.ZSTDDecoder();
zstddec.promise = zstddec.decoder.init();
let zstdDecode = zstddec.decoder.decode;

View File

@@ -401,8 +401,10 @@ function iOSVersion() {
function wqi(data) {
const buffer = data.buffer;
//console.log(buffer);
let vals = new Uint32Array(data.buffer, 0, 8);
data.now = vals[0] / 1000 + vals[1] * 4294967.296;
//console.log(data.now);
let stride = vals[2];
data.global_ac_count_withpos = vals[3];
data.globeIndex = vals[4];

View File

@@ -1043,6 +1043,7 @@
<script src="libs/elm-pep-01.js"></script>
<script src="libs/jquery-ui-1.12.1.min.js"></script>
<script src="libs/jquery.ui.touch-punch-1.12.1.js"></script>
<script src="libs/zstddec-0.0.2.js"></script>
<script src="libs/ol-custom018.js"></script>
<script src="early.js"></script>

File diff suppressed because one or more lines are too long

View File

@@ -360,17 +360,23 @@ function fetchData(options) {
});
if (binCraft && onlyMilitary && ZoomLvl < 5.5) {
ac_url.push('data/globeMil_42777.binCraft');
if (zstd) {
ac_url.push('data/globeMil_42777.binCraft.zst');
} else {
ac_url.push('data/globeMil_42777.binCraft');
}
} else {
indexes = indexes.slice(0, globeSimLoad);
let suffix = binCraft ? '.binCraft' : '.json'
let suffix = zstd ? '.binCraft.zst' : (binCraft ? '.binCraft' : '.json');
let mid = (binCraft && onlyMilitary) ? 'Mil_' : '_';
for (let i in indexes) {
ac_url.push('data/globe' + mid + indexes[i].toString().padStart(4, '0') + suffix);
}
}
} else if (zstd) {
ac_url.push('data/aircraft.binCraft.zst');
} else if (binCraft) {
ac_url.push('data/aircraft.binCraft');
} else {
@@ -383,7 +389,7 @@ function fetchData(options) {
for (let i in ac_url) {
//console.log(ac_url[i]);
let req;
if (binCraft) {
if (binCraft || zstd) {
req = jQuery.ajax({
url: `${ac_url[i]}`, method: 'GET',
xhr: arraybufferRequest,
@@ -401,7 +407,14 @@ function fetchData(options) {
if (data == null) {
return;
}
if (binCraft) {
if (zstd) {
let arr = new Uint8Array(data);
let res = zstdDecode( arr, 0 );
let arrayBuffer = res.buffer
// return type is Uint8Array, wqi requires the ArrayBuffer
data = { buffer: arrayBuffer, };
wqi(data);
} else if (binCraft) {
data = { buffer: data, };
wqi(data);
}
@@ -533,7 +546,9 @@ function initialize() {
push_history();
jQuery.when(historyLoaded).done(function() {
startPage();
zstddec.promise.then(function() {
startPage();
});
});
});
}
@@ -1694,8 +1709,35 @@ function setIntervalTimers() {
}
}
let djson;
let dstring;
let dresult;
function startPage() {
if (0) {
console.log('bla');
jQuery.ajax({
url: 'data/aircraft.json.zst' , method: 'GET',
xhr: arraybufferRequest,
timeout: 15000,
}).done(function(data) {
console.log('asdf');
let arr = new Uint8Array(data);
let uncompressedSize = 83843;
console.time("zstd");
dresult = zstdDecode( arr, 0 );
console.timeEnd("zstd");
console.time("stringify");
dstring = String.fromCharCode.apply(null, dresult);
console.timeEnd("stringify");
console.time("JSON.parse");
djson = JSON.parse(dstring);
console.timeEnd("JSON.parse");
});
}
console.log("Completing init");
if (!globeIndex) {

View File

@@ -4,6 +4,7 @@ location /INSTANCE/data/ {
gzip_static off;
location ~ aircraft\.json$ {
add_header Cache-Control "public, no-cache";
gzip on;
gzip_static on;
}
location /INSTANCE/data/traces/ {