Mapgen: write SuperUltraSigmaMapgen part 6.2
This commit is contained in:
@@ -46,8 +46,8 @@ local Layer = require('MapGen.Layer')
|
||||
---@type MapGen.Peak
|
||||
local Peak = require('MapGen.Peak')
|
||||
|
||||
---@type MapGen.Biome
|
||||
local Biome = require('MapGen.Biome')
|
||||
---@type MapGen.Layer.Biome
|
||||
local Biome = require('MapGen.Layer.Biome')
|
||||
|
||||
---@type MapGen.Triangulation
|
||||
local Triangulation = require('MapGen.Triangulation')
|
||||
@@ -58,8 +58,6 @@ local Cavern = require('MapGen.Layer.Cavern')
|
||||
---@class MapGen
|
||||
---@field layersByName table<string, MapGen.Layer>
|
||||
---@field layersList MapGen.Layer[]
|
||||
---@field biomesList MapGen.Biome[]
|
||||
---@field biomesDiagram table
|
||||
---@field peaksMultinoiseInitialized boolean Is the fractal noise of the peaks initialized? This is necessary for a one-time noise initialization.
|
||||
---@field cavernsNoiseInitialized boolean TODO: описание
|
||||
---@field isRunning boolean A static field that guarantees that only one instance of the `MapGen` class will work.
|
||||
@@ -67,8 +65,6 @@ local Cavern = require('MapGen.Layer.Cavern')
|
||||
local MapGen = {
|
||||
layersByName = {},
|
||||
layersList = {},
|
||||
biomesList = {},
|
||||
biomesDiagram = {},
|
||||
peaksMultinoiseInitialized = false,
|
||||
cavernsNoiseInitialized = false,
|
||||
isRunning = false,
|
||||
@@ -188,19 +184,24 @@ function MapGen:register2DPeaks(layerName, multinoise, peakPoses, groups)
|
||||
end
|
||||
end
|
||||
|
||||
---@param name string
|
||||
---@param tempPoint number
|
||||
---@param humidityPoint number
|
||||
---@param groundNodes MapGen.Biome.GroundNodes
|
||||
---TODO: описание
|
||||
---@param layerName string
|
||||
---@param biomeName string
|
||||
---@param tempPoint number
|
||||
---@param humidityPoint number
|
||||
---@param groundNodes MapGen.Biome.GroundNodes
|
||||
---@param soilHeight number
|
||||
function MapGen:registerBiome(name, tempPoint, humidityPoint, groundNodes, soilHeight)
|
||||
local biome = Biome:new(name, tempPoint, humidityPoint, groundNodes, soilHeight)
|
||||
function MapGen:registerBiome(layerName, biomeName, tempPoint, humidityPoint, groundNodes, soilHeight)
|
||||
local layer = self.layersByName[layerName]
|
||||
assert(layer.biomesByName[biomeName] == nil, ('A biome named `%s` already exists in the `%s` layer.'):format(biomeName, layerName))
|
||||
|
||||
--TODO: добавить MapGen.biomesByName и проверку на существование биома с таким же именем, аналогично `MapGen:registerCavern`
|
||||
--TODO: перенести Biomes в слой
|
||||
table.insert(self.biomesList, biome)
|
||||
local biome = Biome:new(biomeName, tempPoint, humidityPoint, groundNodes, soilHeight)
|
||||
|
||||
layer.biomesByName[biomeName] = biome
|
||||
table.insert(layer.biomesList, biome)
|
||||
end
|
||||
|
||||
---TODO: описание
|
||||
---@param layerName string
|
||||
---@param cavernName string
|
||||
---@param minY number
|
||||
@@ -246,6 +247,7 @@ function MapGen:initPeaksMultinoise()
|
||||
self.peaksMultinoiseInitialized = true
|
||||
end
|
||||
|
||||
---TODO: описаение
|
||||
function MapGen:initCavernsNoise()
|
||||
---@param layer MapGen.Layer
|
||||
for _, layer in ipairs(self.layersList) do
|
||||
@@ -262,27 +264,9 @@ end
|
||||
|
||||
---Initialization of the biome diagram using the Voronoi method.
|
||||
function MapGen:initBiomesDiagram()
|
||||
local diagram = self.biomesDiagram
|
||||
|
||||
for temp = 0, 100 do
|
||||
diagram[temp] = {}
|
||||
|
||||
for humidity = 0, 100 do
|
||||
local minDistance = math.huge
|
||||
local closestBiome = nil
|
||||
|
||||
---@param biome MapGen.Biome
|
||||
for _, biome in ipairs(self.biomesList) do
|
||||
local distance = (temp - biome.tempPoint)^2 + (humidity - biome.humidityPoint)^2
|
||||
|
||||
if distance < minDistance then
|
||||
minDistance = distance
|
||||
closestBiome = biome
|
||||
end
|
||||
end
|
||||
|
||||
diagram[temp][humidity] = closestBiome
|
||||
end
|
||||
---@param layer MapGen.Layer
|
||||
for _, layer in ipairs(self.layersList) do
|
||||
layer:initBiomesDiagram()
|
||||
end
|
||||
end
|
||||
|
||||
@@ -359,7 +343,7 @@ local function generateNode(mapGenerator, layer, hight, temp, humidity, data, in
|
||||
temp = mathMin(100, mathMax(0, temp + m))
|
||||
humidity = mathMin(100, mathMax(0, humidity + m))
|
||||
|
||||
local biome = mapGenerator.biomesDiagram[mathRound(temp)][mathRound(humidity)]
|
||||
local biome = layer.biomesDiagram[mathRound(temp)][mathRound(humidity)]
|
||||
|
||||
if y > hight and y > 0 then
|
||||
data[index] = ids.air
|
||||
|
||||
@@ -5,12 +5,18 @@ local mathSqrt = math.sqrt
|
||||
---@field minY number
|
||||
---@field maxY number
|
||||
---@field peaksList MapGen.Peak[]
|
||||
---@field biomesByName table<string, MapGen.Layer.Biome>
|
||||
---@field biomesList MapGen.Layer.Biome[]
|
||||
---@field biomesDiagram table
|
||||
---@field cavernsByName table<string, MapGen.Layer.Cavern>
|
||||
---@field cavernsList MapGen.Layer.Cavern[]
|
||||
---@field trianglesList MapGen.Triangle[]
|
||||
---@field tetrahedronsList MapGen.Tetrahedron[]
|
||||
local Layer = {
|
||||
peaksList = {},
|
||||
biomesByName = {},
|
||||
biomesList = {},
|
||||
biomesDiagram = {},
|
||||
cavernsByName = {},
|
||||
cavernsList = {},
|
||||
trianglesList = {},
|
||||
@@ -73,4 +79,30 @@ function Layer:getPeaksByPos(xPos, yPos, zPos, radius)
|
||||
return peaks, totalWeight
|
||||
end
|
||||
|
||||
---Initialization of the biome diagram using the Voronoi method.
|
||||
function Layer:initBiomesDiagram()
|
||||
local diagram = self.biomesDiagram
|
||||
|
||||
for temp = 0, 100 do
|
||||
diagram[temp] = {}
|
||||
|
||||
for humidity = 0, 100 do
|
||||
local minDistance = math.huge
|
||||
local closestBiome = nil
|
||||
|
||||
---@param biome MapGen.Layer.Biome
|
||||
for _, biome in ipairs(self.biomesList) do
|
||||
local distance = (temp - biome.tempPoint)^2 + (humidity - biome.humidityPoint)^2
|
||||
|
||||
if distance < minDistance then
|
||||
minDistance = distance
|
||||
closestBiome = biome
|
||||
end
|
||||
end
|
||||
|
||||
diagram[temp][humidity] = closestBiome
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return Layer
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
---@class MapGen.Biome
|
||||
---@class MapGen.Layer.Biome
|
||||
---@field name string
|
||||
---@field tempPoint number
|
||||
---@field humidityPoint number
|
||||
@@ -11,9 +11,9 @@ local Biome = {}
|
||||
---@param humidityPoint number
|
||||
---@param groundNodes MapGen.Biome.GroundNodes
|
||||
---@param soilHeight number
|
||||
---@return MapGen.Biome
|
||||
---@return MapGen.Layer.Biome
|
||||
function Biome:new(name, tempPoint, humidityPoint, groundNodes, soilHeight)
|
||||
---@type MapGen.Biome
|
||||
---@type MapGen.Layer.Biome
|
||||
local instance = setmetatable({
|
||||
name = name,
|
||||
tempPoint = tempPoint,
|
||||
@@ -115,12 +115,12 @@ mapGenerator:registerCavern('world', 'cavern1', -100, -10, 20, {
|
||||
lacunarity = 2.0
|
||||
})
|
||||
|
||||
mapGenerator:registerBiome("biome1", 0, 0, {
|
||||
mapGenerator:registerBiome('world', "biome1", 0, 0, {
|
||||
soil = "soils:clay_soil_baren",
|
||||
turf = "soils:clay_soil_baren",
|
||||
}, 1)
|
||||
|
||||
mapGenerator:registerBiome("biome2", 100, 100, {
|
||||
mapGenerator:registerBiome('world', "biome2", 100, 100, {
|
||||
soil = "soils:rocky_soil_baren",
|
||||
turf = "soils:rocky_soil_baren",
|
||||
}, 1)
|
||||
|
||||
Reference in New Issue
Block a user