mirror of
https://github.com/minetest/minetest.git
synced 2024-11-27 10:03:45 +01:00
VoxelArea: faster iter function (#4490)
This commit is contained in:
parent
09cefc3dfd
commit
9978d0796f
@ -50,7 +50,7 @@ end
|
|||||||
function VoxelArea:position(i)
|
function VoxelArea:position(i)
|
||||||
local p = {}
|
local p = {}
|
||||||
local MinEdge = self.MinEdge
|
local MinEdge = self.MinEdge
|
||||||
|
|
||||||
i = i - 1
|
i = i - 1
|
||||||
|
|
||||||
p.z = math.floor(i / self.zstride) + MinEdge.z
|
p.z = math.floor(i / self.zstride) + MinEdge.z
|
||||||
@ -84,23 +84,46 @@ end
|
|||||||
|
|
||||||
function VoxelArea:iter(minx, miny, minz, maxx, maxy, maxz)
|
function VoxelArea:iter(minx, miny, minz, maxx, maxy, maxz)
|
||||||
local i = self:index(minx, miny, minz) - 1
|
local i = self:index(minx, miny, minz) - 1
|
||||||
local last = self:index(maxx, maxy, maxz)
|
local xrange = maxx - minx + 1
|
||||||
local ystride = self.ystride
|
local nextaction = i + 1 + xrange
|
||||||
local zstride = self.zstride
|
|
||||||
local yoff = (last+1) % ystride
|
local y = 0
|
||||||
local zoff = (last+1) % zstride
|
local yrange = maxy - miny + 1
|
||||||
local ystridediff = (i - last) % ystride
|
local yreqstride = self.ystride - xrange
|
||||||
local zstridediff = (i - last) % zstride
|
|
||||||
|
local z = 0
|
||||||
|
local zrange = maxz - minz + 1
|
||||||
|
local multistride = self.zstride - ((yrange - 1) * self.ystride + xrange)
|
||||||
|
|
||||||
return function()
|
return function()
|
||||||
|
-- continue i until it needs to jump
|
||||||
i = i + 1
|
i = i + 1
|
||||||
if i % zstride == zoff then
|
if i ~= nextaction then
|
||||||
i = i + zstridediff
|
|
||||||
elseif i % ystride == yoff then
|
|
||||||
i = i + ystridediff
|
|
||||||
end
|
|
||||||
if i <= last then
|
|
||||||
return i
|
return i
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- continue y until maxy is exceeded
|
||||||
|
y = y + 1
|
||||||
|
if y ~= yrange then
|
||||||
|
-- set i to index(minx, miny + y, minz + z) - 1
|
||||||
|
i = i + yreqstride
|
||||||
|
nextaction = i + xrange
|
||||||
|
return i
|
||||||
|
end
|
||||||
|
|
||||||
|
-- continue z until maxz is exceeded
|
||||||
|
z = z + 1
|
||||||
|
if z == zrange then
|
||||||
|
-- cuboid finished, return nil
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
-- set i to index(minx, miny, minz + z) - 1
|
||||||
|
i = i + multistride
|
||||||
|
|
||||||
|
y = 0
|
||||||
|
nextaction = i + xrange
|
||||||
|
return i
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user