MapGen: Optimization: add Added detection of adjacent triangles. Close #14
This commit is contained in:
@@ -1,28 +1,18 @@
|
||||
local mathAbs, mathRound, mathMin, mathMax, id
|
||||
= math.abs, math.round, math.min, math.max, core.get_content_id
|
||||
|
||||
---@class MapGen.PastCalcNoiseValue
|
||||
local pastCalcNoiseValue = {
|
||||
---@type MapGen.Triangle?
|
||||
triangle = nil,
|
||||
---@type integer?
|
||||
x = nil,
|
||||
---@type integer?
|
||||
z = nil,
|
||||
---@type number?
|
||||
noiseValue = nil,
|
||||
}
|
||||
local modInfo = Mod.getInfo('smc__core__map_gen')
|
||||
local require = modInfo.require
|
||||
|
||||
---@alias MapGen.PastCalcNoiseValue {triangle:MapGen.Triangle?, x:integer?, z:integer?, noiseValue:number?}
|
||||
|
||||
---@type table<MapGen.Layer.Category, MapGen.PastCalcNoiseValue>
|
||||
local pastNoise2DCalc = {
|
||||
landscape = pastCalcNoiseValue,
|
||||
temp = pastCalcNoiseValue,
|
||||
humidity = pastCalcNoiseValue
|
||||
landscape = {},
|
||||
temp = {},
|
||||
humidity = {}
|
||||
}
|
||||
|
||||
local modInfo = Mod.getInfo('smc__core__map_gen')
|
||||
local require = modInfo.require
|
||||
|
||||
---@type MapGen.Layer
|
||||
local Layer = require('MapGen.Layer')
|
||||
|
||||
@@ -262,7 +252,7 @@ function MapGen:register2DPeaksFromFile(layerName, map, scale,zeroPos, category,
|
||||
for _, peakPos in ipairs(peaksPos) do
|
||||
---@type MapGen.PeakDef
|
||||
local def = {
|
||||
pos = vector.new((peakPos.x - zeroPos.x) * scale, 0, (peakPos.y - zeroPos.y) * scale),
|
||||
pos = vector.new((peakPos.x - zeroPos.x - 1) * scale, 0, (peakPos.y - zeroPos.y - 1) * scale),
|
||||
color = color,
|
||||
groups = groups,
|
||||
}
|
||||
@@ -574,19 +564,34 @@ function MapGen:getNoises2dValue(category, layer, x, y, z)
|
||||
return pastCalc.noiseValue
|
||||
end
|
||||
|
||||
if pastCalc.triangle ~= nil and pointInTriangle(x, z, pastCalc.triangle) then
|
||||
local noiseValue = calcNoise2dValue(category, layer, pastCalc.triangle, x, y, z)
|
||||
if pastCalc.triangle ~= nil then
|
||||
---@type number?
|
||||
local noiseValue
|
||||
|
||||
pastCalc.x = x
|
||||
pastCalc.z = z
|
||||
pastCalc.noiseValue = noiseValue
|
||||
local triangles = {
|
||||
pastCalc.triangle,
|
||||
pastCalc.triangle.neighbours.t1,
|
||||
pastCalc.triangle.neighbours.t2,
|
||||
pastCalc.triangle.neighbours.t3,
|
||||
}
|
||||
|
||||
return noiseValue
|
||||
---@param t MapGen.Triangle
|
||||
for _, t in ipairs(triangles) do
|
||||
if pointInTriangle(x, z, t) then
|
||||
noiseValue = calcNoise2dValue(category, layer, t, x, y, z)
|
||||
|
||||
pastCalc.x = x
|
||||
pastCalc.z = z
|
||||
pastCalc.noiseValue = noiseValue
|
||||
|
||||
return noiseValue
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
---@param triangle MapGen.Triangle
|
||||
for _, triangle in ipairs(layer.trianglesList[category]) do
|
||||
if pointInTriangle(x, z,triangle) then
|
||||
if pointInTriangle(x, z, triangle) then
|
||||
local noiseValue = calcNoise2dValue(category, layer, triangle, x, y, z)
|
||||
|
||||
pastCalc.triangle = triangle
|
||||
@@ -717,7 +722,6 @@ local function generatorHandler(mapGenerator, data, index, x, y, z)
|
||||
return
|
||||
end
|
||||
|
||||
-- Calculating landscape height
|
||||
-- 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) or 0.0
|
||||
|
||||
Reference in New Issue
Block a user