-
-
Notifications
You must be signed in to change notification settings - Fork 680
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Vite ice split draft #1127
Open
StempunkDev
wants to merge
8
commits into
Azgaar:vite
Choose a base branch
from
StempunkDev:vite
base: vite
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Vite ice split draft #1127
Changes from 4 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
21abd9e
fix: options menue now works as intended
StempunkDev b4b7ee0
ice edito, change to new byId
StempunkDev 1684cbe
drawIce now typed
StempunkDev 8f78e46
ice generation and draw now split
StempunkDev 6b5d3fd
requested changes
StempunkDev 0b520da
fix for iceBerg generation
StempunkDev 1a3d7db
parameter changes for getGridPolygonLocal
StempunkDev 85a2308
fix for parameters
StempunkDev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { getGridPolygon } from "utils/graphUtils"; | ||
import { P, normalize, rn, last } from "utils"; | ||
import { clipPoly } from "utils/lineUtils"; | ||
import { ERROR } from "config/logging"; | ||
import * as d3 from "d3"; | ||
|
||
export function drawIce() { | ||
const ice = d3.select("#ice"); | ||
const { ice: icePack } = pack; | ||
|
||
for (const shield of icePack.iceShields) { | ||
ice | ||
.append("polygon") | ||
.attr("points", shield.points.toString()) | ||
} | ||
|
||
for (const iceberg of icePack.icebergs) { | ||
ice | ||
.append("polygon") | ||
.attr("points", iceberg.points.toString()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import { ERROR } from "config/logging"; | ||
import { aleaPRNG } from "scripts/aleaPRNG"; | ||
import { IIce, Iiceberg } from "types/pack/ice"; | ||
import { clipPoly, last, normalize, P, rn } from "utils"; | ||
|
||
export function generateIce( | ||
cells: Pick<IPack["cells"], "i" | "h" | "c" | "v" | "p">, | ||
vertices: IGraphVertices, | ||
temp: Int8Array, | ||
features: TGridFeatures, | ||
gridCells: Pick<IGrid["cells"], "f" | "t">, | ||
): IIce { | ||
const shieldMin = -8; // max temp to form ice shield (glacier) | ||
const icebergMax = 1; // max temp to form an iceberg | ||
const nOfCells = cells.i.length; | ||
const used = new Uint8Array(cells.i.length); | ||
|
||
Math.random = aleaPRNG(seed); | ||
const icePack: IIce = { icebergs: [], iceShields: [] }; | ||
for (const i of cells.i) { | ||
const temperature = temp[i]; | ||
if (temperature > icebergMax) continue; // too warm: no ice | ||
if (temperature > shieldMin && cells.h[i] >= 20) continue; // non-glacier land: no ice | ||
|
||
if (temperature <= shieldMin) { | ||
// very cold: ice shield | ||
if (used[i]) continue; // already rendered | ||
const onborder = cells.c[i].some((n) => temp[n] > shieldMin); | ||
if (!onborder) continue; // need to start from onborder cell | ||
const vertex = cells.v[i].find((v) => | ||
vertices.c[v]?.some((i) => temp[i] > shieldMin) | ||
); | ||
if (vertex === undefined) continue; // no suitable vertex found | ||
const chain = connectVertices(vertex); | ||
if (chain.length < 3) continue; | ||
const points = clipPoly(chain.map((v) => vertices.p[v])); | ||
icePack.iceShields.push({ points, type: "iceShield" }); | ||
continue; | ||
} | ||
// mildly cold: iceberd | ||
if (P(normalize(temperature, -7, 2.5))) continue; // t[-5; 2] cold: skip some cells | ||
if (gridCells.f[i] !== 0 && (features[gridCells.f[i]] as IGridFeature).type === "lake") continue; // lake: no icebers // MARKER as IGridFeature | ||
let size = (6.5 + temperature) / 10; // iceberg size: 0 = full size, 1 = zero size | ||
if (gridCells.t[i] === -1) size *= 1.3; // coasline: smaller icebers | ||
size = Math.min(size * (0.4 + Math.random() * 1.2), 0.95); // randomize iceberg size | ||
icePack.icebergs.push(generateIceberg(i, size)); | ||
} | ||
return icePack; | ||
|
||
// Helper functions | ||
function generateIceberg(i: number, size: number): Iiceberg { | ||
const cellMidPoint = cells.p[i]; | ||
const points = cells.v[i].map(v => vertices.p[v]).map((point) => [ | ||
(point[0] + (cellMidPoint[0] - point[0]) * size) | 0, | ||
(point[1] + (cellMidPoint[1] - point[1]) * size) | 0, | ||
]); | ||
return { points, cell: i, size: rn(1 - size, 2) }; | ||
} | ||
|
||
// connect vertices to chain | ||
function connectVertices(start: number) { | ||
const chain = []; // vertices chain to form a path | ||
for ( | ||
let i = 0, current = start; | ||
i === 0 || (current !== start && i < 20000); | ||
i++ | ||
) { | ||
const prev = last(chain); // previous vertex in chain | ||
chain.push(current); // add current vertex to sequence | ||
const currentVertex = vertices.c[current]; // cells adjacent to vertex | ||
currentVertex | ||
.filter((cellIndicie) => temp[cellIndicie] <= shieldMin) | ||
.forEach((cellIndice) => (used[cellIndice] = 1)); | ||
const c0 = currentVertex[0] >= nOfCells || temp[currentVertex[0]] > shieldMin; | ||
const c1 = currentVertex[1] >= nOfCells || temp[currentVertex[1]] > shieldMin; | ||
const c2 = currentVertex[2] >= nOfCells || temp[currentVertex[2]] > shieldMin; | ||
const vertexNeighbors = vertices.v[current]; // neighboring vertices | ||
if (vertexNeighbors[0] !== prev && c0 !== c1) | ||
current = vertexNeighbors[0]; | ||
else if (vertexNeighbors[1] !== prev && c1 !== c2) | ||
current = vertexNeighbors[1]; | ||
else if (vertexNeighbors[2] !== prev && c0 !== c2) | ||
current = vertexNeighbors[2]; | ||
if (current === chain[chain.length - 1]) { | ||
ERROR && console.error("Next vertex is not found"); | ||
break; | ||
} | ||
} | ||
return chain; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use vanilla JS where possible (create whole html as string and then set to DOM via
element.innerHTML
as once), D3 adds significant memory burden while we don't use its real power anyway