Skip to content

Commit

Permalink
fix: iteration range
Browse files Browse the repository at this point in the history
  • Loading branch information
etienne-85 committed Mar 29, 2024
1 parent e702d6a commit 3129f0e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
10 changes: 5 additions & 5 deletions src/procgen/VoxelMap.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Box3, Vector3 } from 'three'
import { Box3, Vector2, Vector3 } from 'three'
import { IVoxelMap, IVoxelMaterial, IVoxel } from '@aresrpg/aresrpg-engine'

import { VOXEL_TYPE_COLORS } from '../common/types'
Expand Down Expand Up @@ -33,13 +33,13 @@ export class VoxelMap implements IVoxelMap {

iterateOnVoxels(from: Vector3, to: Vector3): Generator<IVoxel, any, unknown> {
const bmin = new Vector3(from.x, from.y, from.z)
const bmax = new Vector3(to.x - 1, to.y - 1, to.z - 1)
const bmax = new Vector3(to.x, to.y, to.z)
const bbox = new Box3(bmin, bmax)
return this.worldGen.generate(bbox)
return this.worldGen.generate(bbox, true)
}

voxelExists(x: number, y: number, z: number): boolean {
const point = new Vector3(x, y, z)
return !!this.worldGen.getVoxel(point)
const h = this.worldGen.getHeight(new Vector2(x, z))
return y < h
}
}
5 changes: 3 additions & 2 deletions src/procgen/WorldGen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export class WorldGenerator {
* @returns null if empty voxel or voxel's type if any
*/
getBlock(position: Vector3) {
// TODO
return position < this.getHeight()
}

adjacentCount(position: Vector3) {
Expand All @@ -102,7 +102,7 @@ export class WorldGenerator {
// sampling volume
for (let { x } = bbox.min; x < bbox.max.x; x++) {
for (let { z } = bbox.min; z < bbox.max.z; z++) {
let { y } = bbox.max
let y = bbox.max.y - 1
let hiddenBlock = false
let existingBlock = false
let groundLevel = this.getHeight(new Vector2(x, z))

Check failure on line 108 in src/procgen/WorldGen.ts

View workflow job for this annotation

GitHub Actions / lint

'groundLevel' is never reassigned. Use 'const' instead
Expand All @@ -123,6 +123,7 @@ export class WorldGenerator {
position: voxelPos,
materialId: this.getVoxelType(voxelPos),
}
console.log(voxelPos.x)
yield voxel
blocksCount++
// hiddenBlock = true
Expand Down

0 comments on commit 3129f0e

Please sign in to comment.