]> git.lizzy.rs Git - minetest.git/blobdiff - src/treegen.cpp
Add clouds API
[minetest.git] / src / treegen.cpp
index a85d88815357ba55d5917b380ad81261ea32f7a8..8bf9619a0eba836b9db3e708b6bbdab07321423e 100644 (file)
@@ -21,17 +21,17 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include <stack>
 #include "util/pointer.h"
 #include "util/numeric.h"
-#include "util/mathconstants.h"
 #include "map.h"
-#include "environment.h"
+#include "serverenvironment.h"
 #include "nodedef.h"
 #include "treegen.h"
+#include "voxelalgorithms.h"
 
 namespace treegen
 {
 
 void make_tree(MMVManip &vmanip, v3s16 p0,
-               bool is_apple_tree, INodeDefManager *ndef, int seed)
+               bool is_apple_tree, INodeDefManager *ndef, s32 seed)
 {
        /*
                NOTE: Tree-placing code is currently duplicated in the engine
@@ -113,7 +113,7 @@ void make_tree(MMVManip &vmanip, v3s16 p0,
 
 // L-System tree LUA spawner
 treegen::error spawn_ltree(ServerEnvironment *env, v3s16 p0,
-               INodeDefManager *ndef, TreeDef tree_definition)
+               INodeDefManager *ndef, const TreeDef &tree_definition)
 {
        ServerMap *map = &env->getServerMap();
        std::map<v3s16, MapBlock*> modified_blocks;
@@ -126,12 +126,8 @@ treegen::error spawn_ltree(ServerEnvironment *env, v3s16 p0,
        if (e != SUCCESS)
                return e;
 
-       vmanip.blitBackAll(&modified_blocks);
+       voxalgo::blit_back_with_light(map, &vmanip, &modified_blocks);
 
-       // update lighting
-       std::map<v3s16, MapBlock*> lighting_modified_blocks;
-       lighting_modified_blocks.insert(modified_blocks.begin(), modified_blocks.end());
-       map->updateLighting(lighting_modified_blocks, modified_blocks);
        // Send a MEET_OTHER event
        MapEditEvent event;
        event.type = MEET_OTHER;
@@ -149,7 +145,7 @@ treegen::error make_ltree(MMVManip &vmanip, v3s16 p0,
                INodeDefManager *ndef, TreeDef tree_definition)
 {
        MapNode dirtnode(ndef->getId("mapgen_dirt"));
-       int seed;
+       s32 seed;
        if (tree_definition.explicit_seed)
                seed = tree_definition.seed + 14002;
        else
@@ -649,15 +645,22 @@ v3f transposeMatrix(irr::core::matrix4 M, v3f v)
 }
 
 
-void make_jungletree(MMVManip &vmanip, v3s16 p0, INodeDefManager *ndef, int seed)
+void make_jungletree(MMVManip &vmanip, v3s16 p0, INodeDefManager *ndef, s32 seed)
 {
        /*
                NOTE: Tree-placing code is currently duplicated in the engine
                and in games that have saplings; both are deprecated but not
                replaced yet
        */
-       MapNode treenode(ndef->getId("mapgen_jungletree"));
-       MapNode leavesnode(ndef->getId("mapgen_jungleleaves"));
+       content_t c_tree   = ndef->getId("mapgen_jungletree");
+       content_t c_leaves = ndef->getId("mapgen_jungleleaves");
+       if (c_tree == CONTENT_IGNORE)
+               c_tree = ndef->getId("mapgen_tree");
+       if (c_leaves == CONTENT_IGNORE)
+               c_leaves = ndef->getId("mapgen_leaves");
+
+       MapNode treenode(c_tree);
+       MapNode leavesnode(c_leaves);
 
        PseudoRandom pr(seed);
        for (s16 x= -1; x <= 1; x++)
@@ -741,21 +744,31 @@ void make_jungletree(MMVManip &vmanip, v3s16 p0, INodeDefManager *ndef, int seed
 }
 
 
-void make_pine_tree(MMVManip &vmanip, v3s16 p0, INodeDefManager *ndef, int seed)
+void make_pine_tree(MMVManip &vmanip, v3s16 p0, INodeDefManager *ndef, s32 seed)
 {
        /*
                NOTE: Tree-placing code is currently duplicated in the engine
                and in games that have saplings; both are deprecated but not
                replaced yet
        */
-       MapNode treenode(ndef->getId("mapgen_pinetree"));
-       MapNode leavesnode(ndef->getId("mapgen_pine_needles"));
-       MapNode snownode(ndef->getId("mapgen_snow"));
+       content_t c_tree   = ndef->getId("mapgen_pine_tree");
+       content_t c_leaves = ndef->getId("mapgen_pine_needles");
+       content_t c_snow = ndef->getId("mapgen_snow");
+       if (c_tree == CONTENT_IGNORE)
+               c_tree = ndef->getId("mapgen_tree");
+       if (c_leaves == CONTENT_IGNORE)
+               c_leaves = ndef->getId("mapgen_leaves");
+       if (c_snow == CONTENT_IGNORE)
+               c_snow = CONTENT_AIR;
+
+       MapNode treenode(c_tree);
+       MapNode leavesnode(c_leaves);
+       MapNode snownode(c_snow);
 
        PseudoRandom pr(seed);
-       s16 trunk_h = pr.range(9, 13);
+       u16 trunk_h = pr.range(9, 13);
        v3s16 p1 = p0;
-       for (s16 ii = 0; ii < trunk_h; ii++) {
+       for (u16 ii = 0; ii < trunk_h; ii++) {
                if (vmanip.m_area.contains(p1)) {
                        u32 vi = vmanip.m_area.index(p1);
                        vmanip.m_data[vi] = treenode;
@@ -773,7 +786,7 @@ void make_pine_tree(MMVManip &vmanip, v3s16 p0, INodeDefManager *ndef, int seed)
                leaves_d[i] = 0;
 
        // Upper branches
-       s16 dev = 3;
+       u16 dev = 3;
        for (s16 yy = -1; yy <= 1; yy++) {
                for (s16 zz = -dev; zz <= dev; zz++) {
                        u32 i = leaves_a.index(v3s16(-dev, yy, zz));