Skip to content

Commit 7f7a1d1

Browse files
committed
Show & control basin chunk
1 parent dffdf88 commit 7f7a1d1

3 files changed

Lines changed: 38 additions & 28 deletions

File tree

src/model/tilemap/worldmap/index.js

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,11 @@ import { WorldTileMapDiagram } from './diagram'
2929

3030

3131
const WORLD_SIZE = 32
32-
const CHUNK_SIZE = 13
33-
const CHUNK_RECT = new Rect(CHUNK_SIZE, CHUNK_SIZE)
3432

3533
const SCHEMA = new Schema(
3634
'WorldTileMap',
37-
Type.number('size', 'Size', { default: WORLD_SIZE, min: WORLD_SIZE, max: WORLD_SIZE }),
35+
Type.number('size', 'Size', { default: WORLD_SIZE, min: 16, max: 128 }),
36+
Type.number('chunk', 'Chunk', {step: 2, default: 15, min: 7, max: 19}),
3837
Type.text('seed', 'Seed', { default: '' }),
3938
Type.number('realms', 'Realms', { default: 8, min: 3, max: 8 }),
4039
)
@@ -50,28 +49,34 @@ export class WorldTileMap extends TileMap {
5049
}
5150

5251
#chunkCache
52+
#chunkRect
5353

5454
constructor(params) {
5555
super(params)
56+
const worldSize = params.get('size')
57+
const chunkSize = params.get('chunk')
58+
this.params = params
5659
this.name = Random.choiceFrom(WORLD_NAMES)
60+
this.#chunkRect = new Rect(chunkSize, chunkSize)
61+
this.#chunkCache = new FIFOCache(worldSize * worldSize)
5762
this.world = this.#buildWorld(params, this.rect)
58-
this.#chunkCache = new FIFOCache(WORLD_SIZE * WORLD_SIZE)
5963
}
6064

6165
#buildWorld(params, rect) {
6266
const start = performance.now()
67+
const chunkSize = params.get('chunk')
6368
// set a global struct for world
6469
const world = {
6570
rect,
6671
seed: this.seed,
67-
size: WORLD_SIZE,
68-
chunkSize: CHUNK_SIZE,
72+
size: params.get('size'),
73+
chunkSize,
6974
}
7075
const context = {
71-
world,
7276
rect,
73-
chunkSize: CHUNK_SIZE,
74-
chunkRect: CHUNK_RECT,
77+
world,
78+
chunkSize,
79+
chunkRect: this.#chunkRect,
7580
realmCount: params.get('realms')
7681
}
7782
// The world creation follows order below
@@ -111,17 +116,18 @@ export class WorldTileMap extends TileMap {
111116
// geração de seed específica para a zona
112117
// para evitar que zonas adjacentes tenham o mesmo conteúdo
113118
const seed = `${this.seed}-${Point.hash(worldPoint)}`
119+
const chunkSize = this.params.get('chunk')
114120
Random.seed = seed // change seed for this specific chunk
115121
// set chunk object
116122
const chunk = {
117-
size: CHUNK_SIZE
123+
size: chunkSize
118124
}
119125
// set context for
120126
const context = {
121127
rect: this.rect,
122128
world: this.world,
123-
chunkSize: CHUNK_SIZE,
124-
chunkRect: CHUNK_RECT,
129+
chunkSize,
130+
chunkRect: this.#chunkRect,
125131
worldPoint,
126132
chunk,
127133
seed

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

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,26 +16,29 @@ export class BasinChunk {
1616
}
1717

1818
draw(props, params) {
19-
const {chunk} = props
20-
chunk.surface.draw(props, params)
21-
this._drawPaths(props, params)
22-
}
23-
24-
_drawPaths(props, params, color='#2f367d') {
2519
const {canvas, canvasPoint, tilePoint, tileSize, world, chunk} = props
2620
const chunkTileSize = tileSize / chunk.size
2721
const basin = world.basin.get(tilePoint)
2822
if (tileSize < 10) return
23+
const showErosion = params.get('showErosion')
24+
let color
2925
for (let x=0; x < chunk.size; x++) {
3026
const xSize = x * chunkTileSize
3127
for (let y=0; y < chunk.size; y++) {
3228
const chunkPoint = [y, x]
3329
const ySize = y * chunkTileSize
3430
let chunkCanvasPoint = Point.plus(canvasPoint, [ySize, xSize])
35-
if (this.has(chunkPoint)) {
36-
canvas.rect(chunkCanvasPoint, chunkTileSize, color)
31+
if (showErosion && this.has(chunkPoint)) {
32+
color = '#3f4693'
33+
} else {
34+
color = '#2f367d'
35+
if (chunk.surface.isLand(chunkPoint)) {
36+
color = '#52a83f'
37+
}
38+
3739
}
38-
if (Point.equals(basin.midpoint, chunkPoint)) {
40+
canvas.rect(chunkCanvasPoint, chunkTileSize, color)
41+
if (showErosion && Point.equals(basin.midpoint, chunkPoint)) {
3942
canvas.rect(chunkCanvasPoint, chunkTileSize, Color.RED.toHex())
4043
}
4144
}

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -153,11 +153,6 @@ class LandBasinFill extends ConcurrentFill {
153153
const survey = surveyMap.get(fill.id)
154154
// the basin opposite border is the parentPoint
155155
this._fillBasin(fill, fillPoint, survey.oppositeBorder)
156-
// update erosion path
157-
for (let neighbor of survey.waterNeighbors) {
158-
const direction = Point.directionBetween(fillPoint, neighbor)
159-
model.directionBitmap.add(fillPoint, direction)
160-
}
161156
}
162157

163158
onFill(fill, fillPoint, parentPoint) {
@@ -239,9 +234,15 @@ class WaterBasinFill extends ConcurrentFill {
239234
// discover adjacent river and water tiles
240235
Point.adjacents(fillPoint, (sidePoint, direction) => {
241236
if (world.surface.isLand(sidePoint)) {
242-
model.erosion.set(fillPoint, direction.id)
237+
const sideDirection = Direction.fromId(model.erosion.get(sidePoint))
238+
const mouth = Point.atDirection(sidePoint, sideDirection)
239+
if (Point.equals(mouth, fillPoint)) {
240+
model.directionBitmap.add(fillPoint, direction)
241+
model.erosion.set(fillPoint, direction.id)
242+
}
243+
} else {
244+
model.directionBitmap.add(fillPoint, direction)
243245
}
244-
model.directionBitmap.add(fillPoint, direction)
245246
})
246247
// diagonals later, only to non-border water sides
247248
Point.diagonals(fillPoint, (sidePoint, direction) => {

0 commit comments

Comments
 (0)