@@ -29,12 +29,11 @@ import { WorldTileMapDiagram } from './diagram'
2929
3030
3131const WORLD_SIZE = 32
32- const CHUNK_SIZE = 13
33- const CHUNK_RECT = new Rect ( CHUNK_SIZE , CHUNK_SIZE )
3432
3533const 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
0 commit comments