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 "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;

View file

@ -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;
/**

View file

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

View file

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

View file

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

View file

@ -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:

View file

@ -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)
{
}

View file

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

View file

@ -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<BaseDefinition*> children_copy = children;
std::vector<DefinitionNode*> 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<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())
{
child->parent = NULL;

View file

@ -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<BaseDefinition*> children;
std::vector<DefinitionNode*> children;
};
}
}
#endif // BASEDEFINITION_H
#endif // DEFINITIONNODE_H

View file

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

View file

@ -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<BaseDefinition*> layers;
BaseDefinition* null_layer;
std::vector<DefinitionNode*> layers;
DefinitionNode* null_layer;
};
}

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

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;

View file

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

View file

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

View file

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

View file

@ -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)
{
}

View file

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

View file

@ -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();

View file

@ -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:

View file

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

View file

@ -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();

View file

@ -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 {

View file

@ -13,7 +13,7 @@
namespace paysages {
namespace definition {
class BaseDefinition;
class DefinitionNode;
class Scenery;
class CameraDefinition;
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 "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());

View file

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