MapGen: add bime weight and minor fixes. Close #7

This commit is contained in:
Van
2026-06-26 22:08:41 +03:00
parent d04f3407b4
commit 80c0f45f34
4 changed files with 62 additions and 32 deletions

View File

@@ -21,7 +21,7 @@ end
local require = Mod.getInfo('smc__core__map_gen').require
---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.
---
@@ -690,8 +690,10 @@ local function generateNode(mapGenerator, layer, factors, data, data2, index, x,
scattHeight, scattTemp, scattHumidity = mathRound(scattHeight), mathRound(scattTemp), mathRound(scattHumidity)
height, temp, humidity = mathRound(height), mathRound(scattTemp), mathRound(scattHumidity)
local diagramPoint = layer.biomesDiagram[height][scattTemp][scattHumidity] -- TODO: разобраться со смещением по вертикали
---@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 y > height and y > waterLevel then
@@ -1036,6 +1038,9 @@ function MapGen:onMapGenerated(voxelManip, minPos, maxPos, blockseed)
end
end
-- Clear post processing tables
dataPostProcessing, vmPostProcessing = {}, {}
core.generate_ores(voxelManip, minPos, maxPos)
core.generate_decorations(voxelManip, minPos, maxPos)

View File

@@ -1,7 +1,7 @@
local assert, dump, type = assert, dump, type
local pairs, ipairs = pairs, ipairs
local mathHuge = math.huge
local mathHuge, mathClamp = math.huge, math.clamp
local tableInsert, tableSort = table.insert, table.sort
local id = core.get_content_id
@@ -39,7 +39,7 @@ local Triangle = require('MapGen.Triangle')
---@field biomesVerticalScattering integer
---@field biomesByName table<string, 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 cavernsList MapGen.Cavern[]
@@ -512,6 +512,7 @@ function Layer:initBiomesDiagram()
for humidity = self.minHumidity, self.maxHumidity do
local minDistance = mathHuge
local pastClosestBiome = nil
local closestBiome = nil
---@param biome MapGen.Biome
@@ -520,17 +521,28 @@ function Layer:initBiomesDiagram()
if distance < minDistance then
minDistance = distance
pastClosestBiome = closestBiome
closestBiome = biome
end
end
-- If there is no nearby biome for this height...
if closestBiome == nil then
-- ... then the first registered biome in the layer will be the default one.
diagram[height][temp][humidity] = self.biomesList[1]
else
diagram[height][temp][humidity] = closestBiome
closestBiome = self.biomesList[1]
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
@@ -540,6 +552,8 @@ function Layer:initBiomesDiagram()
::continue::
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)
end

View File

@@ -38,6 +38,8 @@ local Ore = {}
---
---If `nil`, ore will generate on the entire layer.
---@field biomes string[]?
---@field minY integer
---@field maxY integer
---
---List of node names where ore will spawn.
---@field wherein string[]
@@ -66,6 +68,9 @@ function Ore:new(name, def)
local instance = getInstance(self, {})
instance.name = name
instance.type = def.type
instance.biomes = def.biomes
instance.minY = def.minY
instance.maxY = def.maxY
instance.wherein = def.wherein
instance.nodeName = def.nodeName
instance.nodeParam2 = def.nodeParam2 or 0