Eris 1.3.16

TerrainMod.h

00001 //
00002 // C++ Interface: TerrainMod
00003 //
00004 // Description: The purpose of this class is to handle the bulk of the work
00005 //              involved with using Mercator::TerrainMods. It handles parsing
00006 //              the Atlas data and storing all the information needed by 
00007 //              TerrainGenerator to add and remove them from the Terrain.
00008 //
00009 //              TerrainGenerator listens for changes in the modifier and
00010 //              updates or removes the modifiers from the terrain as needed.
00011 //
00012 //
00013 // Author: Tamas Bates <rhymer@gmail.com>, (C) 2008
00014 // Author: Erik Hjortsberg <erik.hjortsberg@iteam.se>, (C) 2008
00015 //
00016 // This program is free software; you can redistribute it and/or modify
00017 // it under the terms of the GNU General Public License as published by
00018 // the Free Software Foundation; either version 2 of the License, or
00019 // (at your option) any later version.
00020 //
00021 // This program is distributed in the hope that it will be useful,
00022 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00023 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00024 // GNU General Public License for more details.
00025 //
00026 // You should have received a copy of the GNU General Public License
00027 // along with this program; if not, write to the Free Software
00028 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.//
00029 //
00030 #ifndef ERIS_TERRAINMOD_H
00031 #define ERIS_TERRAINMOD_H
00032 
00033 #include <sigc++/signal.h>
00034 #include <Eris/Entity.h>
00035 
00036 namespace Mercator
00037 {
00038     class TerrainMod;
00039     class CraterTerrainMod;
00040 }
00041 
00042 namespace Eris
00043 {
00044 
00045 class Entity;
00046 class TerrainMod;
00047 class InnerTerrainMod_impl;
00048 
00054 class InnerTerrainMod
00055 {
00056 public:
00060     virtual ~InnerTerrainMod();
00061     
00068     const std::string& getTypename() const;
00069     
00077     virtual bool parseAtlasData(const Atlas::Message::MapType& modElement) = 0;
00078     
00084     virtual Mercator::TerrainMod* getModifier() = 0;
00085 
00086 protected:
00087 
00094     InnerTerrainMod(TerrainMod& terrainMod, const std::string& typemod);
00095     
00100     std::string mTypeName;
00101     
00105     TerrainMod& mTerrainMod;
00106     
00114     const std::string& parseShape(const Atlas::Message::MapType& modElement, const Atlas::Message::Element** shapeMap);
00115     
00124     WFMath::Point<3> parsePosition(const Atlas::Message::MapType& modElement);
00125 
00126 //      template <typename InnerTerrainMod_implType>
00127 //      InnerTerrainMod_implType* createInnerTerrainMod_impInstance(const Atlas::Message::MapType& modElement);
00128 
00129 };
00130 
00131 
00138 class InnerTerrainModSlope : public InnerTerrainMod
00139 {
00140 public:
00145     InnerTerrainModSlope(TerrainMod& terrainMod);
00146     
00150     virtual ~InnerTerrainModSlope();
00151     
00155     virtual bool parseAtlasData(const Atlas::Message::MapType& modElement);
00156     
00160     virtual Mercator::TerrainMod* getModifier();
00161 
00162 protected:
00168     InnerTerrainMod_impl* mModifier_impl;
00169 };
00170 
00179 class InnerTerrainModCrater : public InnerTerrainMod
00180 {
00181 public:
00186     InnerTerrainModCrater(TerrainMod& terrainMod);
00187     
00191     virtual ~InnerTerrainModCrater();
00192     
00196     virtual bool parseAtlasData(const Atlas::Message::MapType& modElement);
00197     
00201     virtual Mercator::TerrainMod* getModifier();
00202 
00203 protected:
00208     Mercator::CraterTerrainMod* mModifier;
00209 };
00210 
00218 class InnerTerrainModLevel : public InnerTerrainMod
00219 {
00220 public:
00225     InnerTerrainModLevel(TerrainMod& terrainMod);
00226     
00230     virtual ~InnerTerrainModLevel();
00231     
00235     virtual bool parseAtlasData(const Atlas::Message::MapType& modElement);
00236     
00240     virtual Mercator::TerrainMod* getModifier();
00241 
00242 protected:
00243 
00249     InnerTerrainMod_impl* mModifier_impl;
00250 };
00251 
00259 class InnerTerrainModAdjust : public InnerTerrainMod
00260 {
00261 public:
00266     InnerTerrainModAdjust(TerrainMod& terrainMod);
00267     
00271     virtual ~InnerTerrainModAdjust();
00272     
00276     virtual bool parseAtlasData(const Atlas::Message::MapType& modElement);
00277     
00281     virtual Mercator::TerrainMod* getModifier();
00282 
00283 protected:
00284 
00290     InnerTerrainMod_impl* mModifier_impl;
00291 };
00292 
00293 
00302 class TerrainMod
00303 {
00304 public:
00309     TerrainMod(Entity* entity);
00310 
00314     virtual ~TerrainMod();
00315     
00321     virtual bool init(bool alwaysObserve = false);
00322 
00327     inline Mercator::TerrainMod* getMod() const;
00328 
00329     
00334     sigc::signal<void> ModChanged;
00335 
00340     sigc::signal<void> ModDeleted;
00341     
00346     Entity* getEntity() const;
00347 
00348 protected:
00349     
00353     Entity* mEntity;
00354     
00358     Entity::AttrChangedSlot mAttrChangedSlot;
00359 
00360     
00364     virtual void onModChanged();
00365     
00369     virtual void onModDeleted();
00370     
00375     void attributeChanged(const Atlas::Message::Element& attributeValue);
00376 
00380     void entity_Moved();
00381 
00386     void entity_Deleted();
00387 
00392     virtual void observeEntity();
00393 
00399     virtual bool parseMod();
00400     
00405     virtual void reparseMod();
00406     
00407 
00412     InnerTerrainMod* mInnerMod;
00413 };
00414 
00415 Mercator::TerrainMod* TerrainMod::getMod() const
00416 {
00417     if (mInnerMod) {
00418         return mInnerMod->getModifier();
00419     }
00420     return 0;
00421 }
00422 
00423 }
00424 
00425 
00426 #endif