1
0
mirror of https://github.com/Splizard/minetest-mod-snow.git synced 2024-12-28 07:30:17 +01:00

add back caching ws values, that was a memory bug of minetest and these numbers hardly use memory space I guess

This commit is contained in:
HybridDog 2015-11-21 21:54:25 +01:00
parent 35c21dd879
commit b647842ad4

View File

@ -1,5 +1,6 @@
-- https://github.com/paramat/meru/blob/master/init.lua#L52
-- Parameters must match mgv6 biome noise
local np_default = {
offset = 0,
scale = 1,
@ -9,6 +10,7 @@ local np_default = {
persist = 0.5
}
-- 2D noise for coldness
local mg = snow.mapgen
@ -22,6 +24,7 @@ local np_cold = {
persist = 0.5
}
-- 2D noise for icetype
local np_ice = {
@ -33,6 +36,7 @@ local np_ice = {
persist = 0.5
}
-- Debugging function
local biome_strings = {
@ -55,6 +59,24 @@ local function do_ws_func(a, x)
end
-- caching functions
local ws_lists = {}
local function get_ws_list(a,x)
ws_lists[a] = ws_lists[a] or {}
local v = ws_lists[a][x]
if v then
return v
end
v = {}
for x=x,x + (80 - 1) do
local y = do_ws_func(a, x)
v[x] = y
end
ws_lists[a][x] = v
return v
end
local plantlike_ids = {}
local function is_plantlike(id)
if plantlike_ids[id] ~= nil then
@ -97,6 +119,7 @@ local function is_snowable(id)
return true
end
local c, replacements
local function define_contents()
c = {
@ -235,7 +258,7 @@ minetest.register_on_generated(function(minp, maxp, seed)
if not nvals_ice then
nvals_ice = minetest.get_perlin_map(np_ice, chulens):get2dMap_flat({x=x0, y=z0})
end
local icetype = nvals_ice[ni]
local icetype = nvals_ice[ni]
local cool = icetype > 0 -- only spawns ice on edge of water
local icebergs = icetype > -0.2 and icetype <= 0
local icehole = icetype > -0.4 and icetype <= -0.2 -- icesheet with holes
@ -431,7 +454,11 @@ minetest.register_on_generated(function(minp, maxp, seed)
if test > 0 then
local maxh = math.floor(test*10)%10+1
if maxh ~= 1 then
local h = math.floor( do_ws_func(2, x) + do_ws_func(5, z)*5)%10+1
if not wsz then
wsz = get_ws_list(5, z0)
wsx = get_ws_list(2, x0)
end
local h = math.floor(wsx[x]+wsz[z]*5)%10+1
if h ~= 1 then
-- search for nearby snow
y = y+1
@ -488,4 +515,3 @@ minetest.register_on_generated(function(minp, maxp, seed)
print("[snow] "..biome_string.." x "..minp.x.." z "..minp.z.." time "..chugent.." ms")
end
end)