1
0
Fork 0
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:
cx384 2024-03-12 20:10:28 +01:00 committed by GitHub
parent f07e1026ac
commit 60810c2d37
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 125 additions and 46 deletions

View file

@ -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);
}

View file

@ -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;
}

View file

@ -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)
{

View file

@ -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;