From 549d39d4d22fd9d3465a42965112d6ec7b2515cd Mon Sep 17 00:00:00 2001 From: Craig Robbins Date: Wed, 20 Aug 2014 16:41:43 +1000 Subject: [PATCH] Early exit from abstract_ferns.grow_giant_tree_fern (very) small performance increase --- ferns/gianttreefern.lua | 172 ++++++++++++++++++++-------------------- 1 file changed, 86 insertions(+), 86 deletions(-) diff --git a/ferns/gianttreefern.lua b/ferns/gianttreefern.lua index 689bcac..4898d8e 100644 --- a/ferns/gianttreefern.lua +++ b/ferns/gianttreefern.lua @@ -11,8 +11,14 @@ -- lot of code, lot to load abstract_ferns.grow_giant_tree_fern = function(pos) - local size = math.random(12,16) -- min of range must be >= 4 local pos_01 = {x = pos.x, y = pos.y + 1, z = pos.z} + if minetest.get_node(pos_01).name ~= "air" + and minetest.get_node(pos_01).name ~= "ferns:sapling_giant_tree_fern" + and minetest.get_node(pos_01).name ~= "default:junglegrass" then + return + end + + local size = math.random(12,16) -- min of range must be >= 4 local leave_a_1 = {x = pos.x + 1, y = pos.y + size - 1, z = pos.z } local leave_a_2 = {x = pos.x + 2, y = pos.y + size , z = pos.z } @@ -33,93 +39,87 @@ abstract_ferns.grow_giant_tree_fern = function(pos) local leave_d_2 = {x = pos.x , y = pos.y + size , z = pos.z - 2} local leave_d_3 = {x = pos.x , y = pos.y + size - 1, z = pos.z - 3} local leave_d_4 = {x = pos.x , y = pos.y + size - 2, z = pos.z - 4} - - if minetest.get_node(pos_01).name == "air" -- instead of check_air = true, - or minetest.get_node(pos_01).name == "ferns:sapling_giant_tree_fern" - or minetest.get_node(pos_01).name == "default:junglegrass" then - - for i = 1, size-3 do - minetest.set_node({x = pos.x, y = pos.y + i, z = pos.z}, {name="ferns:fern_trunk_big"}) - end - minetest.set_node({x = pos.x, y = pos.y + size-2, z = pos.z}, {name="ferns:fern_trunk_big_top"}) - minetest.set_node({x = pos.x, y = pos.y + size-1, z = pos.z}, {name="ferns:tree_fern_leaves_giant"}) - - -- all the checking for air below is to prevent some ugly bugs (incomplete trunks of neighbouring trees), it's a bit slower, but worth the result - - if minetest.get_node(leave_a_1).name == "air" then - minetest.set_node(leave_a_1, {name="ferns:tree_fern_leave_big"}) - if minetest.get_node(leave_a_2).name == "air" then - minetest.set_node(leave_a_2, {name="ferns:tree_fern_leave_big"}) - if minetest.get_node(leave_a_3).name == "air" then - minetest.set_node(leave_a_3, {name="ferns:tree_fern_leave_big"}) - if minetest.get_node(leave_a_4).name == "air" then - minetest.set_node(leave_a_4, {name="ferns:tree_fern_leave_big_end", param2=3}) - end - end - end - end - - if minetest.get_node(leave_b_1).name == "air" then - minetest.set_node(leave_b_1, {name="ferns:tree_fern_leave_big"}) - if minetest.get_node(leave_b_2).name == "air" then - minetest.set_node(leave_b_2, {name="ferns:tree_fern_leave_big"}) - if minetest.get_node(leave_b_3).name == "air" then - minetest.set_node(leave_b_3, {name="ferns:tree_fern_leave_big"}) - if minetest.get_node(leave_b_4).name == "air" then - minetest.set_node(leave_b_4, {name="ferns:tree_fern_leave_big_end", param2=1}) - end - end - end - end - - if minetest.get_node(leave_c_1).name == "air" then - minetest.set_node(leave_c_1, {name="ferns:tree_fern_leave_big"}) - if minetest.get_node(leave_c_2).name == "air" then - minetest.set_node(leave_c_2, {name="ferns:tree_fern_leave_big"}) - if minetest.get_node(leave_c_3).name == "air" then - minetest.set_node(leave_c_3, {name="ferns:tree_fern_leave_big"}) - if minetest.get_node(leave_c_4).name == "air" then - minetest.set_node(leave_c_4, {name="ferns:tree_fern_leave_big_end", param2=2}) - end - end - end - end - - if minetest.get_node(leave_d_1).name == "air" then - minetest.set_node(leave_d_1, {name="ferns:tree_fern_leave_big"}) - if minetest.get_node(leave_d_2).name == "air" then - minetest.set_node(leave_d_2, {name="ferns:tree_fern_leave_big"}) - if minetest.get_node(leave_d_3).name == "air" then - minetest.set_node(leave_d_3, {name="ferns:tree_fern_leave_big"}) - if minetest.get_node(leave_d_4).name == "air" then - minetest.set_node(leave_d_4, {name="ferns:tree_fern_leave_big_end", param2=0}) - end - end - end - end - - -- bug fixes # 2 - doesn't really work, so disabled for now - --[[if minetest.get_node(leave_a_4).name == "ferns:tree_fern_leave_big_end" - and minetest.get_node(leave_a_3).name == "ferns:fern_trunk_big" then - minetest.set_node(leave_a_4, {name="air"}) - end - - if minetest.get_node(leave_b_4).name == "ferns:tree_fern_leave_big_end" - and minetest.get_node(leave_b_3).name == "ferns:fern_trunk_big" then - minetest.set_node(leave_b_4, {name="air"}) - end - - if minetest.get_node(leave_c_4).name == "ferns:tree_fern_leave_big_end" - and minetest.get_node(leave_c_3).name == "ferns:fern_trunk_big" then - minetest.set_node(leave_c_4, {name="air"}) - end - - if minetest.get_node(leave_d_4).name == "ferns:tree_fern_leave_big_end" - and minetest.get_node(leave_d_3).name == "ferns:fern_trunk_big" then - minetest.set_node(leave_d_4, {name="air"}) - end]] + for i = 1, size-3 do + minetest.set_node({x = pos.x, y = pos.y + i, z = pos.z}, {name="ferns:fern_trunk_big"}) end + minetest.set_node({x = pos.x, y = pos.y + size-2, z = pos.z}, {name="ferns:fern_trunk_big_top"}) + minetest.set_node({x = pos.x, y = pos.y + size-1, z = pos.z}, {name="ferns:tree_fern_leaves_giant"}) + + -- all the checking for air below is to prevent some ugly bugs (incomplete trunks of neighbouring trees), it's a bit slower, but worth the result + + if minetest.get_node(leave_a_1).name == "air" then + minetest.set_node(leave_a_1, {name="ferns:tree_fern_leave_big"}) + if minetest.get_node(leave_a_2).name == "air" then + minetest.set_node(leave_a_2, {name="ferns:tree_fern_leave_big"}) + if minetest.get_node(leave_a_3).name == "air" then + minetest.set_node(leave_a_3, {name="ferns:tree_fern_leave_big"}) + if minetest.get_node(leave_a_4).name == "air" then + minetest.set_node(leave_a_4, {name="ferns:tree_fern_leave_big_end", param2=3}) + end + end + end + end + + if minetest.get_node(leave_b_1).name == "air" then + minetest.set_node(leave_b_1, {name="ferns:tree_fern_leave_big"}) + if minetest.get_node(leave_b_2).name == "air" then + minetest.set_node(leave_b_2, {name="ferns:tree_fern_leave_big"}) + if minetest.get_node(leave_b_3).name == "air" then + minetest.set_node(leave_b_3, {name="ferns:tree_fern_leave_big"}) + if minetest.get_node(leave_b_4).name == "air" then + minetest.set_node(leave_b_4, {name="ferns:tree_fern_leave_big_end", param2=1}) + end + end + end + end + + if minetest.get_node(leave_c_1).name == "air" then + minetest.set_node(leave_c_1, {name="ferns:tree_fern_leave_big"}) + if minetest.get_node(leave_c_2).name == "air" then + minetest.set_node(leave_c_2, {name="ferns:tree_fern_leave_big"}) + if minetest.get_node(leave_c_3).name == "air" then + minetest.set_node(leave_c_3, {name="ferns:tree_fern_leave_big"}) + if minetest.get_node(leave_c_4).name == "air" then + minetest.set_node(leave_c_4, {name="ferns:tree_fern_leave_big_end", param2=2}) + end + end + end + end + + if minetest.get_node(leave_d_1).name == "air" then + minetest.set_node(leave_d_1, {name="ferns:tree_fern_leave_big"}) + if minetest.get_node(leave_d_2).name == "air" then + minetest.set_node(leave_d_2, {name="ferns:tree_fern_leave_big"}) + if minetest.get_node(leave_d_3).name == "air" then + minetest.set_node(leave_d_3, {name="ferns:tree_fern_leave_big"}) + if minetest.get_node(leave_d_4).name == "air" then + minetest.set_node(leave_d_4, {name="ferns:tree_fern_leave_big_end", param2=0}) + end + end + end + end + + -- bug fixes # 2 - doesn't really work, so disabled for now + --[[if minetest.get_node(leave_a_4).name == "ferns:tree_fern_leave_big_end" + and minetest.get_node(leave_a_3).name == "ferns:fern_trunk_big" then + minetest.set_node(leave_a_4, {name="air"}) + end + + if minetest.get_node(leave_b_4).name == "ferns:tree_fern_leave_big_end" + and minetest.get_node(leave_b_3).name == "ferns:fern_trunk_big" then + minetest.set_node(leave_b_4, {name="air"}) + end + + if minetest.get_node(leave_c_4).name == "ferns:tree_fern_leave_big_end" + and minetest.get_node(leave_c_3).name == "ferns:fern_trunk_big" then + minetest.set_node(leave_c_4, {name="air"}) + end + + if minetest.get_node(leave_d_4).name == "ferns:tree_fern_leave_big_end" + and minetest.get_node(leave_d_3).name == "ferns:fern_trunk_big" then + minetest.set_node(leave_d_4, {name="air"}) + end]] end -----------------------------------------------------------------------------------------------