Mapgen: its work again
This commit is contained in:
@@ -23,8 +23,10 @@ local Region = require("MapGen.Region")
|
|||||||
---@class MapGen
|
---@class MapGen
|
||||||
---@field layersByName table
|
---@field layersByName table
|
||||||
---@field layersList table
|
---@field layersList table
|
||||||
|
---@field multinoiseInitialized boolean Is the fractal noise of the regions initialized? This is necessary for a one-time noise initialization.
|
||||||
---@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.
|
||||||
local MapGen = {
|
local MapGen = {
|
||||||
|
multinoiseInitialized = false,
|
||||||
isRunning = false,
|
isRunning = false,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -99,16 +101,30 @@ function MapGen:RegisterRegion(layerName, minPos, maxPos, multinoise, regionIs2D
|
|||||||
---@type MapGen.Region
|
---@type MapGen.Region
|
||||||
local region = Region:new(minPos, maxPos, multinoise)
|
local region = Region:new(minPos, maxPos, multinoise)
|
||||||
|
|
||||||
--TODO: реализовать регистрацию допольнительных регионов для сглаживания шумов
|
--TODO: реализовать регистрацию дополнительных регионов для сглаживания шумов
|
||||||
|
|
||||||
layer:addRegion(region)
|
layer:addRegion(region)
|
||||||
end
|
end
|
||||||
|
|
||||||
function MapGen:landscapeGeneration(data, area, x, y, z)
|
---Initialize region noise. This should be called after the map object is loaded.
|
||||||
local index = area:index(x, y, z)
|
function MapGen:initRegionsMultinoise()
|
||||||
|
---@param layer MapGen.Layer
|
||||||
|
for _, layer in ipairs(self.layersList) do
|
||||||
|
|
||||||
|
---@param region MapGen.Region
|
||||||
|
for _, region in ipairs(layer.regionsList) do
|
||||||
|
region:initMultinoise()
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
self.multinoiseInitialized = true
|
||||||
|
end
|
||||||
|
|
||||||
|
local function landscapeGeneration(mapGenerator, data, index, x, y, z)
|
||||||
|
|
||||||
-- If generation occurs outside the layers, then a void is generated
|
-- If generation occurs outside the layers, then a void is generated
|
||||||
local layer = self:getLayerByHeight(y)
|
local layer = mapGenerator:getLayerByHeight(y)
|
||||||
if layer == nil then
|
if layer == nil then
|
||||||
data[index] = id_air
|
data[index] = id_air
|
||||||
|
|
||||||
@@ -128,11 +144,9 @@ function MapGen:landscapeGeneration(data, area, x, y, z)
|
|||||||
-- The height noise values of all regions that a node is part of are added together...
|
-- The height noise values of all regions that a node is part of are added together...
|
||||||
---@param region MapGen.Region
|
---@param region MapGen.Region
|
||||||
for _, region in ipairs(regions) do
|
for _, region in ipairs(regions) do
|
||||||
if region.multinoise.landscapeNoise ~= nil then
|
local noise = region:getMultinoise().landscapeNoise
|
||||||
local noise = core.get_value_noise(region.multinoise.landscapeNoise)
|
|
||||||
noiseHeightValue = noiseHeightValue + noise:get_2d({x = x, y = z})
|
|
||||||
|
|
||||||
end
|
noiseHeightValue = noiseHeightValue + noise:get_2d({x = x, y = z})
|
||||||
end
|
end
|
||||||
|
|
||||||
-- ...And the average height is found: this provides smoothing
|
-- ...And the average height is found: this provides smoothing
|
||||||
@@ -141,11 +155,12 @@ function MapGen:landscapeGeneration(data, area, x, y, z)
|
|||||||
if y > noiseHeightValue then
|
if y > noiseHeightValue then
|
||||||
data[index] = id_air
|
data[index] = id_air
|
||||||
else
|
else
|
||||||
data[index] = core.get_content_id("rocks:tauitite") -- TODO: прописать заполнение камнем
|
data[index] = core.get_content_id("rocks:sylite") -- TODO: прописать заполнение камнем
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function MapGen:postprocessGeneration(data, area, x, y, z)
|
local function postprocessGeneration(mapGenerator, data, area, x, y, z)
|
||||||
local index = area:index(x, y, z)
|
local index = area:index(x, y, z)
|
||||||
|
|
||||||
-- TODO: генерация покрытия
|
-- TODO: генерация покрытия
|
||||||
@@ -159,18 +174,24 @@ end
|
|||||||
function MapGen:onMapGenerated(minPos, maxPos, blockseed)
|
function MapGen:onMapGenerated(minPos, maxPos, blockseed)
|
||||||
-- We obtain a generation area for further manipulations
|
-- We obtain a generation area for further manipulations
|
||||||
local voxelManip, eMin, eMax = core.get_mapgen_object("voxelmanip")
|
local voxelManip, eMin, eMax = core.get_mapgen_object("voxelmanip")
|
||||||
|
|
||||||
|
if not self.multinoiseInitialized then
|
||||||
|
self:initRegionsMultinoise()
|
||||||
|
end
|
||||||
|
|
||||||
local data = voxelManip:get_data()
|
local data = voxelManip:get_data()
|
||||||
local area = VoxelArea:new({MinEdge = eMin, MaxEdge = eMax})
|
|
||||||
-- local param2_data = voxelManip:get_param2_data()
|
-- local param2_data = voxelManip:get_param2_data()
|
||||||
|
local area = VoxelArea:new({MinEdge = eMin, MaxEdge = eMax})
|
||||||
|
|
||||||
-- Initial generation: landscape
|
-- Initial generation: landscape
|
||||||
for z = minPos.z, maxPos.z do
|
for z = minPos.z, maxPos.z do
|
||||||
for y = minPos.y, maxPos.y do
|
for y = minPos.y, maxPos.y do
|
||||||
|
local index = area:index(minPos.x, y, z)
|
||||||
|
|
||||||
for x = minPos.x, maxPos.x do
|
for x = minPos.x, maxPos.x do
|
||||||
self:landscapeGeneration(data, area, x, y, z)
|
landscapeGeneration(self, data, index, x, y, z)
|
||||||
--core.handle_async(self.landscapeGeneration, callback, self, data, area, x, y, z)
|
|
||||||
-- вероятно благодаря 2D шуму высоты генерацию ландшафта можно оптимизировать
|
index = index + 1
|
||||||
-- до генерации столбами (т. к. по x, z можно найти требуемый y)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -179,7 +200,7 @@ function MapGen:onMapGenerated(minPos, maxPos, blockseed)
|
|||||||
--[[for z = minPos.z, maxPos.z do
|
--[[for z = minPos.z, maxPos.z do
|
||||||
for y = minPos.y, maxPos.y do
|
for y = minPos.y, maxPos.y do
|
||||||
for x = minPos.x, maxPos.x do
|
for x = minPos.x, maxPos.x do
|
||||||
MapGen:postprocessGeneration(data, area, x, y, z)
|
postprocessGeneration(mapGenerator, data, area, x, y, z)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end --]]
|
end --]]
|
||||||
@@ -189,6 +210,7 @@ function MapGen:onMapGenerated(minPos, maxPos, blockseed)
|
|||||||
-- voxelManip:set_param2_data(param2_data)
|
-- voxelManip:set_param2_data(param2_data)
|
||||||
voxelManip:update_liquids()
|
voxelManip:update_liquids()
|
||||||
voxelManip:calc_lighting()
|
voxelManip:calc_lighting()
|
||||||
|
|
||||||
voxelManip:write_to_map()
|
voxelManip:write_to_map()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -42,13 +42,13 @@ function Layer:getRegionsByPos(xPos, yPos, zPos)
|
|||||||
for _, region in ipairs(self.regionsList) do
|
for _, region in ipairs(self.regionsList) do
|
||||||
|
|
||||||
if (
|
if (
|
||||||
xPos >= region.minPos.x and
|
xPos >= region:getMinPos().x and
|
||||||
yPos >= region.minPos.y and
|
yPos >= region:getMinPos().y and
|
||||||
zPos >= region.minPos.z) and
|
zPos >= region:getMinPos().z) and
|
||||||
(
|
(
|
||||||
xPos <= region.maxPos.x and
|
xPos <= region:getMaxPos().x and
|
||||||
yPos <= region.maxPos.y and
|
yPos <= region:getMaxPos().y and
|
||||||
zPos <= region.maxPos.z
|
zPos <= region:getMaxPos().z
|
||||||
) then
|
) then
|
||||||
table.insert(regions, region)
|
table.insert(regions, region)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
-- TODO: replace `table` with `vector` for minPos and maxPos
|
-- TODO: replace `table` with `vector` for minPos and maxPos
|
||||||
---@class MapGen.Region
|
---@class MapGen.Region
|
||||||
|
|
||||||
local Region = {}
|
local Region = {}
|
||||||
|
|
||||||
---@param multinoiseParams MapGen.Region.MultinoiseParams -- ??? TODO: should be it's own class in EmmyLua
|
---@param multinoiseParams MapGen.Region.MultinoiseParams -- ??? TODO: should be it's own class in EmmyLua
|
||||||
@@ -30,6 +29,7 @@ function Region:new(minPos, maxPos, multinoiseParams)
|
|||||||
|
|
||||||
local instance = setmetatable({}, {__index = self})
|
local instance = setmetatable({}, {__index = self})
|
||||||
|
|
||||||
|
---@return {x:number, y:number, z:number}
|
||||||
function instance:getMinPos()
|
function instance:getMinPos()
|
||||||
return _minPos
|
return _minPos
|
||||||
end
|
end
|
||||||
@@ -39,6 +39,8 @@ function Region:new(minPos, maxPos, multinoiseParams)
|
|||||||
function instance:getMultinoiseParams()
|
function instance:getMultinoiseParams()
|
||||||
return _multinoiseParams
|
return _multinoiseParams
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---@return MapGen.Region.Multinoise
|
||||||
function instance:getMultinoise()
|
function instance:getMultinoise()
|
||||||
return _multinoise
|
return _multinoise
|
||||||
end
|
end
|
||||||
|
|||||||
19
mods/CORE/MapGen/src/MapGen/Region/MultinoiseParams.lua
Normal file
19
mods/CORE/MapGen/src/MapGen/Region/MultinoiseParams.lua
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
---For EmmyLua only
|
||||||
|
|
||||||
|
---@class MapGen.Region.NoiseParams
|
||||||
|
---@field offset number
|
||||||
|
---@field scale number
|
||||||
|
---@field spread vector -- TODO: describe vector class from Luanti (push Alek)
|
||||||
|
---@field seed number
|
||||||
|
---@field octaves number
|
||||||
|
---@field persistence number
|
||||||
|
---@field lacunarity number
|
||||||
|
---@field flags string?
|
||||||
|
|
||||||
|
---@class MapGen.Region.MultinoiseParams
|
||||||
|
---@field landscapeNoise MapGen.Region.NoiseParams?
|
||||||
|
---@field tempNoise MapGen.Region.NoiseParams?
|
||||||
|
---@field humidityNoise MapGen.Region.NoiseParams?
|
||||||
|
local MultinoiseParams = {}
|
||||||
|
|
||||||
|
return MultinoiseParams
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
---For EmmyLua only
|
|
||||||
|
|
||||||
---@class MapGen.Region.NoiseParams
|
|
||||||
---@field offset number
|
|
||||||
---@field scale number
|
|
||||||
---@field spread vector -- TODO: describe vector class from Luanti (push Alek)
|
|
||||||
---@field seed number
|
|
||||||
---@field octaves number
|
|
||||||
---@field persistence number
|
|
||||||
---@field lacunarity number
|
|
||||||
---@field flags string?
|
|
||||||
|
|
||||||
---@class MapGen.Region.MultinoiseParams
|
|
||||||
---@field landscapeNoiseParams MapGen.Region.NoiseParams?
|
|
||||||
---@field tempNoiseParams MapGen.Region.NoiseParams?
|
|
||||||
---@field humidityNoiseParams MapGen.Region.NoiseParams?
|
|
||||||
local MultinoiseParams = {}
|
|
||||||
|
|
||||||
return MultinoiseParams
|
|
||||||
Reference in New Issue
Block a user