Skip to content

Commit

Permalink
feat(world): add fade constants and scaling logic
Browse files Browse the repository at this point in the history
  • Loading branch information
fallenoak committed Feb 4, 2024
1 parent b96720c commit 42cc70a
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions src/lib/world.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
const WORLD_FADE_SIZE_DEFAULT = [1.0, 4.0, 15.0, 100.0, 100000.0];

const WORLD_FADE_DIST_DEFAULT = [30.0, 100.0, 200.0, 750.0, 1250.0];

const WORLD_FADE_RANGE_DEFAULT = [5.0, 10.0, 15.0, 20.0, 50.0];

const WORLD_FADE_SIZE = [1.0, 4.0, 15.0, 100.0, 100000.0];

const WORLD_FADE_DIST_MIN = [25.0, 90.0, 185.0, 730.0, 1200.0];

const WORLD_FADE_DIST_MAX = [30.0, 100.0, 200.0, 750.0, 1250.0];

const getSizeCategory = (size: number) => {
let f: number;
for (f = 0; f < WORLD_FADE_SIZE.length; f++) {
if (size <= WORLD_FADE_SIZE[f]) {
break;
}
}

return f;
};

const scaleFadeDist = (scale: number) => {
for (let i = 0; i < WORLD_FADE_SIZE_DEFAULT.length; i++) {
const first = i === 0;
const last = i === WORLD_FADE_SIZE_DEFAULT.length - 1;
const s = first || last ? 1.0 : scale;

WORLD_FADE_SIZE[i] = WORLD_FADE_SIZE_DEFAULT[i];
WORLD_FADE_DIST_MAX[i] = WORLD_FADE_DIST_DEFAULT[i] * s;
WORLD_FADE_DIST_MIN[i] = WORLD_FADE_DIST_MAX[i] - WORLD_FADE_RANGE_DEFAULT[i];
}
};

// TODO modify scale based on config
scaleFadeDist(1.5);

export {
getSizeCategory,
scaleFadeDist,
WORLD_FADE_SIZE,
WORLD_FADE_DIST_MIN,
WORLD_FADE_DIST_MAX,
};

0 comments on commit 42cc70a

Please sign in to comment.