From 42d3ae4ceb8be1b04c48fe4da7c103a1ac720dce Mon Sep 17 00:00:00 2001 From: Michael Lemaire Date: Wed, 12 Aug 2015 22:21:10 +0200 Subject: [PATCH] Renamed BaseDefinition to DefinitionNode --- src/definition/AtmosphereDefinition.cpp | 6 ++-- src/definition/AtmosphereDefinition.h | 8 ++--- src/definition/CameraDefinition.cpp | 6 ++-- src/definition/CameraDefinition.h | 8 ++--- src/definition/CloudLayerDefinition.cpp | 16 ++++----- src/definition/CloudLayerDefinition.h | 12 +++---- src/definition/CloudsDefinition.cpp | 4 +-- src/definition/CloudsDefinition.h | 2 +- ...{BaseDefinition.cpp => DefinitionNode.cpp} | 28 +++++++-------- .../{BaseDefinition.h => DefinitionNode.h} | 30 ++++++++-------- src/definition/Layers.cpp | 24 ++++++------- src/definition/Layers.h | 24 ++++++------- src/definition/PaintedGrid.cpp | 6 ++-- src/definition/PaintedGrid.h | 8 ++--- src/definition/Scenery.cpp | 6 ++-- src/definition/Scenery.h | 6 ++-- src/definition/TerrainDefinition.cpp | 10 +++--- src/definition/TerrainDefinition.h | 8 ++--- src/definition/TerrainHeightMap.cpp | 2 +- src/definition/TerrainHeightMap.h | 2 +- src/definition/TextureLayerDefinition.cpp | 14 ++++---- src/definition/TextureLayerDefinition.h | 8 ++--- src/definition/TexturesDefinition.cpp | 4 +-- src/definition/TexturesDefinition.h | 2 +- src/definition/WaterDefinition.cpp | 14 ++++---- src/definition/WaterDefinition.h | 8 ++--- src/definition/Zone.cpp | 6 ++-- src/definition/Zone.h | 8 ++--- src/definition/definition.pro | 8 ++--- src/definition/definition_global.h | 2 +- src/tests/BaseDefinition_Test.cpp | 35 ------------------- src/tests/DefinitionNode_Test.cpp | 35 +++++++++++++++++++ src/tests/Layers_Test.cpp | 12 +++---- src/tests/tests.pro | 2 +- 34 files changed, 187 insertions(+), 187 deletions(-) rename src/definition/{BaseDefinition.cpp => DefinitionNode.cpp} (72%) rename src/definition/{BaseDefinition.h => DefinitionNode.h} (50%) delete mode 100644 src/tests/BaseDefinition_Test.cpp create mode 100644 src/tests/DefinitionNode_Test.cpp diff --git a/src/definition/AtmosphereDefinition.cpp b/src/definition/AtmosphereDefinition.cpp index b760ca8..b3e11ba 100644 --- a/src/definition/AtmosphereDefinition.cpp +++ b/src/definition/AtmosphereDefinition.cpp @@ -3,8 +3,8 @@ #include "PackStream.h" #include "RandomGenerator.h" -AtmosphereDefinition::AtmosphereDefinition(BaseDefinition* parent): - BaseDefinition(parent, "atmosphere") +AtmosphereDefinition::AtmosphereDefinition(DefinitionNode* parent): + DefinitionNode(parent, "atmosphere") { } @@ -64,7 +64,7 @@ void AtmosphereDefinition::load(PackStream* stream) validate(); } -void AtmosphereDefinition::copy(BaseDefinition* _destination) const +void AtmosphereDefinition::copy(DefinitionNode* _destination) const { AtmosphereDefinition* destination = (AtmosphereDefinition*)_destination; diff --git a/src/definition/AtmosphereDefinition.h b/src/definition/AtmosphereDefinition.h index 0fbfa92..1d384ef 100644 --- a/src/definition/AtmosphereDefinition.h +++ b/src/definition/AtmosphereDefinition.h @@ -3,7 +3,7 @@ #include "definition_global.h" -#include "BaseDefinition.h" +#include "DefinitionNode.h" #include "Vector3.h" #include "Color.h" @@ -11,7 +11,7 @@ namespace paysages { namespace definition { -class DEFINITIONSHARED_EXPORT AtmosphereDefinition : public BaseDefinition +class DEFINITIONSHARED_EXPORT AtmosphereDefinition : public DefinitionNode { public: typedef struct @@ -37,13 +37,13 @@ public: } AtmospherePreset; public: - AtmosphereDefinition(BaseDefinition* parent); + AtmosphereDefinition(DefinitionNode* parent); virtual ~AtmosphereDefinition(); virtual void save(PackStream* stream) const override; virtual void load(PackStream* stream) override; - virtual void copy(BaseDefinition* destination) const override; + virtual void copy(DefinitionNode* destination) const override; virtual void validate() override; /** diff --git a/src/definition/CameraDefinition.cpp b/src/definition/CameraDefinition.cpp index 1d9ca31..661fc9a 100644 --- a/src/definition/CameraDefinition.cpp +++ b/src/definition/CameraDefinition.cpp @@ -4,8 +4,8 @@ #include "PackStream.h" #include "BoundingBox.h" -CameraDefinition::CameraDefinition(BaseDefinition *parent): - BaseDefinition(parent, "camera") +CameraDefinition::CameraDefinition(DefinitionNode *parent): + DefinitionNode(parent, "camera") { location.x = 0.0; location.y = 0.0; @@ -47,7 +47,7 @@ void CameraDefinition::load(PackStream* stream) validate(); } -void CameraDefinition::copy(BaseDefinition* _destination) const +void CameraDefinition::copy(DefinitionNode* _destination) const { CameraDefinition* destination = (CameraDefinition*)_destination; diff --git a/src/definition/CameraDefinition.h b/src/definition/CameraDefinition.h index 9d928e2..f93fd55 100644 --- a/src/definition/CameraDefinition.h +++ b/src/definition/CameraDefinition.h @@ -3,7 +3,7 @@ #include "definition_global.h" -#include "BaseDefinition.h" +#include "DefinitionNode.h" #include "Vector3.h" #include "Matrix4.h" @@ -19,15 +19,15 @@ typedef struct double zfar; } CameraPerspective; -class DEFINITIONSHARED_EXPORT CameraDefinition: public BaseDefinition +class DEFINITIONSHARED_EXPORT CameraDefinition: public DefinitionNode { public: - CameraDefinition(BaseDefinition *parent = NULL); + CameraDefinition(DefinitionNode *parent = NULL); virtual void save(PackStream* pack) const override; virtual void load(PackStream* pack) override; - virtual void copy(BaseDefinition* destination) const override; + virtual void copy(DefinitionNode* destination) const override; virtual void validate() override; inline Vector3 getLocation() const {return location;} diff --git a/src/definition/CloudLayerDefinition.cpp b/src/definition/CloudLayerDefinition.cpp index 23922bd..f19e23e 100644 --- a/src/definition/CloudLayerDefinition.cpp +++ b/src/definition/CloudLayerDefinition.cpp @@ -5,8 +5,8 @@ #include "SurfaceMaterial.h" #include "PackStream.h" -CloudLayerDefinition::CloudLayerDefinition(BaseDefinition* parent): - BaseDefinition(parent, "layer") +CloudLayerDefinition::CloudLayerDefinition(DefinitionNode* parent): + DefinitionNode(parent, "layer") { type = CIRRUS; altitude = 0.5; @@ -18,14 +18,14 @@ CloudLayerDefinition::~CloudLayerDefinition() { } -CloudLayerDefinition* CloudLayerDefinition::newCopy(const CloudLayerDefinition& other, BaseDefinition* parent) +CloudLayerDefinition* CloudLayerDefinition::newCopy(const CloudLayerDefinition& other, DefinitionNode* parent) { CloudLayerDefinition* layer = new CloudLayerDefinition(parent); other.copy(layer); return layer; } -CloudLayerDefinition* CloudLayerDefinition::newCopy(BaseDefinition* parent) const +CloudLayerDefinition* CloudLayerDefinition::newCopy(DefinitionNode* parent) const { CloudLayerDefinition* layer = new CloudLayerDefinition(parent); copy(layer); @@ -34,7 +34,7 @@ CloudLayerDefinition* CloudLayerDefinition::newCopy(BaseDefinition* parent) cons void CloudLayerDefinition::save(PackStream* stream) const { - BaseDefinition::save(stream); + DefinitionNode::save(stream); int clouds_type = (int)type; @@ -48,7 +48,7 @@ void CloudLayerDefinition::save(PackStream* stream) const void CloudLayerDefinition::load(PackStream* stream) { - BaseDefinition::load(stream); + DefinitionNode::load(stream); int clouds_type; @@ -63,9 +63,9 @@ void CloudLayerDefinition::load(PackStream* stream) validate(); } -void CloudLayerDefinition::copy(BaseDefinition* _destination) const +void CloudLayerDefinition::copy(DefinitionNode* _destination) const { - BaseDefinition::copy(_destination); + DefinitionNode::copy(_destination); CloudLayerDefinition* destination = (CloudLayerDefinition*)_destination; diff --git a/src/definition/CloudLayerDefinition.h b/src/definition/CloudLayerDefinition.h index 593738a..c31f5c5 100644 --- a/src/definition/CloudLayerDefinition.h +++ b/src/definition/CloudLayerDefinition.h @@ -3,28 +3,28 @@ #include "definition_global.h" -#include "BaseDefinition.h" +#include "DefinitionNode.h" #include "NoiseState.h" namespace paysages { namespace definition { -class DEFINITIONSHARED_EXPORT CloudLayerDefinition : public BaseDefinition +class DEFINITIONSHARED_EXPORT CloudLayerDefinition : public DefinitionNode { public: - CloudLayerDefinition(BaseDefinition* parent); + CloudLayerDefinition(DefinitionNode* parent); virtual ~CloudLayerDefinition(); inline const NoiseState &getNoiseState() const {return noise_state;} - static CloudLayerDefinition* newCopy(const CloudLayerDefinition& other, BaseDefinition* parent); - CloudLayerDefinition* newCopy(BaseDefinition* parent) const; + static CloudLayerDefinition* newCopy(const CloudLayerDefinition& other, DefinitionNode* parent); + CloudLayerDefinition* newCopy(DefinitionNode* parent) const; virtual void save(PackStream* pack) const override; virtual void load(PackStream* pack) override; - virtual void copy(BaseDefinition* destination) const override; + virtual void copy(DefinitionNode* destination) const override; virtual void validate() override; public: diff --git a/src/definition/CloudsDefinition.cpp b/src/definition/CloudsDefinition.cpp index 9ccb67f..f17fc99 100644 --- a/src/definition/CloudsDefinition.cpp +++ b/src/definition/CloudsDefinition.cpp @@ -2,12 +2,12 @@ #include "CloudLayerDefinition.h" -static BaseDefinition* _layerConstructor(Layers* parent) +static DefinitionNode* _layerConstructor(Layers* parent) { return new CloudLayerDefinition(parent); } -CloudsDefinition::CloudsDefinition(BaseDefinition* parent): +CloudsDefinition::CloudsDefinition(DefinitionNode* parent): Layers(parent, "clouds", _layerConstructor) { } diff --git a/src/definition/CloudsDefinition.h b/src/definition/CloudsDefinition.h index f7a9ab4..f2305d1 100644 --- a/src/definition/CloudsDefinition.h +++ b/src/definition/CloudsDefinition.h @@ -11,7 +11,7 @@ namespace definition { class DEFINITIONSHARED_EXPORT CloudsDefinition : public Layers { public: - CloudsDefinition(BaseDefinition* parent); + CloudsDefinition(DefinitionNode* parent); inline CloudLayerDefinition* getCloudLayer(int position) const {return (CloudLayerDefinition*)getLayer(position);} diff --git a/src/definition/BaseDefinition.cpp b/src/definition/DefinitionNode.cpp similarity index 72% rename from src/definition/BaseDefinition.cpp rename to src/definition/DefinitionNode.cpp index 9a194cc..d196e38 100644 --- a/src/definition/BaseDefinition.cpp +++ b/src/definition/DefinitionNode.cpp @@ -1,8 +1,8 @@ -#include "BaseDefinition.h" +#include "DefinitionNode.h" #include "PackStream.h" -BaseDefinition::BaseDefinition(BaseDefinition* parent, const std::string &name): +DefinitionNode::DefinitionNode(DefinitionNode* parent, const std::string &name): parent(parent), name(name) { if (parent) @@ -16,7 +16,7 @@ BaseDefinition::BaseDefinition(BaseDefinition* parent, const std::string &name): } } -BaseDefinition::~BaseDefinition() +DefinitionNode::~DefinitionNode() { if (parent) { @@ -25,7 +25,7 @@ BaseDefinition::~BaseDefinition() } // Work on a copy, because the child destructor will modify the array by removing itself using removeChild - std::vector children_copy = children; + std::vector children_copy = children; for (auto child:children_copy) { if (child->getParent() == this) @@ -35,12 +35,12 @@ BaseDefinition::~BaseDefinition() } } -void BaseDefinition::setName(const std::string &name) +void DefinitionNode::setName(const std::string &name) { this->name = name; } -Scenery* BaseDefinition::getScenery() +Scenery* DefinitionNode::getScenery() { if (parent) { @@ -52,7 +52,7 @@ Scenery* BaseDefinition::getScenery() } } -std::string BaseDefinition::toString(int indent) const +std::string DefinitionNode::toString(int indent) const { std::string result; for (int i = 0; i < indent; i++) @@ -70,7 +70,7 @@ std::string BaseDefinition::toString(int indent) const return result; } -void BaseDefinition::save(PackStream* stream) const +void DefinitionNode::save(PackStream* stream) const { stream->write(name); for (auto child: children) @@ -79,7 +79,7 @@ void BaseDefinition::save(PackStream* stream) const } } -void BaseDefinition::load(PackStream* stream) +void DefinitionNode::load(PackStream* stream) { name = stream->readString(); for (auto child: children) @@ -88,13 +88,13 @@ void BaseDefinition::load(PackStream* stream) } } -void BaseDefinition::copy(BaseDefinition* destination) const +void DefinitionNode::copy(DefinitionNode* destination) const { destination->setName(name); // can't copy children as we don't know their types... } -void BaseDefinition::validate() +void DefinitionNode::validate() { for (auto child: children) { @@ -102,7 +102,7 @@ void BaseDefinition::validate() } } -void BaseDefinition::addChild(BaseDefinition* child) +void DefinitionNode::addChild(DefinitionNode* child) { if (std::find(children.begin(), children.end(), child) == children.end()) { @@ -112,9 +112,9 @@ void BaseDefinition::addChild(BaseDefinition* child) } } -void BaseDefinition::removeChild(BaseDefinition* child) +void DefinitionNode::removeChild(DefinitionNode* child) { - std::vector::iterator it = std::find(children.begin(), children.end(), child); + std::vector::iterator it = std::find(children.begin(), children.end(), child); if (it != children.end()) { child->parent = NULL; diff --git a/src/definition/BaseDefinition.h b/src/definition/DefinitionNode.h similarity index 50% rename from src/definition/BaseDefinition.h rename to src/definition/DefinitionNode.h index 7193709..bcf6ba5 100644 --- a/src/definition/BaseDefinition.h +++ b/src/definition/DefinitionNode.h @@ -1,5 +1,5 @@ -#ifndef BASEDEFINITION_H -#define BASEDEFINITION_H +#ifndef DEFINITIONNODE_H +#define DEFINITIONNODE_H #include "definition_global.h" @@ -7,18 +7,18 @@ namespace paysages { namespace definition { /** - * @brief Base class for all definition containers + * Base class for all nodes of the definition tree. */ -class DEFINITIONSHARED_EXPORT BaseDefinition +class DEFINITIONSHARED_EXPORT DefinitionNode { public: - BaseDefinition(BaseDefinition* parent, const std::string &name); - virtual ~BaseDefinition(); + DefinitionNode(DefinitionNode* parent, const std::string &name); + virtual ~DefinitionNode(); virtual void save(PackStream* stream) const; virtual void load(PackStream* stream); - virtual void copy(BaseDefinition* destination) const; + virtual void copy(DefinitionNode* destination) const; virtual void validate(); inline const std::string &getName() const {return name;} @@ -26,8 +26,8 @@ public: virtual Scenery* getScenery(); - inline const BaseDefinition* getParent() const {return parent;} - inline const BaseDefinition* getRoot() const {return root;} + inline const DefinitionNode* getParent() const {return parent;} + inline const DefinitionNode* getRoot() const {return root;} inline int getChildrenCount() const {return children.size();} /** @@ -36,17 +36,17 @@ public: virtual std::string toString(int indent = 0) const; protected: - void addChild(BaseDefinition* child); - void removeChild(BaseDefinition* child); + void addChild(DefinitionNode* child); + void removeChild(DefinitionNode* child); private: - BaseDefinition* parent; - BaseDefinition* root; + DefinitionNode* parent; + DefinitionNode* root; std::string name; - std::vector children; + std::vector children; }; } } -#endif // BASEDEFINITION_H +#endif // DEFINITIONNODE_H diff --git a/src/definition/Layers.cpp b/src/definition/Layers.cpp index 33358f7..127e9f7 100644 --- a/src/definition/Layers.cpp +++ b/src/definition/Layers.cpp @@ -2,8 +2,8 @@ #include "Logs.h" -Layers::Layers(BaseDefinition* parent, const std::string &name, LayerConstructor layer_constructor): - BaseDefinition(parent, name), layer_constructor(layer_constructor) +Layers::Layers(DefinitionNode* parent, const std::string &name, LayerConstructor layer_constructor): + DefinitionNode(parent, name), layer_constructor(layer_constructor) { max_layer_count = 100; null_layer = layer_constructor(this); @@ -15,9 +15,9 @@ Layers::~Layers() delete null_layer; } -void Layers::copy(BaseDefinition* destination_) const +void Layers::copy(DefinitionNode* destination_) const { - BaseDefinition::copy(destination_); + DefinitionNode::copy(destination_); Layers* destination = (Layers*)destination_; @@ -30,7 +30,7 @@ void Layers::copy(BaseDefinition* destination_) const for (auto layer: layers) { int position = destination->addLayer(); - BaseDefinition* new_layer = destination->getLayer(position); + DefinitionNode* new_layer = destination->getLayer(position); layer->copy(new_layer); } } @@ -53,7 +53,7 @@ int Layers::count() const return layers.size(); } -BaseDefinition* Layers::getLayer(int position) const +DefinitionNode* Layers::getLayer(int position) const { if (position >= 0 and position < (int)layers.size()) { @@ -66,7 +66,7 @@ BaseDefinition* Layers::getLayer(int position) const } } -int Layers::findLayer(BaseDefinition* layer) const +int Layers::findLayer(DefinitionNode* layer) const { int i = 0; for (auto it:layers) @@ -81,7 +81,7 @@ int Layers::findLayer(BaseDefinition* layer) const return -1; } -int Layers::addLayer(BaseDefinition* layer) +int Layers::addLayer(DefinitionNode* layer) { if ((int)layers.size() < max_layer_count) { @@ -106,7 +106,7 @@ void Layers::removeLayer(int position) { if (position >= 0 and position < (int)layers.size()) { - BaseDefinition* removed = layers[position]; + DefinitionNode* removed = layers[position]; removeChild(removed); layers.erase(layers.begin() + position); delete removed; @@ -117,7 +117,7 @@ void Layers::removeLayer(int position) } } -void Layers::removeLayer(BaseDefinition* layer) +void Layers::removeLayer(DefinitionNode* layer) { removeLayer(findLayer(layer)); } @@ -126,13 +126,13 @@ void Layers::moveLayer(int old_position, int new_position) { if (old_position >= 0 and old_position < (int)layers.size() and new_position >= 0 and new_position < (int)layers.size()) { - BaseDefinition* layer = layers[old_position]; + DefinitionNode* layer = layers[old_position]; layers.erase(layers.begin() + old_position); layers.insert(layers.begin() + new_position, layer); } } -void Layers::moveLayer(BaseDefinition* layer, int new_position) +void Layers::moveLayer(DefinitionNode* layer, int new_position) { moveLayer(findLayer(layer), new_position); } diff --git a/src/definition/Layers.h b/src/definition/Layers.h index e940228..87ba85d 100644 --- a/src/definition/Layers.h +++ b/src/definition/Layers.h @@ -3,30 +3,30 @@ #include "definition_global.h" -#include "BaseDefinition.h" +#include "DefinitionNode.h" namespace paysages { namespace definition { -typedef BaseDefinition* (*LayerConstructor)(Layers* parent); +typedef DefinitionNode* (*LayerConstructor)(Layers* parent); /** * @brief Layers of definitions, ideally all of the same type. */ -class DEFINITIONSHARED_EXPORT Layers:public BaseDefinition +class DEFINITIONSHARED_EXPORT Layers:public DefinitionNode { public: - Layers(BaseDefinition* parent, const std::string &name, LayerConstructor layer_constructor); + Layers(DefinitionNode* parent, const std::string &name, LayerConstructor layer_constructor); virtual ~Layers(); - virtual void copy(BaseDefinition* destination) const override; + virtual void copy(DefinitionNode* destination) const override; Layers* newCopy() const; void setMaxLayerCount(int max_layer_count); int count() const; - BaseDefinition* getLayer(int position) const; - int findLayer(BaseDefinition* layer) const; + DefinitionNode* getLayer(int position) const; + int findLayer(DefinitionNode* layer) const; /** * @brief Add a new layer @@ -35,19 +35,19 @@ public: * this object (even if the layer could not be added). * @return The position of the new layer, -1 if it couldn't be added. */ - int addLayer(BaseDefinition *layer); + int addLayer(DefinitionNode *layer); int addLayer(); void removeLayer(int position); - void removeLayer(BaseDefinition* layer); + void removeLayer(DefinitionNode* layer); void moveLayer(int old_position, int new_position); - void moveLayer(BaseDefinition* layer, int new_position); + void moveLayer(DefinitionNode* layer, int new_position); void clear(); public: LayerConstructor layer_constructor; int max_layer_count; - std::vector layers; - BaseDefinition* null_layer; + std::vector layers; + DefinitionNode* null_layer; }; } diff --git a/src/definition/PaintedGrid.cpp b/src/definition/PaintedGrid.cpp index 696040b..aa98938 100644 --- a/src/definition/PaintedGrid.cpp +++ b/src/definition/PaintedGrid.cpp @@ -6,8 +6,8 @@ #include "PaintedGridData.h" #include "PaintedGridBrush.h" -PaintedGrid::PaintedGrid(BaseDefinition *parent): - BaseDefinition(parent, "grid") +PaintedGrid::PaintedGrid(DefinitionNode *parent): + DefinitionNode(parent, "grid") { merged_data = new PaintedGridData; brush_data = new PaintedGridData; @@ -19,7 +19,7 @@ PaintedGrid::~PaintedGrid() delete brush_data; } -void PaintedGrid::copy(BaseDefinition *_destination) const +void PaintedGrid::copy(DefinitionNode *_destination) const { PaintedGrid* destination = (PaintedGrid *)_destination; diff --git a/src/definition/PaintedGrid.h b/src/definition/PaintedGrid.h index 49dad40..a593de8 100644 --- a/src/definition/PaintedGrid.h +++ b/src/definition/PaintedGrid.h @@ -3,7 +3,7 @@ #include "definition_global.h" -#include "BaseDefinition.h" +#include "DefinitionNode.h" namespace paysages { namespace definition { @@ -15,13 +15,13 @@ namespace definition { * * Grid cells are considered to be 1.0-sized. */ -class DEFINITIONSHARED_EXPORT PaintedGrid: public BaseDefinition +class DEFINITIONSHARED_EXPORT PaintedGrid: public DefinitionNode { public: - PaintedGrid(BaseDefinition *parent=0); + PaintedGrid(DefinitionNode *parent=0); virtual ~PaintedGrid(); - virtual void copy(BaseDefinition *destination) const override; + virtual void copy(DefinitionNode *destination) const override; virtual void save(PackStream *stream) const override; virtual void load(PackStream *stream) override; diff --git a/src/definition/Scenery.cpp b/src/definition/Scenery.cpp index 402251e..910d484 100644 --- a/src/definition/Scenery.cpp +++ b/src/definition/Scenery.cpp @@ -15,7 +15,7 @@ static const double APP_HEADER = 19866544632.125; static const int DATA_VERSION = 1; Scenery::Scenery(): - BaseDefinition(NULL, "scenery") + DefinitionNode(NULL, "scenery") { addChild(atmosphere = new AtmosphereDefinition(this)); addChild(camera = new CameraDefinition); @@ -25,7 +25,7 @@ Scenery::Scenery(): addChild(water = new WaterDefinition(this)); } -void Scenery::copy(BaseDefinition *destination_) const +void Scenery::copy(DefinitionNode *destination_) const { Scenery* destination = (Scenery*)destination_; @@ -41,7 +41,7 @@ void Scenery::copy(BaseDefinition *destination_) const void Scenery::validate() { - BaseDefinition::validate(); + DefinitionNode::validate(); keepCameraAboveGround(camera); } diff --git a/src/definition/Scenery.h b/src/definition/Scenery.h index 85cfb4f..a3b03d3 100644 --- a/src/definition/Scenery.h +++ b/src/definition/Scenery.h @@ -3,7 +3,7 @@ #include "definition_global.h" -#include "BaseDefinition.h" +#include "DefinitionNode.h" namespace paysages { namespace definition { @@ -13,7 +13,7 @@ namespace definition { * * This class contains the whole scenery definition. */ -class DEFINITIONSHARED_EXPORT Scenery: public BaseDefinition +class DEFINITIONSHARED_EXPORT Scenery: public DefinitionNode { public: typedef enum { @@ -29,7 +29,7 @@ public: Scenery(); virtual void validate() override; - virtual void copy(BaseDefinition *destination) const override; + virtual void copy(DefinitionNode *destination) const override; FileOperationResult saveGlobal(const std::string &filepath) const; FileOperationResult loadGlobal(const std::string &filepath); diff --git a/src/definition/TerrainDefinition.cpp b/src/definition/TerrainDefinition.cpp index 36b0f4a..a7cc29e 100644 --- a/src/definition/TerrainDefinition.cpp +++ b/src/definition/TerrainDefinition.cpp @@ -4,8 +4,8 @@ #include "NoiseGenerator.h" #include "PackStream.h" -TerrainDefinition::TerrainDefinition(BaseDefinition* parent): - BaseDefinition(parent, "terrain") +TerrainDefinition::TerrainDefinition(DefinitionNode* parent): + DefinitionNode(parent, "terrain") { height = 1.0; scaling = 1.0; @@ -41,7 +41,7 @@ void TerrainDefinition::validate() /* TODO Alter with heightmap min/max */ } -void TerrainDefinition::copy(BaseDefinition* _destination) const +void TerrainDefinition::copy(DefinitionNode* _destination) const { TerrainDefinition* destination = (TerrainDefinition*)_destination; @@ -60,7 +60,7 @@ void TerrainDefinition::copy(BaseDefinition* _destination) const void TerrainDefinition::save(PackStream* stream) const { - BaseDefinition::save(stream); + DefinitionNode::save(stream); stream->write(&height); stream->write(&scaling); @@ -71,7 +71,7 @@ void TerrainDefinition::save(PackStream* stream) const void TerrainDefinition::load(PackStream* stream) { - BaseDefinition::load(stream); + DefinitionNode::load(stream); stream->read(&height); stream->read(&scaling); diff --git a/src/definition/TerrainDefinition.h b/src/definition/TerrainDefinition.h index c67fac7..5ceddc2 100644 --- a/src/definition/TerrainDefinition.h +++ b/src/definition/TerrainDefinition.h @@ -3,7 +3,7 @@ #include "definition_global.h" -#include "BaseDefinition.h" +#include "DefinitionNode.h" namespace paysages { namespace definition { @@ -15,16 +15,16 @@ typedef struct double base_height; } HeightInfo; -class DEFINITIONSHARED_EXPORT TerrainDefinition : public BaseDefinition +class DEFINITIONSHARED_EXPORT TerrainDefinition : public DefinitionNode { public: - TerrainDefinition(BaseDefinition* parent); + TerrainDefinition(DefinitionNode* parent); virtual ~TerrainDefinition(); virtual void save(PackStream* stream) const override; virtual void load(PackStream* stream) override; - virtual void copy(BaseDefinition* destination) const override; + virtual void copy(DefinitionNode* destination) const override; virtual void validate() override; double getGridHeight(int x, int z, bool with_painting); diff --git a/src/definition/TerrainHeightMap.cpp b/src/definition/TerrainHeightMap.cpp index a00e809..fac6f19 100644 --- a/src/definition/TerrainHeightMap.cpp +++ b/src/definition/TerrainHeightMap.cpp @@ -8,7 +8,7 @@ TerrainHeightMap::TerrainHeightMap(TerrainDefinition* terrain): { } -void TerrainHeightMap::copy(BaseDefinition* _destination) const +void TerrainHeightMap::copy(DefinitionNode* _destination) const { TerrainHeightMap* destination = (TerrainHeightMap*)_destination; diff --git a/src/definition/TerrainHeightMap.h b/src/definition/TerrainHeightMap.h index 035bf37..63d7c6c 100644 --- a/src/definition/TerrainHeightMap.h +++ b/src/definition/TerrainHeightMap.h @@ -13,7 +13,7 @@ class DEFINITIONSHARED_EXPORT TerrainHeightMap : public PaintedGrid public: TerrainHeightMap(TerrainDefinition *terrain); - virtual void copy(BaseDefinition *destination) const override; + virtual void copy(DefinitionNode *destination) const override; inline TerrainDefinition* getTerrain() const {return terrain;} diff --git a/src/definition/TextureLayerDefinition.cpp b/src/definition/TextureLayerDefinition.cpp index 1da881f..817a1f7 100644 --- a/src/definition/TextureLayerDefinition.cpp +++ b/src/definition/TextureLayerDefinition.cpp @@ -7,8 +7,8 @@ #include "Scenery.h" #include "TerrainDefinition.h" -TextureLayerDefinition::TextureLayerDefinition(BaseDefinition* parent): - BaseDefinition(parent, "texture") +TextureLayerDefinition::TextureLayerDefinition(DefinitionNode* parent): + DefinitionNode(parent, "texture") { terrain_zone = new Zone; _displacement_noise = new NoiseGenerator; @@ -29,7 +29,7 @@ TextureLayerDefinition::~TextureLayerDefinition() void TextureLayerDefinition::validate() { - BaseDefinition::validate(); + DefinitionNode::validate(); if (displacement_scaling < 0.000001) { @@ -58,9 +58,9 @@ void TextureLayerDefinition::validate() } } -void TextureLayerDefinition::copy(BaseDefinition *_destination) const +void TextureLayerDefinition::copy(DefinitionNode *_destination) const { - BaseDefinition::copy(_destination); + DefinitionNode::copy(_destination); TextureLayerDefinition* destination = (TextureLayerDefinition*)_destination; @@ -77,7 +77,7 @@ void TextureLayerDefinition::copy(BaseDefinition *_destination) const void TextureLayerDefinition::save(PackStream* stream) const { - BaseDefinition::save(stream); + DefinitionNode::save(stream); terrain_zone->save(stream); stream->write(&displacement_scaling); @@ -91,7 +91,7 @@ void TextureLayerDefinition::save(PackStream* stream) const void TextureLayerDefinition::load(PackStream* stream) { - BaseDefinition::load(stream); + DefinitionNode::load(stream); terrain_zone->load(stream); stream->read(&displacement_scaling); diff --git a/src/definition/TextureLayerDefinition.h b/src/definition/TextureLayerDefinition.h index 0ff750c..e8696fc 100644 --- a/src/definition/TextureLayerDefinition.h +++ b/src/definition/TextureLayerDefinition.h @@ -3,12 +3,12 @@ #include "definition_global.h" -#include "BaseDefinition.h" +#include "DefinitionNode.h" namespace paysages { namespace definition { -class DEFINITIONSHARED_EXPORT TextureLayerDefinition : public BaseDefinition +class DEFINITIONSHARED_EXPORT TextureLayerDefinition : public DefinitionNode { public: typedef enum @@ -27,13 +27,13 @@ public: } TextureLayerPreset; public: - TextureLayerDefinition(BaseDefinition* parent); + TextureLayerDefinition(DefinitionNode* parent); virtual ~TextureLayerDefinition(); virtual void save(PackStream* stream) const override; virtual void load(PackStream* stream) override; - virtual void copy(BaseDefinition* destination) const override; + virtual void copy(DefinitionNode* destination) const override; virtual void validate() override; void applyPreset(TextureLayerPreset preset); diff --git a/src/definition/TexturesDefinition.cpp b/src/definition/TexturesDefinition.cpp index 9c1dc94..e253cec 100644 --- a/src/definition/TexturesDefinition.cpp +++ b/src/definition/TexturesDefinition.cpp @@ -2,12 +2,12 @@ #include "TextureLayerDefinition.h" -static BaseDefinition* _layer_constructor(Layers* parent) +static DefinitionNode* _layer_constructor(Layers* parent) { return new TextureLayerDefinition(parent); } -TexturesDefinition::TexturesDefinition(BaseDefinition *parent): +TexturesDefinition::TexturesDefinition(DefinitionNode *parent): Layers(parent, "textures", _layer_constructor) { } diff --git a/src/definition/TexturesDefinition.h b/src/definition/TexturesDefinition.h index 3d1460f..a71b299 100644 --- a/src/definition/TexturesDefinition.h +++ b/src/definition/TexturesDefinition.h @@ -11,7 +11,7 @@ namespace definition { class DEFINITIONSHARED_EXPORT TexturesDefinition : public Layers { public: - TexturesDefinition(BaseDefinition *parent); + TexturesDefinition(DefinitionNode *parent); inline TextureLayerDefinition* getTextureLayer(int position) const {return (TextureLayerDefinition*)getLayer(position);} diff --git a/src/definition/WaterDefinition.cpp b/src/definition/WaterDefinition.cpp index 6f98ff4..501a93c 100644 --- a/src/definition/WaterDefinition.cpp +++ b/src/definition/WaterDefinition.cpp @@ -5,8 +5,8 @@ #include "Color.h" #include "SurfaceMaterial.h" -WaterDefinition::WaterDefinition(BaseDefinition* parent): - BaseDefinition(parent, "water") +WaterDefinition::WaterDefinition(DefinitionNode* parent): + DefinitionNode(parent, "water") { material = new SurfaceMaterial; depth_color = new Color; @@ -34,7 +34,7 @@ WaterDefinition::~WaterDefinition() void WaterDefinition::save(PackStream* stream) const { - BaseDefinition::save(stream); + DefinitionNode::save(stream); material->save(stream); depth_color->save(stream); @@ -56,7 +56,7 @@ void WaterDefinition::save(PackStream* stream) const void WaterDefinition::load(PackStream* stream) { - BaseDefinition::load(stream); + DefinitionNode::load(stream); material->load(stream); depth_color->load(stream); @@ -78,9 +78,9 @@ void WaterDefinition::load(PackStream* stream) validate(); } -void WaterDefinition::copy(BaseDefinition* _destination) const +void WaterDefinition::copy(DefinitionNode* _destination) const { - BaseDefinition::copy(_destination); + DefinitionNode::copy(_destination); WaterDefinition* destination = (WaterDefinition*)_destination; *destination->material = *material; @@ -100,7 +100,7 @@ void WaterDefinition::copy(BaseDefinition* _destination) const void WaterDefinition::validate() { - BaseDefinition::validate(); + DefinitionNode::validate(); material->validate(); foam_material->validate(); diff --git a/src/definition/WaterDefinition.h b/src/definition/WaterDefinition.h index 3db7b3c..5564c0a 100644 --- a/src/definition/WaterDefinition.h +++ b/src/definition/WaterDefinition.h @@ -3,21 +3,21 @@ #include "definition_global.h" -#include "BaseDefinition.h" +#include "DefinitionNode.h" namespace paysages { namespace definition { -class DEFINITIONSHARED_EXPORT WaterDefinition: public BaseDefinition +class DEFINITIONSHARED_EXPORT WaterDefinition: public DefinitionNode { public: - WaterDefinition(BaseDefinition* parent); + WaterDefinition(DefinitionNode* parent); virtual ~WaterDefinition(); virtual void save(PackStream* stream) const override; virtual void load(PackStream* stream) override; - virtual void copy(BaseDefinition* destination) const override; + virtual void copy(DefinitionNode* destination) const override; virtual void validate() override; public: diff --git a/src/definition/Zone.cpp b/src/definition/Zone.cpp index b109052..380047f 100644 --- a/src/definition/Zone.cpp +++ b/src/definition/Zone.cpp @@ -5,8 +5,8 @@ #include "PackStream.h" #include "Vector3.h" -Zone::Zone(BaseDefinition *parent): - BaseDefinition(parent, "zone") +Zone::Zone(DefinitionNode *parent): + DefinitionNode(parent, "zone") { value_by_height = new Curve; absolute_height = 1; @@ -43,7 +43,7 @@ void Zone::load(PackStream* stream) value_by_slope->load(stream); } -void Zone::copy(BaseDefinition* _destination) const +void Zone::copy(DefinitionNode* _destination) const { Zone* destination = (Zone*)_destination; diff --git a/src/definition/Zone.h b/src/definition/Zone.h index 0a60285..0a5b4d3 100644 --- a/src/definition/Zone.h +++ b/src/definition/Zone.h @@ -3,21 +3,21 @@ #include "definition_global.h" -#include "BaseDefinition.h" +#include "DefinitionNode.h" namespace paysages { namespace definition { -class DEFINITIONSHARED_EXPORT Zone : public BaseDefinition +class DEFINITIONSHARED_EXPORT Zone : public DefinitionNode { public: - Zone(BaseDefinition *parent = 0); + Zone(DefinitionNode *parent = 0); virtual ~Zone(); virtual void save(PackStream* stream) const override; virtual void load(PackStream* stream) override; - virtual void copy(BaseDefinition* destination) const override; + virtual void copy(DefinitionNode* destination) const override; void clear(); diff --git a/src/definition/definition.pro b/src/definition/definition.pro index b56b5fb..3156846 100644 --- a/src/definition/definition.pro +++ b/src/definition/definition.pro @@ -14,7 +14,6 @@ DEFINES += DEFINITION_LIBRARY include(../common.pri) SOURCES += \ - BaseDefinition.cpp \ Layers.cpp \ WaterDefinition.cpp \ SurfaceMaterial.cpp \ @@ -30,11 +29,11 @@ SOURCES += \ Scenery.cpp \ PaintedGrid.cpp \ PaintedGridBrush.cpp \ - PaintedGridData.cpp + PaintedGridData.cpp \ + DefinitionNode.cpp HEADERS +=\ definition_global.h \ - BaseDefinition.h \ Layers.h \ WaterDefinition.h \ SurfaceMaterial.h \ @@ -50,7 +49,8 @@ HEADERS +=\ Scenery.h \ PaintedGrid.h \ PaintedGridBrush.h \ - PaintedGridData.h + PaintedGridData.h \ + DefinitionNode.h unix:!symbian { maemo5 { diff --git a/src/definition/definition_global.h b/src/definition/definition_global.h index c120893..3f40a44 100644 --- a/src/definition/definition_global.h +++ b/src/definition/definition_global.h @@ -13,7 +13,7 @@ namespace paysages { namespace definition { - class BaseDefinition; + class DefinitionNode; class Scenery; class CameraDefinition; class SurfaceMaterial; diff --git a/src/tests/BaseDefinition_Test.cpp b/src/tests/BaseDefinition_Test.cpp deleted file mode 100644 index c046fc9..0000000 --- a/src/tests/BaseDefinition_Test.cpp +++ /dev/null @@ -1,35 +0,0 @@ -#include "BaseTestCase.h" - -#include "BaseDefinition.h" - -TEST(BaseDefinition, toString) -{ - BaseDefinition root(NULL, "root"); - BaseDefinition branch(&root, "branch"); - BaseDefinition leaf1(&branch, "leaf1"); - BaseDefinition leaf2(&branch, "leaf2"); - - EXPECT_EQ("root\n branch\n leaf1\n leaf2", root.toString()); - EXPECT_EQ("branch\n leaf1\n leaf2", branch.toString()); -} - -TEST(BaseDefinition, attachDetach) -{ - BaseDefinition* root = new BaseDefinition(NULL, "root"); - BaseDefinition* child1 = new BaseDefinition(root, "child1"); - BaseDefinition* child2 = new BaseDefinition(root, "child2"); - - EXPECT_EQ(root, child1->getParent()); - EXPECT_EQ(root, child2->getParent()); - EXPECT_EQ(2, root->getChildrenCount()); - - delete child1; - - EXPECT_EQ(1, root->getChildrenCount()); - - delete child2; - - EXPECT_EQ(0, root->getChildrenCount()); - - delete root; -} diff --git a/src/tests/DefinitionNode_Test.cpp b/src/tests/DefinitionNode_Test.cpp new file mode 100644 index 0000000..ea8eb26 --- /dev/null +++ b/src/tests/DefinitionNode_Test.cpp @@ -0,0 +1,35 @@ +#include "BaseTestCase.h" + +#include "DefinitionNode.h" + +TEST(DefinitionNode, toString) +{ + DefinitionNode root(NULL, "root"); + DefinitionNode branch(&root, "branch"); + DefinitionNode leaf1(&branch, "leaf1"); + DefinitionNode leaf2(&branch, "leaf2"); + + EXPECT_EQ("root\n branch\n leaf1\n leaf2", root.toString()); + EXPECT_EQ("branch\n leaf1\n leaf2", branch.toString()); +} + +TEST(DefinitionNode, attachDetach) +{ + DefinitionNode* root = new DefinitionNode(NULL, "root"); + DefinitionNode* child1 = new DefinitionNode(root, "child1"); + DefinitionNode* child2 = new DefinitionNode(root, "child2"); + + EXPECT_EQ(root, child1->getParent()); + EXPECT_EQ(root, child2->getParent()); + EXPECT_EQ(2, root->getChildrenCount()); + + delete child1; + + EXPECT_EQ(1, root->getChildrenCount()); + + delete child2; + + EXPECT_EQ(0, root->getChildrenCount()); + + delete root; +} diff --git a/src/tests/Layers_Test.cpp b/src/tests/Layers_Test.cpp index 9fa1dfa..e191344 100644 --- a/src/tests/Layers_Test.cpp +++ b/src/tests/Layers_Test.cpp @@ -3,14 +3,14 @@ #include "Layers.h" #include "PackStream.h" -BaseDefinition* _construc1(Layers*) +DefinitionNode* _construc1(Layers*) { - return new BaseDefinition(NULL, "test"); + return new DefinitionNode(NULL, "test"); } -BaseDefinition* _construc2(Layers* parent) +DefinitionNode* _construc2(Layers* parent) { - BaseDefinition* result = new BaseDefinition(parent, "test"); + DefinitionNode* result = new DefinitionNode(parent, "test"); return result; } @@ -26,8 +26,8 @@ TEST(Layers, NullLayer) for (int i = -2; i < 5; i++) { - BaseDefinition* layer = layers1.getLayer(0); - EXPECT_NE((BaseDefinition*)NULL, layer); + DefinitionNode* layer = layers1.getLayer(0); + EXPECT_NE((DefinitionNode*)NULL, layer); EXPECT_EQ(NULL, layer->getParent()); EXPECT_EQ(layer, layer->getRoot()); diff --git a/src/tests/tests.pro b/src/tests/tests.pro index 66802c7..2a01973 100644 --- a/src/tests/tests.pro +++ b/src/tests/tests.pro @@ -23,7 +23,7 @@ SOURCES += main.cpp \ CanvasPreview_Test.cpp \ AtmosphereDefinition_Test.cpp \ Scenery_Test.cpp \ - BaseDefinition_Test.cpp + DefinitionNode_Test.cpp HEADERS += \ BaseTestCase.h