MapGen: There is now only one triangulation map instead of three.
This commit is contained in:
@@ -26,14 +26,10 @@ local require = modInfo.require
|
||||
|
||||
---@alias MapGen.factors {height:number, temp:number, humidity:number}
|
||||
|
||||
---@alias MapGen.PastCalcNoiseValue {triangle:MapGen.Triangle?, x:integer?, z:integer?, noiseValue:number?}
|
||||
---@alias MapGen.PastCalcNoiseValue {triangle:MapGen.Triangle?, x:integer?, z:integer?, height:number?, temp:number?, humidity:number?}
|
||||
|
||||
---@type table<MapGen.Layer.Category, MapGen.PastCalcNoiseValue>
|
||||
local pastNoise2DCalc = {
|
||||
landscape = {},
|
||||
temp = {},
|
||||
humidity = {}
|
||||
}
|
||||
---@type MapGen.PastCalcNoiseValue
|
||||
local pastNoisesCalc = {}
|
||||
|
||||
---@type MapGen.Layer
|
||||
local Layer = require('MapGen.Layer')
|
||||
@@ -146,16 +142,15 @@ end
|
||||
|
||||
---Returns the `MapGen.Peak` at the coordinates. If there is no peak at these coordinates, it returns `nil`.
|
||||
---@param layer string|MapGen.Layer The layer or name of the layer in which the peak is located.
|
||||
---@param category MapGen.Layer.Category The category in which the peak is located.
|
||||
---@param pos MapPosition Coordinate of the desired peak.
|
||||
---@return MapGen.Peak?
|
||||
function MapGen:getPeakByPos(layer, category, pos)
|
||||
function MapGen:getPeakByPos(layer, pos)
|
||||
if type(layer) == 'string' then
|
||||
local layerName = layer
|
||||
layer = self:getLayerByName(layerName)
|
||||
end
|
||||
|
||||
return layer:getPeakByPos(category, pos)
|
||||
return layer:getPeakByPos(pos)
|
||||
end
|
||||
|
||||
---Checks if a point is inside a triangle using the vector product method.
|
||||
@@ -189,14 +184,13 @@ function MapGen:isPointInTriangle(triangle, pointPos)
|
||||
end
|
||||
|
||||
---@param layer MapGen.Layer The layer of the layer the triangle is in.
|
||||
---@param category MapGen.Layer.Category The category in which the triangle is in.
|
||||
---@param x integer
|
||||
---@param z integer
|
||||
---@param triangle MapGen.Triangle?
|
||||
---@return MapGen.Triangle?
|
||||
function MapGen:findTriangle(layer, category, x, z, triangle)
|
||||
function MapGen:findTriangle(layer, x, z, triangle)
|
||||
if triangle == nil then
|
||||
triangle = layer.trianglesList[category][1]
|
||||
triangle = layer.trianglesList[1]
|
||||
end
|
||||
|
||||
local iterationCount = 1000000
|
||||
@@ -209,7 +203,9 @@ function MapGen:findTriangle(layer, category, x, z, triangle)
|
||||
end
|
||||
iterationCount = iterationCount - 1
|
||||
|
||||
assert(triangle)
|
||||
if triangle == nil then
|
||||
return nil
|
||||
end
|
||||
|
||||
isFound, triangle = self:isPointInTriangle(triangle, v(x, 0, z))
|
||||
end
|
||||
@@ -498,9 +494,8 @@ end
|
||||
|
||||
---Initialize the boundary region for a layer and category.
|
||||
---@param layer MapGen.Layer
|
||||
---@param category MapGen.Layer.Category
|
||||
function MapGen:initTriangultaionBoundaryRegion(layer, category)
|
||||
local triangles = layer.trianglesList[category]
|
||||
local triangles = layer.trianglesList
|
||||
local regionVertices = self:getTriangulateBoundaryVertices(triangles)
|
||||
|
||||
local regionName = category..'_boundary'
|
||||
@@ -771,55 +766,61 @@ end
|
||||
---@param x integer
|
||||
---@param y integer
|
||||
---@param z integer
|
||||
---@return number?
|
||||
---@return number?, number?, number?
|
||||
function MapGen:getNoises2dValue(category, layer, x, y, z)
|
||||
---@type MapGen.PastCalcNoiseValue
|
||||
local pastCalc = pastNoise2DCalc[category]
|
||||
|
||||
if (pastCalc.x ~= nil and pastCalc.z ~= nil) and (x == pastCalc.x and z == pastCalc.z) then
|
||||
return pastCalc.noiseValue
|
||||
if (pastNoisesCalc.x ~= nil and pastNoisesCalc.z ~= nil) and (x == pastNoisesCalc.x and z == pastNoisesCalc.z) then
|
||||
return pastNoisesCalc.height, pastNoisesCalc.temp, pastNoisesCalc.humidity
|
||||
end
|
||||
|
||||
-- TODO: это сильно тормозит обычные чанки, но ускоряет те, что находятся за границей
|
||||
if not self:pointInRegion2D(layer, category..'_boundary', {x=x, y=y, z=z}) then
|
||||
return nil
|
||||
return
|
||||
end
|
||||
|
||||
if pastCalc.triangle ~= nil then
|
||||
---@type number?
|
||||
local noiseValue
|
||||
|
||||
if pastNoisesCalc.triangle ~= nil then
|
||||
local triangles = {
|
||||
pastCalc.triangle,
|
||||
pastCalc.triangle.neighbours[1],
|
||||
pastCalc.triangle.neighbours[2],
|
||||
pastCalc.triangle.neighbours[3],
|
||||
pastNoisesCalc.triangle,
|
||||
pastNoisesCalc.triangle.neighbours[1],
|
||||
pastNoisesCalc.triangle.neighbours[2],
|
||||
pastNoisesCalc.triangle.neighbours[3],
|
||||
}
|
||||
|
||||
---@param t MapGen.Triangle
|
||||
for _, t in ipairs(triangles) do
|
||||
if self:isPointInTriangle(t, v(x, 0, z)) then
|
||||
noiseValue = calcNoise2dValue(category, layer, t, x, y, z)
|
||||
---@param triangle MapGen.Triangle
|
||||
for _, triangle in ipairs(triangles) do
|
||||
if self:isPointInTriangle(triangle, v(x, 0, z)) then
|
||||
local height = calcNoise2dValue('landscape', layer, triangle, x, y, z)
|
||||
local temp = calcNoise2dValue('temp', layer, triangle, x, y, z)
|
||||
local humidity = calcNoise2dValue('humidity', layer, triangle, x, y, z)
|
||||
|
||||
pastCalc.x = x
|
||||
pastCalc.z = z
|
||||
pastCalc.noiseValue = noiseValue
|
||||
pastNoisesCalc.x = x
|
||||
pastNoisesCalc.z = z
|
||||
pastNoisesCalc.height = height
|
||||
pastNoisesCalc.temp = temp
|
||||
pastNoisesCalc.humidity = humidity
|
||||
|
||||
return noiseValue
|
||||
return height, temp, humidity
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local triangle = self:findTriangle(layer, category, x, z, pastCalc.triangle)
|
||||
assert(triangle ~= nil)
|
||||
local triangle = self:findTriangle(layer, x, z, pastNoisesCalc.triangle)
|
||||
if triangle == nil then
|
||||
return
|
||||
end
|
||||
|
||||
local noiseValue = calcNoise2dValue(category, layer, triangle, x, y, z)
|
||||
local height = calcNoise2dValue('landscape', layer, triangle, x, y, z)
|
||||
local temp = calcNoise2dValue('temp', layer, triangle, x, y, z)
|
||||
local humidity = calcNoise2dValue('humidity', layer, triangle, x, y, z)
|
||||
|
||||
pastCalc.triangle = triangle
|
||||
pastCalc.x = x
|
||||
pastCalc.z = z
|
||||
pastCalc.noiseValue = noiseValue
|
||||
pastNoisesCalc.triangle = triangle
|
||||
pastNoisesCalc.x = x
|
||||
pastNoisesCalc.z = z
|
||||
pastNoisesCalc.height = height
|
||||
pastNoisesCalc.temp = temp
|
||||
pastNoisesCalc.humidity = humidity
|
||||
|
||||
return noiseValue
|
||||
return height, temp, humidity
|
||||
end
|
||||
|
||||
---Generator handler for specific coordinates.
|
||||
@@ -852,36 +853,22 @@ local function generatorHandler(mapGenerator, layer, data, index, x, y, z)
|
||||
local startNoiseCalcTime = endGetLayerTime
|
||||
-- If the value of the noise is `nil`,
|
||||
-- then the point does not fall within any of the triangles.
|
||||
local noiseHeightValue = mapGenerator:getNoises2dValue('landscape', layer, x, y, z)
|
||||
if noiseHeightValue == nil then
|
||||
data[index] = core.CONTENT_IGNORE
|
||||
|
||||
return endGetLayerTime - startGetLayerTime, core.get_us_time() - startNoiseCalcTime, 0
|
||||
end
|
||||
|
||||
local noiseTempValue = mapGenerator:getNoises2dValue('temp', layer, x, y, z)
|
||||
if noiseTempValue == nil then
|
||||
data[index] = core.CONTENT_IGNORE
|
||||
|
||||
return endGetLayerTime - startGetLayerTime, core.get_us_time() - startNoiseCalcTime, 0
|
||||
end
|
||||
|
||||
local noiseHumidityValue = mapGenerator:getNoises2dValue('humidity', layer, x, y, z)
|
||||
if noiseHumidityValue == nil then
|
||||
local height, temp, humidity = mapGenerator:getNoises2dValue('landscape', layer, x, y, z)
|
||||
if height == nil or temp == nil or humidity == nil then
|
||||
data[index] = core.CONTENT_IGNORE
|
||||
|
||||
return endGetLayerTime - startGetLayerTime, core.get_us_time() - startNoiseCalcTime, 0
|
||||
end
|
||||
|
||||
-- We recalculate the climate based on altitude.
|
||||
noiseTempValue = layer:calcTemp(noiseTempValue, y)
|
||||
noiseHumidityValue = layer:calcHumidity(noiseHumidityValue, y)
|
||||
temp = layer:calcTemp(temp, y)
|
||||
humidity = layer:calcHumidity(humidity, y)
|
||||
|
||||
---@type MapGen.factors
|
||||
local factors = {
|
||||
height = noiseHeightValue,
|
||||
temp = noiseTempValue,
|
||||
humidity = noiseHumidityValue,
|
||||
height = height,
|
||||
temp = temp,
|
||||
humidity = humidity,
|
||||
}
|
||||
|
||||
local endNoiseCalcTime = core.get_us_time()
|
||||
|
||||
Reference in New Issue
Block a user