mercator  0.4.0
A terrain generation library for the Worldforge system.
Mercator::Forest Class Reference

This is the core class for any area to be populated with vegetation. More...

#include <Forest.h>

Public Types

typedef std::map< int, PlantPlantColumn
 STL map to store a sparse array of Plant objects. More...
 
typedef std::map< int, PlantColumnPlantStore
 STL map to store a sparse array of PlantColumn objects. More...
 
typedef std::vector< SpeciesPlantSpecies
 STL vector of plant species in this forest. More...
 

Public Member Functions

 Forest (unsigned long seed=0)
 Construct a new forest with the given seed. More...
 
 ~Forest ()
 Destruct a forest. More...
 
AreagetArea () const
 Accessor for polygonal area. More...
 
PlantSpeciesspecies ()
 Accessor for list of species in this forest. More...
 
const PlantStoregetPlants () const
 Accessor for container of vegetation. More...
 
void setArea (Area *a)
 Assign an area to this forest. More...
 
void populate ()
 This function uses a pseudo-random technique to populate the forest with trees. This algorithm as the following essental properties: More...
 

Detailed Description

This is the core class for any area to be populated with vegetation.

Each instance of vegetation is represented by the Plant class, and are stored in a 2 dimensional mapping container, which allows the entire contents to be iterated, or a given square two dimenstional area to be examined using the STL map API.

Definition at line 57 of file Forest.h.

Member Typedef Documentation

◆ PlantColumn

typedef std::map<int, Plant> Mercator::Forest::PlantColumn

STL map to store a sparse array of Plant objects.

Integer key is effectively used as an index.

Definition at line 62 of file Forest.h.

◆ PlantSpecies

STL vector of plant species in this forest.

Definition at line 71 of file Forest.h.

◆ PlantStore

typedef std::map<int, PlantColumn> Mercator::Forest::PlantStore

STL map to store a sparse array of PlantColumn objects.

The end effect is a sparse two dimensional array of plant objects which can be efficiently queried and scanned using STL iterators.

Definition at line 68 of file Forest.h.

Constructor & Destructor Documentation

◆ Forest()

Mercator::Forest::Forest ( unsigned long  seed = 0)
explicit

Construct a new forest with the given seed.

Definition at line 24 of file Forest.cpp.

◆ ~Forest()

Mercator::Forest::~Forest ( )
default

Destruct a forest.

All contained vegetation is lost, so references to contained vegetation must not be maintained if this is likely to occur.

Member Function Documentation

◆ getArea()

Area* Mercator::Forest::getArea ( ) const
inline

Accessor for polygonal area.

Definition at line 91 of file Forest.h.

◆ getPlants()

const PlantStore& Mercator::Forest::getPlants ( ) const
inline

Accessor for container of vegetation.

Returns
A const reference to the container.

Definition at line 102 of file Forest.h.

◆ populate()

void Mercator::Forest::populate ( )

This function uses a pseudo-random technique to populate the forest with trees. This algorithm as the following essental properties:

  • It is repeatable. It can be repeated on the client and the server, and give identical results.
  • It is location independent. It gives the same results even if the forest is in a different place.
  • It is shape and size independent. A given area of the forest is the same even if the borders of the forest change.
  • It is localizable. It is possible to only partially populate the the forest, and still get the same results in that area.

This function will have no effect if the area defining the forest remains uninitialised. Any previously generated contents are erased. For each instance a new seed is used to ensure it is repeatable, and height, displacement and orientation are calculated.

Definition at line 67 of file Forest.cpp.

References Mercator::Effector::bbox(), Mercator::Area::contains(), Mercator::Plant::m_displacement, Mercator::Plant::m_orientation, and species().

◆ setArea()

void Mercator::Forest::setArea ( Area a)

Assign an area to this forest.

Definition at line 38 of file Forest.cpp.

◆ species()

PlantSpecies& Mercator::Forest::species ( )
inline

Accessor for list of species in this forest.

Definition at line 96 of file Forest.h.

Referenced by populate().


The documentation for this class was generated from the following files: