aboutsummaryrefslogtreecommitdiff
path: root/builtin/game/voxelarea.lua
diff options
context:
space:
mode:
authorest31 <MTest31@outlook.com>2016-12-22 23:16:00 +0100
committerest31 <MTest31@outlook.com>2016-12-22 23:16:00 +0100
commit81d56b94919dceb7b2e51d70b21a7ca22f852bd5 (patch)
tree1e9ef1be1b3295a8673d6e4f0bdeb4c2d3a6015f /builtin/game/voxelarea.lua
parent8077612dcb48221281e726a60eb97bf73fde462b (diff)
parent231ac33d34dfaaddf292c5f31b1eae43eeefba2d (diff)
downloadminetest-81d56b94919dceb7b2e51d70b21a7ca22f852bd5.tar.gz
minetest-81d56b94919dceb7b2e51d70b21a7ca22f852bd5.tar.bz2
minetest-81d56b94919dceb7b2e51d70b21a7ca22f852bd5.zip
Merge 0.4.15 changes into stable-0.4
0.4.15 release!
Diffstat (limited to 'builtin/game/voxelarea.lua')
-rw-r--r--builtin/game/voxelarea.lua49
1 files changed, 36 insertions, 13 deletions
diff --git a/builtin/game/voxelarea.lua b/builtin/game/voxelarea.lua
index 6d926c940..724761414 100644
--- a/builtin/game/voxelarea.lua
+++ b/builtin/game/voxelarea.lua
@@ -50,7 +50,7 @@ end
function VoxelArea:position(i)
local p = {}
local MinEdge = self.MinEdge
-
+
i = i - 1
p.z = math.floor(i / self.zstride) + MinEdge.z
@@ -84,23 +84,46 @@ end
function VoxelArea:iter(minx, miny, minz, maxx, maxy, maxz)
local i = self:index(minx, miny, minz) - 1
- local last = self:index(maxx, maxy, maxz)
- local ystride = self.ystride
- local zstride = self.zstride
- local yoff = (last+1) % ystride
- local zoff = (last+1) % zstride
- local ystridediff = (i - last) % ystride
- local zstridediff = (i - last) % zstride
+ local xrange = maxx - minx + 1
+ local nextaction = i + 1 + xrange
+
+ local y = 0
+ local yrange = maxy - miny + 1
+ local yreqstride = self.ystride - xrange
+
+ local z = 0
+ local zrange = maxz - minz + 1
+ local multistride = self.zstride - ((yrange - 1) * self.ystride + xrange)
+
return function()
+ -- continue i until it needs to jump
i = i + 1
- if i % zstride == zoff then
- i = i + zstridediff
- elseif i % ystride == yoff then
- i = i + ystridediff
+ if i ~= nextaction then
+ return i
end
- if i <= last then
+
+ -- 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