aboutsummaryrefslogtreecommitdiff
path: root/po/ja
diff options
context:
space:
mode:
authorest31 <MTest31@outlook.com>2015-09-03 05:58:29 +0200
committerest31 <MTest31@outlook.com>2015-09-03 06:17:02 +0200
commit2035bfc3a64e7c0c82f0cb100cd7d4cc588d0203 (patch)
tree931323002cbf8b54c34118c32a3bd7093022fb12 /po/ja
parentd4938554818aa71aceb0d360f33c6cfd42f67008 (diff)
downloadminetest-2035bfc3a64e7c0c82f0cb100cd7d4cc588d0203.tar.gz
minetest-2035bfc3a64e7c0c82f0cb100cd7d4cc588d0203.tar.bz2
minetest-2035bfc3a64e7c0c82f0cb100cd7d4cc588d0203.zip
Areastore: fix "attempt to index a number value"
Before, calling get_areas_in_area for an areastore with both include_borders and include_data would result in a lua error, if there was at least one area as result: attempt to index a number value in function 'get_areas_in_area'
Diffstat (limited to 'po/ja')
0 files changed, 0 insertions, 0 deletions
> 117 118 119 120 121 122 123 124 125 126
-- Prevent anyone else accessing those functions
local forceload_block = core.forceload_block
local forceload_free_block = core.forceload_free_block
core.forceload_block = nil
core.forceload_free_block = nil

local blocks_forceloaded
local blocks_temploaded = {}
local total_forceloaded = 0

-- true, if the forceloaded blocks got changed (flag for persistence on-disk)
local forceload_blocks_changed = false

local BLOCKSIZE = core.MAP_BLOCKSIZE
local function get_blockpos(pos)
	return {
		x = math.floor(pos.x/BLOCKSIZE),
		y = math.floor(pos.y/BLOCKSIZE),
		z = math.floor(pos.z/BLOCKSIZE)}
end

-- When we create/free a forceload, it's either transient or persistent. We want
-- to add to/remove from the table that corresponds to the type of forceload, but
-- we also need the other table because whether we forceload a block depends on
-- both tables.
-- This function returns the "primary" table we are adding to/removing from, and
-- the other table.
local function get_relevant_tables(transient)
	if transient then
		return blocks_temploaded, blocks_forceloaded
	else
		return blocks_forceloaded, blocks_temploaded
	end
end

function core.forceload_block(pos, transient)
	-- set changed flag
	forceload_blocks_changed = true

	local blockpos = get_blockpos(pos)
	local hash = core.hash_node_position(blockpos)
	local relevant_table, other_table = get_relevant_tables(transient)
	if relevant_table[hash] ~= nil then
		relevant_table[hash] = relevant_table[hash] + 1
		return true
	elseif other_table[hash] ~= nil then
		relevant_table[hash] = 1
	else
		if total_forceloaded >= (tonumber(core.settings:get("max_forceloaded_blocks")) or 16) then
			return false
		end
		total_forceloaded = total_forceloaded+1
		relevant_table[hash] = 1
		forceload_block(blockpos)
		return true
	end
end