API to reset the shared tree geometry

This commit is contained in:
James Turner 2020-08-14 15:40:47 +01:00 committed by Automatic Release Builder
parent 672afdbc34
commit 6167159795
2 changed files with 36 additions and 15 deletions

View File

@ -151,14 +151,26 @@ Geometry* makeSharedTreeGeometry(int numQuads)
return result;
}
ref_ptr<Geometry> sharedTreeGeometry;
static std::mutex static_sharedGeometryMutex;
static ref_ptr<Geometry> sharedTreeGeometry;
void clearSharedTreeGeometry()
{
std::lock_guard<std::mutex> g(static_sharedGeometryMutex);
sharedTreeGeometry = {};
}
Geometry* createTreeGeometry(float width, float height, int varieties)
{
Geometry* quadGeom = nullptr;
{
std::lock_guard<std::mutex> g(static_sharedGeometryMutex);
if (!sharedTreeGeometry)
sharedTreeGeometry = makeSharedTreeGeometry(1600);
Geometry* quadGeom = simgear::clone(sharedTreeGeometry.get(),
quadGeom = simgear::clone(sharedTreeGeometry.get(),
CopyOp::SHALLOW_COPY);
}
Vec3Array* params = new Vec3Array;
params->push_back(Vec3(width, height, (float)varieties));
quadGeom->setNormalArray(params);

View File

@ -35,11 +35,14 @@ namespace simgear
{
class TreeBin {
public:
~TreeBin() = default;
struct Tree {
SGVec3f position;
SGVec3f tnormal;
Tree(const SGVec3f& p, const SGVec3f& t) : position(p),tnormal(t)
{ }
Tree(const SGVec3f& p, const SGVec3f& t) : position(p), tnormal(t)
{
}
};
typedef std::vector<Tree> TreeList;
@ -55,19 +58,25 @@ public:
{ _trees.push_back(t); }
void insert(const SGVec3f& p, const SGVec3f& tnorm)
{insert(Tree(p,tnorm));}
{
_trees.emplace_back(p, tnorm);
}
unsigned getNumTrees() const
{ return _trees.size(); }
const Tree& getTree(unsigned i) const
{ return _trees[i]; }
{
assert(i < _trees.size());
return _trees.at(i);
}
TreeList _trees;
~TreeBin() {
_trees.clear();
}
};
void clearSharedTreeGeometry();
typedef std::list<TreeBin*> SGTreeBinList;
osg::Group* createForest(SGTreeBinList& forestList, const osg::Matrix& transform,