Eris
1.3.19
|
Base class for all terrain mod specific classes.This is not meant to be used directly by anything else than the TerrainMod class. The TerrainMod class in itself doesn't hold the actual reference to the terrain mod, and doesn't handle the final parsing of Atlas data. This is instead handled by the different subclasses of this class. Since the different kinds of terrain mods found in Mercator behave differently depending on their type and the kind of shape used, we need to separate the code for handling them into different classes. More...
#include <TerrainModTranslator.h>
Public Member Functions | |
bool | parseData (const WFMath::Point< 3 > &pos, const WFMath::Quaternion &, const Atlas::Message::MapType &) |
Parse the Atlas data and create the terrain mod instance with it. | |
Mercator::TerrainMod * | getModifier () |
Accessor for the Mercator::TerrainMod created and held by this instance. | |
TerrainModTranslator () | |
Ctor. | |
template<template< int > class Shape> | |
bool | parseStuff (const WFMath::Point< 3 > &pos, const WFMath::Quaternion &orientation, const MapType &modElement, const std::string &typeName, Shape< 2 > &shape, const Element &shapeMap) |
Parse the shape data and create the terrain mod instance with it. | |
template<template< int > class Shape> | |
bool | parseShape (const Element &shapeElement, const WFMath::Point< 3 > &pos, const WFMath::Quaternion &orientation, Shape< 2 > &shape) |
Common method for parsing shape data from Atlas. | |
template<template< template< int > class Shape > class Mod, template< int > class Shape> | |
bool | createInstance (Shape< 2 > &shape, const WFMath::Point< 3 > &pos, const MapType &modElement, float, float) |
Create or update an instance from the passed in atlas data. | |
template<template< template< int > class S > class Mod, template< int > class Shape> | |
bool | createInstance (Shape< 2 > &shape, const WFMath::Point< 3 > &pos, const MapType &modElement) |
Create or update an instance from the passed in atlas data. | |
Protected Member Functions | |
template<template< int > class Shape> | |
bool | parseStuff (const WFMath::Point< 3 > &pos, const WFMath::Quaternion &orientation, const Atlas::Message::MapType &modElement, const std::string &typeName, Shape< 2 > &shape, const Atlas::Message::Element &shapeElement) |
template<template< template< int > class Shape > class Mod, template< int > class Shape> | |
bool | createInstance (Shape< 2 > &shape, const WFMath::Point< 3 > &pos, const Atlas::Message::MapType &, float, float) |
template<template< template< int > class Shape > class Mod, template< int > class Shape> | |
bool | createInstance (Shape< 2 > &shape, const WFMath::Point< 3 > &pos, const Atlas::Message::MapType &) |
Static Protected Member Functions | |
static float | parsePosition (const WFMath::Point< 3 > &pos, const Atlas::Message::MapType &modElement) |
Parses the changes to the position of the mod If no height data is given the height of the entity the mod belongs to will be used. | |
template<template< int > class Shape> | |
static bool | parseShape (const Atlas::Message::Element &shapeElement, const WFMath::Point< 3 > &pos, const WFMath::Quaternion &orientation, Shape< 2 > &shape) |
Protected Attributes | |
Mercator::TerrainMod * | m_mod |
Base class for all terrain mod specific classes.This is not meant to be used directly by anything else than the TerrainMod class. The TerrainMod class in itself doesn't hold the actual reference to the terrain mod, and doesn't handle the final parsing of Atlas data. This is instead handled by the different subclasses of this class. Since the different kinds of terrain mods found in Mercator behave differently depending on their type and the kind of shape used, we need to separate the code for handling them into different classes.
bool Eris::TerrainModTranslator::createInstance | ( | Shape< 2 > & | shape, |
const WFMath::Point< 3 > & | pos, | ||
const MapType & | modElement, | ||
float | , | ||
float | |||
) |
Create or update an instance from the passed in atlas data.
shape | The modified shape of the mod |
pos | Position of the mod entity |
bool Eris::TerrainModTranslator::createInstance | ( | Shape< 2 > & | shape, |
const WFMath::Point< 3 > & | pos, | ||
const MapType & | modElement | ||
) |
Create or update an instance from the passed in atlas data.
shape | The modified shape of the mod |
pos | Position of the mod entity |
Mercator::TerrainMod * Eris::TerrainModTranslator::getModifier | ( | ) |
Accessor for the Mercator::TerrainMod created and held by this instance.
If no terrain mod could be created, such as with faulty Atlas data, or if parseData() hasn't been called yet, this will return a null pointer.
Referenced by Eris::TerrainModObserver::getMod().
bool Eris::TerrainModTranslator::parseData | ( | const WFMath::Point< 3 > & | pos, |
const WFMath::Quaternion & | , | ||
const Atlas::Message::MapType & | |||
) |
Parse the Atlas data and create the terrain mod instance with it.
pos | Position of the mod entity |
orientation | Orientation of the mod entity |
modElement | Atlas data describing the mod |
Referenced by Eris::TerrainModObserver::parseMod().
float Eris::TerrainModTranslator::parsePosition | ( | const WFMath::Point< 3 > & | pos, |
const Atlas::Message::MapType & | modElement | ||
) | [static, protected] |
Parses the changes to the position of the mod If no height data is given the height of the entity the mod belongs to will be used.
If however a "height" value is set, that will be used instead. If no "height" value is set, but a "heightoffset" is present, that value will be added to the height set by the position of the entity the mod belongs to.
pos | Position of the mod entity |
modElement | Atlas data describing the mod |
If the height is specified use that, else check for a height offset. If none is found, use the default height of the entity position
bool Eris::TerrainModTranslator::parseShape | ( | const Element & | shapeElement, |
const WFMath::Point< 3 > & | pos, | ||
const WFMath::Quaternion & | orientation, | ||
Shape< 2 > & | shape | ||
) |
Common method for parsing shape data from Atlas.
Since each different shape expects different Atlas data this is a templated method with specialized implemtations for each available shape. If you call this and get error regarding missing implementations it probably means that there's no implementation for the type of shape you're calling it with. Note that a new shape instance will be put on the heap if the parsing is successful, and it's up to the calling code to properly delete it when done.
shapeElement | The atlas map element which contains the shape data. Often this is found with the key "shape" in the atlas data. |
pos | The original position of the entity to which this shape will belong. The shape will be positioned according to this. |
shape | The resulting shape is meant to be put here, if successfully created. That means that a new shape instance will be created, and it's then up to the calling method to properly delete it, to avoid memory leaks. |
Just log an error and return false, this isn't fatal.
rotation about Z axis
bool Eris::TerrainModTranslator::parseStuff | ( | const WFMath::Point< 3 > & | pos, |
const WFMath::Quaternion & | orientation, | ||
const MapType & | modElement, | ||
const std::string & | typeName, | ||
Shape< 2 > & | shape, | ||
const Element & | shapeMap | ||
) |
Parse the shape data and create the terrain mod instance with it.
pos | Position of the mod entity |
orientation | Orientation of the mod entity |
modElement | Atlas data describing the mod |
typeName | Name of the type of mod from the Atlas data |
shape | Reference to the shape object to be populated |
shapeMap | Atlas data containing the shape parameters |