Fixed vegetation definition, due to layers refactoring in master

This commit is contained in:
Michaël Lemaire 2015-11-20 01:16:48 +01:00
parent 8cf2881a73
commit 01992a0019
6 changed files with 13 additions and 12 deletions

View file

@ -119,7 +119,7 @@ bool Layers::applyDiff(const DefinitionDiff *diff, bool backward) {
void Layers::generateInitDiffs(std::vector<const DefinitionDiff *> *diffs) const {
int i = 0;
for (auto layer: layers) {
for (auto layer : layers) {
auto diff = new LayersDiff(this, LayersDiff::LAYER_ADDED, i++);
diff->saveLayer(*layer);
diffs->push_back(diff);

View file

@ -3,8 +3,8 @@
#include "VegetationLayerDefinition.h"
#include "VegetationModelDefinition.h"
static DefinitionNode *_layer_constructor(Layers *parent) {
return new VegetationLayerDefinition(parent);
static DefinitionNode *_layer_constructor(Layers *parent, const std::string &name) {
return new VegetationLayerDefinition(parent, name);
}
VegetationDefinition::VegetationDefinition(DefinitionNode *parent) : Layers(parent, "vegetation", _layer_constructor) {
@ -12,7 +12,7 @@ VegetationDefinition::VegetationDefinition(DefinitionNode *parent) : Layers(pare
double VegetationDefinition::getMaxHeight() const {
double max_height = 0.0;
int n = count();
int n = getLayerCount();
for (int i = 0; i < n; i++) {
double layer_height = getVegetationLayer(i)->getMaxHeight();
@ -25,13 +25,13 @@ double VegetationDefinition::getMaxHeight() const {
}
void VegetationDefinition::applyPreset(VegetationPreset preset) {
VegetationLayerDefinition *layer;
VegetationLayerDefinition layer(this, "temp");
clear();
if (preset == VEGETATION_PRESET_TEMPERATE) {
layer = getVegetationLayer(addLayer());
layer->applyPreset(VegetationLayerDefinition::VEGETATION_BASIC_TREES);
layer->setName("Basic tree");
layer.applyPreset(VegetationLayerDefinition::VEGETATION_BASIC_TREES);
layer.setName("Basic tree");
addLayer(layer);
}
}

View file

@ -3,7 +3,8 @@
#include "VegetationModelDefinition.h"
#include "VegetationPresenceDefinition.h"
VegetationLayerDefinition::VegetationLayerDefinition(DefinitionNode *parent) : DefinitionNode(parent, "layer") {
VegetationLayerDefinition::VegetationLayerDefinition(DefinitionNode *parent, const std::string &name)
: DefinitionNode(parent, name, "vegetationlayer") {
model = new VegetationModelDefinition(this);
presence = new VegetationPresenceDefinition(this);
}

View file

@ -13,7 +13,7 @@ namespace definition {
*/
class DEFINITIONSHARED_EXPORT VegetationLayerDefinition : public DefinitionNode {
public:
VegetationLayerDefinition(DefinitionNode *parent);
VegetationLayerDefinition(DefinitionNode *parent, const std::string &name);
inline const VegetationPresenceDefinition *getPresence() const {
return presence;

View file

@ -103,7 +103,7 @@ RayCastingResult VegetationRenderer::getBoundResult(const SpaceSegment &segment,
}
// Iterate all layers and instances
int n = vegetation->count();
int n = vegetation->getLayerCount();
for (int i = 0; i < n; i++) {
VegetationLayerDefinition *layer = vegetation->getVegetationLayer(i);

View file

@ -186,7 +186,7 @@ TEST(Layers, generateInitDiffs) {
EXPECT_EQ(3, (int)diffs.size());
Layers layers1(NULL, "layers", _construc1);
for (auto diff: diffs) {
for (auto diff : diffs) {
layers1.applyDiff(diff);
}
ASSERT_EQ(3, layers1.getLayerCount());