MapGen: add bime weight and minor fixes. Close #7
This commit is contained in:
@@ -21,7 +21,7 @@ end
|
|||||||
local require = Mod.getInfo('smc__core__map_gen').require
|
local require = Mod.getInfo('smc__core__map_gen').require
|
||||||
|
|
||||||
---Numeric values defining the surface height and climate for the node.
|
---Numeric values defining the surface height and climate for the node.
|
||||||
---@alias MapGen.Factors {height:number, temp:number, humidity:number}
|
---@alias MapGen.Factors {height:number, temp:number, humidity:number, weight:number}
|
||||||
|
|
||||||
---Table of all past generation factor calculations for nodes.
|
---Table of all past generation factor calculations for nodes.
|
||||||
---
|
---
|
||||||
@@ -690,8 +690,10 @@ local function generateNode(mapGenerator, layer, factors, data, data2, index, x,
|
|||||||
scattHeight, scattTemp, scattHumidity = mathRound(scattHeight), mathRound(scattTemp), mathRound(scattHumidity)
|
scattHeight, scattTemp, scattHumidity = mathRound(scattHeight), mathRound(scattTemp), mathRound(scattHumidity)
|
||||||
height, temp, humidity = mathRound(height), mathRound(scattTemp), mathRound(scattHumidity)
|
height, temp, humidity = mathRound(height), mathRound(scattTemp), mathRound(scattHumidity)
|
||||||
|
|
||||||
|
local diagramPoint = layer.biomesDiagram[height][scattTemp][scattHumidity] -- TODO: разобраться со смещением по вертикали
|
||||||
---@type MapGen.Biome
|
---@type MapGen.Biome
|
||||||
local biome = layer.biomesDiagram[scattHeight][scattTemp][scattHumidity]
|
local biome = diagramPoint.biome
|
||||||
|
factors.weight = diagramPoint.weight
|
||||||
|
|
||||||
-- If the block is above surface height and above water level...
|
-- If the block is above surface height and above water level...
|
||||||
if y > height and y > waterLevel then
|
if y > height and y > waterLevel then
|
||||||
@@ -1036,6 +1038,9 @@ function MapGen:onMapGenerated(voxelManip, minPos, maxPos, blockseed)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Clear post processing tables
|
||||||
|
dataPostProcessing, vmPostProcessing = {}, {}
|
||||||
|
|
||||||
core.generate_ores(voxelManip, minPos, maxPos)
|
core.generate_ores(voxelManip, minPos, maxPos)
|
||||||
core.generate_decorations(voxelManip, minPos, maxPos)
|
core.generate_decorations(voxelManip, minPos, maxPos)
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
local assert, dump, type = assert, dump, type
|
local assert, dump, type = assert, dump, type
|
||||||
local pairs, ipairs = pairs, ipairs
|
local pairs, ipairs = pairs, ipairs
|
||||||
|
|
||||||
local mathHuge = math.huge
|
local mathHuge, mathClamp = math.huge, math.clamp
|
||||||
local tableInsert, tableSort = table.insert, table.sort
|
local tableInsert, tableSort = table.insert, table.sort
|
||||||
|
|
||||||
local id = core.get_content_id
|
local id = core.get_content_id
|
||||||
@@ -39,7 +39,7 @@ local Triangle = require('MapGen.Triangle')
|
|||||||
---@field biomesVerticalScattering integer
|
---@field biomesVerticalScattering integer
|
||||||
---@field biomesByName table<string, MapGen.Biome>
|
---@field biomesByName table<string, MapGen.Biome>
|
||||||
---@field biomesList MapGen.Biome[]
|
---@field biomesList MapGen.Biome[]
|
||||||
---@field biomesDiagram table
|
---@field biomesDiagram table<integer, table<integer, table<integer, {biome:MapGen.Biome, weight:number}>>>
|
||||||
---
|
---
|
||||||
---@field cavernsByName table<string, MapGen.Cavern>
|
---@field cavernsByName table<string, MapGen.Cavern>
|
||||||
---@field cavernsList MapGen.Cavern[]
|
---@field cavernsList MapGen.Cavern[]
|
||||||
@@ -512,6 +512,7 @@ function Layer:initBiomesDiagram()
|
|||||||
|
|
||||||
for humidity = self.minHumidity, self.maxHumidity do
|
for humidity = self.minHumidity, self.maxHumidity do
|
||||||
local minDistance = mathHuge
|
local minDistance = mathHuge
|
||||||
|
local pastClosestBiome = nil
|
||||||
local closestBiome = nil
|
local closestBiome = nil
|
||||||
|
|
||||||
---@param biome MapGen.Biome
|
---@param biome MapGen.Biome
|
||||||
@@ -520,17 +521,28 @@ function Layer:initBiomesDiagram()
|
|||||||
|
|
||||||
if distance < minDistance then
|
if distance < minDistance then
|
||||||
minDistance = distance
|
minDistance = distance
|
||||||
|
pastClosestBiome = closestBiome
|
||||||
closestBiome = biome
|
closestBiome = biome
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- If there is no nearby biome for this height...
|
|
||||||
if closestBiome == nil then
|
if closestBiome == nil then
|
||||||
-- ... then the first registered biome in the layer will be the default one.
|
closestBiome = self.biomesList[1]
|
||||||
diagram[height][temp][humidity] = self.biomesList[1]
|
|
||||||
else
|
|
||||||
diagram[height][temp][humidity] = closestBiome
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local weight
|
||||||
|
if pastClosestBiome ~= nil then
|
||||||
|
---Distances from the center of the nearest biome to the current point.
|
||||||
|
local distance1 = (temp - closestBiome.tempPoint)^2 + (humidity - closestBiome.humidityPoint)^2
|
||||||
|
---Half the distance between the centers of two nearest biomes (i.e. the distance to the biome boundary)
|
||||||
|
local distance2 = (pastClosestBiome.tempPoint - closestBiome.tempPoint)^2 + (pastClosestBiome.humidityPoint - closestBiome.humidityPoint) / 2
|
||||||
|
|
||||||
|
weight = mathClamp(distance1 / distance2, 0, 1)
|
||||||
|
else
|
||||||
|
weight = 1
|
||||||
|
end
|
||||||
|
|
||||||
|
diagram[height][temp][humidity] = { biome = closestBiome, weight = weight}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -540,6 +552,8 @@ function Layer:initBiomesDiagram()
|
|||||||
::continue::
|
::continue::
|
||||||
end
|
end
|
||||||
|
|
||||||
|
print(dump(diagram[0][50][50]))
|
||||||
|
|
||||||
Logger.infoLog('MapGen.Layer.initBiomesDiagram(): Initialized to %s unique slices for the layer `%s` biome diagram.', uniqueDiagramSlices, self.name)
|
Logger.infoLog('MapGen.Layer.initBiomesDiagram(): Initialized to %s unique slices for the layer `%s` biome diagram.', uniqueDiagramSlices, self.name)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -38,6 +38,8 @@ local Ore = {}
|
|||||||
---
|
---
|
||||||
---If `nil`, ore will generate on the entire layer.
|
---If `nil`, ore will generate on the entire layer.
|
||||||
---@field biomes string[]?
|
---@field biomes string[]?
|
||||||
|
---@field minY integer
|
||||||
|
---@field maxY integer
|
||||||
---
|
---
|
||||||
---List of node names where ore will spawn.
|
---List of node names where ore will spawn.
|
||||||
---@field wherein string[]
|
---@field wherein string[]
|
||||||
@@ -66,6 +68,9 @@ function Ore:new(name, def)
|
|||||||
local instance = getInstance(self, {})
|
local instance = getInstance(self, {})
|
||||||
instance.name = name
|
instance.name = name
|
||||||
instance.type = def.type
|
instance.type = def.type
|
||||||
|
instance.biomes = def.biomes
|
||||||
|
instance.minY = def.minY
|
||||||
|
instance.maxY = def.maxY
|
||||||
instance.wherein = def.wherein
|
instance.wherein = def.wherein
|
||||||
instance.nodeName = def.nodeName
|
instance.nodeName = def.nodeName
|
||||||
instance.nodeParam2 = def.nodeParam2 or 0
|
instance.nodeParam2 = def.nodeParam2 or 0
|
||||||
|
|||||||
@@ -48,8 +48,8 @@ mapGenerator:registerLayer('midgard', {
|
|||||||
maxHumidity = 100,
|
maxHumidity = 100,
|
||||||
calcTemp = calcTemp,
|
calcTemp = calcTemp,
|
||||||
calcHumidity = calcHumidity,
|
calcHumidity = calcHumidity,
|
||||||
biomesVerticalScattering = 5,
|
biomesVerticalScattering = 2,
|
||||||
biomesGorizontalScattering = 5,
|
biomesGorizontalScattering = 0,
|
||||||
triangulationLandscapeFile = 'tarion.json',
|
triangulationLandscapeFile = 'tarion.json',
|
||||||
triangulationTempFile = 'tarion.json',
|
triangulationTempFile = 'tarion.json',
|
||||||
triangulationHumidityFile = 'tarion.json',
|
triangulationHumidityFile = 'tarion.json',
|
||||||
@@ -730,9 +730,9 @@ end
|
|||||||
|
|
||||||
mapGenerator:registerBiome('midgard', 'green_meadow', {
|
mapGenerator:registerBiome('midgard', 'green_meadow', {
|
||||||
tempPoint = 80,
|
tempPoint = 80,
|
||||||
humidityPoint = 60,
|
humidityPoint = 80,
|
||||||
minY = 100,
|
minY = -50,
|
||||||
maxY = -50,
|
maxY = 100,
|
||||||
groundNodes = {
|
groundNodes = {
|
||||||
soil = 'soils:humus',
|
soil = 'soils:humus',
|
||||||
turf = 'soils:turf_meadow',
|
turf = 'soils:turf_meadow',
|
||||||
@@ -763,6 +763,30 @@ mapGenerator:registerBiome('midgard', 'green_meadow', {
|
|||||||
--postProcessing = postProcessing
|
--postProcessing = postProcessing
|
||||||
})
|
})
|
||||||
|
|
||||||
|
mapGenerator:registerBiome('midgard', 'test_factors_biome', {
|
||||||
|
tempPoint = 10,
|
||||||
|
humidityPoint = 10,
|
||||||
|
minY = -50,
|
||||||
|
maxY = 100,
|
||||||
|
groundNodes = {
|
||||||
|
soil = 'soils:humus',
|
||||||
|
turf = 'soils:turf_meadow',
|
||||||
|
rock = 'rocks:sylite',
|
||||||
|
bottom = 'soils:humus',
|
||||||
|
},
|
||||||
|
soilHeight = 5,
|
||||||
|
generateTurf = function (self, mapGenerator, factors, data, data2, index, x, y, z)
|
||||||
|
local weight = factors.weight
|
||||||
|
if weight <= 0.3 then
|
||||||
|
data[index] = id('rocks:sylite')
|
||||||
|
elseif weight <= 0.6 then
|
||||||
|
data[index] = id('rocks:sylite_gray')
|
||||||
|
else
|
||||||
|
data[index] = id('rocks:sylite_black')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
})
|
||||||
|
|
||||||
mapGenerator:registerTree('test_tree', {
|
mapGenerator:registerTree('test_tree', {
|
||||||
path = core.get_modpath(core.get_current_modname())..'/schems/test_tree.mts',
|
path = core.get_modpath(core.get_current_modname())..'/schems/test_tree.mts',
|
||||||
})
|
})
|
||||||
@@ -816,22 +840,4 @@ mapGenerator:registerCavern('midgard', 'test_cavern', {
|
|||||||
step = 100
|
step = 100
|
||||||
})--]]
|
})--]]
|
||||||
|
|
||||||
mapGenerator:registerOre('midgard', 'test_ore', {
|
|
||||||
type = 'cheesed',
|
|
||||||
nodeName = 'air',
|
|
||||||
wherein = {'rocks:sylite'},
|
|
||||||
threshold = 0.5,
|
|
||||||
noiseParams = {
|
|
||||||
baseNoise = {
|
|
||||||
offset = 0,
|
|
||||||
scale = 4,
|
|
||||||
spread = {x = 10, y = 30, z = 30},
|
|
||||||
seed = 12,
|
|
||||||
octaves = 2,
|
|
||||||
persistence = 0.6,
|
|
||||||
lacunarity = 2
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
return mapGenerator
|
return mapGenerator
|
||||||
|
|||||||
Reference in New Issue
Block a user