Skip to content

Commit

Permalink
style: lint & code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
etienne-85 committed Apr 3, 2024
1 parent dd0a6ef commit 8b83c53
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 29 deletions.
8 changes: 0 additions & 8 deletions src/common/misc.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export enum BlockType {
}

export type Block = {
pos: Vector3,
pos: Vector3
type: BlockType
}

Expand Down
7 changes: 4 additions & 3 deletions src/common/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Vector2, Vector3 } from 'three'

import { GenStats } from './stats'
import { BlockNeighbour } from './types'

Expand Down Expand Up @@ -37,9 +38,9 @@ const interpolatePoints = (p1: Vector2, p2: Vector2, t: number) => {
return p1.y + slope * (t - p1.x)
}
/**
* Direct neighbours e.g.
* - FRONT/BACK,
* - TOP/BOTTOM,
* Direct neighbours e.g.
* - FRONT/BACK,
* - TOP/BOTTOM,
* - LEFT/RIGHT
*/
const AdjacentNeighbours = [
Expand Down
2 changes: 1 addition & 1 deletion src/procgen/ProcGenLayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ export class ProcGenLayer extends GenLayer {
return vals * 255
}

static layerIndex(index: number){
static layerIndex(index: number) {
return `layer#${index}`
}

Expand Down
32 changes: 16 additions & 16 deletions src/procgen/WorldGen.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { Vector2, Vector3, Box3 } from 'three'

import { Block, BlockType } from '../common/types'
import { GenLayer } from './ProcGenLayer'
import { GenStats } from '../common/stats'
import * as Utils from '../common/utils'

import { GenLayer } from './ProcGenLayer'

export class WorldGenerator {
// eslint-disable-next-line no-use-before-define
static singleton: WorldGenerator
parent: any
samplingScale: number = 1 / 8 // 8 blocks per unit of noise
Expand All @@ -13,16 +16,6 @@ export class WorldGenerator {
procLayers!: GenLayer
layerSelection!: string

constructor() {
// blending map
// const transitionThreshold = 0.5
// const transitionRange = 0.1
// const transition = {
// lower: round2(transitionThreshold - transitionRange / 2),
// upper: round2(transitionThreshold + transitionRange / 2)
// }
}

static get instance() {
WorldGenerator.singleton = WorldGenerator.singleton || new WorldGenerator()
return WorldGenerator.singleton
Expand Down Expand Up @@ -71,7 +64,7 @@ export class WorldGenerator {
}

/**
* Checking neighbours surrounding block's position
* Checking neighbours surrounding block's position
* to determine if block is hidden or not
*/
hiddenBlock(position: Vector3) {
Expand Down Expand Up @@ -119,9 +112,15 @@ export class WorldGenerator {
// for (let y = bbox.max.y - 1; y >= bbox.min.y; y--) {
while (!hidden && y >= bbox.min.y) {
const blockPos = new Vector3(x, y, z)
const blockType = blockPos.y < groundLevel ? this.blockTypeMapper(blockPos.y) : BlockType.NONE
const blockType =
blockPos.y < groundLevel
? this.blockTypeMapper(blockPos.y)
: BlockType.NONE
const block: Block = { pos: blockPos, type: blockType }
hidden = pruning && block.type !== BlockType.NONE && this.hiddenBlock(block.pos)
hidden =
pruning &&
block.type !== BlockType.NONE &&
this.hiddenBlock(block.pos)
// only existing and visible block, e.g with a face in contact with air
if (block.type !== BlockType.NONE && !hidden) {
yield block
Expand All @@ -145,9 +144,10 @@ export class WorldGenerator {
iterations: iterCount,
}
}

/**
* @param bbox
* @returns
* @param bbox
* @returns
*/
estimatedVoxelsCount(bbox: Box3): number {
const range = bbox.getSize(new Vector3())
Expand Down

0 comments on commit 8b83c53

Please sign in to comment.