MapGen: Optimization: Added single-color triangles. Close #10
This commit is contained in:
@@ -517,6 +517,14 @@ end
|
||||
---@param z integer
|
||||
---@return number
|
||||
local function calcNoise2dValue(category, layer, triangle, x, y, z)
|
||||
local triangleColor = triangle.color
|
||||
|
||||
-- If the triangle is monochromatic (all peaks have the same color and,
|
||||
-- accordingly, the same noise), then there is no point in smoothing out the noise.
|
||||
if triangleColor ~= nil then
|
||||
return layer:getNoiseByColor(category, triangleColor):get_2d({x = x, y = z})
|
||||
end
|
||||
|
||||
local peak1 = triangle.p1
|
||||
local peak2 = triangle.p2
|
||||
local peak3 = triangle.p3
|
||||
|
||||
@@ -71,6 +71,7 @@ end
|
||||
---@field h2 MapGen.Triangulation.Edge
|
||||
---@field h3 MapGen.Triangulation.Edge
|
||||
---@field neighbours MapGen.Triangle.Neighbours
|
||||
---@field color ColorString?
|
||||
local Triangle = {
|
||||
neighbours = {}
|
||||
}
|
||||
@@ -83,6 +84,15 @@ function Triangle:new(p1, p2, p3)
|
||||
assert(not isFlatAngle(p1, p2, p3), ("angle (p1, p2, p3) is flat:\n %s\n %s\n %s")
|
||||
:format(tostring(p1), tostring(p2), tostring(p3)))
|
||||
|
||||
---@type ColorString?
|
||||
local color = nil
|
||||
|
||||
local c1, c2, c3 = p1.getColor(), p2.getColor(), p3.getColor()
|
||||
|
||||
if c1 == c2 and c2 == c3 and c3 == c1 then
|
||||
color = c1
|
||||
end
|
||||
|
||||
local instance = setmetatable({
|
||||
p1 = p1,
|
||||
p2 = p2,
|
||||
@@ -92,7 +102,8 @@ function Triangle:new(p1, p2, p3)
|
||||
h3 = Triangle:getHeight(p3, p1, p2),
|
||||
e1 = Edge:new(p1, p2),
|
||||
e2 = Edge:new(p2, p3),
|
||||
e3 = Edge:new(p3, p1)
|
||||
e3 = Edge:new(p3, p1),
|
||||
color = color
|
||||
},
|
||||
{
|
||||
__index = self,
|
||||
|
||||
Reference in New Issue
Block a user