2016-09-19 18:01:01 +02:00
|
|
|
//
|
|
|
|
|
// C++ Interface: TerrainMod
|
|
|
|
|
//
|
|
|
|
|
// Description: The purpose of this class is to handle the bulk of the work
|
|
|
|
|
// involved with using Mercator::TerrainMods. It handles parsing
|
|
|
|
|
// the Atlas data and storing all the information needed by
|
|
|
|
|
// TerrainGenerator to add and remove them from the Terrain.
|
|
|
|
|
//
|
|
|
|
|
// TerrainGenerator listens for changes in the modifier and
|
|
|
|
|
// updates or removes the modifiers from the terrain as needed.
|
|
|
|
|
//
|
|
|
|
|
//
|
|
|
|
|
// Author: Tamas Bates <rhymer@gmail.com>, (C) 2008
|
|
|
|
|
// Author: Erik Ogenvik <erik@ogenvik.org>, (C) 2008
|
2010-09-13 02:09:26 +01:00
|
|
|
//
|
|
|
|
|
// This program is free software; you can redistribute it and/or modify
|
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
|
// the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
// (at your option) any later version.
|
2016-09-19 18:01:01 +02:00
|
|
|
//
|
2010-09-13 02:09:26 +01:00
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2016-09-19 18:01:01 +02:00
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2010-09-13 02:09:26 +01:00
|
|
|
// GNU General Public License for more details.
|
2016-09-19 18:01:01 +02:00
|
|
|
//
|
2010-09-13 02:09:26 +01:00
|
|
|
// You should have received a copy of the GNU General Public License
|
2016-09-19 18:01:01 +02:00
|
|
|
// along with this program; if not, write to the Free Software
|
|
|
|
|
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.//
|
|
|
|
|
//
|
|
|
|
|
#ifndef TERRAINMODTRANSLATOR_H
|
|
|
|
|
#define TERRAINMODTRANSLATOR_H
|
2010-09-13 02:09:26 +01:00
|
|
|
|
|
|
|
|
#include <Atlas/Message/Element.h>
|
|
|
|
|
|
|
|
|
|
#include <wfmath/point.h>
|
|
|
|
|
|
2016-09-19 18:01:01 +02:00
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
|
|
namespace Mercator
|
|
|
|
|
{
|
|
|
|
|
class TerrainMod;
|
2010-09-13 02:09:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2016-09-19 18:01:01 +02:00
|
|
|
* @author Erik Ogenvik <erik@ogenvik.org>
|
|
|
|
|
* @brief Handles translation of terrain mod data into Mercator::TerrainMod instances.
|
|
|
|
|
*
|
|
|
|
|
*/
|
2011-01-06 19:01:37 +00:00
|
|
|
class TerrainModTranslator
|
2010-09-13 02:09:26 +01:00
|
|
|
{
|
2010-11-10 16:11:21 +00:00
|
|
|
public:
|
|
|
|
|
|
2016-09-19 18:01:01 +02:00
|
|
|
explicit TerrainModTranslator(const Atlas::Message::MapType& data);
|
|
|
|
|
~TerrainModTranslator() = default;
|
2010-11-10 17:52:01 +00:00
|
|
|
|
2016-09-19 18:01:01 +02:00
|
|
|
/**
|
|
|
|
|
* Creates a TerrainMod instance, if possible.
|
|
|
|
|
* @param pos
|
|
|
|
|
* @param orientation
|
|
|
|
|
* @return A terrain mod instance, or null if none could be created.
|
|
|
|
|
*/
|
|
|
|
|
Mercator::TerrainMod* parseData(const WFMath::Point<3> & pos, const WFMath::Quaternion & orientation);
|
2010-11-04 10:39:43 +00:00
|
|
|
|
2016-09-19 18:01:01 +02:00
|
|
|
/**
|
|
|
|
|
* @brief True if there's a valid inner translator.
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
bool isValid() const;
|
2010-11-05 00:41:12 +00:00
|
|
|
|
2016-09-19 18:01:01 +02:00
|
|
|
/**
|
|
|
|
|
* Removes any internal translator.
|
|
|
|
|
*/
|
|
|
|
|
void reset();
|
2010-11-05 00:41:12 +00:00
|
|
|
|
2016-09-19 18:01:01 +02:00
|
|
|
static float parsePosition(const WFMath::Point<3> & pos, const Atlas::Message::MapType& modElement);
|
2010-11-05 00:41:12 +00:00
|
|
|
|
2016-09-19 18:01:01 +02:00
|
|
|
protected:
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Interface for inner translator.
|
|
|
|
|
*
|
|
|
|
|
* Concrete templated subclasses are used for both shapes and mod types.
|
|
|
|
|
*/
|
|
|
|
|
class InnerTranslator
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
InnerTranslator(const Atlas::Message::MapType &);
|
|
|
|
|
virtual Mercator::TerrainMod* createInstance(const WFMath::Point<3>& pos, const WFMath::Quaternion& orientation) = 0;
|
|
|
|
|
protected:
|
|
|
|
|
const Atlas::Message::MapType mData;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
template<template<int> class Shape>
|
|
|
|
|
InnerTranslator* buildTranslator(const Atlas::Message::MapType& modElement, const std::string & typeName, Shape<2> & shape, const Atlas::Message::Element & shapeElement);
|
|
|
|
|
|
|
|
|
|
std::shared_ptr<TerrainModTranslator::InnerTranslator> mInnerTranslator;
|
2010-09-13 02:09:26 +01:00
|
|
|
};
|
|
|
|
|
|
2016-09-19 18:01:01 +02:00
|
|
|
|
|
|
|
|
#endif
|