forked from mtcontrib/minetest-mod-snow
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:
parent
35c21dd879
commit
b647842ad4
@ -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 = {
|
||||
@ -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)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user