Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
illuna-minetest
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Illuna-Minetest
illuna-minetest
Commits
9978d079
Commit
9978d079
authored
8 years ago
by
HybridDog
Committed by
Zeno-
8 years ago
Browse files
Options
Downloads
Patches
Plain Diff
VoxelArea: faster iter function (#4490)
parent
09cefc3d
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
builtin/game/voxelarea.lua
+36
-13
36 additions, 13 deletions
builtin/game/voxelarea.lua
with
36 additions
and
13 deletions
builtin/game/voxelarea.lua
+
36
−
13
View file @
9978d079
...
...
@@ -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
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment