free cave node array memory if a cave hasn't been generated in a minute
This commit is contained in:
parent
bd5b1d22c8
commit
6662133650
70
init.lua
70
init.lua
@ -138,28 +138,40 @@ local inside_column = 6
|
|||||||
-- Note that table.getn and # will not correctly report the number of items in these since they're reused
|
-- Note that table.getn and # will not correctly report the number of items in these since they're reused
|
||||||
-- between calls and are not cleared for efficiency. You can iterate through them using ipairs,
|
-- between calls and are not cleared for efficiency. You can iterate through them using ipairs,
|
||||||
-- and you can get their content count from the similarly-named variable associated with them.
|
-- and you can get their content count from the similarly-named variable associated with them.
|
||||||
local cavern_data = {}
|
local cavern_data
|
||||||
local cavern_floor_nodes = {}
|
local cavern_floor_nodes
|
||||||
cavern_data.cavern_floor_nodes = cavern_floor_nodes
|
local cavern_ceiling_nodes
|
||||||
cavern_data.cavern_floor_count = 0
|
local warren_floor_nodes
|
||||||
local cavern_ceiling_nodes = {}
|
local warren_ceiling_nodes
|
||||||
cavern_data.cavern_ceiling_nodes = cavern_ceiling_nodes
|
local tunnel_floor_nodes
|
||||||
cavern_data.cavern_ceiling_count = 0
|
local tunnel_ceiling_nodes
|
||||||
local warren_floor_nodes = {}
|
local column_nodes
|
||||||
cavern_data.warren_floor_nodes = warren_floor_nodes
|
|
||||||
cavern_data.warren_floor_count = 0
|
local initialize_node_arrays = function()
|
||||||
local warren_ceiling_nodes = {}
|
cavern_data = {}
|
||||||
cavern_data.warren_ceiling_nodes = warren_ceiling_nodes
|
cavern_floor_nodes = {}
|
||||||
cavern_data.warren_ceiling_count = 0
|
cavern_data.cavern_floor_nodes = cavern_floor_nodes
|
||||||
local tunnel_floor_nodes = {}
|
cavern_data.cavern_floor_count = 0
|
||||||
cavern_data.tunnel_floor_nodes = tunnel_floor_nodes
|
cavern_ceiling_nodes = {}
|
||||||
cavern_data.tunnel_floor_count = 0
|
cavern_data.cavern_ceiling_nodes = cavern_ceiling_nodes
|
||||||
local tunnel_ceiling_nodes = {}
|
cavern_data.cavern_ceiling_count = 0
|
||||||
cavern_data.tunnel_ceiling_nodes = tunnel_ceiling_nodes
|
warren_floor_nodes = {}
|
||||||
cavern_data.tunnel_ceiling_count = 0
|
cavern_data.warren_floor_nodes = warren_floor_nodes
|
||||||
local column_nodes = {}
|
cavern_data.warren_floor_count = 0
|
||||||
cavern_data.column_nodes = column_nodes
|
warren_ceiling_nodes = {}
|
||||||
cavern_data.column_count = 0
|
cavern_data.warren_ceiling_nodes = warren_ceiling_nodes
|
||||||
|
cavern_data.warren_ceiling_count = 0
|
||||||
|
tunnel_floor_nodes = {}
|
||||||
|
cavern_data.tunnel_floor_nodes = tunnel_floor_nodes
|
||||||
|
cavern_data.tunnel_floor_count = 0
|
||||||
|
tunnel_ceiling_nodes = {}
|
||||||
|
cavern_data.tunnel_ceiling_nodes = tunnel_ceiling_nodes
|
||||||
|
cavern_data.tunnel_ceiling_count = 0
|
||||||
|
column_nodes = {}
|
||||||
|
cavern_data.column_nodes = column_nodes
|
||||||
|
cavern_data.column_count = 0
|
||||||
|
end
|
||||||
|
initialize_node_arrays()
|
||||||
|
|
||||||
-- inserts nil after the last node so that ipairs will function correctly
|
-- inserts nil after the last node so that ipairs will function correctly
|
||||||
local close_node_arrays = function()
|
local close_node_arrays = function()
|
||||||
@ -249,6 +261,7 @@ end
|
|||||||
-- cavern_def = cave_layer_def -- a reference to the cave layer def.
|
-- cavern_def = cave_layer_def -- a reference to the cave layer def.
|
||||||
--}
|
--}
|
||||||
|
|
||||||
|
local t_start = os.clock()
|
||||||
subterrane.register_layer = function(cave_layer_def)
|
subterrane.register_layer = function(cave_layer_def)
|
||||||
local error_out = false
|
local error_out = false
|
||||||
if cave_layer_def.y_min == nil then
|
if cave_layer_def.y_min == nil then
|
||||||
@ -338,7 +351,7 @@ minetest.register_on_generated(function(minp, maxp, seed)
|
|||||||
if minp.y > YMAX or maxp.y < YMIN then
|
if minp.y > YMAX or maxp.y < YMIN then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
local t_start = os.clock()
|
t_start = os.clock()
|
||||||
|
|
||||||
if c_lava_set == nil then
|
if c_lava_set == nil then
|
||||||
c_lava_set = {}
|
c_lava_set = {}
|
||||||
@ -587,4 +600,15 @@ end)
|
|||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local last_check = os.clock()
|
||||||
|
minetest.register_globalstep(function(dtime)
|
||||||
|
local current_time = os.clock()
|
||||||
|
local threshold = t_start + 60
|
||||||
|
if last_check < threshold and current_time > threshold then
|
||||||
|
-- It's been 60 seconds since we last generated a cavern, release the memory the cavern arrays are being stored in.
|
||||||
|
initialize_node_arrays()
|
||||||
|
end
|
||||||
|
last_check = current_time
|
||||||
|
end)
|
||||||
|
|
||||||
minetest.log("info", "[Subterrane] loaded!")
|
minetest.log("info", "[Subterrane] loaded!")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user