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 GitHub
parent e480c1c8e5
commit f4efedcf9d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
18 changed files with 192 additions and 186 deletions

View file

@ -32,7 +32,7 @@
drawBurgs();
function placeCapitals() {
console.time('placeCapitals');
TIME && console.time('placeCapitals');
let count = +regionsInput.value;
let burgs = [0];
@ -41,8 +41,8 @@
if (sorted.length < count * 10) {
count = Math.floor(sorted.length / 10);
if (!count) {console.warn(`There is no populated cells. Cannot generate states`); return burgs;}
else {console.warn(`Not enough populated cells (${sorted.length}). Will generate only ${count} states`);}
if (!count) {WARN && console.warn(`There is no populated cells. Cannot generate states`); return burgs;}
else {WARN && console.warn(`Not enough populated cells (${sorted.length}). Will generate only ${count} states`);}
}
let burgsTree = d3.quadtree();
@ -57,20 +57,20 @@
}
if (i === sorted.length - 1) {
console.warn("Cannot place capitals with current spacing. Trying again with reduced spacing");
WARN && console.warn("Cannot place capitals with current spacing. Trying again with reduced spacing");
burgsTree = d3.quadtree();
i = -1, burgs = [0], spacing /= 1.2;
}
}
burgs[0] = burgsTree;
console.timeEnd('placeCapitals');
TIME && console.timeEnd('placeCapitals');
return burgs;
}
// For each capital create a state
function createStates() {
console.time('createStates');
TIME && console.time('createStates');
const states = [{i:0, name: "Neutrals"}];
const colors = getColors(burgs.length-1);
@ -94,13 +94,13 @@
cells.burg[b.cell] = i;
});
console.timeEnd('createStates');
TIME && console.timeEnd('createStates');
return states;
}
// place secondary settlements based on geo and economical evaluation
function placeTowns() {
console.time('placeTowns');
TIME && console.time('placeTowns');
const score = new Int16Array(cells.s.map(s => s * gauss(1,3,0,20,3))); // a bit randomized cell score for towns placement
const sorted = cells.i.filter(i => !cells.burg[i] && score[i] > 0 && cells.culture[i]).sort((a, b) => score[b] - score[a]); // filtered and sorted array of indexes
@ -129,17 +129,17 @@
}
if (manorsInput.value != 1000 && burgsAdded < desiredNumber) {
console.error(`Cannot place all burgs. Requested ${desiredNumber}, placed ${burgsAdded}`);
ERROR && console.error(`Cannot place all burgs. Requested ${desiredNumber}, placed ${burgsAdded}`);
}
burgs[0] = {name:undefined}; // do not store burgsTree anymore
console.timeEnd('placeTowns');
TIME && console.timeEnd('placeTowns');
}
}
// define burg coordinates, port status and define details
const specifyBurgs = function() {
console.time("specifyBurgs");
TIME && console.time("specifyBurgs");
const cells = pack.cells, vertices = pack.vertices, features = pack.features, temp = grid.cells.temp;
for (const b of pack.burgs) {
@ -185,7 +185,7 @@
if (featurePorts.length === 1) featurePorts[0].port = 0;
}
console.timeEnd("specifyBurgs");
TIME && console.timeEnd("specifyBurgs");
}
const defineBurgFeatures = function(newburg) {
@ -202,7 +202,7 @@
}
const drawBurgs = function() {
console.time("drawBurgs");
TIME && console.time("drawBurgs");
// remove old data
burgIcons.selectAll("circle").remove();
@ -251,12 +251,12 @@
.attr("x", d => rn(d.x - taSize * .47, 2)).attr("y", d => rn(d.y - taSize * .47, 2))
.attr("width", taSize).attr("height", taSize);
console.timeEnd("drawBurgs");
TIME && console.timeEnd("drawBurgs");
}
// growth algorithm to assign cells to states like we did for cultures
const expandStates = function() {
console.time("expandStates");
TIME && console.time("expandStates");
const cells = pack.cells, states = pack.states, cultures = pack.cultures, burgs = pack.burgs;
cells.state = new Uint16Array(cells.i.length); // cell state
@ -331,11 +331,11 @@
return 0;
}
console.timeEnd("expandStates");
TIME && console.timeEnd("expandStates");
}
const normalizeStates = function() {
console.time("normalizeStates");
TIME && console.time("normalizeStates");
const cells = pack.cells, burgs = pack.burgs;
for (const i of cells.i) {
@ -350,13 +350,13 @@
cells.state[i] = cells.state[adversaries[0]];
//debug.append("circle").attr("cx", cells.p[i][0]).attr("cy", cells.p[i][1]).attr("r", .5).attr("fill", "red");
}
console.timeEnd("normalizeStates");
TIME && console.timeEnd("normalizeStates");
}
// Resets the cultures of all burgs and states to their
// cell or center cell's (respectively) culture.
const updateCultures = function () {
console.time('updateCulturesForBurgsAndStates');
TIME && console.time('updateCulturesForBurgsAndStates');
// Assign the culture associated with the burgs cell.
pack.burgs = pack.burgs.map( (burg, index) => {
@ -376,12 +376,12 @@
return {...state, culture: pack.cells.culture[state.center]};
});
console.timeEnd('updateCulturesForBurgsAndStates');
TIME && console.timeEnd('updateCulturesForBurgsAndStates');
}
// calculate and draw curved state labels for a list of states
const drawStateLabels = function(list) {
console.time("drawStateLabels");
TIME && console.time("drawStateLabels");
const cells = pack.cells, features = pack.features, states = pack.states;
const paths = []; // text paths
lineGen.curve(d3.curveBundle.beta(1));
@ -563,12 +563,12 @@
if (!displayed) toggleLabels();
}()
console.timeEnd("drawStateLabels");
TIME && console.timeEnd("drawStateLabels");
}
// calculate states data like area, population etc.
const collectStatistics = function() {
console.time("collectStatistics");
TIME && console.time("collectStatistics");
const cells = pack.cells, states = pack.states;
states.forEach(s => {
s.cells = s.area = s.burgs = s.rural = s.urban = 0;
@ -595,11 +595,11 @@
// convert neighbors Set object into array
states.forEach(s => s.neighbors = Array.from(s.neighbors));
console.timeEnd("collectStatistics");
TIME && console.timeEnd("collectStatistics");
}
const assignColors = function() {
console.time("assignColors");
TIME && console.time("assignColors");
const colors = ["#66c2a5", "#fc8d62", "#8da0cb", "#e78ac3", "#a6d854", "#ffd92f"]; // d3.schemeSet2;
// assin basic color using greedy coloring algorithm
@ -620,7 +620,7 @@
});
});
console.timeEnd("assignColors");
TIME && console.timeEnd("assignColors");
}
// generate historical conflicts of each state
@ -641,7 +641,7 @@
// generate Diplomatic Relationships
const generateDiplomacy = function() {
console.time("generateDiplomacy");
TIME && console.time("generateDiplomacy");
const cells = pack.cells, states = pack.states;
const chronicle = states[0].diplomacy = [];
const valid = states.filter(s => s.i && !states.removed);
@ -782,13 +782,13 @@
chronicle.push(war); // add a record to diplomatical history
}
console.timeEnd("generateDiplomacy");
TIME && console.timeEnd("generateDiplomacy");
//console.table(states.map(s => s.diplomacy));
}
// select a forms for listed or all valid states
const defineStateForms = function(list) {
console.time("defineStateForms");
TIME && console.time("defineStateForms");
const states = pack.states.filter(s => s.i && !s.removed);
if (states.length < 1) return;
@ -878,7 +878,7 @@
}
}
console.timeEnd("defineStateForms");
TIME && console.timeEnd("defineStateForms");
}
const getFullName = function(s) {
@ -890,7 +890,7 @@
}
const generateProvinces = function(regenerate) {
console.time("generateProvinces");
TIME && console.time("generateProvinces");
const localSeed = regenerate ? Math.floor(Math.random() * 1e9).toString() : seed;
Math.seedrandom(localSeed);
@ -1050,7 +1050,7 @@
}
});
console.timeEnd("generateProvinces");
TIME && console.timeEnd("generateProvinces");
}
return {generate, expandStates, normalizeStates, assignColors,

View file

@ -7,7 +7,7 @@
let cells;
const generate = function() {
console.time('generateCultures');
TIME && console.time('generateCultures');
cells = pack.cells;
cells.culture = new Uint16Array(cells.i.length); // cell cultures
let count = Math.min(+culturesInput.value, +culturesSet.selectedOptions[0].dataset.max);
@ -16,7 +16,7 @@
if (populated.length < count * 25) {
count = Math.floor(populated.length / 50);
if (!count) {
console.warn(`There are no populated cells. Cannot generate cultures`);
WARN && console.warn(`There are no populated cells. Cannot generate cultures`);
pack.cultures = [{name:"Wildlands", i:0, base:1}];
alertMessage.innerHTML = `
The climate is harsh and people cannot live in this world.<br>
@ -27,7 +27,7 @@
});
return;
} else {
console.warn(`Not enough populated cells (${populated.length}). Will generate only ${count} cultures`);
WARN && console.warn(`Not enough populated cells (${populated.length}). Will generate only ${count} cultures`);
alertMessage.innerHTML = `
There are only ${populated.length} populated cells and it's insufficient livable area.<br>
Only ${count} out of ${culturesInput.value} requested cultures will be generated.<br>
@ -68,7 +68,7 @@
cultures.unshift({name:"Wildlands", i:0, base:1, origin:null});
// make sure all bases exist in nameBases
if (!nameBases.length) {console.error("Name base is empty, default nameBases will be applied"); nameBases = Names.getNameBases();}
if (!nameBases.length) {ERROR && console.error("Name base is empty, default nameBases will be applied"); nameBases = Names.getNameBases();}
cultures.forEach(c => c.base = c.base % nameBases.length);
function getRandomCultures(c) {
@ -108,7 +108,7 @@
return rn((Math.random() * powerInput.value / 2 + 1) * base, 1);
}
console.timeEnd('generateCultures');
TIME && console.timeEnd('generateCultures');
}
// assign a unique two-letters code (abbreviation)
@ -355,7 +355,7 @@
// expand cultures across the map (Dijkstra-like algorithm)
const expand = function() {
console.time('expandCultures');
TIME && console.time('expandCultures');
cells = pack.cells;
const queue = new PriorityQueue({comparator: (a, b) => a.p - b.p});
@ -392,7 +392,7 @@
});
}
//debug.selectAll(".text").data(cost).enter().append("text").attr("x", (d, e) => cells.p[e][0]-1).attr("y", (d, e) => cells.p[e][1]-1).text(d => d ? rn(d) : "").attr("font-size", 2);
console.timeEnd('expandCultures');
TIME && console.timeEnd('expandCultures');
}
function getBiomeCost(c, biome, type) {

View file

@ -7,7 +7,7 @@
let cells, p;
const generate = function() {
console.time('generateHeightmap');
TIME && console.time('generateHeightmap');
cells = grid.cells, p = grid.points;
cells.h = new Uint8Array(grid.points.length);
@ -25,7 +25,7 @@
case "Shattered": templateShattered(); break;
}
console.timeEnd('generateHeightmap');
TIME && console.timeEnd('generateHeightmap');
}
// parse template step
@ -507,7 +507,7 @@
}
function getPointInRange(range, length) {
if (typeof range !== "string") {console.error("Range should be a string"); return;}
if (typeof range !== "string") {ERROR && console.error("Range should be a string"); return;}
const min = range.split("-")[0]/100 || 0;
const max = range.split("-")[1]/100 || 100;
return rand(min * length, max * length);

View file

@ -7,7 +7,7 @@
let cells, p, states;
const generate = function() {
console.time("generateMilitaryForces");
TIME && console.time("generateMilitaryForces");
cells = pack.cells, p = cells.p, states = pack.states;
const valid = states.filter(s => s.i && !s.removed); // valid states
if (!options.military) options.military = getDefaultOptions();
@ -176,7 +176,7 @@
return regiments;
}
console.timeEnd("generateMilitaryForces");
TIME && console.timeEnd("generateMilitaryForces");
}
const getDefaultOptions = function() {

View file

@ -56,13 +56,13 @@
// generate name using Markov's chain
const getBase = function(base, min, max, dupl) {
if (base === undefined) {console.error("Please define a base"); return;}
if (base === undefined) {ERROR && console.error("Please define a base"); return;}
if (!chains[base]) updateChain(base);
const data = chains[base];
if (!data || data[""] === undefined) {
tip("Namesbase " + base + " is incorrect. Please check in namesbase editor", false, "error");
console.error("Namebase " + base + " is incorrect!");
ERROR && console.error("Namebase " + base + " is incorrect!");
return "ERROR";
}
@ -106,7 +106,7 @@
if (name.split(" ").some(part => part.length < 2)) name = name.split(" ").map((p,i) => i ? p.toLowerCase() : p).join("");
if (name.length < 2) {
console.error("Name is too short! Random name will be selected");
ERROR && console.error("Name is too short! Random name will be selected");
name = ra(nameBases[base].b.split(","));
}
@ -115,14 +115,14 @@
// generate name for culture
const getCulture = function(culture, min, max, dupl) {
if (culture === undefined) {console.error("Please define a culture"); return;}
if (culture === undefined) {ERROR && console.error("Please define a culture"); return;}
const base = pack.cultures[culture].base;
return getBase(base, min, max, dupl);
}
// generate short name for culture
const getCultureShort = function(culture) {
if (culture === undefined) {console.error("Please define a culture"); return;}
if (culture === undefined) {ERROR && console.error("Please define a culture"); return;}
return getBaseShort(pack.cultures[culture].base);
}
@ -139,8 +139,8 @@
// generate state name based on capital or random name and culture-specific suffix
const getState = function(name, culture, base) {
if (name === undefined) {console.error("Please define a base name"); return;}
if (culture === undefined && base === undefined) {console.error("Please define a culture"); return;}
if (name === undefined) {ERROR && console.error("Please define a base name"); return;}
if (culture === undefined && base === undefined) {ERROR && console.error("Please define a culture"); return;}
if (base === undefined) base = pack.cultures[culture].base;
// exclude endings inappropriate for states name

View file

@ -9,7 +9,7 @@
const OceanLayers = function OceanLayers() {
const outline = oceanLayers.attr("layers");
if (outline === "none") return;
console.time("drawOceanLayers");
TIME && console.time("drawOceanLayers");
lineGen.curve(d3.curveBasisClosed);
cells = grid.cells, pointsN = grid.cells.i.length, vertices = grid.vertices;
@ -51,7 +51,7 @@
return cells.v[i][cells.c[i].findIndex(c => cells.t[c] < t || !cells.t[c])];
}
console.timeEnd("drawOceanLayers");
TIME && console.timeEnd("drawOceanLayers");
}
function randomizeOutline() {
@ -89,7 +89,7 @@
if (v[0] !== undefined && v[0] !== prev && c0 !== c1) current = v[0];
else if (v[1] !== undefined && v[1] !== prev && c1 !== c2) current = v[1];
else if (v[2] !== undefined && 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(chain[0]); // push first vertex as the last one
return chain;

View file

@ -5,7 +5,7 @@
}(this, (function () {'use strict';
const ReliefIcons = function() {
console.time('drawRelief');
TIME && console.time('drawRelief');
terrain.selectAll("*").remove();
const density = terrain.attr("density") || .4;
const size = 1.6 * (terrain.attr("size") || 1);
@ -69,7 +69,7 @@
terrain.html(reliefHTML);
}()
console.timeEnd('drawRelief');
TIME && console.timeEnd('drawRelief');
}
function getBiomeIcon(i, b) {

View file

@ -54,7 +54,7 @@
};
const generate = function() {
console.time('generateReligions');
TIME && console.time('generateReligions');
const cells = pack.cells, states = pack.states, cultures = pack.cultures;
const religions = pack.religions = [];
cells.religion = new Uint16Array(cells.culture); // cell religion; initially based on culture
@ -164,7 +164,7 @@
expandHeresies();
checkCenters();
console.timeEnd('generateReligions');
TIME && console.timeEnd('generateReligions');
}
const add = function(center) {
@ -280,14 +280,14 @@
}
function updateCultures() {
console.time('updateCulturesForReligions');
TIME && console.time('updateCulturesForReligions');
pack.religions = pack.religions.map( (religion, index) => {
if(index === 0) {
return religion;
}
return {...religion, culture: pack.cells.culture[religion.center]};
});
console.timeEnd('updateCulturesForReligions');
TIME && console.timeEnd('updateCulturesForReligions');
}
// assign a unique two-letters code (abbreviation)
@ -303,7 +303,7 @@
// get supreme deity name
const getDeityName = function(culture) {
if (culture === undefined) {console.error("Please define a culture"); return;}
if (culture === undefined) {ERROR && console.error("Please define a culture"); return;}
const meaning = generateMeaning();
const cultureName = Names.getCulture(culture, null, null, "", .8);
return cultureName + ", The " + meaning;

View file

@ -5,7 +5,7 @@
}(this, (function () {'use strict';
const generate = function(changeHeights = true) {
console.time('generateRivers');
TIME && console.time('generateRivers');
Math.seedrandom(seed);
const cells = pack.cells, p = cells.p, features = pack.features;
@ -136,7 +136,7 @@
// apply change heights as basic one
if (changeHeights) cells.h = Uint8Array.from(h);
console.timeEnd('generateRivers');
TIME && console.timeEnd('generateRivers');
}
// depression filling algorithm (for a correct water flux modeling)

View file

@ -5,7 +5,7 @@
}(this, (function () {'use strict';
const getRoads = function() {
console.time("generateMainRoads");
TIME && console.time("generateMainRoads");
const cells = pack.cells, burgs = pack.burgs.filter(b => b.i && !b.removed);
const capitals = burgs.filter(b => b.capital);
if (capitals.length < 2) return []; // not enough capitals to build main roads
@ -21,12 +21,12 @@
}
cells.i.forEach(i => cells.s[i] += cells.road[i] / 2); // add roads to suitability score
console.timeEnd("generateMainRoads");
TIME && console.timeEnd("generateMainRoads");
return paths;
}
const getTrails = function() {
console.time("generateTrails");
TIME && console.time("generateTrails");
const cells = pack.cells, burgs = pack.burgs.filter(b => b.i && !b.removed);
if (burgs.length < 2) return []; // not enough burgs to build trails
@ -55,12 +55,12 @@
});
}
console.timeEnd("generateTrails");
TIME && console.timeEnd("generateTrails");
return paths;
}
const getSearoutes = function() {
console.time("generateSearoutes");
TIME && console.time("generateSearoutes");
const allPorts = pack.burgs.filter(b => b.port > 0 && !b.removed);
if (allPorts.length < 2) return [];
@ -93,12 +93,12 @@
});
console.timeEnd("generateSearoutes");
TIME && console.timeEnd("generateSearoutes");
return paths;
}
const draw = function(main, small, ocean) {
console.time("drawRoutes");
TIME && console.time("drawRoutes");
const cells = pack.cells, burgs = pack.burgs;
lineGen.curve(d3.curveCatmullRom.alpha(0.1));
@ -133,7 +133,7 @@
return [x, y];
})), 1));
console.timeEnd("drawRoutes");
TIME && console.timeEnd("drawRoutes");
}
const regenerate = function() {

View file

@ -3,7 +3,7 @@
// download map as SVG
async function saveSVG() {
console.time("saveSVG");
TIME && console.time("saveSVG");
const url = await getMapURL("svg");
const link = document.createElement("a");
link.download = getFileName() + ".svg";
@ -12,12 +12,12 @@ async function saveSVG() {
link.click();
tip(`${link.download} is saved. Open "Downloads" screen (crtl + J) to check. You can set image scale in options`, true, "success", 5000);
console.timeEnd("saveSVG");
TIME && console.timeEnd("saveSVG");
}
// download map as PNG
async function savePNG() {
console.time("savePNG");
TIME && console.time("savePNG");
const url = await getMapURL("png");
const link = document.createElement("a");
@ -43,12 +43,12 @@ async function savePNG() {
});
}
console.timeEnd("savePNG");
TIME && console.timeEnd("savePNG");
}
// download map as JPEG
async function saveJPEG() {
console.time("saveJPEG");
TIME && console.time("saveJPEG");
const url = await getMapURL("png");
const canvas = document.createElement("canvas");
@ -70,7 +70,7 @@ async function saveJPEG() {
window.setTimeout(() => window.URL.revokeObjectURL(URL), 5000);
}
console.timeEnd("saveJPEG");
TIME && console.timeEnd("saveJPEG");
}
// parse map svg to object url
@ -228,7 +228,7 @@ function GFontToDataURI(url) {
// prepare map data for saving
function getMapData() {
console.time("createMapDataBlob");
TIME && console.time("createMapDataBlob");
return new Promise(resolve => {
const date = new Date();
@ -283,7 +283,7 @@ function getMapData() {
namesData, rivers].join("\r\n");
const blob = new Blob([data], {type: "text/plain"});
console.timeEnd("createMapDataBlob");
TIME && console.timeEnd("createMapDataBlob");
resolve(blob);
});
@ -448,7 +448,7 @@ function quickLoad() {
loadMapPrompt(blob);
} else {
tip("No map stored. Save map to storage first", true, "error", 2000);
console.error("No map stored");
ERROR && console.error("No map stored");
}
});
}
@ -467,12 +467,12 @@ function loadMapPrompt(blob) {
});
function loadLastSavedMap() {
console.warn("Load last saved map");
WARN && console.warn("Load last saved map");
try {
uploadMap(blob);
}
catch(error) {
console.error(error);
ERROR && console.error(error);
tip("Cannot load last saved map", true, "error", 2000);
}
}
@ -564,7 +564,7 @@ function parseLoadedData(data) {
mapId = params[6] ? +params[6] : Date.now();
}()
console.group("Loaded Map " + seed);
INFO && console.group("Loaded Map " + seed);
void function parseSettings() {
const settings = data[1].split("|");
@ -1006,49 +1006,49 @@ function parseLoadedData(data) {
invalidStates.forEach(s => {
const invalidCells = cells.i.filter(i => cells.state[i] === s);
invalidCells.forEach(i => cells.state[i] = 0);
console.error("Data Integrity Check. Invalid state", s, "is assigned to cells", invalidCells);
ERROR && console.error("Data Integrity Check. Invalid state", s, "is assigned to cells", invalidCells);
});
const invalidProvinces = [...new Set(cells.province)].filter(p => p && (!pack.provinces[p] || pack.provinces[p].removed));
invalidProvinces.forEach(p => {
const invalidCells = cells.i.filter(i => cells.province[i] === p);
invalidCells.forEach(i => cells.province[i] = 0);
console.error("Data Integrity Check. Invalid province", p, "is assigned to cells", invalidCells);
ERROR && console.error("Data Integrity Check. Invalid province", p, "is assigned to cells", invalidCells);
});
const invalidCultures = [...new Set(cells.culture)].filter(c => !pack.cultures[c] || pack.cultures[c].removed);
invalidCultures.forEach(c => {
const invalidCells = cells.i.filter(i => cells.culture[i] === c);
invalidCells.forEach(i => cells.province[i] = 0);
console.error("Data Integrity Check. Invalid culture", c, "is assigned to cells", invalidCells);
ERROR && console.error("Data Integrity Check. Invalid culture", c, "is assigned to cells", invalidCells);
});
const invalidReligions = [...new Set(cells.religion)].filter(r => !pack.religions[r] || pack.religions[r].removed);
invalidReligions.forEach(r => {
const invalidCells = cells.i.filter(i => cells.religion[i] === r);
invalidCells.forEach(i => cells.religion[i] = 0);
console.error("Data Integrity Check. Invalid religion", c, "is assigned to cells", invalidCells);
ERROR && console.error("Data Integrity Check. Invalid religion", c, "is assigned to cells", invalidCells);
});
const invalidFeatures = [...new Set(cells.f)].filter(f => f && !pack.features[f]);
invalidFeatures.forEach(f => {
const invalidCells = cells.i.filter(i => cells.f[i] === f);
// No fix as for now
console.error("Data Integrity Check. Invalid feature", f, "is assigned to cells", invalidCells);
ERROR && console.error("Data Integrity Check. Invalid feature", f, "is assigned to cells", invalidCells);
});
const invalidBurgs = [...new Set(cells.burg)].filter(b => b && (!pack.burgs[b] || pack.burgs[b].removed));
invalidBurgs.forEach(b => {
const invalidCells = cells.i.filter(i => cells.burg[i] === b);
invalidCells.forEach(i => cells.burg[i] = 0);
console.error("Data Integrity Check. Invalid burg", b, "is assigned to cells", invalidCells);
ERROR && console.error("Data Integrity Check. Invalid burg", b, "is assigned to cells", invalidCells);
});
pack.burgs.forEach(b => {
if (!b.i || b.removed) return;
if (b.port < 0) {console.error("Data Integrity Check. Burg", b.i, "has invalid port value", b.port); b.port = 0;}
if (b.port < 0) {ERROR && console.error("Data Integrity Check. Burg", b.i, "has invalid port value", b.port); b.port = 0;}
if (b.cell < cells.i.length) return;
console.error("Data Integrity Check. Burg", b.i, "is linked to invalid cell", b.cell);
ERROR && console.error("Data Integrity Check. Burg", b.i, "is linked to invalid cell", b.cell);
b.cell = findCell(b.x, b.y);
cells.i.filter(i => cells.burg[i] === b.i).forEach(i => cells.burg[i] = 0);
cells.burg[b.cell] = b.i;
@ -1065,13 +1065,13 @@ function parseLoadedData(data) {
focusOn(); // based on searchParams focus on point, cell or burg
invokeActiveZooming();
console.warn(`TOTAL: ${rn((performance.now()-uploadMap.timeStart)/1000,2)}s`);
WARN && console.warn(`TOTAL: ${rn((performance.now()-uploadMap.timeStart)/1000,2)}s`);
showStatistics();
console.groupEnd("Loaded Map " + seed);
INFO && console.groupEnd("Loaded Map " + seed);
tip("Map is successfully loaded", true, "success", 7000);
}
catch(error) {
console.error(error);
ERROR && console.error(error);
clearMainTip();
alertMessage.innerHTML = `An error is occured on map loading. Select a different file to load,

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");

View file

@ -471,14 +471,14 @@ function lim(v) {
// get number from string in format "1-3" or "2" or "0.5"
function getNumberInRange(r) {
if (typeof r !== "string") {console.error("The value should be a string", r); return 0;}
if (typeof r !== "string") {ERROR && console.error("The value should be a string", r); return 0;}
if (!isNaN(+r)) return ~~r + +P(r - ~~r);
const sign = r[0] === "-" ? -1 : 1;
if (isNaN(+r[0])) r = r.slice(1);
const range = r.includes("-") ? r.split("-") : null;
if (!range) {console.error("Cannot parse the number. Check the format", r); return 0;}
if (!range) {ERROR && console.error("Cannot parse the number. Check the format", r); return 0;}
const count = rand(range[0] * sign, +range[1]);
if (isNaN(count) || count < 0) {console.error("Cannot parse number. Check the format", r); return 0;}
if (isNaN(count) || count < 0) {ERROR && console.error("Cannot parse number. Check the format", r); return 0;}
return count;
}
@ -603,7 +603,7 @@ void function() {
const form = prompt.querySelector("#promptForm");
window.prompt = function(promptText = "Please provide an input", options = {default:1, step:.01, min:0, max:100}, callback) {
if (options.default === undefined) {console.error("Prompt: options object does not have default value defined"); return;}
if (options.default === undefined) {ERROR && console.error("Prompt: options object does not have default value defined"); return;}
const input = prompt.querySelector("#promptInput");
prompt.querySelector("#promptText").innerHTML = promptText;
const type = typeof(options.default) === "number" ? "number" : "text";
@ -628,4 +628,4 @@ void function() {
}()
// indexedDB; ldb object
!function(){function e(t,o){return n?void(n.transaction("s").objectStore("s").get(t).onsuccess=function(e){var t=e.target.result&&e.target.result.v||null;o(t)}):void setTimeout(function(){e(t,o)},100)}var t=window.indexedDB||window.mozIndexedDB||window.webkitIndexedDB||window.msIndexedDB;if(!t)return void console.error("indexedDB not supported");var n,o={k:"",v:""},r=t.open("d2",1);r.onsuccess=function(e){n=this.result},r.onerror=function(e){console.error("indexedDB request error"),console.log(e)},r.onupgradeneeded=function(e){n=null;var t=e.target.result.createObjectStore("s",{keyPath:"k"});t.transaction.oncomplete=function(e){n=e.target.db}},window.ldb={get:e,set:function(e,t){o.k=e,o.v=t,n.transaction("s","readwrite").objectStore("s").put(o)}}}();
!function(){function e(t,o){return n?void(n.transaction("s").objectStore("s").get(t).onsuccess=function(e){var t=e.target.result&&e.target.result.v||null;o(t)}):void setTimeout(function(){e(t,o)},100)}var t=window.indexedDB||window.mozIndexedDB||window.webkitIndexedDB||window.msIndexedDB;if(!t)return void ERROR && console.error("indexedDB not supported");var n,o={k:"",v:""},r=t.open("d2",1);r.onsuccess=function(e){n=this.result},r.onerror=function(e){ERROR && console.error("indexedDB request error"),INFO && console.log(e)},r.onupgradeneeded=function(e){n=null;var t=e.target.result.createObjectStore("s",{keyPath:"k"});t.transaction.oncomplete=function(e){n=e.target.db}},window.ldb={get:e,set:function(e,t){o.k=e,o.v=t,n.transaction("s","readwrite").objectStore("s").put(o)}}}();