mirror of
https://github.com/DoomKitty87/seafoam.git
synced 2024-12-28 16:06:39 +01:00
working on generation :( doesnt work well and idk why its the same asC++
This commit is contained in:
parent
cdfc0de53e
commit
9a2a72d0d7
2 changed files with 39 additions and 31 deletions
|
@ -134,6 +134,8 @@
|
||||||
</div>
|
</div>
|
||||||
<script>
|
<script>
|
||||||
async function generateRoute(sector, allowedOOB, priority, waypointCount) {
|
async function generateRoute(sector, allowedOOB, priority, waypointCount) {
|
||||||
|
allowedOOB = parseInt(allowedOOB);
|
||||||
|
waypointCount = parseInt(waypointCount);
|
||||||
const readTextFile = window.__TAURI__.fs.readTextFile;
|
const readTextFile = window.__TAURI__.fs.readTextFile;
|
||||||
const resolveResource = window.__TAURI__.path.resolveResource;
|
const resolveResource = window.__TAURI__.path.resolveResource;
|
||||||
const padPath = await resolveResource('assets/padsv3.txt')
|
const padPath = await resolveResource('assets/padsv3.txt')
|
||||||
|
@ -187,6 +189,7 @@
|
||||||
const desiredPathLength = waypointCount;
|
const desiredPathLength = waypointCount;
|
||||||
const padCoords = [];
|
const padCoords = [];
|
||||||
const secDensities = [];
|
const secDensities = [];
|
||||||
|
console.log(sectors[sector][0] + allowedOOB, sectors[sector][2] - allowedOOB, sectors[sector][1] - allowedOOB, sectors[sector][3] + allowedOOB)
|
||||||
for (var i = 0; i < overallPads.length / 3; i++) {
|
for (var i = 0; i < overallPads.length / 3; i++) {
|
||||||
if (overallPads[i * 3] <= sectors[sector][0] + allowedOOB && overallPads[i * 3] > sectors[sector][2] - allowedOOB && overallPads[i * 3 + 2] >= sectors[sector][1] - allowedOOB && overallPads[i * 3 + 2] < sectors[sector][3] + allowedOOB) {
|
if (overallPads[i * 3] <= sectors[sector][0] + allowedOOB && overallPads[i * 3] > sectors[sector][2] - allowedOOB && overallPads[i * 3 + 2] >= sectors[sector][1] - allowedOOB && overallPads[i * 3 + 2] < sectors[sector][3] + allowedOOB) {
|
||||||
padCoords.push(overallPads[i * 3]);
|
padCoords.push(overallPads[i * 3]);
|
||||||
|
@ -264,7 +267,7 @@
|
||||||
lowestIndex = j;
|
lowestIndex = j;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var blocked = true;
|
var blocked = false;
|
||||||
while (blocked) {
|
while (blocked) {
|
||||||
blocked = false;
|
blocked = false;
|
||||||
const headx = path[path.length - 3];
|
const headx = path[path.length - 3];
|
||||||
|
@ -289,7 +292,7 @@
|
||||||
lowestWeight = Infinity;
|
lowestWeight = Infinity;
|
||||||
lowestIndex = -1;
|
lowestIndex = -1;
|
||||||
for (var k = 0; k < weightChart.length; k++) {
|
for (var k = 0; k < weightChart.length; k++) {
|
||||||
if (j == i && path.length == 6) continue;
|
if (k == i && path.length == 6) continue;
|
||||||
if (weightChart[k] < lowestWeight) {
|
if (weightChart[k] < lowestWeight) {
|
||||||
lowestWeight = weightChart[k];
|
lowestWeight = weightChart[k];
|
||||||
lowestIndex = k;
|
lowestIndex = k;
|
||||||
|
@ -302,8 +305,12 @@
|
||||||
if (lowestWeight == Infinity) break;
|
if (lowestWeight == Infinity) break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lowestWeight == Infinity) break;
|
if (lowestWeight == Infinity) {
|
||||||
|
console.log("Route blocked.");
|
||||||
|
break;
|
||||||
|
}
|
||||||
if (lowestIndex == i) {
|
if (lowestIndex == i) {
|
||||||
|
console.log("Route complete.");
|
||||||
done = true;
|
done = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -332,6 +339,7 @@
|
||||||
highestDensityPath = path;
|
highestDensityPath = path;
|
||||||
highestDensityDist = avgDist;
|
highestDensityDist = avgDist;
|
||||||
}
|
}
|
||||||
|
console.log(path.length / 3, density, avgDist);
|
||||||
}
|
}
|
||||||
//Choose between density and dist in settings as well though
|
//Choose between density and dist in settings as well though
|
||||||
var outPath = [];
|
var outPath = [];
|
||||||
|
@ -353,8 +361,9 @@
|
||||||
if (i != outPath.length / 3 - 1) pathOutput += ",";
|
if (i != outPath.length / 3 - 1) pathOutput += ",";
|
||||||
}
|
}
|
||||||
pathOutput += "]";
|
pathOutput += "]";
|
||||||
|
document.getElementsByClassName("routeoutput")[0].innerHTML = pathOutput;
|
||||||
return pathOutput, outPath.length, outPathDensity, outPathDist;
|
console.log(outPath.length / 3, outPathDensity, outPathDist);
|
||||||
|
return pathOutput, outPath.length / 3, outPathDensity, outPathDist;
|
||||||
}
|
}
|
||||||
var activeSquare = -1;
|
var activeSquare = -1;
|
||||||
var currentStep = 1;
|
var currentStep = 1;
|
||||||
|
@ -378,9 +387,8 @@
|
||||||
activeSquare = parseInt(indx);
|
activeSquare = parseInt(indx);
|
||||||
document.getElementById(indx).style.backgroundColor = "#ffffff";
|
document.getElementById(indx).style.backgroundColor = "#ffffff";
|
||||||
}
|
}
|
||||||
async function getRoute() {
|
function getRoute() {
|
||||||
var output = generateRoute(activeSquare, allowedOOB, priority, waypointNumber);
|
var output = generateRoute(activeSquare, allowedOOB, priority, waypointNumber);
|
||||||
//document.getElementsByClassName("routeoutput")[0].innerHTML = output[0];
|
|
||||||
}
|
}
|
||||||
async function resetMenu() {
|
async function resetMenu() {
|
||||||
document.getElementById("menua" + (currentStep)).style.opacity = 0;
|
document.getElementById("menua" + (currentStep)).style.opacity = 0;
|
||||||
|
|
|
@ -49,10 +49,10 @@ async function generateRoute(sector, allowedOOB, priority, waypointCount) {
|
||||||
sectors.push(sector);
|
sectors.push(sector);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
document.getElementsByClassName("routeoutput")[0].innerHTML = "Generating route...";
|
|
||||||
const desiredPathLength = waypointCount;
|
const desiredPathLength = waypointCount;
|
||||||
const padCoords = [];
|
const padCoords = [];
|
||||||
const secDensities = [];
|
const secDensities = [];
|
||||||
|
console.log(sectors[sector][0] + allowedOOB, sectors[sector][2] - allowedOOB, sectors[sector][1] - allowedOOB, sectors[sector][3] + allowedOOB)
|
||||||
for (var i = 0; i < overallPads.length / 3; i++) {
|
for (var i = 0; i < overallPads.length / 3; i++) {
|
||||||
if (overallPads[i * 3] <= sectors[sector][0] + allowedOOB && overallPads[i * 3] > sectors[sector][2] - allowedOOB && overallPads[i * 3 + 2] >= sectors[sector][1] - allowedOOB && overallPads[i * 3 + 2] < sectors[sector][3] + allowedOOB) {
|
if (overallPads[i * 3] <= sectors[sector][0] + allowedOOB && overallPads[i * 3] > sectors[sector][2] - allowedOOB && overallPads[i * 3 + 2] >= sectors[sector][1] - allowedOOB && overallPads[i * 3 + 2] < sectors[sector][3] + allowedOOB) {
|
||||||
padCoords.push(overallPads[i * 3]);
|
padCoords.push(overallPads[i * 3]);
|
||||||
|
@ -67,13 +67,13 @@ async function generateRoute(sector, allowedOOB, priority, waypointCount) {
|
||||||
var highestDensity = 0;
|
var highestDensity = 0;
|
||||||
var highestDensityPath = [];
|
var highestDensityPath = [];
|
||||||
var highestDensityDist = Infinity;
|
var highestDensityDist = Infinity;
|
||||||
|
console.log(padCoords.length / 3);
|
||||||
for (var i = 0; i < padCoords.length / 3; i++) {
|
for (var i = 0; i < padCoords.length / 3; i++) {
|
||||||
document.getElementsByClassName("routeoutput")[0].innerHTML = "Generating route... " + floor(i / padCoords.length * 100) + "%";
|
console.log("Generating route... " + Math.floor(i / padCoords.length * 100) + "%");
|
||||||
const path = [];
|
const path = [];
|
||||||
path.push_back(padCoords[i * 3]);
|
path.push(padCoords[i * 3]);
|
||||||
path.push_back(padCoords[i * 3 + 1]);
|
path.push(padCoords[i * 3 + 1]);
|
||||||
path.push_back(padCoords[i * 3 + 2]);
|
path.push(padCoords[i * 3 + 2]);
|
||||||
|
|
||||||
var density = secDensities[i];
|
var density = secDensities[i];
|
||||||
const usedPads = [];
|
const usedPads = [];
|
||||||
|
@ -84,20 +84,20 @@ async function generateRoute(sector, allowedOOB, priority, waypointCount) {
|
||||||
for (var j = 0; j < padCoords.length / 3; j++) {
|
for (var j = 0; j < padCoords.length / 3; j++) {
|
||||||
var weight = 0;
|
var weight = 0;
|
||||||
|
|
||||||
const xdiff = abs(path[path.length - 3] - padCoords[j * 3]);
|
const xdiff = Math.abs(path[path.length - 3] - padCoords[j * 3]);
|
||||||
const ydiff = abs(path[path.length - 2] - padCoords[j * 3 + 1]);
|
const ydiff = Math.abs(path[path.length - 2] - padCoords[j * 3 + 1]);
|
||||||
const zdiff = abs(path[path.length - 1] - padCoords[j * 3 + 2]);
|
const zdiff = Math.abs(path[path.length - 1] - padCoords[j * 3 + 2]);
|
||||||
const dist = sqrt(xdiff * xdiff + ydiff * ydiff + zdiff * zdiff);
|
const dist = Math.sqrt(xdiff * xdiff + ydiff * ydiff + zdiff * zdiff);
|
||||||
const startdiffx = abs(path[0] - padCoords[j * 3]);
|
const startdiffx = Math.abs(path[0] - padCoords[j * 3]);
|
||||||
const startdiffy = abs(path[1] - padCoords[j * 3 + 1]);
|
const startdiffy = Math.abs(path[1] - padCoords[j * 3 + 1]);
|
||||||
const startdiffz = abs(path[2] - padCoords[j * 3 + 2]);
|
const startdiffz = Math.abs(path[2] - padCoords[j * 3 + 2]);
|
||||||
const startdist = sqrt(startdiffx * startdiffx + startdiffy * startdiffy + startdiffz * startdiffz);
|
const startdist = Math.sqrt(startdiffx * startdiffx + startdiffy * startdiffy + startdiffz * startdiffz);
|
||||||
const gemDensity = secDensities[j];
|
const gemDensity = secDensities[j];
|
||||||
var angleWeight = 1;
|
var angleWeight = 1;
|
||||||
const angleDiff = 180 / Math.PI * abs(atan2(path[path.length - 6] - path[path.length - 3], path[path.length - 4] - path[path.length - 1]) - atan2(padCoords[j * 3] - path[path.length - 3], padCoords[j * 3 + 2] - path[path.length - 1]));
|
const angleDiff = 180 / Math.PI * Math.abs(Math.atan2(path[path.length - 6] - path[path.length - 3], path[path.length - 4] - path[path.length - 1]) - Math.atan2(padCoords[j * 3] - path[path.length - 3], padCoords[j * 3 + 2] - path[path.length - 1]));
|
||||||
//Include settable angle weighting later
|
//Include settable angle weighting later
|
||||||
|
|
||||||
weight = angleWeight * (pow(dist, 2) + pow(startdist, 2 * usedPads.length + 1 / desiredPathLength)) / ((gemDensity - 44) * 4);
|
weight = angleWeight * (Math.pow(dist, 2) + Math.pow(startdist, 2 * usedPads.length + 1 / desiredPathLength)) / ((gemDensity - 44) * 4);
|
||||||
if (dist > 62) weight = Infinity;
|
if (dist > 62) weight = Infinity;
|
||||||
|
|
||||||
weightChart.push(weight);
|
weightChart.push(weight);
|
||||||
|
@ -120,7 +120,7 @@ async function generateRoute(sector, allowedOOB, priority, waypointCount) {
|
||||||
weightChart[j] = Infinity;
|
weightChart[j] = Infinity;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (abs(padCoords[j * 3] - padCoords[usedPads[k] * 3]) < 3 && abs(padCoords[j * 3 + 1] - padCoords[usedPads[k] * 3 + 1]) < 3 && abs(padCoords[j * 3 + 2] - padCoords[usedPads[k] * 3 + 2]) < 3) {
|
if (Math.abs(padCoords[j * 3] - padCoords[usedPads[k] * 3]) < 3 && Math.abs(padCoords[j * 3 + 1] - padCoords[usedPads[k] * 3 + 1]) < 3 && Math.abs(padCoords[j * 3 + 2] - padCoords[usedPads[k] * 3 + 2]) < 3) {
|
||||||
weightChart[j] = Infinity;
|
weightChart[j] = Infinity;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -142,12 +142,12 @@ async function generateRoute(sector, allowedOOB, priority, waypointCount) {
|
||||||
const xdist = tailx - headx;
|
const xdist = tailx - headx;
|
||||||
const ydist = taily - heady;
|
const ydist = taily - heady;
|
||||||
const zdist = tailz - headz;
|
const zdist = tailz - headz;
|
||||||
const interval = floor(sqrt(xdist * xdist + ydist * ydist + zdist * zdist));
|
const interval = Math.floor(Math.sqrt(xdist * xdist + ydist * ydist + zdist * zdist));
|
||||||
for (var j = 1; j < interval; j++) {
|
for (var j = 1; j < interval; j++) {
|
||||||
const x = round(headx + j * xdist / interval);
|
const x = Math.round(headx + j * xdist / interval);
|
||||||
const y = round(heady + j * ydist / interval);
|
const y = Math.round(heady + j * ydist / interval);
|
||||||
const z = round(headz + j * zdist / interval);
|
const z = Math.round(headz + j * zdist / interval);
|
||||||
if (max(abs(x - headx), abs(z - headz)) < 2 && abs(y - heady) < 2) continue;
|
if (Math.max(Math.abs(x - headx), Math.abs(z - headz)) < 2 && Math.abs(y - heady) < 2) continue;
|
||||||
if (x - 202 > 621 || x - 202 < 0 || y > 255 || y < 0 || z - 202 > 621 || z - 202 < 0) continue;
|
if (x - 202 > 621 || x - 202 < 0 || y > 255 || y < 0 || z - 202 > 621 || z - 202 < 0) continue;
|
||||||
if (blockData[x - 202][y][z - 202] != 0) blocked = true;
|
if (blockData[x - 202][y][z - 202] != 0) blocked = true;
|
||||||
if (blocked) {
|
if (blocked) {
|
||||||
|
@ -183,9 +183,9 @@ async function generateRoute(sector, allowedOOB, priority, waypointCount) {
|
||||||
|
|
||||||
var avgDist;
|
var avgDist;
|
||||||
for (var j = 0; j < path.length / 3 - 1; j++) {
|
for (var j = 0; j < path.length / 3 - 1; j++) {
|
||||||
avgDist += sqrt(pow(path[j * 3] - path[j * 3 + 3], 2) + pow(path[j * 3 + 1] + 2 - path[j * 3 + 4], 2) + pow(path[j * 3 + 2] - path[j * 3 + 5], 2));
|
avgDist += Math.sqrt(Math.pow(path[j * 3] - path[j * 3 + 3], 2) + Math.pow(path[j * 3 + 1] + 2 - path[j * 3 + 4], 2) + Math.pow(path[j * 3 + 2] - path[j * 3 + 5], 2));
|
||||||
}
|
}
|
||||||
avgDist += sqrt(pow(path[path.length - 3] - path[0], 2) + pow(path[j * 3 + 1] + 2 - path[1], 2) + pow(path[path.length - 1] - path[2], 2));
|
avgDist += Math.sqrt(Math.pow(path[path.length - 3] - path[0], 2) + Math.pow(path[j * 3 + 1] + 2 - path[1], 2) + Math.pow(path[path.length - 1] - path[2], 2));
|
||||||
avgDist /= path.length / 3 + 1;
|
avgDist /= path.length / 3 + 1;
|
||||||
density /= path.length / 3;
|
density /= path.length / 3;
|
||||||
if (avgDist < lowestAvgDist && desiredPathLength - desiredPathLength / 10 <= path.length / 3 && path.length / 3 <= desiredPathLength + desiredPathLength / 10) {
|
if (avgDist < lowestAvgDist && desiredPathLength - desiredPathLength / 10 <= path.length / 3 && path.length / 3 <= desiredPathLength + desiredPathLength / 10) {
|
||||||
|
|
Loading…
Reference in a new issue