Eris  1.3.23
Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | List of all members
Eris::TerrainModObserver Class Reference

Wrapper class that envelopes a Mercator::TerrainMod. This class is mainly responsible for parsing atlas data and create or update an instance of Mercator::TerrainMod with the correct data. The actual application of the Mercator::TerrainMod to the terrain and the subsequent update of the rendering display (i.e. the Ogre terrain) is handled mainly by TerrainGenerator, which reacts to the events emitted by this class whenever a terrain mod changes or is moved. After you've created an instance of this you must call the init() method. More...

#include <TerrainModObserver.h>

Public Member Functions

 TerrainModObserver (Entity *entity)
 Ctor. More...
 
virtual ~TerrainModObserver ()
 Dtor.
 
virtual bool init (bool alwaysObserve=false)
 Sets up the observation of the entity, and parses the mod info, creating the initial mod instance. More...
 
Mercator::TerrainMod * getMod () const
 Used to retrieve a pointer to this modifier. More...
 
EntitygetEntity () const
 Accessor for the entity to which this terrain mod belongs. More...
 

Public Attributes

sigc::signal< void > ModChanged
 Emitted whenever the modifier is changed or moved. More...
 
sigc::signal< void > ModDeleted
 Emitted just before the entity owning this mod is deleted. More...
 

Protected Member Functions

virtual void onModChanged ()
 Called before the ModChanged signal is emitted.
 
virtual void onModDeleted ()
 Called before the ModDeleted signal is emitted.
 
void attributeChanged (const Atlas::Message::Element &attributeValue)
 Called whenever a modifier is changed and handles the update. More...
 
void entity_Moved ()
 Called whenever a modifier is moved and handles the update.
 
void entity_Deleted ()
 Called whenever the entity holding a modifier is deleted and handles removing the mod from the terrain.
 
virtual void observeEntity ()
 Sets up the previous three handler functions to be called when a change is made to the entity holding the modifier.
 
virtual bool parseMod ()
 Parses the Atlas data for a modifier. More...
 
virtual void reparseMod ()
 If an existing mod changes we need to reparse it. More...
 

Protected Attributes

EntitymEntity
 The owner of this modifier.
 
Entity::AttrChangedSlot mAttrChangedSlot
 Slot used to listen for changes to attributes in the Entity to which this mod belongs to.
 
TerrainModTranslatormInnerMod
 The inner terrain mod instance which holds the actual Mercator::TerrainMod instance and handles the parsing of it. More...
 

Detailed Description

Wrapper class that envelopes a Mercator::TerrainMod. This class is mainly responsible for parsing atlas data and create or update an instance of Mercator::TerrainMod with the correct data. The actual application of the Mercator::TerrainMod to the terrain and the subsequent update of the rendering display (i.e. the Ogre terrain) is handled mainly by TerrainGenerator, which reacts to the events emitted by this class whenever a terrain mod changes or is moved. After you've created an instance of this you must call the init() method.

Author
Tamas Bates
Erik Hjortsberg

Constructor & Destructor Documentation

§ TerrainModObserver()

Eris::TerrainModObserver::TerrainModObserver ( Entity entity)

Ctor.

Parameters
entityThe entity to which this mod belongs.

Member Function Documentation

§ attributeChanged()

void Eris::TerrainModObserver::attributeChanged ( const Atlas::Message::Element &  attributeValue)
protected

Called whenever a modifier is changed and handles the update.

Parameters
attributeValueThe new Atlas data for the terrain mod

References reparseMod().

Referenced by observeEntity().

§ getEntity()

Entity * Eris::TerrainModObserver::getEntity ( ) const

Accessor for the entity to which this terrain mod belongs.

Returns
A pointer to the entity to which this terrain mod belongs.

References mEntity.

§ getMod()

Mercator::TerrainMod * Eris::TerrainModObserver::getMod ( ) const

Used to retrieve a pointer to this modifier.

Returns
a pointer to this modifier

References Eris::TerrainModTranslator::getModifier(), and mInnerMod.

§ init()

bool Eris::TerrainModObserver::init ( bool  alwaysObserve = false)
virtual

Sets up the observation of the entity, and parses the mod info, creating the initial mod instance.

Parameters
alwaysObserveIf set to true, the observation of the entity will be set up even if the parsing failed. If false however, if there was an error during the parsing no observation will be set up. The calling code is then expected to delete this instance.
Returns
True if the atlas data was conformant and successfully parsed.

References observeEntity(), and parseMod().

§ parseMod()

bool Eris::TerrainModObserver::parseMod ( )
protectedvirtual

Parses the Atlas data for a modifier.

Returns
True if it was able to successfully create a Mercator::TerrainMod, False otherwise All work specific to a certain kind of TerrainMod is handled by the functions below.

Don't log anything since it's expected that instances of this can be attached to entities where not terrainmod is present.

References Eris::Entity::getOrientation(), Eris::Entity::getPosition(), Eris::Entity::hasAttr(), mEntity, mInnerMod, Eris::TerrainModTranslator::parseData(), and Eris::Entity::valueOfAttr().

Referenced by init(), and reparseMod().

§ reparseMod()

void Eris::TerrainModObserver::reparseMod ( )
protectedvirtual

If an existing mod changes we need to reparse it.

Call this method in those cases. If there's already an existing mod, that will be deleted. If the changes to the entity results in an invalid parsing, the Deleted signal will be emitted. If the parsing was successful however the Changed signal will be emitted.

If the parsing failed and there was an old mod, we need to temporarily set the inner mod to the old one while we emit the deleted event.

References mInnerMod, onModChanged(), onModDeleted(), and parseMod().

Referenced by attributeChanged(), and entity_Moved().

Member Data Documentation

§ mInnerMod

TerrainModTranslator* Eris::TerrainModObserver::mInnerMod
protected

The inner terrain mod instance which holds the actual Mercator::TerrainMod instance and handles the parsing of it.

In order to be able to better support different types of mods the actual instance will be any of the subclasses of InnerTerrainMod, depending on the type of the mod.

Referenced by entity_Deleted(), getMod(), parseMod(), and reparseMod().

§ ModChanged

sigc::signal<void> Eris::TerrainModObserver::ModChanged

Emitted whenever the modifier is changed or moved.

Should be caught by a listener to apply the change to the terrain.

Referenced by onModChanged().

§ ModDeleted

sigc::signal<void> Eris::TerrainModObserver::ModDeleted

Emitted just before the entity owning this mod is deleted.

Should be caught by a listener to remove this mod from the terrain.

Referenced by onModDeleted().


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