mirror of
https://github.com/luanti-org/luanti.git
synced 2025-09-15 18:57:08 +00:00
Add L-system trees as decorations (#14355)
This commit is contained in:
parent
f07e1026ac
commit
60810c2d37
10 changed files with 125 additions and 46 deletions
|
@ -27,6 +27,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
#include "util/numeric.h"
|
||||
#include <algorithm>
|
||||
#include <vector>
|
||||
#include "mapgen/treegen.h"
|
||||
|
||||
|
||||
FlagDesc flagdesc_deco[] = {
|
||||
|
@ -472,3 +473,24 @@ size_t DecoSchematic::generate(MMVManip *vm, PcgRandom *pr, v3s16 p, bool ceilin
|
|||
|
||||
return 1;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
ObjDef *DecoLSystem::clone() const
|
||||
{
|
||||
auto def = new DecoLSystem();
|
||||
Decoration::cloneTo(def);
|
||||
|
||||
def->tree_def = tree_def;
|
||||
return def;
|
||||
}
|
||||
|
||||
|
||||
size_t DecoLSystem::generate(MMVManip *vm, PcgRandom *pr, v3s16 p, bool ceiling)
|
||||
{
|
||||
if (!canPlaceDecoration(vm, p))
|
||||
return 0;
|
||||
|
||||
// Make sure that tree_def can't be modified, since it is shared.
|
||||
const auto &ref = *tree_def;
|
||||
return treegen::make_ltree(*vm, p, m_ndef, ref);
|
||||
}
|
||||
|
|
|
@ -31,6 +31,7 @@ class Mapgen;
|
|||
class MMVManip;
|
||||
class PcgRandom;
|
||||
class Schematic;
|
||||
namespace treegen { struct TreeDef; }
|
||||
|
||||
enum DecorationType {
|
||||
DECO_SIMPLE,
|
||||
|
@ -112,12 +113,15 @@ public:
|
|||
};
|
||||
|
||||
|
||||
/*
|
||||
class DecoLSystem : public Decoration {
|
||||
public:
|
||||
virtual void generate(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax);
|
||||
ObjDef *clone() const;
|
||||
|
||||
virtual size_t generate(MMVManip *vm, PcgRandom *pr, v3s16 p, bool ceiling);
|
||||
|
||||
// In case it gets cloned it uses the same tree def.
|
||||
std::shared_ptr<treegen::TreeDef> tree_def;
|
||||
};
|
||||
*/
|
||||
|
||||
|
||||
class DecorationManager : public ObjDefManager {
|
||||
|
@ -139,8 +143,8 @@ public:
|
|||
return new DecoSimple;
|
||||
case DECO_SCHEMATIC:
|
||||
return new DecoSchematic;
|
||||
//case DECO_LSYSTEM:
|
||||
// return new DecoLSystem;
|
||||
case DECO_LSYSTEM:
|
||||
return new DecoLSystem;
|
||||
default:
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
@ -32,6 +32,16 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
namespace treegen
|
||||
{
|
||||
|
||||
void TreeDef::resolveNodeNames()
|
||||
{
|
||||
getIdFromNrBacklog(&trunknode.param0, "", CONTENT_IGNORE);
|
||||
getIdFromNrBacklog(&leavesnode.param0, "", CONTENT_IGNORE);
|
||||
if (leaves2_chance)
|
||||
getIdFromNrBacklog(&leaves2node.param0, "", CONTENT_IGNORE);
|
||||
if (fruit_chance)
|
||||
getIdFromNrBacklog(&fruitnode.param0, "", CONTENT_IGNORE);
|
||||
}
|
||||
|
||||
void make_tree(MMVManip &vmanip, v3s16 p0, bool is_apple_tree,
|
||||
const NodeDefManager *ndef, s32 seed)
|
||||
{
|
||||
|
|
|
@ -35,7 +35,9 @@ namespace treegen {
|
|||
UNBALANCED_BRACKETS
|
||||
};
|
||||
|
||||
struct TreeDef {
|
||||
struct TreeDef : public NodeResolver {
|
||||
virtual void resolveNodeNames();
|
||||
|
||||
std::string initial_axiom;
|
||||
std::string rules_a;
|
||||
std::string rules_b;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue