Skip to content

Commit

Permalink
misc: changes required to support node bundling
Browse files Browse the repository at this point in the history
  • Loading branch information
etienne-85 committed Jan 16, 2025
1 parent 49ebe2d commit 397682d
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 19 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ dist/
.discarded
*.schem
*.layer
.todo.md
.local
.parcel-cache
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@
"name": "@aresrpg/aresrpg-world",
"version": "1.7.3",
"description": "Procedural voxel terrain generation for AresRPG",
"main": "dist/index.js",
"source": "src/index.ts",
"main": "dist/index.mjs",
"types": "dist/types.d.ts",
"scripts": {
"watch": "tsc --watch",
"build": "tsc",
"bundle": "parcel build",
"clean": "rm -rf .parcel-cache && rm -rf dist/",
"lint": "eslint . --ext .ts && prettier . --check && npm run typecheck",
"typecheck": "tsc --build",
"format": "prettier . --write && eslint . --fix --ext .ts",
Expand Down Expand Up @@ -44,6 +48,7 @@
"eslint-plugin-import": "2.31.0",
"husky": "^4.3.8",
"lint-staged": "15.2.11",
"parcel": "^2.13.3",
"prettier": "3.4.2",
"typescript": "^5.7.2"
},
Expand Down
5 changes: 3 additions & 2 deletions src/config/demo-samples/configs/blocks_mappings.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { BlockType, WorldUtils } from '../../../index'
import { BlockType } from '../../../index'
import { typesNumbering } from '../../../utils/misc'

/**
* Extending world reserved blocks
Expand All @@ -17,7 +18,7 @@ export const ExtBlock = {
}

// assing an enum id to each additional type
WorldUtils.misc.typesNumbering(ExtBlock, BlockType.LAST_PLACEHOLDER)
typesNumbering(ExtBlock, BlockType.LAST_PLACEHOLDER)

/**
* Blocks color mapping
Expand Down
6 changes: 4 additions & 2 deletions src/factory/ChunksFactory.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { MathUtils, Vector3 } from 'three'
// import { MathUtils, Vector3 } from 'three'
import { Vector3 } from 'three'

import { WorldEnv } from '../config/WorldEnv'
import { asVect2, serializePatchId, asBox2 } from '../utils/convert'
Expand All @@ -10,6 +11,7 @@ import {
} from '../datacontainers/ChunkContainer'
import { BlockType, Biome, BiomeType, DensityVolume } from '../index'
import { GroundPatch, parseGroundFlags } from '../processing/GroundPatch'
import { clamp } from '../utils/math'

export class EmptyChunk extends ChunkContainer {
constructor(chunkKey: ChunkKey) {
Expand Down Expand Up @@ -47,7 +49,7 @@ export class GroundChunk extends ChunkContainer {
landConf.subtype || BlockType.BEDROCK,
)
// generate ground buffer
const buffSize = MathUtils.clamp(block.data.level - ymin, 0, ymax - ymin)
const buffSize = clamp(block.data.level - ymin, 0, ymax - ymin)
if (buffSize > 0) {
const groundBuffer = new Uint16Array(block.data.level - ymin)
// fill with bedrock first
Expand Down
7 changes: 5 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Utils
export * as WorldUtils from './utils/index'
// export * as WorldUtils from './utils/index'
export { getPatchId, asVect2, asVect3 } from './utils/convert'
export { BlockMode } from './utils/types'
// Processing
export { ProcessingTask } from './processing/TaskProcessing'
Expand All @@ -20,6 +21,7 @@ export {
DistributionProfile,
} from './processing/RandomDistributionMap'
export { ChunksProcessor } from './processing/ChunksProcessing'
export { ProcessingState } from './processing/TaskProcessing'
// Procgen
export { Biome, BiomeType, BlockType } from './procgen/Biome'
export { Heightmap } from './procgen/Heightmap'
Expand All @@ -40,4 +42,5 @@ export {
// export * as ProceduralGenerators from './tools/ProceduralGenerators'
// Config
export { WorldEnv } from './config/WorldEnv'
export * as WorldDevSetup from './config/demo-samples/configs/world_dev_setup'
// export * as WorldDevSetup from './config/demo-samples/configs/world_dev_setup'
export { EnvOverride, BlocksColorOverride } from './config/demo-samples/configs/world_dev_setup'
17 changes: 8 additions & 9 deletions src/procgen/Biome.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Vector2, Vector3 } from 'three'
// import { MappingProfiles, ProfilePreset } from "../tools/MappingPresets"
import { smoothstep } from 'three/src/math/MathUtils'

// import { smoothstep as smoothStep } from 'three/src/math/MathUtils'
import { LinkedList } from '../datacontainers/LinkedList'
import {
BiomeLandKey,
Expand All @@ -11,7 +10,7 @@ import {
BiomeLands,
} from '../utils/types'
import { WorldEnv } from '../index'
import { clamp, roundToDec } from '../utils/math'
import {clamp, roundToDec, smoothStep } from '../utils/math'
import {
findMatchingRange,
MappingRangeSorter,
Expand Down Expand Up @@ -241,7 +240,7 @@ export class Biome {
}
// dec LOW, inc MID
else if (value < steps.mid) {
const interp = smoothstep(value, steps.lowToMid, steps.mid)
const interp = smoothStep(value, steps.lowToMid, steps.mid)
contributions.low = 1 - interp
contributions.mid = interp
}
Expand All @@ -251,7 +250,7 @@ export class Biome {
}
// dec MID/ inc HIGH
else if (value < steps.high) {
const interp = smoothstep(value, steps.midToHigh, steps.high)
const interp = smoothStep(value, steps.midToHigh, steps.high)
contributions.mid = 1 - interp
contributions.high = interp
}
Expand Down Expand Up @@ -301,10 +300,10 @@ export class Biome {
})
Object.keys(biomeContribs).forEach(
k =>
(biomeContribs[k as BiomeType] = roundToDec(
biomeContribs[k as BiomeType],
2,
)),
(biomeContribs[k as BiomeType] = roundToDec(
biomeContribs[k as BiomeType],
2,
)),
)

// biomeContribs[BiomeType.Arctic] = 1
Expand Down
4 changes: 2 additions & 2 deletions src/utils/math.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,5 +136,5 @@ export const vectRoundToDec = (input: Vector2 | Vector3, n_pow: number) => {
}

// Clamp number between two values:
export const clamp = (num: number, min: number, max: number) =>
Math.min(Math.max(num, min), max)
export const clamp = (val: number, min: number, max: number) =>
Math.min(Math.max(val, min), max)

0 comments on commit 397682d

Please sign in to comment.