Renamed BaseDefinition to DefinitionNode

This commit is contained in:
Michaël Lemaire 2015-08-12 22:21:10 +02:00
parent a4edc9568b
commit 42d3ae4ceb
34 changed files with 187 additions and 187 deletions

View file

@ -3,8 +3,8 @@
#include "PackStream.h" #include "PackStream.h"
#include "RandomGenerator.h" #include "RandomGenerator.h"
AtmosphereDefinition::AtmosphereDefinition(BaseDefinition* parent): AtmosphereDefinition::AtmosphereDefinition(DefinitionNode* parent):
BaseDefinition(parent, "atmosphere") DefinitionNode(parent, "atmosphere")
{ {
} }
@ -64,7 +64,7 @@ void AtmosphereDefinition::load(PackStream* stream)
validate(); validate();
} }
void AtmosphereDefinition::copy(BaseDefinition* _destination) const void AtmosphereDefinition::copy(DefinitionNode* _destination) const
{ {
AtmosphereDefinition* destination = (AtmosphereDefinition*)_destination; AtmosphereDefinition* destination = (AtmosphereDefinition*)_destination;

View file

@ -3,7 +3,7 @@
#include "definition_global.h" #include "definition_global.h"
#include "BaseDefinition.h" #include "DefinitionNode.h"
#include "Vector3.h" #include "Vector3.h"
#include "Color.h" #include "Color.h"
@ -11,7 +11,7 @@
namespace paysages { namespace paysages {
namespace definition { namespace definition {
class DEFINITIONSHARED_EXPORT AtmosphereDefinition : public BaseDefinition class DEFINITIONSHARED_EXPORT AtmosphereDefinition : public DefinitionNode
{ {
public: public:
typedef struct typedef struct
@ -37,13 +37,13 @@ public:
} AtmospherePreset; } AtmospherePreset;
public: public:
AtmosphereDefinition(BaseDefinition* parent); AtmosphereDefinition(DefinitionNode* parent);
virtual ~AtmosphereDefinition(); virtual ~AtmosphereDefinition();
virtual void save(PackStream* stream) const override; virtual void save(PackStream* stream) const override;
virtual void load(PackStream* stream) 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; virtual void validate() override;
/** /**

View file

@ -4,8 +4,8 @@
#include "PackStream.h" #include "PackStream.h"
#include "BoundingBox.h" #include "BoundingBox.h"
CameraDefinition::CameraDefinition(BaseDefinition *parent): CameraDefinition::CameraDefinition(DefinitionNode *parent):
BaseDefinition(parent, "camera") DefinitionNode(parent, "camera")
{ {
location.x = 0.0; location.x = 0.0;
location.y = 0.0; location.y = 0.0;
@ -47,7 +47,7 @@ void CameraDefinition::load(PackStream* stream)
validate(); validate();
} }
void CameraDefinition::copy(BaseDefinition* _destination) const void CameraDefinition::copy(DefinitionNode* _destination) const
{ {
CameraDefinition* destination = (CameraDefinition*)_destination; CameraDefinition* destination = (CameraDefinition*)_destination;

View file

@ -3,7 +3,7 @@
#include "definition_global.h" #include "definition_global.h"
#include "BaseDefinition.h" #include "DefinitionNode.h"
#include "Vector3.h" #include "Vector3.h"
#include "Matrix4.h" #include "Matrix4.h"
@ -19,15 +19,15 @@ typedef struct
double zfar; double zfar;
} CameraPerspective; } CameraPerspective;
class DEFINITIONSHARED_EXPORT CameraDefinition: public BaseDefinition class DEFINITIONSHARED_EXPORT CameraDefinition: public DefinitionNode
{ {
public: public:
CameraDefinition(BaseDefinition *parent = NULL); CameraDefinition(DefinitionNode *parent = NULL);
virtual void save(PackStream* pack) const override; virtual void save(PackStream* pack) const override;
virtual void load(PackStream* pack) 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; virtual void validate() override;
inline Vector3 getLocation() const {return location;} inline Vector3 getLocation() const {return location;}

View file

@ -5,8 +5,8 @@
#include "SurfaceMaterial.h" #include "SurfaceMaterial.h"
#include "PackStream.h" #include "PackStream.h"
CloudLayerDefinition::CloudLayerDefinition(BaseDefinition* parent): CloudLayerDefinition::CloudLayerDefinition(DefinitionNode* parent):
BaseDefinition(parent, "layer") DefinitionNode(parent, "layer")
{ {
type = CIRRUS; type = CIRRUS;
altitude = 0.5; 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); CloudLayerDefinition* layer = new CloudLayerDefinition(parent);
other.copy(layer); other.copy(layer);
return layer; return layer;
} }
CloudLayerDefinition* CloudLayerDefinition::newCopy(BaseDefinition* parent) const CloudLayerDefinition* CloudLayerDefinition::newCopy(DefinitionNode* parent) const
{ {
CloudLayerDefinition* layer = new CloudLayerDefinition(parent); CloudLayerDefinition* layer = new CloudLayerDefinition(parent);
copy(layer); copy(layer);
@ -34,7 +34,7 @@ CloudLayerDefinition* CloudLayerDefinition::newCopy(BaseDefinition* parent) cons
void CloudLayerDefinition::save(PackStream* stream) const void CloudLayerDefinition::save(PackStream* stream) const
{ {
BaseDefinition::save(stream); DefinitionNode::save(stream);
int clouds_type = (int)type; int clouds_type = (int)type;
@ -48,7 +48,7 @@ void CloudLayerDefinition::save(PackStream* stream) const
void CloudLayerDefinition::load(PackStream* stream) void CloudLayerDefinition::load(PackStream* stream)
{ {
BaseDefinition::load(stream); DefinitionNode::load(stream);
int clouds_type; int clouds_type;
@ -63,9 +63,9 @@ void CloudLayerDefinition::load(PackStream* stream)
validate(); validate();
} }
void CloudLayerDefinition::copy(BaseDefinition* _destination) const void CloudLayerDefinition::copy(DefinitionNode* _destination) const
{ {
BaseDefinition::copy(_destination); DefinitionNode::copy(_destination);
CloudLayerDefinition* destination = (CloudLayerDefinition*)_destination; CloudLayerDefinition* destination = (CloudLayerDefinition*)_destination;

View file

@ -3,28 +3,28 @@
#include "definition_global.h" #include "definition_global.h"
#include "BaseDefinition.h" #include "DefinitionNode.h"
#include "NoiseState.h" #include "NoiseState.h"
namespace paysages { namespace paysages {
namespace definition { namespace definition {
class DEFINITIONSHARED_EXPORT CloudLayerDefinition : public BaseDefinition class DEFINITIONSHARED_EXPORT CloudLayerDefinition : public DefinitionNode
{ {
public: public:
CloudLayerDefinition(BaseDefinition* parent); CloudLayerDefinition(DefinitionNode* parent);
virtual ~CloudLayerDefinition(); virtual ~CloudLayerDefinition();
inline const NoiseState &getNoiseState() const {return noise_state;} inline const NoiseState &getNoiseState() const {return noise_state;}
static CloudLayerDefinition* newCopy(const CloudLayerDefinition& other, BaseDefinition* parent); static CloudLayerDefinition* newCopy(const CloudLayerDefinition& other, DefinitionNode* parent);
CloudLayerDefinition* newCopy(BaseDefinition* parent) const; CloudLayerDefinition* newCopy(DefinitionNode* parent) const;
virtual void save(PackStream* pack) const override; virtual void save(PackStream* pack) const override;
virtual void load(PackStream* pack) 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; virtual void validate() override;
public: public:

View file

@ -2,12 +2,12 @@
#include "CloudLayerDefinition.h" #include "CloudLayerDefinition.h"
static BaseDefinition* _layerConstructor(Layers* parent) static DefinitionNode* _layerConstructor(Layers* parent)
{ {
return new CloudLayerDefinition(parent); return new CloudLayerDefinition(parent);
} }
CloudsDefinition::CloudsDefinition(BaseDefinition* parent): CloudsDefinition::CloudsDefinition(DefinitionNode* parent):
Layers(parent, "clouds", _layerConstructor) Layers(parent, "clouds", _layerConstructor)
{ {
} }

View file

@ -11,7 +11,7 @@ namespace definition {
class DEFINITIONSHARED_EXPORT CloudsDefinition : public Layers class DEFINITIONSHARED_EXPORT CloudsDefinition : public Layers
{ {
public: public:
CloudsDefinition(BaseDefinition* parent); CloudsDefinition(DefinitionNode* parent);
inline CloudLayerDefinition* getCloudLayer(int position) const {return (CloudLayerDefinition*)getLayer(position);} inline CloudLayerDefinition* getCloudLayer(int position) const {return (CloudLayerDefinition*)getLayer(position);}

View file

@ -1,8 +1,8 @@
#include "BaseDefinition.h" #include "DefinitionNode.h"
#include "PackStream.h" #include "PackStream.h"
BaseDefinition::BaseDefinition(BaseDefinition* parent, const std::string &name): DefinitionNode::DefinitionNode(DefinitionNode* parent, const std::string &name):
parent(parent), name(name) parent(parent), name(name)
{ {
if (parent) if (parent)
@ -16,7 +16,7 @@ BaseDefinition::BaseDefinition(BaseDefinition* parent, const std::string &name):
} }
} }
BaseDefinition::~BaseDefinition() DefinitionNode::~DefinitionNode()
{ {
if (parent) 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 // Work on a copy, because the child destructor will modify the array by removing itself using removeChild
std::vector<BaseDefinition*> children_copy = children; std::vector<DefinitionNode*> children_copy = children;
for (auto child:children_copy) for (auto child:children_copy)
{ {
if (child->getParent() == this) 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; this->name = name;
} }
Scenery* BaseDefinition::getScenery() Scenery* DefinitionNode::getScenery()
{ {
if (parent) 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; std::string result;
for (int i = 0; i < indent; i++) for (int i = 0; i < indent; i++)
@ -70,7 +70,7 @@ std::string BaseDefinition::toString(int indent) const
return result; return result;
} }
void BaseDefinition::save(PackStream* stream) const void DefinitionNode::save(PackStream* stream) const
{ {
stream->write(name); stream->write(name);
for (auto child: children) 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(); name = stream->readString();
for (auto child: children) 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); destination->setName(name);
// can't copy children as we don't know their types... // can't copy children as we don't know their types...
} }
void BaseDefinition::validate() void DefinitionNode::validate()
{ {
for (auto child: children) 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()) 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<BaseDefinition*>::iterator it = std::find(children.begin(), children.end(), child); std::vector<DefinitionNode*>::iterator it = std::find(children.begin(), children.end(), child);
if (it != children.end()) if (it != children.end())
{ {
child->parent = NULL; child->parent = NULL;

View file

@ -1,5 +1,5 @@
#ifndef BASEDEFINITION_H #ifndef DEFINITIONNODE_H
#define BASEDEFINITION_H #define DEFINITIONNODE_H
#include "definition_global.h" #include "definition_global.h"
@ -7,18 +7,18 @@ namespace paysages {
namespace definition { 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: public:
BaseDefinition(BaseDefinition* parent, const std::string &name); DefinitionNode(DefinitionNode* parent, const std::string &name);
virtual ~BaseDefinition(); virtual ~DefinitionNode();
virtual void save(PackStream* stream) const; virtual void save(PackStream* stream) const;
virtual void load(PackStream* stream); virtual void load(PackStream* stream);
virtual void copy(BaseDefinition* destination) const; virtual void copy(DefinitionNode* destination) const;
virtual void validate(); virtual void validate();
inline const std::string &getName() const {return name;} inline const std::string &getName() const {return name;}
@ -26,8 +26,8 @@ public:
virtual Scenery* getScenery(); virtual Scenery* getScenery();
inline const BaseDefinition* getParent() const {return parent;} inline const DefinitionNode* getParent() const {return parent;}
inline const BaseDefinition* getRoot() const {return root;} inline const DefinitionNode* getRoot() const {return root;}
inline int getChildrenCount() const {return children.size();} inline int getChildrenCount() const {return children.size();}
/** /**
@ -36,17 +36,17 @@ public:
virtual std::string toString(int indent = 0) const; virtual std::string toString(int indent = 0) const;
protected: protected:
void addChild(BaseDefinition* child); void addChild(DefinitionNode* child);
void removeChild(BaseDefinition* child); void removeChild(DefinitionNode* child);
private: private:
BaseDefinition* parent; DefinitionNode* parent;
BaseDefinition* root; DefinitionNode* root;
std::string name; std::string name;
std::vector<BaseDefinition*> children; std::vector<DefinitionNode*> children;
}; };
} }
} }
#endif // BASEDEFINITION_H #endif // DEFINITIONNODE_H

View file

@ -2,8 +2,8 @@
#include "Logs.h" #include "Logs.h"
Layers::Layers(BaseDefinition* parent, const std::string &name, LayerConstructor layer_constructor): Layers::Layers(DefinitionNode* parent, const std::string &name, LayerConstructor layer_constructor):
BaseDefinition(parent, name), layer_constructor(layer_constructor) DefinitionNode(parent, name), layer_constructor(layer_constructor)
{ {
max_layer_count = 100; max_layer_count = 100;
null_layer = layer_constructor(this); null_layer = layer_constructor(this);
@ -15,9 +15,9 @@ Layers::~Layers()
delete null_layer; 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_; Layers* destination = (Layers*)destination_;
@ -30,7 +30,7 @@ void Layers::copy(BaseDefinition* destination_) const
for (auto layer: layers) for (auto layer: layers)
{ {
int position = destination->addLayer(); int position = destination->addLayer();
BaseDefinition* new_layer = destination->getLayer(position); DefinitionNode* new_layer = destination->getLayer(position);
layer->copy(new_layer); layer->copy(new_layer);
} }
} }
@ -53,7 +53,7 @@ int Layers::count() const
return layers.size(); return layers.size();
} }
BaseDefinition* Layers::getLayer(int position) const DefinitionNode* Layers::getLayer(int position) const
{ {
if (position >= 0 and position < (int)layers.size()) 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; int i = 0;
for (auto it:layers) for (auto it:layers)
@ -81,7 +81,7 @@ int Layers::findLayer(BaseDefinition* layer) const
return -1; return -1;
} }
int Layers::addLayer(BaseDefinition* layer) int Layers::addLayer(DefinitionNode* layer)
{ {
if ((int)layers.size() < max_layer_count) if ((int)layers.size() < max_layer_count)
{ {
@ -106,7 +106,7 @@ void Layers::removeLayer(int position)
{ {
if (position >= 0 and position < (int)layers.size()) if (position >= 0 and position < (int)layers.size())
{ {
BaseDefinition* removed = layers[position]; DefinitionNode* removed = layers[position];
removeChild(removed); removeChild(removed);
layers.erase(layers.begin() + position); layers.erase(layers.begin() + position);
delete removed; delete removed;
@ -117,7 +117,7 @@ void Layers::removeLayer(int position)
} }
} }
void Layers::removeLayer(BaseDefinition* layer) void Layers::removeLayer(DefinitionNode* layer)
{ {
removeLayer(findLayer(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()) 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.erase(layers.begin() + old_position);
layers.insert(layers.begin() + new_position, layer); 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); moveLayer(findLayer(layer), new_position);
} }

View file

@ -3,30 +3,30 @@
#include "definition_global.h" #include "definition_global.h"
#include "BaseDefinition.h" #include "DefinitionNode.h"
namespace paysages { namespace paysages {
namespace definition { namespace definition {
typedef BaseDefinition* (*LayerConstructor)(Layers* parent); typedef DefinitionNode* (*LayerConstructor)(Layers* parent);
/** /**
* @brief Layers of definitions, ideally all of the same type. * @brief Layers of definitions, ideally all of the same type.
*/ */
class DEFINITIONSHARED_EXPORT Layers:public BaseDefinition class DEFINITIONSHARED_EXPORT Layers:public DefinitionNode
{ {
public: public:
Layers(BaseDefinition* parent, const std::string &name, LayerConstructor layer_constructor); Layers(DefinitionNode* parent, const std::string &name, LayerConstructor layer_constructor);
virtual ~Layers(); virtual ~Layers();
virtual void copy(BaseDefinition* destination) const override; virtual void copy(DefinitionNode* destination) const override;
Layers* newCopy() const; Layers* newCopy() const;
void setMaxLayerCount(int max_layer_count); void setMaxLayerCount(int max_layer_count);
int count() const; int count() const;
BaseDefinition* getLayer(int position) const; DefinitionNode* getLayer(int position) const;
int findLayer(BaseDefinition* layer) const; int findLayer(DefinitionNode* layer) const;
/** /**
* @brief Add a new layer * @brief Add a new layer
@ -35,19 +35,19 @@ public:
* this object (even if the layer could not be added). * this object (even if the layer could not be added).
* @return The position of the new layer, -1 if it couldn't 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(); int addLayer();
void removeLayer(int position); void removeLayer(int position);
void removeLayer(BaseDefinition* layer); void removeLayer(DefinitionNode* layer);
void moveLayer(int old_position, int new_position); void moveLayer(int old_position, int new_position);
void moveLayer(BaseDefinition* layer, int new_position); void moveLayer(DefinitionNode* layer, int new_position);
void clear(); void clear();
public: public:
LayerConstructor layer_constructor; LayerConstructor layer_constructor;
int max_layer_count; int max_layer_count;
std::vector<BaseDefinition*> layers; std::vector<DefinitionNode*> layers;
BaseDefinition* null_layer; DefinitionNode* null_layer;
}; };
} }

View file

@ -6,8 +6,8 @@
#include "PaintedGridData.h" #include "PaintedGridData.h"
#include "PaintedGridBrush.h" #include "PaintedGridBrush.h"
PaintedGrid::PaintedGrid(BaseDefinition *parent): PaintedGrid::PaintedGrid(DefinitionNode *parent):
BaseDefinition(parent, "grid") DefinitionNode(parent, "grid")
{ {
merged_data = new PaintedGridData; merged_data = new PaintedGridData;
brush_data = new PaintedGridData; brush_data = new PaintedGridData;
@ -19,7 +19,7 @@ PaintedGrid::~PaintedGrid()
delete brush_data; delete brush_data;
} }
void PaintedGrid::copy(BaseDefinition *_destination) const void PaintedGrid::copy(DefinitionNode *_destination) const
{ {
PaintedGrid* destination = (PaintedGrid *)_destination; PaintedGrid* destination = (PaintedGrid *)_destination;

View file

@ -3,7 +3,7 @@
#include "definition_global.h" #include "definition_global.h"
#include "BaseDefinition.h" #include "DefinitionNode.h"
namespace paysages { namespace paysages {
namespace definition { namespace definition {
@ -15,13 +15,13 @@ namespace definition {
* *
* Grid cells are considered to be 1.0-sized. * Grid cells are considered to be 1.0-sized.
*/ */
class DEFINITIONSHARED_EXPORT PaintedGrid: public BaseDefinition class DEFINITIONSHARED_EXPORT PaintedGrid: public DefinitionNode
{ {
public: public:
PaintedGrid(BaseDefinition *parent=0); PaintedGrid(DefinitionNode *parent=0);
virtual ~PaintedGrid(); 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 save(PackStream *stream) const override;
virtual void load(PackStream *stream) override; virtual void load(PackStream *stream) override;

View file

@ -15,7 +15,7 @@ static const double APP_HEADER = 19866544632.125;
static const int DATA_VERSION = 1; static const int DATA_VERSION = 1;
Scenery::Scenery(): Scenery::Scenery():
BaseDefinition(NULL, "scenery") DefinitionNode(NULL, "scenery")
{ {
addChild(atmosphere = new AtmosphereDefinition(this)); addChild(atmosphere = new AtmosphereDefinition(this));
addChild(camera = new CameraDefinition); addChild(camera = new CameraDefinition);
@ -25,7 +25,7 @@ Scenery::Scenery():
addChild(water = new WaterDefinition(this)); addChild(water = new WaterDefinition(this));
} }
void Scenery::copy(BaseDefinition *destination_) const void Scenery::copy(DefinitionNode *destination_) const
{ {
Scenery* destination = (Scenery*)destination_; Scenery* destination = (Scenery*)destination_;
@ -41,7 +41,7 @@ void Scenery::copy(BaseDefinition *destination_) const
void Scenery::validate() void Scenery::validate()
{ {
BaseDefinition::validate(); DefinitionNode::validate();
keepCameraAboveGround(camera); keepCameraAboveGround(camera);
} }

View file

@ -3,7 +3,7 @@
#include "definition_global.h" #include "definition_global.h"
#include "BaseDefinition.h" #include "DefinitionNode.h"
namespace paysages { namespace paysages {
namespace definition { namespace definition {
@ -13,7 +13,7 @@ namespace definition {
* *
* This class contains the whole scenery definition. * This class contains the whole scenery definition.
*/ */
class DEFINITIONSHARED_EXPORT Scenery: public BaseDefinition class DEFINITIONSHARED_EXPORT Scenery: public DefinitionNode
{ {
public: public:
typedef enum { typedef enum {
@ -29,7 +29,7 @@ public:
Scenery(); Scenery();
virtual void validate() override; 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 saveGlobal(const std::string &filepath) const;
FileOperationResult loadGlobal(const std::string &filepath); FileOperationResult loadGlobal(const std::string &filepath);

View file

@ -4,8 +4,8 @@
#include "NoiseGenerator.h" #include "NoiseGenerator.h"
#include "PackStream.h" #include "PackStream.h"
TerrainDefinition::TerrainDefinition(BaseDefinition* parent): TerrainDefinition::TerrainDefinition(DefinitionNode* parent):
BaseDefinition(parent, "terrain") DefinitionNode(parent, "terrain")
{ {
height = 1.0; height = 1.0;
scaling = 1.0; scaling = 1.0;
@ -41,7 +41,7 @@ void TerrainDefinition::validate()
/* TODO Alter with heightmap min/max */ /* TODO Alter with heightmap min/max */
} }
void TerrainDefinition::copy(BaseDefinition* _destination) const void TerrainDefinition::copy(DefinitionNode* _destination) const
{ {
TerrainDefinition* destination = (TerrainDefinition*)_destination; TerrainDefinition* destination = (TerrainDefinition*)_destination;
@ -60,7 +60,7 @@ void TerrainDefinition::copy(BaseDefinition* _destination) const
void TerrainDefinition::save(PackStream* stream) const void TerrainDefinition::save(PackStream* stream) const
{ {
BaseDefinition::save(stream); DefinitionNode::save(stream);
stream->write(&height); stream->write(&height);
stream->write(&scaling); stream->write(&scaling);
@ -71,7 +71,7 @@ void TerrainDefinition::save(PackStream* stream) const
void TerrainDefinition::load(PackStream* stream) void TerrainDefinition::load(PackStream* stream)
{ {
BaseDefinition::load(stream); DefinitionNode::load(stream);
stream->read(&height); stream->read(&height);
stream->read(&scaling); stream->read(&scaling);

View file

@ -3,7 +3,7 @@
#include "definition_global.h" #include "definition_global.h"
#include "BaseDefinition.h" #include "DefinitionNode.h"
namespace paysages { namespace paysages {
namespace definition { namespace definition {
@ -15,16 +15,16 @@ typedef struct
double base_height; double base_height;
} HeightInfo; } HeightInfo;
class DEFINITIONSHARED_EXPORT TerrainDefinition : public BaseDefinition class DEFINITIONSHARED_EXPORT TerrainDefinition : public DefinitionNode
{ {
public: public:
TerrainDefinition(BaseDefinition* parent); TerrainDefinition(DefinitionNode* parent);
virtual ~TerrainDefinition(); virtual ~TerrainDefinition();
virtual void save(PackStream* stream) const override; virtual void save(PackStream* stream) const override;
virtual void load(PackStream* stream) 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; virtual void validate() override;
double getGridHeight(int x, int z, bool with_painting); double getGridHeight(int x, int z, bool with_painting);

View file

@ -8,7 +8,7 @@ TerrainHeightMap::TerrainHeightMap(TerrainDefinition* terrain):
{ {
} }
void TerrainHeightMap::copy(BaseDefinition* _destination) const void TerrainHeightMap::copy(DefinitionNode* _destination) const
{ {
TerrainHeightMap* destination = (TerrainHeightMap*)_destination; TerrainHeightMap* destination = (TerrainHeightMap*)_destination;

View file

@ -13,7 +13,7 @@ class DEFINITIONSHARED_EXPORT TerrainHeightMap : public PaintedGrid
public: public:
TerrainHeightMap(TerrainDefinition *terrain); TerrainHeightMap(TerrainDefinition *terrain);
virtual void copy(BaseDefinition *destination) const override; virtual void copy(DefinitionNode *destination) const override;
inline TerrainDefinition* getTerrain() const {return terrain;} inline TerrainDefinition* getTerrain() const {return terrain;}

View file

@ -7,8 +7,8 @@
#include "Scenery.h" #include "Scenery.h"
#include "TerrainDefinition.h" #include "TerrainDefinition.h"
TextureLayerDefinition::TextureLayerDefinition(BaseDefinition* parent): TextureLayerDefinition::TextureLayerDefinition(DefinitionNode* parent):
BaseDefinition(parent, "texture") DefinitionNode(parent, "texture")
{ {
terrain_zone = new Zone; terrain_zone = new Zone;
_displacement_noise = new NoiseGenerator; _displacement_noise = new NoiseGenerator;
@ -29,7 +29,7 @@ TextureLayerDefinition::~TextureLayerDefinition()
void TextureLayerDefinition::validate() void TextureLayerDefinition::validate()
{ {
BaseDefinition::validate(); DefinitionNode::validate();
if (displacement_scaling < 0.000001) 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; TextureLayerDefinition* destination = (TextureLayerDefinition*)_destination;
@ -77,7 +77,7 @@ void TextureLayerDefinition::copy(BaseDefinition *_destination) const
void TextureLayerDefinition::save(PackStream* stream) const void TextureLayerDefinition::save(PackStream* stream) const
{ {
BaseDefinition::save(stream); DefinitionNode::save(stream);
terrain_zone->save(stream); terrain_zone->save(stream);
stream->write(&displacement_scaling); stream->write(&displacement_scaling);
@ -91,7 +91,7 @@ void TextureLayerDefinition::save(PackStream* stream) const
void TextureLayerDefinition::load(PackStream* stream) void TextureLayerDefinition::load(PackStream* stream)
{ {
BaseDefinition::load(stream); DefinitionNode::load(stream);
terrain_zone->load(stream); terrain_zone->load(stream);
stream->read(&displacement_scaling); stream->read(&displacement_scaling);

View file

@ -3,12 +3,12 @@
#include "definition_global.h" #include "definition_global.h"
#include "BaseDefinition.h" #include "DefinitionNode.h"
namespace paysages { namespace paysages {
namespace definition { namespace definition {
class DEFINITIONSHARED_EXPORT TextureLayerDefinition : public BaseDefinition class DEFINITIONSHARED_EXPORT TextureLayerDefinition : public DefinitionNode
{ {
public: public:
typedef enum typedef enum
@ -27,13 +27,13 @@ public:
} TextureLayerPreset; } TextureLayerPreset;
public: public:
TextureLayerDefinition(BaseDefinition* parent); TextureLayerDefinition(DefinitionNode* parent);
virtual ~TextureLayerDefinition(); virtual ~TextureLayerDefinition();
virtual void save(PackStream* stream) const override; virtual void save(PackStream* stream) const override;
virtual void load(PackStream* stream) 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; virtual void validate() override;
void applyPreset(TextureLayerPreset preset); void applyPreset(TextureLayerPreset preset);

View file

@ -2,12 +2,12 @@
#include "TextureLayerDefinition.h" #include "TextureLayerDefinition.h"
static BaseDefinition* _layer_constructor(Layers* parent) static DefinitionNode* _layer_constructor(Layers* parent)
{ {
return new TextureLayerDefinition(parent); return new TextureLayerDefinition(parent);
} }
TexturesDefinition::TexturesDefinition(BaseDefinition *parent): TexturesDefinition::TexturesDefinition(DefinitionNode *parent):
Layers(parent, "textures", _layer_constructor) Layers(parent, "textures", _layer_constructor)
{ {
} }

View file

@ -11,7 +11,7 @@ namespace definition {
class DEFINITIONSHARED_EXPORT TexturesDefinition : public Layers class DEFINITIONSHARED_EXPORT TexturesDefinition : public Layers
{ {
public: public:
TexturesDefinition(BaseDefinition *parent); TexturesDefinition(DefinitionNode *parent);
inline TextureLayerDefinition* getTextureLayer(int position) const {return (TextureLayerDefinition*)getLayer(position);} inline TextureLayerDefinition* getTextureLayer(int position) const {return (TextureLayerDefinition*)getLayer(position);}

View file

@ -5,8 +5,8 @@
#include "Color.h" #include "Color.h"
#include "SurfaceMaterial.h" #include "SurfaceMaterial.h"
WaterDefinition::WaterDefinition(BaseDefinition* parent): WaterDefinition::WaterDefinition(DefinitionNode* parent):
BaseDefinition(parent, "water") DefinitionNode(parent, "water")
{ {
material = new SurfaceMaterial; material = new SurfaceMaterial;
depth_color = new Color; depth_color = new Color;
@ -34,7 +34,7 @@ WaterDefinition::~WaterDefinition()
void WaterDefinition::save(PackStream* stream) const void WaterDefinition::save(PackStream* stream) const
{ {
BaseDefinition::save(stream); DefinitionNode::save(stream);
material->save(stream); material->save(stream);
depth_color->save(stream); depth_color->save(stream);
@ -56,7 +56,7 @@ void WaterDefinition::save(PackStream* stream) const
void WaterDefinition::load(PackStream* stream) void WaterDefinition::load(PackStream* stream)
{ {
BaseDefinition::load(stream); DefinitionNode::load(stream);
material->load(stream); material->load(stream);
depth_color->load(stream); depth_color->load(stream);
@ -78,9 +78,9 @@ void WaterDefinition::load(PackStream* stream)
validate(); validate();
} }
void WaterDefinition::copy(BaseDefinition* _destination) const void WaterDefinition::copy(DefinitionNode* _destination) const
{ {
BaseDefinition::copy(_destination); DefinitionNode::copy(_destination);
WaterDefinition* destination = (WaterDefinition*)_destination; WaterDefinition* destination = (WaterDefinition*)_destination;
*destination->material = *material; *destination->material = *material;
@ -100,7 +100,7 @@ void WaterDefinition::copy(BaseDefinition* _destination) const
void WaterDefinition::validate() void WaterDefinition::validate()
{ {
BaseDefinition::validate(); DefinitionNode::validate();
material->validate(); material->validate();
foam_material->validate(); foam_material->validate();

View file

@ -3,21 +3,21 @@
#include "definition_global.h" #include "definition_global.h"
#include "BaseDefinition.h" #include "DefinitionNode.h"
namespace paysages { namespace paysages {
namespace definition { namespace definition {
class DEFINITIONSHARED_EXPORT WaterDefinition: public BaseDefinition class DEFINITIONSHARED_EXPORT WaterDefinition: public DefinitionNode
{ {
public: public:
WaterDefinition(BaseDefinition* parent); WaterDefinition(DefinitionNode* parent);
virtual ~WaterDefinition(); virtual ~WaterDefinition();
virtual void save(PackStream* stream) const override; virtual void save(PackStream* stream) const override;
virtual void load(PackStream* stream) 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; virtual void validate() override;
public: public:

View file

@ -5,8 +5,8 @@
#include "PackStream.h" #include "PackStream.h"
#include "Vector3.h" #include "Vector3.h"
Zone::Zone(BaseDefinition *parent): Zone::Zone(DefinitionNode *parent):
BaseDefinition(parent, "zone") DefinitionNode(parent, "zone")
{ {
value_by_height = new Curve; value_by_height = new Curve;
absolute_height = 1; absolute_height = 1;
@ -43,7 +43,7 @@ void Zone::load(PackStream* stream)
value_by_slope->load(stream); value_by_slope->load(stream);
} }
void Zone::copy(BaseDefinition* _destination) const void Zone::copy(DefinitionNode* _destination) const
{ {
Zone* destination = (Zone*)_destination; Zone* destination = (Zone*)_destination;

View file

@ -3,21 +3,21 @@
#include "definition_global.h" #include "definition_global.h"
#include "BaseDefinition.h" #include "DefinitionNode.h"
namespace paysages { namespace paysages {
namespace definition { namespace definition {
class DEFINITIONSHARED_EXPORT Zone : public BaseDefinition class DEFINITIONSHARED_EXPORT Zone : public DefinitionNode
{ {
public: public:
Zone(BaseDefinition *parent = 0); Zone(DefinitionNode *parent = 0);
virtual ~Zone(); virtual ~Zone();
virtual void save(PackStream* stream) const override; virtual void save(PackStream* stream) const override;
virtual void load(PackStream* stream) override; virtual void load(PackStream* stream) override;
virtual void copy(BaseDefinition* destination) const override; virtual void copy(DefinitionNode* destination) const override;
void clear(); void clear();

View file

@ -14,7 +14,6 @@ DEFINES += DEFINITION_LIBRARY
include(../common.pri) include(../common.pri)
SOURCES += \ SOURCES += \
BaseDefinition.cpp \
Layers.cpp \ Layers.cpp \
WaterDefinition.cpp \ WaterDefinition.cpp \
SurfaceMaterial.cpp \ SurfaceMaterial.cpp \
@ -30,11 +29,11 @@ SOURCES += \
Scenery.cpp \ Scenery.cpp \
PaintedGrid.cpp \ PaintedGrid.cpp \
PaintedGridBrush.cpp \ PaintedGridBrush.cpp \
PaintedGridData.cpp PaintedGridData.cpp \
DefinitionNode.cpp
HEADERS +=\ HEADERS +=\
definition_global.h \ definition_global.h \
BaseDefinition.h \
Layers.h \ Layers.h \
WaterDefinition.h \ WaterDefinition.h \
SurfaceMaterial.h \ SurfaceMaterial.h \
@ -50,7 +49,8 @@ HEADERS +=\
Scenery.h \ Scenery.h \
PaintedGrid.h \ PaintedGrid.h \
PaintedGridBrush.h \ PaintedGridBrush.h \
PaintedGridData.h PaintedGridData.h \
DefinitionNode.h
unix:!symbian { unix:!symbian {
maemo5 { maemo5 {

View file

@ -13,7 +13,7 @@
namespace paysages { namespace paysages {
namespace definition { namespace definition {
class BaseDefinition; class DefinitionNode;
class Scenery; class Scenery;
class CameraDefinition; class CameraDefinition;
class SurfaceMaterial; class SurfaceMaterial;

View file

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

View file

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

View file

@ -3,14 +3,14 @@
#include "Layers.h" #include "Layers.h"
#include "PackStream.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; return result;
} }
@ -26,8 +26,8 @@ TEST(Layers, NullLayer)
for (int i = -2; i < 5; i++) for (int i = -2; i < 5; i++)
{ {
BaseDefinition* layer = layers1.getLayer(0); DefinitionNode* layer = layers1.getLayer(0);
EXPECT_NE((BaseDefinition*)NULL, layer); EXPECT_NE((DefinitionNode*)NULL, layer);
EXPECT_EQ(NULL, layer->getParent()); EXPECT_EQ(NULL, layer->getParent());
EXPECT_EQ(layer, layer->getRoot()); EXPECT_EQ(layer, layer->getRoot());

View file

@ -23,7 +23,7 @@ SOURCES += main.cpp \
CanvasPreview_Test.cpp \ CanvasPreview_Test.cpp \
AtmosphereDefinition_Test.cpp \ AtmosphereDefinition_Test.cpp \
Scenery_Test.cpp \ Scenery_Test.cpp \
BaseDefinition_Test.cpp DefinitionNode_Test.cpp
HEADERS += \ HEADERS += \
BaseTestCase.h BaseTestCase.h