Skip to content

Commit 6592c2b

Browse files
committed
Debug basin
1 parent 0736759 commit 6592c2b

File tree

6 files changed

+20
-22
lines changed

6 files changed

+20
-22
lines changed

src/model/tilemap/worldmap/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ export class WorldTileMap extends TileMap {
6060
// set a global struct for world
6161
const world = {
6262
rect,
63+
seed: this.seed,
6364
size: rect.width
6465
}
6566
const context = {

src/model/tilemap/worldmap/world/basin/index.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,18 @@ export class BasinLayer {
5353
const {canvas, canvasPoint, tileSize, tilePoint} = props
5454
const basin = this.get(tilePoint)
5555
const isWater = this.#world.surface.isWater(tilePoint)
56+
if (! basin.id) {
57+
canvas.rect(canvasPoint, tileSize, WaterBasin.color.toHex())
58+
return
59+
}
5660
const basinColor = isWater ? WaterBasin.color : basin.type.color
5761
const color = basin.isDivide ? basinColor.brighten(20) : basinColor
5862
canvas.rect(canvasPoint, tileSize, color.toHex())
5963
if (params.get('showErosion')) {
60-
const text = basin.erosion.symbol
61-
const textColor = color.invert().toHex()
62-
// canvas.text(canvasPoint, tileSize, text, textColor)
6364
this.#drawErosionPath(props, basin)
65+
// const text = basin.erosion.symbol
66+
// const textColor = color.invert().toHex()
67+
// canvas.text(canvasPoint, tileSize, text, textColor)
6468
}
6569
}
6670

src/model/tilemap/worldmap/world/basin/model.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ function buildBasinGrid(context) {
7575
const type = detectLandBasinType(world, survey)
7676
surveyMap.set(basinId, survey)
7777
model.type.set(basinId, type.id)
78-
landFillMap.set(basinId, {origin: point})
78+
landFillMap.set(basinId, {origin: point, type})
7979
basinId++
8080
} else if (isBorder && world.surface.isWater(point)) {
8181
const type = WaterBasin
@@ -157,7 +157,10 @@ class LandBasinFill extends ConcurrentFill {
157157
if (basinGrid.get(fillPoint) !== EMPTY) return false
158158
// avoid erosion flow on land borders
159159
if (world.surface.isBorder(fillPoint)) return false
160-
if (fill.level >= basin.reach) return false
160+
if (fill.level >= basin.reach) {
161+
// basinGrid.set(fillPoint, fill.id)
162+
return false
163+
}
161164
const target = world.surface.get(fillPoint)
162165
const parent = world.surface.get(parentPoint)
163166
// avoid fill if different types
@@ -189,13 +192,10 @@ class WaterBasinFill extends ConcurrentFill {
189192
basinGrid.set(fillPoint, fill.id) // basin id is the same as fill id
190193
// discover adjacent river and water tiles
191194
Point.adjacents(fillPoint, (sidePoint, direction) => {
192-
const sideId = basinGrid.get(sidePoint)
193-
const sideType = Basin.parse(model.type.get(sideId))
194-
const isLand = world.surface.isLand(sidePoint)
195-
if (isLand) {
195+
if (world.surface.isLand(sidePoint)) {
196196
const sideDirection = Direction.fromId(model.erosion.get(sidePoint))
197197
const mouth = Point.atDirection(sidePoint, sideDirection)
198-
if (sideType.hasRivers && Point.equals(mouth, fillPoint)) {
198+
if (Point.equals(mouth, fillPoint)) {
199199
model.directionBitmask.add(fillPoint, direction)
200200
model.erosion.set(fillPoint, direction.id)
201201
}
@@ -220,14 +220,14 @@ class WaterBasinFill extends ConcurrentFill {
220220

221221
onFill(fill, fillPoint, parentPoint) {
222222
const { world, model, basinGrid } = fill.context
223+
const upstream = Point.directionBetween(fillPoint, parentPoint)
224+
model.erosion.set(fillPoint, upstream.id)
225+
// calculate downstream directions
223226
Point.adjacents(fillPoint, (sidePoint, direction) => {
224227
if (world.surface.isWater(sidePoint)) {
225228
model.directionBitmask.add(fillPoint, direction)
226229
}
227230
})
228-
const upstream = Point.directionBetween(fillPoint, parentPoint)
229-
// model.directionBitmask.add(parentPoint, downstream)
230-
model.erosion.set(fillPoint, upstream.id)
231231
basinGrid.set(fillPoint, fill.id)
232232
}
233233
}

src/model/tilemap/worldmap/world/basin/type.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ import { Color } from '/src/lib/color'
22

33

44
export class Basin {
5-
static color = Color.fromHex('#8c8c8c')
6-
75
static parse(id) {
86
return BASIN_MAP[id]
97
}
@@ -14,7 +12,6 @@ export class ExorheicBasin extends Basin {
1412
static id = 0
1513
static name = 'Exorheic river'
1614
static reach = Infinity
17-
static hasRivers = true
1815
static color = Color.fromHex('#38a378')
1916
}
2017

@@ -23,7 +20,6 @@ export class EndorheicSeaBasin extends Basin {
2320
static id = 1
2421
static name = 'Endorheic sea'
2522
static reach = 1
26-
static hasRivers = true
2723
static color = Color.fromHex('#7fc3c5')
2824
}
2925

@@ -32,7 +28,6 @@ export class EndorheicLakeBasin extends Basin {
3228
static id = 2
3329
static name = 'Endorheic lake'
3430
static reach = 0
35-
static hasRivers = true
3631
static color = Color.fromHex('#6caca1')
3732
}
3833

@@ -41,7 +36,6 @@ export class WaterBasin extends Basin {
4136
static id = 3
4237
static name = 'Water'
4338
static reach = Infinity
44-
static hasRivers = false
4539
static color = Color.fromHex('#285879')
4640
}
4741

src/model/tilemap/worldmap/world/relief/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export class ReliefLayer {
4343
#detectLandType(world, point) {
4444
const grainedNoise = world.noise.get4DGrained(this.rect, point)
4545
const basin = world.basin.get(point)
46-
if (basin.type.hasRivers && basin.isDivide) {
46+
if (basin.isDivide) {
4747
if (grainedNoise >= MOUNTAIN_RATIO) return Relief.MOUNTAIN
4848
if (grainedNoise < HILL_RATIO) return Relief.HILL
4949
return Relief.PLAIN

src/model/tilemap/worldmap/world/river/model.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,8 @@ export function buildRiverModel(context) {
2323
const estuaries = new PointSet(rect)
2424
const riverGrid = Grid.fromRect(rect, point => {
2525
const basin = world.basin.get(point)
26-
const isDivide = basin.type.hasRivers && basin.isDivide
2726
const rainsEnough = world.rain.canCreateRiver(point)
28-
if (isDivide && rainsEnough) {
27+
if (basin.isDivide && rainsEnough) {
2928
riverSources.push(point)
3029
}
3130
return null

0 commit comments

Comments
 (0)