mirror of
https://github.com/rollerozxa/voxelmanip-wiki
synced 2024-05-05 08:01:02 -07:00
Mapgen Optimisations: edit
This commit is contained in:
parent
48c9688da6
commit
af38464e31
@ -73,5 +73,25 @@ minetest.register_on_generated(function(minp, maxp, seed)
|
||||
end)
|
||||
```
|
||||
|
||||
## Conserve VoxelArea:index calls
|
||||
What the `:index` method of [[VoxelArea]] does is convert the position provided with XYZ coordinates into the corresponding table index in the data table. This method is fast, but obviously not instant, doing some amount of calculations every time.
|
||||
|
||||
In order to conserve the amount of calls to `:index`, you can take advantage of the fact incrementing the index will move you on the X-axis:
|
||||
|
||||
```lua
|
||||
for z = minp.z, maxp.z do
|
||||
for y = minp.y, maxp.y do
|
||||
local vi = area:index(minp.x, y, z)
|
||||
for x = minp.x, maxp.x do
|
||||
--[[ code here ]]
|
||||
|
||||
vi = vi + 1
|
||||
end
|
||||
end
|
||||
end
|
||||
```
|
||||
|
||||
This will significantly cut down on the amount of index calls required by the main mapgen loop.
|
||||
|
||||
---
|
||||
*This article is originally based on an article from the Minetest Developer Wiki: [Mapgen memory optimisations](https://dev.minetest.net/Mapgen_memory_optimisations) by Naj and Wuzzy, licensed under CC-BY-SA 3.0, in turn based on [this forum topic](https://forum.minetest.net/viewtopic.php?t=16043) by paramat*
|
Loading…
x
Reference in New Issue
Block a user