MapGen: Optimization: Added single-color triangles. Close #10
This commit is contained in:
@@ -517,6 +517,14 @@ end
|
|||||||
---@param z integer
|
---@param z integer
|
||||||
---@return number
|
---@return number
|
||||||
local function calcNoise2dValue(category, layer, triangle, x, y, z)
|
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 peak1 = triangle.p1
|
||||||
local peak2 = triangle.p2
|
local peak2 = triangle.p2
|
||||||
local peak3 = triangle.p3
|
local peak3 = triangle.p3
|
||||||
|
|||||||
@@ -71,6 +71,7 @@ end
|
|||||||
---@field h2 MapGen.Triangulation.Edge
|
---@field h2 MapGen.Triangulation.Edge
|
||||||
---@field h3 MapGen.Triangulation.Edge
|
---@field h3 MapGen.Triangulation.Edge
|
||||||
---@field neighbours MapGen.Triangle.Neighbours
|
---@field neighbours MapGen.Triangle.Neighbours
|
||||||
|
---@field color ColorString?
|
||||||
local Triangle = {
|
local Triangle = {
|
||||||
neighbours = {}
|
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")
|
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)))
|
: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({
|
local instance = setmetatable({
|
||||||
p1 = p1,
|
p1 = p1,
|
||||||
p2 = p2,
|
p2 = p2,
|
||||||
@@ -92,7 +102,8 @@ function Triangle:new(p1, p2, p3)
|
|||||||
h3 = Triangle:getHeight(p3, p1, p2),
|
h3 = Triangle:getHeight(p3, p1, p2),
|
||||||
e1 = Edge:new(p1, p2),
|
e1 = Edge:new(p1, p2),
|
||||||
e2 = Edge:new(p2, p3),
|
e2 = Edge:new(p2, p3),
|
||||||
e3 = Edge:new(p3, p1)
|
e3 = Edge:new(p3, p1),
|
||||||
|
color = color
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
__index = self,
|
__index = self,
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ mapGenerator:registerLayer('midgard', {
|
|||||||
|
|
||||||
local land1 = {
|
local land1 = {
|
||||||
offset = -20,
|
offset = -20,
|
||||||
scale = 0,
|
scale = 10,
|
||||||
spread = {x = 10, y = 10, z = 10},
|
spread = {x = 10, y = 10, z = 10},
|
||||||
seed = 47,
|
seed = 47,
|
||||||
octaves = 3,
|
octaves = 3,
|
||||||
@@ -62,7 +62,7 @@ local land1 = {
|
|||||||
|
|
||||||
local land2 = {
|
local land2 = {
|
||||||
offset = 10,
|
offset = 10,
|
||||||
scale = 0,
|
scale = 10,
|
||||||
spread = {x = 30, y = 30, z = 30},
|
spread = {x = 30, y = 30, z = 30},
|
||||||
seed = 47,
|
seed = 47,
|
||||||
octaves = 3,
|
octaves = 3,
|
||||||
|
|||||||
Reference in New Issue
Block a user