Eris  1.3.19
Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | List of all members
Eris::TerrainModTranslator Class Reference

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

Detailed Description

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.

Author
Erik Hjortsberg erik..nosp@m.hjor.nosp@m.tsber.nosp@m.g@it.nosp@m.eam.s.nosp@m.e

Member Function Documentation

template<template< template< int > class Shape > class Mod, template< int > class Shape>
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.

Parameters
shapeThe modified shape of the mod
posPosition of the mod entity
Returns
True if the atlas data could be successfully parsed
template<template< template< int > class S > class Mod, template< int > class Shape>
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.

Parameters
shapeThe modified shape of the mod
posPosition of the mod entity
Returns
True if the atlas data could be successfully parsed
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.

Returns
A pointer to the TerrainMod held by this instance, or null if none created.

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.

Parameters
posPosition of the mod entity
orientationOrientation of the mod entity
modElementAtlas data describing the mod
Returns
true if translation succeeds

Referenced by Eris::TerrainModObserver::parseMod().

float Eris::TerrainModTranslator::parsePosition ( const WFMath::Point< 3 > &  pos,
const Atlas::Message::MapType &  modElement 
)
staticprotected

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.

Parameters
posPosition of the mod entity
modElementAtlas data describing the mod
Returns
The adjusted height of 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

template<template< int > class Shape>
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.

Parameters
shapeElementThe atlas map element which contains the shape data. Often this is found with the key "shape" in the atlas data.
posThe original position of the entity to which this shape will belong. The shape will be positioned according to this.
shapeThe 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.
Returns
True if the atlas data was successfully parsed and a shape was created.

Just log an error and return false, this isn't fatal.

rotation about Z axis

template<template< int > class Shape>
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.

Parameters
posPosition of the mod entity
orientationOrientation of the mod entity
modElementAtlas data describing the mod
typeNameName of the type of mod from the Atlas data
shapeReference to the shape object to be populated
shapeMapAtlas data containing the shape parameters

The documentation for this class was generated from the following files: