Mapgen: write SuperUltraSigmaMapgen part 8.1
This commit is contained in:
@@ -27,14 +27,14 @@ local Layer = require('MapGen.Layer')
|
||||
---@type MapGen.Peak
|
||||
local Peak = require('MapGen.Peak')
|
||||
|
||||
---@type MapGen.Layer.Biome
|
||||
local Biome = require('MapGen.Layer.Biome')
|
||||
---@type MapGen.Biome
|
||||
local Biome = require('MapGen.Biome')
|
||||
|
||||
---@type MapGen.Triangulation
|
||||
local Triangulation = require('MapGen.Triangulation')
|
||||
|
||||
---@type MapGen.Layer.Cavern
|
||||
local Cavern = require('MapGen.Layer.Cavern')
|
||||
---@type MapGen.Cavern
|
||||
local Cavern = require('MapGen.Cavern')
|
||||
|
||||
---@class MapGen
|
||||
---@field layersByName table<string, MapGen.Layer>
|
||||
@@ -52,7 +52,8 @@ local MapGen = {
|
||||
isRunning = false,
|
||||
}
|
||||
|
||||
---@param nodeIDs table<string, number>
|
||||
---@param nodeIDs table<string, number>
|
||||
---@param waterLevel number
|
||||
---@return MapGen
|
||||
function MapGen:new(nodeIDs, waterLevel)
|
||||
---@type MapGen
|
||||
@@ -90,9 +91,9 @@ end
|
||||
---Mark the world area between two heights as a `MapGen.Layer`.
|
||||
---
|
||||
---Note: layers must not overlap.
|
||||
---@param name string
|
||||
---@param minY number
|
||||
---@param maxY number
|
||||
---@param name string The name that will be assigned to the layer. The name must be unique for each layer.
|
||||
---@param minY number Minimum layer generation height.
|
||||
---@param maxY number Maximum layer generation height.
|
||||
function MapGen:RegisterLayer(name, minY, maxY)
|
||||
-- Layers with the same name cannot exist.
|
||||
assert(self.layersByName[name] == nil, ('A layer named `%s` is already registered.'):format(name))
|
||||
@@ -112,14 +113,13 @@ function MapGen:RegisterLayer(name, minY, maxY)
|
||||
end)
|
||||
end
|
||||
|
||||
-- TODO: переписать описание функции
|
||||
---Mark a peak of the world as a cubic peak by two opposite vertices.
|
||||
---Mark a world point as `MapGen.Peak` and assign it a specific noise that will affect the generation.
|
||||
---
|
||||
---Peaks must be included in layers and may overlap each other.
|
||||
---@param layerName string The name of the layer in which the new peak will be included.
|
||||
---@param peakPos vector
|
||||
---@param multinoise MapGen.Peak.MultinoiseParams Noise that will be assigned to the peak and that will influence map generation
|
||||
---@param groups table<string, number>? TODO: описание
|
||||
---Note: The peaks shouldn't overlap. This won't cause any errors, but it might ruin the generation.
|
||||
---@param layerName string The name of the layer in which the new peak will be included.
|
||||
---@param peakPos vector The coordinate where the peak will be placed.
|
||||
---@param multinoise MapGen.Peak.MultinoiseParams Noise that will be assigned to the peak and that will influence map generation
|
||||
---@param groups table<string, number>? Peak groups that may affect processing.
|
||||
function MapGen:registerPeak(layerName, peakPos, multinoise, groups)
|
||||
---@type MapGen.Layer
|
||||
local layer = self.layersByName[layerName]
|
||||
@@ -130,22 +130,22 @@ function MapGen:registerPeak(layerName, peakPos, multinoise, groups)
|
||||
error('Invalid layer: ' .. layerName)
|
||||
end
|
||||
|
||||
--TODO: добавить проверку, что координата ячейки не совпадают
|
||||
--TODO: Добавить проверку, что координата ячейки не выходит за границы слоя
|
||||
--TODO: добавить проверку, что координата пиков не совпадают
|
||||
|
||||
---@type MapGen.Peak
|
||||
local peak = Peak:new(peakPos, multinoise, groups)
|
||||
|
||||
layer:addPeak(peak)
|
||||
|
||||
return peak --TODO: временно?
|
||||
end
|
||||
|
||||
---TODO: описание
|
||||
---@param layerName string The name of the layer in which the new peak will be included.
|
||||
---@param peakPos vector
|
||||
---@param multinoise MapGen.Peak.MultinoiseParams Noise that will be assigned to the peak and that will influence map generation
|
||||
---@param groups table<string, number>? TODO: описание
|
||||
---Mark a world point as `MapGen.Peak` and assign it a specific noise that will affect the generation.
|
||||
---The Y coordinate will be forced to zero, and the `is2d` group will be added to the groups field.
|
||||
---
|
||||
---Note: The peaks shouldn't overlap. This won't cause any errors, but it might ruin the generation.
|
||||
---@param layerName string The name of the layer in which the new peak will be included.
|
||||
---@param peakPos vector The coordinate where the peak will be placed.
|
||||
---@param multinoise MapGen.Peak.MultinoiseParams Noise that will be assigned to the peak and that will influence map generation.
|
||||
---@param groups table<string, number>? Peak groups that may affect processing.
|
||||
function MapGen:register2DPeak(layerName, peakPos, multinoise, groups)
|
||||
local _peakPos = table.copy_with_metatables(peakPos)
|
||||
_peakPos.y = 0
|
||||
@@ -159,21 +159,24 @@ function MapGen:register2DPeak(layerName, peakPos, multinoise, groups)
|
||||
self:registerPeak(layerName, _peakPos, multinoise, groups)
|
||||
end
|
||||
|
||||
---TODO: описание
|
||||
---@param layerName string The name of the layer in which the new peak will be included.
|
||||
---@param multinoise MapGen.Peak.MultinoiseParams Noise that will be assigned to the peak and that will influence map generation
|
||||
---@param peakPoses vector[]
|
||||
---@param groups table<string, number>? TODO: описание
|
||||
---Mark the world points as `MapGen.Peak` and assign them all a specific noise that will affect generation.
|
||||
---The Y coordinate will be forced to zero, and the `is2d` group will be added to the groups field.
|
||||
---
|
||||
---Note: The peaks shouldn't overlap. This won't cause any errors, but it might ruin the generation.
|
||||
---@param layerName string The name of the layer in which the new peaks will be included.
|
||||
---@param multinoise MapGen.Peak.MultinoiseParams The noise that will be assigned to each peak and will affect the map generation.
|
||||
---@param peakPoses vector[] Set the coordinates where the peaks will be placed.
|
||||
---@param groups table<string, number>? Peak groups that may affect processing.
|
||||
function MapGen:register2DPeaks(layerName, multinoise, peakPoses, groups)
|
||||
for _, peakPos in ipairs(peakPoses) do
|
||||
self:register2DPeak(layerName, peakPos, multinoise, groups)
|
||||
end
|
||||
end
|
||||
|
||||
---TODO: описание
|
||||
---@param layerName string
|
||||
---@param biomeName string
|
||||
---@param def MapGen.Layer.BiomeDef
|
||||
---Mark a point on the biomes diagram and constrain the world area by height to mark it as `MapGen.Biome`.
|
||||
---@param layerName string The name of the layer in which the new biome will be included.
|
||||
---@param biomeName string The name to be assigned to the biome. The name must be unique for each biome.
|
||||
---@param def MapGen.BiomeDef Biome description table, see details `MapGen.BiomeDef`
|
||||
function MapGen:registerBiome(layerName, biomeName, def)
|
||||
local layer = self.layersByName[layerName]
|
||||
assert(layer ~= nil, ('There is no layer named `%s` registered.'):format(layerName))
|
||||
@@ -181,14 +184,13 @@ function MapGen:registerBiome(layerName, biomeName, def)
|
||||
|
||||
local biome = Biome:new(biomeName, def)
|
||||
|
||||
layer.biomesByName[biomeName] = biome
|
||||
table.insert(layer.biomesList, biome)
|
||||
layer:addBiome(biomeName, biome)
|
||||
end
|
||||
|
||||
---TODO: описание
|
||||
---@param layerName string
|
||||
---@param cavernName string
|
||||
---@param def MapGen.Layer.CavernDef
|
||||
---Mark the world area between two heights as a `MapGen.Cavern` and assign the noise that the cave will be generated from.
|
||||
---@param layerName string The name of the layer in which the new cavern will be included.
|
||||
---@param cavernName string The name to be assigned to the cavern. The name must be unique for each cavern.
|
||||
---@param def MapGen.CavernDef Cavern description table, see details `MapGen.CavernDef`
|
||||
function MapGen:registerCavern(layerName, cavernName, def)
|
||||
local layer = self.layersByName[layerName]
|
||||
assert(layer ~= nil, ('There is no layer named `%s` registered.'):format(layerName))
|
||||
@@ -196,15 +198,14 @@ function MapGen:registerCavern(layerName, cavernName, def)
|
||||
|
||||
local cavern = Cavern:new(cavernName, def)
|
||||
|
||||
layer.cavernsByName[cavernName] = cavern
|
||||
table.insert(layer.cavernsList, cavern)
|
||||
layer:addCavern(cavernName, cavern)
|
||||
end
|
||||
|
||||
|
||||
|
||||
-- --- INITIALIZATION METHODS ---
|
||||
|
||||
---Initializing layer triangulation.
|
||||
---Divide all layers into triangles whose vertices are the `Mapgen.Peak` belonging to these layers.
|
||||
function MapGen:initLayersTriangultaion()
|
||||
---@param layer MapGen.Layer
|
||||
for _, layer in ipairs(self.layersList) do
|
||||
@@ -213,6 +214,15 @@ function MapGen:initLayersTriangultaion()
|
||||
end
|
||||
end
|
||||
|
||||
---Initialization of the biome diagram using the Voronoi method.
|
||||
function MapGen:initBiomesDiagram()
|
||||
---@param layer MapGen.Layer
|
||||
for _, layer in ipairs(self.layersList) do
|
||||
layer:initBiomesDiagram()
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
---Initialize peak's noises. This should be called after the map object is loaded.
|
||||
function MapGen:initPeaksMultinoise()
|
||||
---@param layer MapGen.Layer
|
||||
@@ -228,7 +238,7 @@ function MapGen:initPeaksMultinoise()
|
||||
self.peaksMultinoiseInitialized = true
|
||||
end
|
||||
|
||||
---TODO: описание
|
||||
---Initialize caverns's noises. This should be called after the map object is loaded.
|
||||
function MapGen:initCavernsNoise()
|
||||
---@param layer MapGen.Layer
|
||||
for _, layer in ipairs(self.layersList) do
|
||||
@@ -243,18 +253,11 @@ function MapGen:initCavernsNoise()
|
||||
self.cavernsNoiseInitialized = true
|
||||
end
|
||||
|
||||
---Initialization of the biome diagram using the Voronoi method.
|
||||
function MapGen:initBiomesDiagram()
|
||||
---@param layer MapGen.Layer
|
||||
for _, layer in ipairs(self.layersList) do
|
||||
layer:initBiomesDiagram()
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
-- --- GENERATION METHODS ---
|
||||
|
||||
---Returns `true` if there is a cavern at the specified coordinates.
|
||||
---@param layer MapGen.Layer
|
||||
---@param x number
|
||||
---@param y number
|
||||
@@ -270,9 +273,11 @@ local function isCavern(layer, x, y, z)
|
||||
return false
|
||||
end
|
||||
|
||||
---The core logic of world generation. Determines which node type (water, rock, soil, air)
|
||||
---and which biome will be generated at the specified coordinates.
|
||||
---@param mapGenerator MapGen
|
||||
---@param layer MapGen.Layer
|
||||
---@param height number
|
||||
---@param height number
|
||||
---@param temp number
|
||||
---@param humidity number
|
||||
---@param data number[]
|
||||
@@ -290,7 +295,7 @@ local function generateNode(mapGenerator, layer, height, temp, humidity, data, i
|
||||
humidity = mathMin(100, mathMax(0, humidity + m))
|
||||
--_height = mathMin(layer.maxY, mathMax(layer.minY, y + m))
|
||||
|
||||
---@type MapGen.Layer.Biome
|
||||
---@type MapGen.Biome
|
||||
local biome = layer.biomesDiagram[y][mathRound(temp)][mathRound(humidity)]
|
||||
|
||||
if y > height and y > waterLevel then
|
||||
@@ -309,10 +314,15 @@ local function generateNode(mapGenerator, layer, height, temp, humidity, data, i
|
||||
end
|
||||
else
|
||||
data[index] = ids.air
|
||||
-- TODO: добавить error
|
||||
|
||||
Logger.warningLog('If you see this error, it means that the map generator does'..
|
||||
'not handle all cases of generation on coordinates: %s, %s, %s.', x, y, z)
|
||||
end
|
||||
end
|
||||
|
||||
---Calculates a weight for a coordinate using the projection onto
|
||||
---the triangle's height and specifying the distance to the peak
|
||||
---for which the weight is calculated.
|
||||
---@param height MapGen.Triangulation.Edge
|
||||
---@param x number
|
||||
---@param y number
|
||||
@@ -336,6 +346,8 @@ local function calcWeight(height, x, y, z)
|
||||
return 1 - vector.distance(pos2, posP) / height:length()
|
||||
end
|
||||
|
||||
---Returns `true` if the point is within the triangle's region.
|
||||
---The barycentric coordinate method is used.
|
||||
---@param px number
|
||||
---@param pz number
|
||||
---@param triangle MapGen.Triangle
|
||||
@@ -362,6 +374,7 @@ local function pointInTriangle(px, pz, triangle)
|
||||
return (u >= 0) and (v >= 0) and (u + v <= 1)
|
||||
end
|
||||
|
||||
---Returns the weighted values of 2d noises.
|
||||
---@param triangle MapGen.Triangle
|
||||
---@param x number
|
||||
---@param y number
|
||||
@@ -542,6 +555,7 @@ function MapGen:getNoises3dValues(layer, x, y, z)
|
||||
end
|
||||
--]]
|
||||
|
||||
---Generator handler for specific coordinates.
|
||||
---@param mapGenerator MapGen
|
||||
---@param data number[]
|
||||
---@param index number
|
||||
@@ -572,6 +586,7 @@ local function generatorHandler(mapGenerator, data, index, x, y, z)
|
||||
generateNode(mapGenerator, layer, noiseHeightValue, noiseTempValue, noiseHumidityValue, data, index, x, y, z)
|
||||
end
|
||||
|
||||
---Chunk generation handler.
|
||||
---@param voxelManip VoxelManip
|
||||
---@param minPos table
|
||||
---@param maxPos table
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
---@class MapGen.Layer.Biome
|
||||
---@class MapGen.Biome
|
||||
---@field name string
|
||||
---@field tempPoint number
|
||||
---@field humidityPoint number
|
||||
@@ -6,27 +6,30 @@
|
||||
---@field maxY number
|
||||
---@field groundNodes MapGen.Biome.GroundNodes
|
||||
---@field soilHeight number
|
||||
---@field generateRock fun(mapGenerator:MapGen, biome:MapGen.Layer.Biome, data:number[], index:number, x:number, y:number, z:number)
|
||||
---@field generateSoil fun(mapGenerator:MapGen, biome:MapGen.Layer.Biome, data:number[], index:number, x:number, y:number, z:number)
|
||||
---@field generateBottom fun(mapGenerator:MapGen, biome:MapGen.Layer.Biome, data:number[], index:number, x:number, y:number, z:number)
|
||||
---@field generateRock fun(mapGenerator:MapGen, biome:MapGen.Biome, data:number[], index:number, x:number, y:number, z:number)
|
||||
---@field generateSoil fun(mapGenerator:MapGen, biome:MapGen.Biome, data:number[], index:number, x:number, y:number, z:number)
|
||||
---@field generateBottom fun(mapGenerator:MapGen, biome:MapGen.Biome, data:number[], index:number, x:number, y:number, z:number)
|
||||
local Biome = {}
|
||||
|
||||
---@class MapGen.Layer.BiomeDef
|
||||
---Definition table for the `MapGen.Biome`.
|
||||
---
|
||||
---**Only for EmmyLua.**
|
||||
---@class MapGen.BiomeDef
|
||||
---@field tempPoint number
|
||||
---@field humidityPoint number
|
||||
---@field minY number
|
||||
---@field maxY number
|
||||
---@field groundNodes MapGen.Biome.GroundNodes
|
||||
---@field soilHeight number
|
||||
---@field generateRock fun(mapGenerator:MapGen, biome:MapGen.Layer.Biome, data:number[], index:number, x:number, y:number, z:number)?
|
||||
---@field generateSoil fun(mapGenerator:MapGen, biome:MapGen.Layer.Biome, data:number[], index:number, x:number, y:number, z:number)?
|
||||
---@field generateBottom fun(mapGenerator:MapGen, biome:MapGen.Layer.Biome, data:number[], index:number, x:number, y:number, z:number)?
|
||||
---@field generateRock fun(mapGenerator:MapGen, biome:MapGen.Biome, data:number[], index:number, x:number, y:number, z:number)?
|
||||
---@field generateSoil fun(mapGenerator:MapGen, biome:MapGen.Biome, data:number[], index:number, x:number, y:number, z:number)?
|
||||
---@field generateBottom fun(mapGenerator:MapGen, biome:MapGen.Biome, data:number[], index:number, x:number, y:number, z:number)?
|
||||
|
||||
|
||||
-- Default generate functions
|
||||
|
||||
---@param mapGenerator MapGen
|
||||
---@param biome MapGen.Layer.Biome
|
||||
---@param biome MapGen.Biome
|
||||
---@param data number[]
|
||||
---@param index number
|
||||
---@param x number
|
||||
@@ -37,7 +40,7 @@ local defaultGenerateRock = function(mapGenerator, biome, data, index, x, y, z)
|
||||
end
|
||||
|
||||
---@param mapGenerator MapGen
|
||||
---@param biome MapGen.Layer.Biome
|
||||
---@param biome MapGen.Biome
|
||||
---@param data number[]
|
||||
---@param index number
|
||||
---@param x number
|
||||
@@ -48,7 +51,7 @@ local defaultGenerateSoil = function(mapGenerator, biome, data, index, x, y, z)
|
||||
end
|
||||
|
||||
---@param mapGenerator MapGen
|
||||
---@param biome MapGen.Layer.Biome
|
||||
---@param biome MapGen.Biome
|
||||
---@param data number[]
|
||||
---@param index number
|
||||
---@param x number
|
||||
@@ -60,25 +63,25 @@ end
|
||||
|
||||
|
||||
---@param name string
|
||||
---@param def MapGen.Layer.BiomeDef
|
||||
---@return MapGen.Layer.Biome
|
||||
---@param def MapGen.BiomeDef
|
||||
---@return MapGen.Biome
|
||||
function Biome:new(name, def)
|
||||
if def.generateRock == nil then
|
||||
Logger.warningLog('MapGen.Layer.Biome: The `%s` biome does not have a specified `generateRock()` function. The default function is used.', name)
|
||||
Logger.warningLog('MapGen.Biome: The `%s` biome does not have a specified `generateRock()` function. The default function is used.', name)
|
||||
def.generateRock = defaultGenerateRock
|
||||
end
|
||||
|
||||
if def.generateSoil == nil then
|
||||
Logger.warningLog('MapGen.Layer.Biome: The `%s` biome does not have a specified `generateSoil()` function. The default function is used.', name)
|
||||
Logger.warningLog('MapGen.Biome: The `%s` biome does not have a specified `generateSoil()` function. The default function is used.', name)
|
||||
def.generateSoil = defaultGenerateSoil
|
||||
end
|
||||
|
||||
if def.generateBottom == nil then
|
||||
Logger.warningLog('MapGen.Layer.Biome: The `%s` biome does not have a specified `generateBottom()` function. The default function is used.', name)
|
||||
Logger.warningLog('MapGen.Biome: The `%s` biome does not have a specified `generateBottom()` function. The default function is used.', name)
|
||||
def.generateBottom = defaultGenerateBottom
|
||||
end
|
||||
|
||||
---@type MapGen.Layer.Biome
|
||||
---@type MapGen.Biome
|
||||
local instance = setmetatable({
|
||||
name = name,
|
||||
tempPoint = def.tempPoint,
|
||||
@@ -95,4 +98,4 @@ function Biome:new(name, def)
|
||||
return instance
|
||||
end
|
||||
|
||||
return Biome
|
||||
return Biome
|
||||
@@ -1,8 +1,9 @@
|
||||
--- Only for EmmyLua
|
||||
|
||||
---**Only for EmmyLua.**
|
||||
---@class MapGen.Biome.GroundNodes
|
||||
---@field turf string The soil covering the surface of the biome
|
||||
---@field soil string The soil beneath the turf. The height of this layer depends on `Biome.soilHeight`
|
||||
local GroundNodes = {}
|
||||
|
||||
return GroundNodes
|
||||
return GroundNodes
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
local mathMin, mathMax, mathAbs
|
||||
= math.min, math.max, math.abs
|
||||
|
||||
---@class MapGen.Layer.Cavern
|
||||
---@class MapGen.Cavern
|
||||
---@field name string
|
||||
---@field minY number
|
||||
---@field maxY number
|
||||
@@ -12,10 +12,10 @@ local mathMin, mathMax, mathAbs
|
||||
---@field getGroups fun():table<string, number>
|
||||
local Cavern = {}
|
||||
|
||||
---Definition table for the `MapGen.Layer.Cavern`.
|
||||
---Definition table for the `MapGen.Cavern`.
|
||||
---
|
||||
---**Only for EmmyLua.**
|
||||
---@class MapGen.Layer.CavernDef
|
||||
---@class MapGen.CavernDef
|
||||
---@field minY number
|
||||
---@field maxY number
|
||||
---@field noiseParams NoiseParams
|
||||
@@ -24,8 +24,8 @@ local Cavern = {}
|
||||
---@field groups table<string, number>?
|
||||
|
||||
---@param name string
|
||||
---@param def MapGen.Layer.CavernDef
|
||||
---@return MapGen.Layer.Cavern
|
||||
---@param def MapGen.CavernDef
|
||||
---@return MapGen.Cavern
|
||||
function Cavern:new(name, def)
|
||||
assert(def.maxY > def.minY, 'maxY there should be more minY')
|
||||
assert(def.smoothDistance < mathAbs(def.maxY - def.minY)/2, 'The smoothing distance cannot be greater than half the distance between minY and maxY')
|
||||
@@ -49,7 +49,7 @@ function Cavern:new(name, def)
|
||||
_groups = def.groups
|
||||
end
|
||||
|
||||
---@type MapGen.Layer.Cavern
|
||||
---@type MapGen.Cavern
|
||||
local instance = setmetatable({
|
||||
name = name,
|
||||
minY = def.minY,
|
||||
@@ -89,6 +89,7 @@ local function calcCavernWeight(y, smoothDistance, minY, maxY)
|
||||
return mathMax(0, mathMin(maxDist / smoothDistance, minDist / smoothDistance, 1))
|
||||
end
|
||||
|
||||
---Returns `true` if there is a cavern at the specified coordinates.
|
||||
---@param x number
|
||||
---@param y number
|
||||
---@param z number
|
||||
@@ -106,4 +107,4 @@ function Cavern:isCavern(x, y, z)
|
||||
return noise:get_3d({x = x, y = y, z = z}) * weight > self.threshold
|
||||
end
|
||||
|
||||
return Cavern
|
||||
return Cavern
|
||||
15
mods/CORE/MapGen/src/MapGen/Decoration.lua
Normal file
15
mods/CORE/MapGen/src/MapGen/Decoration.lua
Normal file
@@ -0,0 +1,15 @@
|
||||
---**NOT IMPLEMENTED**
|
||||
---@class MapGen.Decoration
|
||||
local Decoration = {}
|
||||
|
||||
---@return MapGen.Decoration
|
||||
function Decoration:new()
|
||||
---@type MapGen.Decoration
|
||||
local instance = setmetatable({
|
||||
|
||||
}, {__index = self})
|
||||
|
||||
return instance
|
||||
end
|
||||
|
||||
return Decoration
|
||||
@@ -1,25 +1,23 @@
|
||||
local mathSqrt = math.sqrt
|
||||
|
||||
---@class MapGen.Layer
|
||||
---@field name string
|
||||
---@field minY number
|
||||
---@field maxY number
|
||||
---@field peaksList MapGen.Peak[]
|
||||
---@field biomesByName table<string, MapGen.Layer.Biome>
|
||||
---@field biomesList MapGen.Layer.Biome[]
|
||||
---@field biomesByName table<string, MapGen.Biome>
|
||||
---@field biomesList MapGen.Biome[]
|
||||
---@field biomesDiagram table
|
||||
---@field cavernsByName table<string, MapGen.Layer.Cavern>
|
||||
---@field cavernsList MapGen.Layer.Cavern[]
|
||||
---@field cavernsByName table<string, MapGen.Cavern>
|
||||
---@field cavernsList MapGen.Cavern[]
|
||||
---@field trianglesList MapGen.Triangle[]
|
||||
---@field tetrahedronsList MapGen.Tetrahedron[]
|
||||
local Layer = {
|
||||
peaksList = {},
|
||||
biomesByName = {},
|
||||
biomesList = {},
|
||||
biomesDiagram = {},
|
||||
cavernsByName = {},
|
||||
cavernsList = {},
|
||||
trianglesList = {},
|
||||
peaksList = {},
|
||||
biomesByName = {},
|
||||
biomesList = {},
|
||||
biomesDiagram = {},
|
||||
cavernsByName = {},
|
||||
cavernsList = {},
|
||||
trianglesList = {},
|
||||
tetrahedronsList = {},
|
||||
}
|
||||
|
||||
@@ -38,14 +36,31 @@ function Layer:new(name, minY, maxY)
|
||||
return instance
|
||||
end
|
||||
|
||||
---Adds a peak to the `Layer.peaksList`
|
||||
---@param peak MapGen.Peak
|
||||
function Layer:addPeak(peak)
|
||||
table.insert(self.peaksList, peak)
|
||||
end
|
||||
|
||||
---Adds a biome to the `Layer.biomesByName` & `Layer.biomesList`
|
||||
---@param biomeName string
|
||||
---@param biome MapGen.Biome
|
||||
function Layer:addBiome(biomeName, biome)
|
||||
self.biomesByName[biomeName] = biome
|
||||
table.insert(self.biomesList, self)
|
||||
end
|
||||
|
||||
---Adds a cavern to the `Layer.cavernsByName` & `Layer.cavernsList`
|
||||
---@param cavernName string
|
||||
---@param cavern MapGen.Cavern
|
||||
function Layer:addCavern(cavernName, cavern)
|
||||
self.cavernsByName[cavernName] = cavern
|
||||
table.insert(self.cavernsList, cavern)
|
||||
end
|
||||
|
||||
---@param height number
|
||||
---@param biomesList MapGen.Layer.Biome[]
|
||||
---@return string[], MapGen.Layer.Biome[]
|
||||
---@param biomesList MapGen.Biome[]
|
||||
---@return string[], MapGen.Biome[]
|
||||
local function getBiomesNamesByHeight(height, biomesList)
|
||||
local biomesNames = {}
|
||||
local biomes = {}
|
||||
@@ -90,7 +105,7 @@ function Layer:initBiomesDiagram()
|
||||
local minDistance = math.huge
|
||||
local closestBiome = nil
|
||||
|
||||
---@param biome MapGen.Layer.Biome
|
||||
---@param biome MapGen.Biome
|
||||
for _, biome in ipairs(biomes) do
|
||||
local distance = (temp - biome.tempPoint)^2 + (humidity - biome.humidityPoint)^2
|
||||
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
---@class MapGen.Layer.Decoration
|
||||
local Decoration = {}
|
||||
|
||||
---@return MapGen.Layer.Decoration
|
||||
function Decoration:new(tempPoint, humidityPoint, groundNodes, soilHeight)
|
||||
---@type MapGen.Layer.Decoration
|
||||
local instance = setmetatable({
|
||||
|
||||
}, {__index = self})
|
||||
|
||||
return instance
|
||||
end
|
||||
|
||||
return Decoration
|
||||
@@ -4,11 +4,13 @@
|
||||
---@field getMultinoiseParams fun():MapGen.Peak.MultinoiseParams
|
||||
---@field getMultinoise fun():MapGen.Peak.Multinoise
|
||||
---@field initMultinoise fun()
|
||||
---@field getGroups fun():table<string, number>
|
||||
---@field getGroups fun():table<string, number>
|
||||
local Peak = {
|
||||
id = 0,
|
||||
}
|
||||
|
||||
-- --- Helpers functions ---
|
||||
|
||||
---@param multinoiseParams MapGen.Peak.MultinoiseParams
|
||||
---@return MapGen.Peak.Multinoise
|
||||
local function multinoiseParamsToMultinoise(multinoiseParams)
|
||||
@@ -23,6 +25,10 @@ local function multinoiseParamsToMultinoise(multinoiseParams)
|
||||
return multinoise
|
||||
end
|
||||
|
||||
|
||||
|
||||
-- --- Class registration ---
|
||||
|
||||
---@param peakPos vector
|
||||
---@param multinoiseParams MapGen.Peak.MultinoiseParams
|
||||
---@param groups? table<string, number>
|
||||
@@ -62,12 +68,20 @@ function Peak:new(peakPos, multinoiseParams, groups)
|
||||
end
|
||||
|
||||
function instance:getMultinoise()
|
||||
if not table.is_empty(_multinoise) then
|
||||
error('Attempt to get `MapGen.Triangulation.FakePeak` noise (empty noise).')
|
||||
end
|
||||
|
||||
return _multinoise
|
||||
end
|
||||
|
||||
function instance:initMultinoise()
|
||||
if not table.is_empty(_multinoise) then
|
||||
minetest.log('warning', 'Multinoise has already been initialized. Re-initialization is not recommended.')
|
||||
Logger.warningLog('Multinoise has already been initialized. Re-initialization is not recommended.')
|
||||
end
|
||||
|
||||
if not table.is_empty(_multinoiseParams) then
|
||||
error('Attempt to initialize `MapGen.Triangulation.FakePeak` noise (noise parameter empty).')
|
||||
end
|
||||
|
||||
_multinoise = multinoiseParamsToMultinoise(_multinoiseParams)
|
||||
@@ -87,9 +101,10 @@ function Peak:toString()
|
||||
return ('Peak (%s) x: %.2f y: %.2f z: %.2f'):format( self.id, pos.x, pos.y, pos.z)
|
||||
end
|
||||
|
||||
---Returns true if the peaks are equivalent.
|
||||
---@param other MapGen.Peak
|
||||
---@return boolean
|
||||
function Peak:eq( other )
|
||||
function Peak:eq(other)
|
||||
local pos1 = self:getPeakPos()
|
||||
local pos2 = other:getPeakPos()
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
---For EmmyLua only
|
||||
|
||||
---**For EmmyLua only**
|
||||
---@class MapGen.Peak.Multinoise
|
||||
---@field landscapeNoise ValueNoise
|
||||
---@field tempNoise ValueNoise
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
---For EmmyLua only
|
||||
|
||||
---**For EmmyLua only**
|
||||
---@class MapGen.Peak.MultinoiseParams
|
||||
---@field landscapeNoise NoiseParams
|
||||
---@field tempNoise NoiseParams
|
||||
|
||||
@@ -9,7 +9,7 @@ local Edge = require('MapGen.Triangulation.Edge')
|
||||
---@type MapGen.Triangulation.FakePeak
|
||||
local FakePeak = require('MapGen.Triangulation.FakePeak')
|
||||
|
||||
-- Helpers functions --
|
||||
-- --- Helpers functions ---
|
||||
|
||||
---Triangle semi-perimeter by Heron's formula
|
||||
---@param a number
|
||||
@@ -50,7 +50,9 @@ local function isFlatAngle(p1, p2, p3)
|
||||
return mathAbs(dot + 1.0) < 0
|
||||
end
|
||||
|
||||
-- Class registration --
|
||||
|
||||
|
||||
-- --- Class registration ---
|
||||
|
||||
---@class MapGen.Triangle
|
||||
---@field p1 MapGen.Peak
|
||||
@@ -102,12 +104,14 @@ function Triangle:toString()
|
||||
)
|
||||
end
|
||||
|
||||
---Returns true if the triangles are equivalent.
|
||||
---@param other MapGen.Triangle
|
||||
---@return boolean
|
||||
function Triangle:eq( other )
|
||||
return self.p1 == other.p1 and self.p2 == other.p2 and self.p3 == other.p3
|
||||
end
|
||||
|
||||
---Returns true if the triangles are similar.
|
||||
---@param other MapGen.Triangle
|
||||
---@return boolean
|
||||
function Triangle:same(other)
|
||||
@@ -116,7 +120,7 @@ function Triangle:same(other)
|
||||
or (self.p1 == other.p3 and self.p2 == other.p1 and self.p3 == other.p2)
|
||||
end
|
||||
|
||||
---Returns the coordinates of the center
|
||||
---Returns the coordinates of the triangle's center.
|
||||
---@return vector
|
||||
function Triangle:getCenter()
|
||||
local pos1 = self.p1:getPeakPos()
|
||||
@@ -126,7 +130,7 @@ function Triangle:getCenter()
|
||||
return (pos1 + pos2 + pos3) / 3
|
||||
end
|
||||
|
||||
---Returns the area
|
||||
---Returns the area of a triangle.
|
||||
---@return number
|
||||
function Triangle:getArea()
|
||||
local a, b, c = self:getSidesLength()
|
||||
@@ -134,8 +138,7 @@ function Triangle:getArea()
|
||||
return (quatCross(a, b, c) / 4)
|
||||
end
|
||||
|
||||
---Returns the length of the perpendicular
|
||||
---from Peak1 to the line Peak2-Peak3
|
||||
---Returns the perpendicular from the vertex Peak1 to the line Peak2-Peak3.
|
||||
---@param p1 MapGen.Peak
|
||||
---@param p2 MapGen.Peak
|
||||
---@param p3 MapGen.Peak
|
||||
@@ -158,8 +161,10 @@ function Triangle:getHeight(p1, p2, p3)
|
||||
return Edge:new(p1, FakePeak:new(posP))
|
||||
end
|
||||
|
||||
---Returns the length of the perpendicular
|
||||
---from Peak1 to the line Peak2-Peak3
|
||||
---Returns the perpendicular from the vertex Peak1 to the line Peak2-Peak3.
|
||||
---
|
||||
---Note: This function does not take into account the Y-coordinate,
|
||||
---that is, the calculation is performed on the projection of the triangle XZ.
|
||||
---@param p1 MapGen.Peak
|
||||
---@param p2 MapGen.Peak
|
||||
---@param p3 MapGen.Peak
|
||||
@@ -192,10 +197,10 @@ function Triangle:getSidesLength()
|
||||
return self.e1:length(), self.e2:length(), self.e3:length()
|
||||
end
|
||||
|
||||
---Returns the length of the edges
|
||||
---Returns the length of the edges.
|
||||
---
|
||||
---Note: This function does not take into account the Y-coordinate,
|
||||
---that is, the calculation is performed on the projection of the triangle XZ
|
||||
---that is, the calculation is performed on the projection of the triangle XZ.
|
||||
---@return number, number, number
|
||||
function Triangle:getSidesLength2D()
|
||||
local pos1 = self.p1:getPeakPos()
|
||||
@@ -209,10 +214,10 @@ function Triangle:getSidesLength2D()
|
||||
return (pos2 - pos1):length(), (pos3 - pos2):length(), (pos1 - pos3):length()
|
||||
end
|
||||
|
||||
---Returns the coordinates of the circumcircle center
|
||||
---Returns the coordinates of the circumcircle center.
|
||||
---
|
||||
---Note: This function does not take into account the Y-coordinate,
|
||||
---that is, the calculation is performed on the projection of the triangle XZ
|
||||
---that is, the calculation is performed on the projection of the triangle XZ.
|
||||
---@return vector
|
||||
function Triangle:getCircumCenter2D()
|
||||
local pos1 = self.p1:getPeakPos()
|
||||
@@ -232,10 +237,10 @@ function Triangle:getCircumCenter2D()
|
||||
return vector.new(x / D, 0, z / D)
|
||||
end
|
||||
|
||||
---Returns the radius of the circumcircle
|
||||
---Returns the radius of the circumcircle.
|
||||
---
|
||||
---Note: This function does not take into account the Y-coordinate,
|
||||
---that is, the calculation is performed on the projection of the triangle XZ
|
||||
---that is, the calculation is performed on the projection of the triangle XZ.
|
||||
---@return number
|
||||
function Triangle:getCircumRadius2D()
|
||||
local a, b, c = self:getSidesLength2D()
|
||||
@@ -243,10 +248,10 @@ function Triangle:getCircumRadius2D()
|
||||
return ((a * b * c) / quatCross(a, b, c))
|
||||
end
|
||||
|
||||
---Returns the coordinates of the circumcircle center and its radius
|
||||
---Returns the coordinates of the circumcircle center and its radius.
|
||||
---
|
||||
---Note: This function does not take into account the Y-coordinate,
|
||||
---that is, the calculation is performed on the projection of the triangle XZ
|
||||
---that is, the calculation is performed on the projection of the triangle XZ.
|
||||
---@return vector, number
|
||||
function Triangle:getCircumCircle2D()
|
||||
local c = self:getCircumCenter2D()
|
||||
@@ -255,10 +260,10 @@ function Triangle:getCircumCircle2D()
|
||||
return c, r
|
||||
end
|
||||
|
||||
---Checks if a given point lies into the triangle circumcircle
|
||||
---Checks if a given point lies into the triangle circumcircle.
|
||||
---
|
||||
---Note: This function does not take into account the Y-coordinate,
|
||||
---that is, the calculation is performed on the projection of the triangle XZ
|
||||
---that is, the calculation is performed on the projection of the triangle XZ.
|
||||
---@param p MapGen.Peak
|
||||
---@return boolean
|
||||
function Triangle:inCircumCircle2D(p)
|
||||
@@ -271,4 +276,4 @@ function Triangle:inCircumCircle2D(p)
|
||||
return distance <= r
|
||||
end
|
||||
|
||||
return Triangle
|
||||
return Triangle
|
||||
|
||||
@@ -7,6 +7,7 @@ local Edge = {}
|
||||
---@param p2 MapGen.Peak
|
||||
---@return MapGen.Triangulation.Edge
|
||||
function Edge:new( p1, p2 )
|
||||
---@type MapGen.Triangulation.Edge
|
||||
local instance = setmetatable({
|
||||
p1 = p1,
|
||||
p2 = p2
|
||||
@@ -26,12 +27,14 @@ function Edge:toString()
|
||||
return (('Edge :\n %s\n %s'):format(tostring(self.p1), tostring(self.p2)))
|
||||
end
|
||||
|
||||
---Returns true if the edges are equivalent.
|
||||
---@param other MapGen.Triangulation.Edge
|
||||
---@return boolean
|
||||
function Edge:eq(other)
|
||||
return self.p1 == other.p1 and self.p2 == other.p2
|
||||
end
|
||||
|
||||
---Returns true if the edges are similar.
|
||||
---@param other MapGen.Triangulation.Edge
|
||||
---@return boolean
|
||||
function Edge:same(other)
|
||||
@@ -39,11 +42,13 @@ function Edge:same(other)
|
||||
or (self.p1 == other.p2 and self.p2 == other.p1)
|
||||
end
|
||||
|
||||
---Returns the length of an edge.
|
||||
---@return number
|
||||
function Edge:length()
|
||||
return (self.p1.getPeakPos() - self.p2.getPeakPos()):length()
|
||||
end
|
||||
|
||||
---Returns the vector of the point located in the middle of the edge.
|
||||
---@return vector
|
||||
function Edge:getMidPoint()
|
||||
local pos1 = self.p1:getPeakPos()
|
||||
@@ -52,4 +57,4 @@ function Edge:getMidPoint()
|
||||
return (pos1 + pos2 )/2
|
||||
end
|
||||
|
||||
return Edge
|
||||
return Edge
|
||||
|
||||
@@ -4,11 +4,16 @@ local require = modInfo.require
|
||||
---@type MapGen.Peak
|
||||
local Peak = require('MapGen.Peak')
|
||||
|
||||
---Allows you to create a `MapGen.Peak` without specifying a noise parameter.
|
||||
---
|
||||
---**WARNING: MUST NOT BE PARTICIPATED IN GENERATION**
|
||||
---@class MapGen.Triangulation.FakePeak : MapGen.Peak
|
||||
---@field id number
|
||||
---@field getPeakPos fun():vector
|
||||
local FakePeak = Mod:getClassExtended(Peak, {})
|
||||
|
||||
---Returns a fake `MapGen.Peak` that has no noise parameters.
|
||||
---Note that the initialized peak should not be used in generation.
|
||||
---@param peakPos vector
|
||||
---@return MapGen.Peak
|
||||
function FakePeak:new(peakPos)
|
||||
@@ -18,4 +23,4 @@ function FakePeak:new(peakPos)
|
||||
return instance
|
||||
end
|
||||
|
||||
return FakePeak
|
||||
return FakePeak
|
||||
|
||||
Reference in New Issue
Block a user