@@ -10,6 +10,10 @@ import { buildRegionGridMap } from './region'
1010const SURFACE_NOISE_RATIO = .6
1111const SURFACE_GRID_CACHE = new FIFOCache ( 256 )
1212
13+ const m = [
14+
15+ ]
16+
1317
1418export function buildModel ( context ) {
1519 const hash = Point . hash ( context . worldPoint )
@@ -18,64 +22,79 @@ export function buildModel(context) {
1822 return SURFACE_GRID_CACHE . get ( hash )
1923 }
2024 const { regionGrid, originMap, regionColorMap} = buildRegionGridMap ( context )
25+ const regionTypes = buildRegionSurfaceMap ( { ...context , regionGrid} )
2126 const landMaskGrid = buildLandMaskGrid ( context )
2227 const model = { landMaskGrid, regionGrid, originMap, regionColorMap}
2328 SURFACE_GRID_CACHE . set ( hash , model )
2429 return model
2530}
2631
2732
28- function buildLandMaskGrid ( context ) {
29- // generate a grid with (land or water) information in bool
30- const { worldPoint, world, rect, zoneRect} = context
31- const relativePoint = Point . multiplyScalar ( worldPoint , zoneRect . width )
32- const noiseRect = Rect . multiply ( rect , zoneRect . width )
33- return Grid . fromRect ( zoneRect , zonePoint => {
34- const noisePoint = Point . plus ( relativePoint , zonePoint )
35- const noise = world . noise . get4DZoneOutline ( noiseRect , noisePoint )
36- return noise > SURFACE_NOISE_RATIO
33+ function buildRegionSurfaceMap ( context ) {
34+ const { world, worldPoint, regionGrid, zoneRect} = context
35+ const regionTypes = new Map ( )
36+ const isWorldPointLand = world . surface . isLand ( worldPoint )
37+ const middle = Math . floor ( zoneRect . with / 2 )
38+ const midPoint = [ middle , middle ]
39+ // const isLake = world.surface.isLake(worldPoint)
40+ Point . around ( worldPoint , ( sidePoint , direction ) => {
41+ if ( isWorldPointLand ) {
42+ if ( world . surface . isLand ( sidePoint ) ) {
43+ if ( isWaterChannel ( context , direction ) ) {
44+ // mark regions as water for in 4n square
45+ if ( Point . equals ( worldPoint , [ 39 , 8 ] ) ) {
46+ console . log ( worldPoint , direction ) ;
47+ }
48+ } else {
49+ const x = selectRegionsInLine ( context , midPoint , direction )
50+ // mark regions as land
51+ }
52+ }
53+ } else {
54+ // water
55+ if ( world . surface . isLand ( sidePoint ) ) {
56+ if ( world . river . has ( sidePoint ) ) {
57+
58+ }
59+ } else {
60+ // mark regions as water
61+ }
62+ }
3763 } )
64+ return regionTypes
3865}
3966
4067
41- function buildRegionSurfaceMap ( context ) {
42- const { world, worldPoint, zone, zoneRect} = context
43- const regionSurfaceMap = new Map ( )
44- const isLand = world . surface . isLand ( worldPoint )
45- const isLake = world . surface . isLake ( worldPoint )
46- // read first edges, then corners
47- // const gridPoints = [...getEdgePoints(zoneRect), ...getCornerPoints(zoneRect)]
48- // for (let [zonePoint, direction] of gridPoints) {
49- // const regionId = zone.topology.getRegion(zonePoint)
50-
51- // const worldSidePoint = Point.atDirection(worldPoint, direction)
52- // const sideSurface = world.surface.get(worldSidePoint)
53- // // rule for lake zone
54- // if (isLake && world.surface.isLand(worldSidePoint)) {
55- // regionSurfaceMap.set(regionId, sideSurface)
56- // }
57- // // rule for general land zone
58- // const isSideOcean = world.surface.isOcean(worldSidePoint)
59- // const isSideSea = world.surface.isSea(worldSidePoint)
60- // if (isLand && (isSideOcean || isSideSea)) {
61- // regionSurfaceMap.set(regionId, sideSurface)
62- // }
63- // }
64- return regionSurfaceMap
68+ function isWaterChannel ( context , direction ) {
69+ const { world, worldPoint} = context
70+ const ortoDirs = Direction . getComponents ( direction )
71+ if ( ortoDirs . length != 2 ) return false
72+ const isWater1 = world . surface . isWater ( Point . atDirection ( worldPoint , ortoDirs [ 0 ] ) )
73+ const isWater2 = world . surface . isWater ( Point . atDirection ( worldPoint , ortoDirs [ 1 ] ) )
74+ return isWater1 && isWater2
6575}
6676
6777
78+ function selectRegionsInLine ( context , target , direction ) {
79+ const { worldPoint, regionGrid, zoneRect} = context
80+ const regions = [ ]
81+ // regionGrid.get(zonePoint)
82+ return regions
83+ }
6884
6985
70- function getCornerPoints ( rect ) {
71- const xMax = rect . width - 1
72- const yMax = rect . height - 1
73- return [
74- [ [ 0 , 0 ] , Direction . NORTHWEST ] ,
75- [ [ xMax , 0 ] , Direction . NORTHEAST ] ,
76- [ [ 0 , yMax ] , Direction . SOUTHWEST ] ,
77- [ [ xMax , yMax ] , Direction . SOUTHEAST ] ,
78- ]
86+ function buildLandMaskGrid ( context ) {
87+ /*
88+ Generate a boolean grid (land or water)
89+ */
90+ const { worldPoint, world, rect, zoneRect} = context
91+ const relativePoint = Point . multiplyScalar ( worldPoint , zoneRect . width )
92+ const noiseRect = Rect . multiply ( rect , zoneRect . width )
93+ return Grid . fromRect ( zoneRect , zonePoint => {
94+ const noisePoint = Point . plus ( relativePoint , zonePoint )
95+ const noise = world . noise . get4DZoneOutline ( noiseRect , noisePoint )
96+ return noise > SURFACE_NOISE_RATIO
97+ } )
7998}
8099
81100
0 commit comments