reduce index calculations (untested)

M  nether/init.lua
This commit is contained in:
HybridDog 2016-09-15 11:57:06 +02:00
parent dac86dae07
commit c33e306849
1 changed files with 39 additions and 36 deletions

View File

@ -456,17 +456,18 @@ minetest.register_on_generated(function(minp, maxp, seed)
py_h_g = nether.buildings-7 py_h_g = nether.buildings-7
end end
local vi = area:index(x, minp.y, z)
if buildings == 1 if buildings == 1
and noisp then and noisp then
if noisp == 1 then if noisp == 1 then
for y=minp.y, maxp.y do for _ = 1,side_length do
local p_addpos = area:index(x, y, z) data[vi] = c.netherrack_brick
data[p_addpos] = c.netherrack_brick vi = vi + area.ystride
end end
else else
for y=minp.y, maxp.y do for _ = 1,side_length do
local p_addpos = area:index(x, y, z) data[vi] = c.lava
data[p_addpos] = c.lava vi = vi + area.ystride
end end
end end
else else
@ -495,50 +496,49 @@ minetest.register_on_generated(function(minp, maxp, seed)
end end
for y=minp.y, maxp.y do for y=minp.y, maxp.y do
local p_addpos = area:index(x, y, z) local d_p_addp = data[vi]
local d_p_addp = data[p_addpos]
--if py_h >= maxp.y-4 then --if py_h >= maxp.y-4 then
if y <= py_h if y <= py_h
and noisp then and noisp then
if noisp == 1 then if noisp == 1 then
data[p_addpos] = c.netherrack_brick data[vi] = c.netherrack_brick
elseif noisp == 2 then elseif noisp == 2 then
if y == py_h then if y == py_h then
data[p_addpos] = c.netherrack_brick data[vi] = c.netherrack_brick
elseif y == py_h_g elseif y == py_h_g
and pr:next(1,3) <= 2 then and pr:next(1,3) <= 2 then
data[p_addpos] = c.netherrack data[vi] = c.netherrack
elseif y <= py_h_g then elseif y <= py_h_g then
data[p_addpos] = c.lava data[vi] = c.lava
else else
data[p_addpos] = c.air data[vi] = c.air
end end
end end
elseif d_p_addp ~= c.air then elseif d_p_addp ~= c.air then
if is_forest if is_forest
and y == f_bottom then and y == f_bottom then
data[p_addpos] = c.nether_dirt_top data[vi] = c.nether_dirt_top
elseif is_forest elseif is_forest
and y < f_bottom and y < f_bottom
and y >= f_h_dirt then and y >= f_h_dirt then
data[p_addpos] = c.nether_dirt data[vi] = c.nether_dirt
elseif is_forest elseif is_forest
and y == f_h_dirt-1 then and y == f_h_dirt-1 then
data[p_addpos] = c.nether_dirt_bottom data[vi] = c.nether_dirt_bottom
elseif is_forest elseif is_forest
and y == f_h_dirt+1 then and y == f_h_dirt+1 then
if pr:next(1,tree_rarity) == 1 then if pr:next(1,tree_rarity) == 1 then
trees[num_trees] = {x=x, y=y, z=z} trees[num_trees] = {x=x, y=y, z=z}
num_trees = num_trees+1 num_trees = num_trees+1
elseif pr:next(1,mushroom_rarity) == 1 then elseif pr:next(1,mushroom_rarity) == 1 then
data[p_addpos] = c.nether_shroom data[vi] = c.nether_shroom
elseif pr:next(1,glowflower_rarity) == 1 then elseif pr:next(1,glowflower_rarity) == 1 then
data[p_addpos] = c.glowflower data[vi] = c.glowflower
elseif pr:next(1,grass_rarity) == 1 then elseif pr:next(1,grass_rarity) == 1 then
data[p_addpos] = c.nether_grass[pr:next(1,3)] data[vi] = c.nether_grass[pr:next(1,3)]
else else
data[p_addpos] = c.air data[vi] = c.air
end end
elseif is_forest elseif is_forest
and y > f_bottom and y > f_bottom
@ -547,26 +547,26 @@ minetest.register_on_generated(function(minp, maxp, seed)
{c.nether_tree, c.nether_tree_corner, c.nether_leaves, c.nether_fruit}, {c.nether_tree, c.nether_tree_corner, c.nether_leaves, c.nether_fruit},
d_p_addp d_p_addp
) then ) then
data[p_addpos] = c.air data[vi] = c.air
end end
elseif is_forest elseif is_forest
and y == f_top then and y == f_top then
local sel = math.floor(strassx[x]+strassz[z]+0.5)%10 local sel = math.floor(strassx[x]+strassz[z]+0.5)%10
if sel <= 5 then if sel <= 5 then
data[p_addpos] = return_nether_ore(d_p_addp, true) data[vi] = return_nether_ore(d_p_addp, true)
elseif sel == 6 then elseif sel == 6 then
data[p_addpos] = c.netherrack_black data[vi] = c.netherrack_black
elseif sel == 7 then elseif sel == 7 then
data[p_addpos] = c.glowstone data[vi] = c.glowstone
else else
data[p_addpos] = c.air data[vi] = c.air
end end
elseif y <= NETHER_BOTTOM then elseif y <= NETHER_BOTTOM then
if y <= bottom then if y <= bottom then
data[p_addpos] = return_nether_ore(d_p_addp, true) data[vi] = return_nether_ore(d_p_addp, true)
else else
data[p_addpos] = c.lava data[vi] = c.lava
end end
elseif r_structure == 1 elseif r_structure == 1
and y == bottom then and y == bottom then
@ -574,26 +574,27 @@ minetest.register_on_generated(function(minp, maxp, seed)
num = num+1 num = num+1
elseif y <= bottom then elseif y <= bottom then
if pr:next(1,LAVA_FREQ) == 1 then if pr:next(1,LAVA_FREQ) == 1 then
data[p_addpos] = c.lava data[vi] = c.lava
else else
data[p_addpos] = return_nether_ore(d_p_addp, false) data[vi] = return_nether_ore(d_p_addp, false)
end end
elseif r_shroom == 1 elseif r_shroom == 1
and r_structure ~= 1 and r_structure ~= 1
and y == bottom+1 then and y == bottom+1 then
data[p_addpos] = c.nether_shroom data[vi] = c.nether_shroom
elseif (y == top and r_glowstone == 1) then elseif (y == top and r_glowstone == 1) then
data[p_addpos] = c.glowstone data[vi] = c.glowstone
elseif y >= top then elseif y >= top then
data[p_addpos] = return_nether_ore(d_p_addp, true) data[vi] = return_nether_ore(d_p_addp, true)
elseif y <= top-1 elseif y <= top-1
and generate_vine and generate_vine
and y >= top-r_vine_length then and y >= top-r_vine_length then
data[p_addpos] = c.nether_vine data[vi] = c.nether_vine
else else
data[p_addpos] = c.air data[vi] = c.air
end end
end end
vi = vi + area.ystride
end end
end end
end end
@ -649,8 +650,10 @@ function nether.grow_netherstructure(pos, generated)
local area = r_area(manip, 2, height, pos) local area = r_area(manip, 2, height, pos)
local nodes = manip:get_data() local nodes = manip:get_data()
for i = 0, height-1 do local vi = area:indexp(pos)
nodes[area:index(pos.x, pos.y+i, pos.z)] = c.blood_stem for _ = 0, height-1 do
nodes[vi] = c.blood_stem
vi = vi + area.ystride
end end
for i = -1,1 do for i = -1,1 do