Added Logging Options to Improve Performance (#529)

* Added Logging Options to Improve Performance

* Requested Changes

Co-authored-by: Onyx Azryn <brycekabat@onyxazryn.com>
This commit is contained in:
Bryce Kabat 2020-10-21 17:32:57 -05:00 committed by Azgaar
parent ae58634dee
commit 122c456588
18 changed files with 192 additions and 186 deletions

View file

@ -141,7 +141,7 @@ function editBurg(id) {
const label = document.querySelector("#burgLabels [data-id='" + id + "']");
const icon = document.querySelector("#burgIcons [data-id='" + id + "']");
const anchor = document.querySelector("#anchors [data-id='" + id + "']");
if (!label || !icon) {console.error("Cannot find label or icon elements"); return;}
if (!label || !icon) {ERROR && console.error("Cannot find label or icon elements"); return;}
const labelG = document.querySelector("#burgLabels > #"+oldGroup);
const iconG = document.querySelector("#burgIcons > #"+oldGroup);

View file

@ -141,7 +141,7 @@ function moveBurgToGroup(id, g) {
const label = document.querySelector("#burgLabels [data-id='" + id + "']");
const icon = document.querySelector("#burgIcons [data-id='" + id + "']");
const anchor = document.querySelector("#anchors [data-id='" + id + "']");
if (!label || !icon) {console.error("Cannot find label or icon elements"); return;}
if (!label || !icon) {ERROR && console.error("Cannot find label or icon elements"); return;}
document.querySelector("#burgLabels > #"+g).appendChild(label);
document.querySelector("#burgIcons > #"+g).appendChild(icon);
@ -639,7 +639,7 @@ function selectIcon(initial, callback) {
// Calls the refresh functionality on all editors currently open.
function refreshAllEditors() {
console.time('refreshAllEditors');
TIME && console.time('refreshAllEditors');
if (document.getElementById('culturesEditorRefresh').offsetParent) culturesEditorRefresh.click();
if (document.getElementById('biomesEditorRefresh').offsetParent) biomesEditorRefresh.click();
if (document.getElementById('diplomacyEditorRefresh').offsetParent) diplomacyEditorRefresh.click();
@ -647,5 +647,5 @@ function refreshAllEditors() {
if (document.getElementById('religionsEditorRefresh').offsetParent) religionsEditorRefresh.click();
if (document.getElementById('statesEditorRefresh').offsetParent) statesEditorRefresh.click();
if (document.getElementById('zonesEditorRefresh').offsetParent) zonesEditorRefresh.click();
console.timeEnd('refreshAllEditors');
TIME && console.timeEnd('refreshAllEditors');
}

View file

@ -164,8 +164,8 @@ function editHeightmap() {
}
function regenerateErasedData() {
console.group("Edit Heightmap");
console.time("regenerateErasedData");
INFO && console.group("Edit Heightmap");
TIME && console.time("regenerateErasedData");
const change = changeHeights.checked;
markFeatures();
@ -204,8 +204,8 @@ function editHeightmap() {
Military.generate();
addMarkers();
addZones();
console.timeEnd("regenerateErasedData");
console.groupEnd("Edit Heightmap");
TIME && console.timeEnd("regenerateErasedData");
INFO && console.groupEnd("Edit Heightmap");
}
function restoreKeptData() {
@ -216,8 +216,8 @@ function editHeightmap() {
}
function restoreRiskedData() {
console.group("Edit Heightmap");
console.time("restoreRiskedData");
INFO && console.group("Edit Heightmap");
TIME && console.time("restoreRiskedData");
// assign pack data to grid cells
const l = grid.cells.i.length;
@ -401,8 +401,8 @@ function editHeightmap() {
.attr("points", d => getPackPolygon(d)).attr("id", d => base + d);
});
console.timeEnd("restoreRiskedData");
console.groupEnd("Edit Heightmap");
TIME && console.timeEnd("restoreRiskedData");
INFO && console.groupEnd("Edit Heightmap");
}
// trigger heightmap redraw and history update if at least 1 cell is changed
@ -954,7 +954,7 @@ function editHeightmap() {
templateBody.innerHTML = "";
for (const s of steps) {
const step = s.split(" ");
if (step.length !== 5) {console.error("Cannot parse step, wrong arguments count", s); continue;}
if (step.length !== 5) {ERROR && console.error("Cannot parse step, wrong arguments count", s); continue;}
addStep(step[0], step[1], step[2], step[3], step[4]);
}

View file

@ -131,7 +131,7 @@ function toggleHeight(event) {
}
function drawHeightmap() {
console.time("drawHeightmap");
TIME && console.time("drawHeightmap");
terrs.selectAll("*").remove();
const cells = pack.cells, vertices = pack.vertices, n = cells.i.length;
const used = new Uint8Array(cells.i.length);
@ -188,7 +188,7 @@ function drawHeightmap() {
if (v[0] !== prev && c0 !== c1) current = v[0];
else if (v[1] !== prev && c1 !== c2) current = v[1];
else if (v[2] !== prev && c0 !== c2) current = v[2];
if (current === chain[chain.length - 1]) {console.error("Next vertex is not found"); break;}
if (current === chain[chain.length - 1]) {ERROR && console.error("Next vertex is not found"); break;}
}
return chain;
}
@ -199,7 +199,7 @@ function drawHeightmap() {
return chain.filter((d, i) => i % n === 0);
}
console.timeEnd("drawHeightmap");
TIME && console.timeEnd("drawHeightmap");
}
function getColorScheme() {
@ -228,7 +228,7 @@ function toggleTemp(event) {
}
function drawTemp() {
console.time("drawTemp");
TIME && console.time("drawTemp");
temperature.selectAll("*").remove();
lineGen.curve(d3.curveBasisClosed);
const scheme = d3.scaleSequential(d3.interpolateSpectral);
@ -311,12 +311,12 @@ function drawTemp() {
if (v[0] !== prev && c0 !== c1) current = v[0];
else if (v[1] !== prev && c1 !== c2) current = v[1];
else if (v[2] !== prev && c0 !== c2) current = v[2];
if (current === chain[chain.length - 1]) {console.error("Next vertex is not found"); break;}
if (current === chain[chain.length - 1]) {ERROR && console.error("Next vertex is not found"); break;}
}
chain.push(start);
return chain;
}
console.timeEnd("drawTemp");
TIME && console.timeEnd("drawTemp");
}
function toggleBiomes(event) {
@ -370,7 +370,7 @@ function drawBiomes() {
if (v[0] !== prev && c0 !== c1) current = v[0];
else if (v[1] !== prev && c1 !== c2) current = v[1];
else if (v[2] !== prev && c0 !== c2) current = v[2];
if (current === chain[chain.length - 1]) {console.error("Next vertex is not found"); break;}
if (current === chain[chain.length - 1]) {ERROR && console.error("Next vertex is not found"); break;}
}
return chain;
}
@ -526,7 +526,7 @@ function drawIce() {
if (v[0] !== prev && c0 !== c1) current = v[0];
else if (v[1] !== prev && c1 !== c2) current = v[1];
else if (v[2] !== prev && c0 !== c2) current = v[2];
if (current === chain[chain.length - 1]) {console.error("Next vertex is not found"); break;}
if (current === chain[chain.length - 1]) {ERROR && console.error("Next vertex is not found"); break;}
}
return chain;
}
@ -547,7 +547,7 @@ function toggleCultures(event) {
}
function drawCultures() {
console.time("drawCultures");
TIME && console.time("drawCultures");
cults.selectAll("path").remove();
const cells = pack.cells, vertices = pack.vertices, cultures = pack.cultures, n = cells.i.length;
@ -586,11 +586,11 @@ function drawCultures() {
if (v[0] !== prev && c0 !== c1) current = v[0];
else if (v[1] !== prev && c1 !== c2) current = v[1];
else if (v[2] !== prev && c0 !== c2) current = v[2];
if (current === chain[chain.length - 1]) {console.error("Next vertex is not found"); break;}
if (current === chain[chain.length - 1]) {ERROR && console.error("Next vertex is not found"); break;}
}
return chain;
}
console.timeEnd("drawCultures");
TIME && console.timeEnd("drawCultures");
}
function toggleReligions(event) {
@ -607,7 +607,7 @@ function toggleReligions(event) {
}
function drawReligions() {
console.time("drawReligions");
TIME && console.time("drawReligions");
relig.selectAll("path").remove();
const cells = pack.cells, vertices = pack.vertices, religions = pack.religions, features = pack.features, n = cells.i.length;
@ -657,12 +657,12 @@ function drawReligions() {
if (v[0] !== prev && c0 !== c1) {current = v[0]; check(c0 ? c[0] : c[1]);} else
if (v[1] !== prev && c1 !== c2) {current = v[1]; check(c1 ? c[1] : c[2]);} else
if (v[2] !== prev && c0 !== c2) {current = v[2]; check(c2 ? c[2] : c[0]);}
if (current === chain[chain.length - 1][0]) {console.error("Next vertex is not found"); break;}
if (current === chain[chain.length - 1][0]) {ERROR && console.error("Next vertex is not found"); break;}
}
return chain;
}
console.timeEnd("drawReligions");
TIME && console.timeEnd("drawReligions");
}
function toggleStates(event) {
@ -680,7 +680,7 @@ function toggleStates(event) {
// draw states
function drawStates() {
console.time("drawStates");
TIME && console.time("drawStates");
regions.selectAll("path").remove();
const cells = pack.cells, vertices = pack.vertices, states = pack.states, n = cells.i.length;
@ -741,18 +741,18 @@ function drawStates() {
if (v[0] !== prev && c0 !== c1) {current = v[0]; check(c0 ? c[0] : c[1]);} else
if (v[1] !== prev && c1 !== c2) {current = v[1]; check(c1 ? c[1] : c[2]);} else
if (v[2] !== prev && c0 !== c2) {current = v[2]; check(c2 ? c[2] : c[0]);}
if (current === chain[chain.length - 1][0]) {console.error("Next vertex is not found"); break;}
if (current === chain[chain.length - 1][0]) {ERROR && console.error("Next vertex is not found"); break;}
}
chain.push([start, state, land]); // add starting vertex to sequence to close the path
return chain;
}
invokeActiveZooming();
console.timeEnd("drawStates");
TIME && console.timeEnd("drawStates");
}
// draw state and province borders
function drawBorders() {
console.time("drawBorders");
TIME && console.time("drawBorders");
borders.selectAll("path").remove();
const cells = pack.cells, vertices = pack.vertices, n = cells.i.length;
@ -807,7 +807,7 @@ function drawBorders() {
// find starting vertex
for (let i=0; i < 1000; i++) {
if (i === 999) console.error("Find starting vertex: limit is reached", current, f, t);
if (i === 999) ERROR && console.error("Find starting vertex: limit is reached", current, f, t);
const p = chain[chain.length-2] || -1; // previous vertex
const v = vertices.v[current], c = vertices.c[current];
@ -825,7 +825,7 @@ function drawBorders() {
chain = [current]; // vertices chain to form a path
// find path
for (let i=0; i < 1000; i++) {
if (i === 999) console.error("Find path: limit is reached", current, f, t);
if (i === 999) ERROR && console.error("Find path: limit is reached", current, f, t);
const p = chain[chain.length-2] || -1; // previous vertex
const v = vertices.v[current], c = vertices.c[current];
c.filter(c => array[c] === t).forEach(c => used[f][c] = t);
@ -845,7 +845,7 @@ function drawBorders() {
return chain;
}
console.timeEnd("drawBorders");
TIME && console.timeEnd("drawBorders");
}
function toggleBorders(event) {
@ -873,7 +873,7 @@ function toggleProvinces(event) {
}
function drawProvinces() {
console.time("drawProvinces");
TIME && console.time("drawProvinces");
const labelsOn = provs.attr("data-labels") == 1;
provs.selectAll("*").remove();
@ -937,12 +937,12 @@ function drawProvinces() {
if (v[0] !== prev && c0 !== c1) {current = v[0]; check(c0 ? c[0] : c[1]);} else
if (v[1] !== prev && c1 !== c2) {current = v[1]; check(c1 ? c[1] : c[2]);} else
if (v[2] !== prev && c0 !== c2) {current = v[2]; check(c2 ? c[2] : c[0]);}
if (current === chain[chain.length-1][0]) {console.error("Next vertex is not found"); break;}
if (current === chain[chain.length-1][0]) {ERROR && console.error("Next vertex is not found"); break;}
}
chain.push([start, province, land]); // add starting vertex to sequence to close the path
return chain;
}
console.timeEnd("drawProvinces");
TIME && console.timeEnd("drawProvinces");
}
function toggleGrid(event) {
@ -959,7 +959,7 @@ function toggleGrid(event) {
}
function drawGrid() {
console.time("drawGrid");
TIME && console.time("drawGrid");
gridOverlay.selectAll("*").remove();
const type = styleGridType.value;
const size = Math.max(+styleGridSize.value, 2);
@ -1003,7 +1003,7 @@ function drawGrid() {
});
}
console.timeEnd("drawGrid");
TIME && console.timeEnd("drawGrid");
}
function toggleCoordinates(event) {

View file

@ -653,7 +653,7 @@ function setBase64Texture(url) {
};
function fetchTextureURL(url) {
console.log("Provided URL is", url);
INFO && console.log("Provided URL is", url);
const img = new Image();
img.onload = function () {
const canvas = document.getElementById("texturePreview");