finally added simplex noise, but broke everything else

This commit is contained in:
2026-08-15 02:48:33 -06:00
parent a7fde20dd6
commit a695a37bf7
3 changed files with 639 additions and 3 deletions
+76
View File
@@ -0,0 +1,76 @@
-- NOTE the API of this file should probably change?
local simplex = require "lib.simplex"
local generate = function()
simplex.Seed(math.random())
local map = {}
map.size = 500
map.tile_size = 1 -- TODO tile_size really shouldn't be the responsibility of the map generator - it's a rendering detail, not a map feature
map.altitude = {} -- TEMP only one noise map
local scale = 0.005
local min, max = math.huge, -math.huge
for x = 1, map.size do
map.altitude[x] = {}
for y = 1, map.size do
local value = simplex.Noise2D(x * scale, y * scale)
if value > max then max = value end
if value < min then min = value end
map.altitude[x][y] = value
end
end
print("Altitude", "Min:", min, "Max:", max)
-- TEMP hacked in copy to fix the issue so I can make sure everything is correct aaa
local function min(t)
local r = t[1][1]
for i=1,#t do
for j=1,#t[1] do
if r > t[i][j] then r = t[i][j] end
end
end
return r
end
local function max(t)
local r = t[1][1]
for i=1,#t do
for j=1,#t[1] do
if r < t[i][j] then r = t[i][j] end
end
end
return r
end
local function normalize(map, new_min, new_max)
local minimum = min(map)
local initialRange = max(map) - minimum
local finalRange = new_max - new_min
for i = 1, #map do
for j = 1, #map[1] do
map[i][j] = (map[i][j] - minimum) / initialRange * finalRange + new_min
end
end
map.min = min(map)
map.max = max(map)
return map -- superfluous
end
normalize(map.altitude, 0, 1)
map.terrain = {}
for x = 1, map.size do
map.terrain[x] = {}
for y = 1, map.size do
local value = map.altitude[x][y]
map.terrain[x][y] = {value, value, value, 1}
end
end
-- NOTE this is missing the radius modifier, so it's a square map
return map
end
return {
generate = generate,
}