From 43bee3dae0beaa6624629220071e6d529b7d3797 Mon Sep 17 00:00:00 2001 From: Vanic Date: Thu, 15 Jan 2026 14:03:37 +0300 Subject: [PATCH] MapGen: Optimization: Added single-color triangles. Close #10 --- mods/CORE/MapGen/src/MapGen.lua | 8 ++++++++ mods/CORE/MapGen/src/MapGen/Triangle.lua | 13 ++++++++++++- mods/ENVIRONMENT/mapGenerator/src/mapGenerator.lua | 4 ++-- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/mods/CORE/MapGen/src/MapGen.lua b/mods/CORE/MapGen/src/MapGen.lua index b0da822..b770986 100644 --- a/mods/CORE/MapGen/src/MapGen.lua +++ b/mods/CORE/MapGen/src/MapGen.lua @@ -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 diff --git a/mods/CORE/MapGen/src/MapGen/Triangle.lua b/mods/CORE/MapGen/src/MapGen/Triangle.lua index cf4a36e..42ac035 100644 --- a/mods/CORE/MapGen/src/MapGen/Triangle.lua +++ b/mods/CORE/MapGen/src/MapGen/Triangle.lua @@ -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, diff --git a/mods/ENVIRONMENT/mapGenerator/src/mapGenerator.lua b/mods/ENVIRONMENT/mapGenerator/src/mapGenerator.lua index 44d9cb7..cb93de2 100644 --- a/mods/ENVIRONMENT/mapGenerator/src/mapGenerator.lua +++ b/mods/ENVIRONMENT/mapGenerator/src/mapGenerator.lua @@ -52,7 +52,7 @@ mapGenerator:registerLayer('midgard', { local land1 = { offset = -20, - scale = 0, + scale = 10, spread = {x = 10, y = 10, z = 10}, seed = 47, octaves = 3, @@ -62,7 +62,7 @@ local land1 = { local land2 = { offset = 10, - scale = 0, + scale = 10, spread = {x = 30, y = 30, z = 30}, seed = 47, octaves = 3,