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