From 982e3cdd3e93ed06c6524e35a563cbb8d620bf3f Mon Sep 17 00:00:00 2001 From: proller Date: Sun, 3 Sep 2023 05:30:46 +0300 Subject: [PATCH] Tree tune grow --- CMakeLists.txt | 11 ++- src/content_abm_grow_tree.cpp | 132 +++++++++++++++++++--------------- util/autotest/auto.pl | 2 +- 3 files changed, 86 insertions(+), 59 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1273d41b0..e5e812ba9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -117,8 +117,15 @@ endif() MESSAGE(STATUS "Build type: ${CMAKE_BUILD_TYPE}") -if (NOT NO_LTO AND (CMAKE_BUILD_TYPE STREQUAL "Release" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")) # AND NOT CMAKE_SYSTEM_NAME STREQUAL "Emscripten" - # include(CheckIPOSupported) + +if(NOT NO_LTO AND NOT DEVELOPMENT_BUILD AND(CMAKE_BUILD_TYPE STREQUAL "Release" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")) + option(USE_LTO "Use LTO" ON) +else() + option(USE_LTO "Use LTO" OFF) +endif() + +if (USE_LTO) + # include(CheckIPOSupported) # check_ipo_supported(RESULT supported OUTPUT error) set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE) message(STATUS "Using lto") diff --git a/src/content_abm_grow_tree.cpp b/src/content_abm_grow_tree.cpp index 2a2b3b782..a71a5718e 100644 --- a/src/content_abm_grow_tree.cpp +++ b/src/content_abm_grow_tree.cpp @@ -445,13 +445,13 @@ class GrowTree : public ActiveBlockModifier nb.is_liquid || nb.is_soil || nb.cf->groups.contains("sand"))) return false; - if (nb.top && nb.content == CONTENT_AIR) - return false; - - if (nb.top && nb.is_any_leaves) { - if (nb.light < params.leaves_grow_light_min) + if (nb.top) { + if (nb.content == CONTENT_AIR && + nb.light > params.leaves_grow_light_min) return false; + //if (nb.is_any_leaves) return false; + if (!(allow_grow_by_light || up_all_leaves)) return false; } @@ -482,44 +482,55 @@ class GrowTree : public ActiveBlockModifier if (tree_grow()) break; - if ((((!nb.top || nb.is_other_tree) && !nb.bottom && nb.is_tree && - !around_all_is_tree) || - nb.is_my_leaves)) { + auto water_pump = [&]() { + if (!(((!nb.top || nb.is_other_tree) && !nb.bottom && nb.is_tree && + !around_all_is_tree) || + nb.is_my_leaves)) + return false; + + if (nb.side && nb.is_tree && self_allow_grow_by_rotation) + // DUMP("skip tr side pump", water_level, nb.is_tree, allow_grow_up_by_rotation), + return false; + + // DUMP(nb.node, self_water_level, water_level); + //??if (is_tree && dir_allow_grow_up_by_rotation && n_water_level >= params.tree_water_max) continue; + + if (!(!nb.is_my_leaves || + (nb.is_my_leaves && (nb.top || !self_allow_grow_by_rotation || + (!nb.top && top_is_not_tree))))) + return false; + auto water_level = nb.content == leaves_content ? get_leaves_water_level(nb.node) : get_tree_water_level(nb.node); //DUMP(water_level, nb.is_leaves, allow_grow_up_by_rotation, nb.top, top_is_not_tree); - if (!nb.is_my_leaves || - (nb.is_my_leaves && (nb.top || !self_allow_grow_by_rotation || - (!nb.top && top_is_not_tree)))) - - if (water_level < (nb.is_my_leaves ? params.leaves_water_max - : params.tree_water_max) && - self_water_level > water_level + (nb.top ? 1 : 0) - /* !!! + + if (water_level >= (nb.is_my_leaves ? params.leaves_water_max + : params.tree_water_max)) + return false; + + if (self_water_level <= water_level + (nb.top ? 2 : 1) + /* !!! n_water_level > wl_dir + (top ? -1 :bottom ? 1 : 0) */ - ) { - if (nb.side && nb.is_tree && self_allow_grow_by_rotation) { - // DUMP("skip tr side pump", water_level, nb.is_tree, allow_grow_up_by_rotation); - continue; - } - // DUMP(nb.node, self_water_level, water_level); - //??if (is_tree && dir_allow_grow_up_by_rotation && n_water_level >= params.tree_water_max) continue; - - if (!decrease(self_water_level)) { - // if (grow_debug) DUMP("pumpfail", n_water_level, n_water_level_orig, wl_dir, top, bottom, c_dir, c); - break; - } - //if (grow_debug)DUMP("tr pump", pos.Y, self_water_level,self_water_level_orig, water_level, nb.top,nb.bottom, nb.content, content); - ++water_level; - nb.is_my_leaves ? set_leaves_water_level(nb.node, water_level) - : set_tree_water_level(nb.node, water_level); - - map->setNode(nb.pos, nb.node); - } - } + ) + return false; + + if (!decrease(self_water_level)) { + // if (grow_debug) DUMP("pumpfail", n_water_level, n_water_level_orig, wl_dir, top, bottom, c_dir, c); + return true; + } + //if (grow_debug)DUMP("tr pump", pos.Y, self_water_level,self_water_level_orig, water_level, nb.top,nb.bottom, nb.content, content); + ++water_level; + nb.is_my_leaves ? set_leaves_water_level(nb.node, water_level) + : set_tree_water_level(nb.node, water_level); + + map->setNode(nb.pos, nb.node); + return true; + }; + if (water_pump()) + break; // Dont grow after top //if ((nb.top && nb.is_my_leaves) || nb.content == content) { @@ -527,29 +538,38 @@ class GrowTree : public ActiveBlockModifier //} //DUMP(allow_grow_leaves, leaves_c, heat , params.leaves_grow_heat_min, params.leaves_grow_heat_max, n_water_level, light_dir); - if ( - //allow_grow_leaves - (nb.allow_grow_by_rotation && nbh[D_TOP].content != content) && - leaves_content != CONTENT_IGNORE && - heat >= params.leaves_grow_heat_min && - heat <= params.leaves_grow_heat_max && - (self_water_level >= (nb.top ? params.leaves_grow_water_min_top - : params.leaves_grow_water_min_side)) && - // can_grow_leaves(n_water_level, top, bottom) && - nb.light >= params.leaves_grow_light_min) { - if (nb.cf->buildable_to && !nb.is_liquid) { - if (!decrease(self_water_level)) - break; - //if (grow_debug)DUMP("tr->lv", nb.pos, self_water_level, self_water_level_orig,nb.light_dir); - map->setNode(nb.pos, {leaves_content, nb.node.param1, 1}); + auto leaves_grow = [&]() { + if (!nb.allow_grow_by_rotation) + return false; + if (nbh[D_TOP].content == content) // TODO not top, by grow direction + return false; + if (leaves_content == CONTENT_IGNORE) + return false; + if (!(heat >= params.leaves_grow_heat_min && + heat <= params.leaves_grow_heat_max)) + return false; + if (!(self_water_level >= (nb.top ? params.leaves_grow_water_min_top + : params.leaves_grow_water_min_side))) + return false; + if (nb.light < params.leaves_grow_light_min) + return false; + if (!nb.cf->buildable_to || nb.is_liquid) + return false; + if (!decrease(self_water_level)) + return true; + //if (grow_debug)DUMP("tr->lv", nb.pos, self_water_level, self_water_level_orig,nb.light_dir); - if (const auto block = map->getBlock(getNodeBlockPos(nb.pos)); - block) { - block->setLightingExpired(true); - } + map->setNode(nb.pos, {leaves_content, nb.node.param1, 1}); + + if (const auto block = map->getBlock(getNodeBlockPos(nb.pos)); block) { + block->setLightingExpired(true); } - } + return true; + }; + + if (leaves_grow()) + break; } // up-down distribute of rest diff --git a/util/autotest/auto.pl b/util/autotest/auto.pl index 5cd4711c4..510832e5a 100755 --- a/util/autotest/auto.pl +++ b/util/autotest/auto.pl @@ -376,7 +376,7 @@ () $D{USE_LIBCXX} = $config->{cmake_libcxx} if defined $config->{cmake_libcxx}; $D{USE_TOUCHSCREENGUI} = $config->{cmake_touchscreen} if defined $config->{cmake_touchscreen}; $D{USE_GPERF} = $config->{cmake_gperf} if defined $config->{cmake_gperf}; - $D{NO_LTO} = $config->{cmake_no_lto} // 1; + $D{USE_LTO} = $config->{cmake_lto} if defined $config->{cmake_lto}; $D{EXCEPTION_DEBUG} = $config->{cmake_exception_debug} if defined $config->{cmake_exception_debug}; $D{USE_DEBUG_HELPERS} = 1;