Skip to content

Commit 5f54db2

Browse files
committed
Set erosion to all neighbors
1 parent 2e078e2 commit 5f54db2

File tree

4 files changed

+64
-2
lines changed

4 files changed

+64
-2
lines changed

src/model/tilemap/worldmap/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { CivilLayer } from './world/civil'
2020

2121
import { WorldTileMapDiagram } from './diagram'
2222

23+
import { LandMaskZone } from './zone/landmask'
2324
import { SurfaceZone } from './zone/surface'
2425
import { RiverZone } from './zone/river'
2526

@@ -114,6 +115,7 @@ export class WorldTileMap extends TileMap {
114115
seed
115116
}
116117
Random.seed = seed // change seed for this specific zone
118+
zone.landmask = new LandMaskZone(context)
117119
zone.surface = new SurfaceZone(context)
118120
zone.river = new RiverZone(context)
119121
return zone

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ class BasinGridFill extends ConcurrentFill {
7878
}
7979

8080
getNeighbors(fill, parentPoint) {
81-
return Point.adjacents(parentPoint)
81+
return Point.around(parentPoint)
8282
}
8383

8484
_fillBasin(fill, fillPoint, parentPoint) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ export class RiverLayer {
8484

8585
draw(props, params) {
8686
const {canvas, canvasPoint, tileSize, tilePoint} = props
87-
props.world.biome.draw(props, params)
87+
props.world.surface.draw(props, params)
8888
if (! this.has(tilePoint)) {
8989
return
9090
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import { Point } from '/src/lib/geometry/point'
2+
import { Rect } from '/src/lib/geometry/rect'
3+
import { Grid } from '/src/lib/grid'
4+
5+
6+
const SURFACE_NOISE_RATIO = .6
7+
const REGION_WATER = false
8+
const REGION_LAND = true
9+
10+
11+
export class LandMaskZone {
12+
#landMaskGrid
13+
14+
constructor(context) {
15+
this.size = context.zoneSize
16+
this.#landMaskGrid = buildModel(context)
17+
}
18+
19+
get(zonePoint) {
20+
const isLand = this.#landMaskGrid.get(zonePoint)
21+
return isLand
22+
}
23+
24+
draw(props, params) {
25+
const {canvas, canvasPoint, tileSize} = props
26+
const zoneSize = this.size
27+
const size = tileSize / zoneSize
28+
// render zone tiles
29+
for (let x=0; x < zoneSize; x++) {
30+
const xSize = x * size
31+
for (let y=0; y < zoneSize; y++) {
32+
const zonePoint = [y, x]
33+
const ySize = y * size
34+
const zoneCanvasPoint = Point.plus(canvasPoint, [ySize, xSize])
35+
const color = this.get(zonePoint) ? '#71b13e' : '#1d2255'
36+
canvas.rect(zoneCanvasPoint, size, color)
37+
}
38+
}
39+
}
40+
}
41+
42+
43+
function buildModel(context) {
44+
const hash = Point.hash(context.worldPoint)
45+
// cache de zone grid noise
46+
// if (SURFACE_GRID_CACHE.has(hash)) {
47+
// return SURFACE_GRID_CACHE.get(hash)
48+
// }
49+
// Generate a boolean grid (land or water)
50+
const {worldPoint, world, rect, zoneRect} = context
51+
const relativePoint = Point.multiplyScalar(worldPoint, zoneRect.width)
52+
const noiseRect = Rect.multiply(rect, zoneRect.width)
53+
const landMaskGrid = Grid.fromRect(zoneRect, zonePoint => {
54+
const noisePoint = Point.plus(relativePoint, zonePoint)
55+
const noise = world.noise.get4DZoneOutline(noiseRect, noisePoint)
56+
return noise > SURFACE_NOISE_RATIO ? REGION_LAND : REGION_WATER
57+
})
58+
// SURFACE_GRID_CACHE.set(hash, landMaskGrid)
59+
return landMaskGrid
60+
}

0 commit comments

Comments
 (0)