32 #include "ext/tinyxml/fife_tinyxml.h"
69 : m_model(model), m_vfs(vfs), m_imageManager(imageManager), m_renderBackend(renderBackend),
70 m_loaderName(
"fife"), m_mapDirectory(
"") {
87 bfs::path mapPath(filename);
96 TiXmlDocument mapFile;
98 std::string mapFilename = mapPath.string();
107 if (mapFile.Error()) {
108 std::ostringstream oss;
109 oss <<
" Failed to load"
112 <<
" [" << __LINE__ <<
"]"
138 const TiXmlElement* root = mapFile.RootElement();
141 const std::string* loaderName = root->Attribute(std::string(
"loaderName"));
148 root->QueryValueAttribute(
"elements", &numElements);
151 const std::string* mapName = root->Attribute(std::string(
"id"));
157 catch (NameClash& e) {
168 for (
const TiXmlElement *importElement = root->FirstChildElement(
"import"); importElement; importElement = importElement->NextSiblingElement(
"import")) {
169 const std::string* importDir = importElement->Attribute(std::string(
"dir"));
170 const std::string* importFile = importElement->Attribute(std::string(
"file"));
172 std::string directory =
"";
174 directory = *importDir;
177 std::string file =
"";
182 if (importDir && !importFile) {
184 fullPath /= directory;
187 else if (importFile) {
188 bfs::path fullFilePath(file);
189 bfs::path fullDirPath(directory);
192 fullDirPath /= directory;
196 fullFilePath /= file;
203 std::list<std::string>::iterator name_it = namespaces.begin();
204 for (; name_it != namespaces.end(); ++name_it) {
206 std::list<Object*>::iterator object_it = objects.begin();
207 for (; object_it != objects.end(); ++object_it) {
208 if ((*object_it)->isMultiObject()) {
209 const std::list<std::string>& multiParts = (*object_it)->getMultiPartIds();
210 std::list<std::string>::const_iterator multi_it = multiParts.begin();
211 for (; multi_it != multiParts.end(); ++multi_it) {
215 (*object_it)->addMultiPart(partObj);
223 for (
const TiXmlElement* layerElement = root->FirstChildElement(
"layer"); layerElement; layerElement = layerElement->NextSiblingElement(
"layer")) {
225 double xOffset = 0.0;
226 double yOffset = 0.0;
227 double zOffset = 0.0;
231 double rotation = 0.0;
233 int xOffsetRetVal = layerElement->QueryValueAttribute(
"x_offset", &xOffset);
234 int yOffsetRetVal = layerElement->QueryValueAttribute(
"y_offset", &yOffset);
235 layerElement->QueryValueAttribute(
"z_offset", &zOffset);
236 int xScaleRetVal = layerElement->QueryValueAttribute(
"x_scale", &xScale);
237 int yScaleRetVal = layerElement->QueryValueAttribute(
"y_scale", &yScale);
238 layerElement->QueryValueAttribute(
"z_scale", &zScale);
239 int rotationRetVal = layerElement->QueryValueAttribute(
"rotation", &rotation);
241 const std::string* layerName = layerElement->Attribute(std::string(
"id"));
242 const std::string* pathing = layerElement->Attribute(std::string(
"pathing"));
243 const std::string* sorting = layerElement->Attribute(std::string(
"sorting"));
244 const std::string* gridType = layerElement->Attribute(std::string(
"grid_type"));
245 const std::string* layerType = layerElement->Attribute(std::string(
"layer_type"));
246 const std::string* layerTypeName = layerElement->Attribute(std::string(
"layer_type_id"));
248 if (xOffsetRetVal == TIXML_SUCCESS &&
249 yOffsetRetVal == TIXML_SUCCESS &&
250 xScaleRetVal == TIXML_SUCCESS &&
251 yScaleRetVal == TIXML_SUCCESS &&
252 rotationRetVal == TIXML_SUCCESS &&
258 if (
"cell_edges_and_diagonals" == *pathing) {
264 if (*sorting ==
"location") {
266 }
else if (*sorting ==
"camera_and_location") {
301 if (*layerType ==
"walkable") {
303 }
else if (*layerType ==
"interact") {
311 for (
const TiXmlElement* instances = layerElement->FirstChildElement(
"instances"); instances; instances = instances->NextSiblingElement(
"instances")) {
312 for (
const TiXmlElement* instance = instances->FirstChildElement(
"i"); instance; instance = instance->NextSiblingElement(
"i")) {
319 int visitorRadius = 0;
321 const std::string* instanceId = instance->Attribute(std::string(
"id"));
322 const std::string* objectId = instance->Attribute(std::string(
"o"));
323 const std::string* costId = instance->Attribute(std::string(
"cost_id"));
326 objectId = instance->Attribute(std::string(
"object"));
330 objectId = instance->Attribute(std::string(
"obj"));
333 const std::string* namespaceId = instance->Attribute(std::string(
"ns"));
336 namespaceId = instance->Attribute(std::string(
"namespace"));
339 int xRetVal = instance->QueryValueAttribute(
"x", &x);
340 int yRetVal = instance->QueryValueAttribute(
"y", &y);
341 instance->QueryValueAttribute(
"z", &z);
342 int rRetVal = instance->QueryValueAttribute(
"r", &r);
344 if (xRetVal == TIXML_SUCCESS) {
351 if (yRetVal == TIXML_SUCCESS) {
358 if (rRetVal != TIXML_SUCCESS) {
359 rRetVal = instance->QueryValueAttribute(
"rotation", &r);
362 int stackRetVal = instance->QueryValueAttribute(
"stackpos", &stackpos);
363 int cellStackRetVal = instance->QueryValueAttribute(
"cellstack", &cellStack);
364 int visitorRetVal = instance->QueryValueAttribute(
"visitor_radius", &visitorRadius);
365 const std::string* shapeType = instance->Attribute(std::string(
"visitor_shape"));
368 if (
"quad" == *shapeType) {
370 }
else if (
"circle" == *shapeType) {
392 if (rRetVal != TIXML_SUCCESS) {
394 std::vector<int> angles;
396 if (!angles.empty()) {
405 if (instVisual && (stackRetVal == TIXML_SUCCESS)) {
409 if (cellStackRetVal == TIXML_SUCCESS) {
413 if (visitorRetVal == TIXML_SUCCESS) {
421 int costRetVal = instance->QueryValueAttribute(
"cost", &cost);
422 if (costRetVal == TIXML_SUCCESS) {
430 inst->
act(
"default", target,
true);
435 std::ostringstream oss;
436 oss <<
" Failed to create instance of object "
439 <<
" [" << __LINE__ <<
"]"
461 for (
const TiXmlElement* cacheElements = root->FirstChildElement(
"cellcaches"); cacheElements; cacheElements = cacheElements->NextSiblingElement(
"cellcaches")) {
462 for (
const TiXmlElement* cacheElement = cacheElements->FirstChildElement(
"cellcache"); cacheElement; cacheElement = cacheElement->NextSiblingElement(
"cellcache")) {
463 double cacheCost = 1.0;
464 double cacheSpeed = 1.0;
465 const std::string* layerId = cacheElement->Attribute(std::string(
"id"));
468 cacheElement->QueryDoubleAttribute(
"default_cost", &cacheCost);
469 cacheElement->QueryDoubleAttribute(
"default_speed", &cacheSpeed);
475 int searchNarrow = 0;
476 cacheElement->QueryIntAttribute(
"search_narrow", &searchNarrow);
481 for (
const TiXmlElement* cellElement = cacheElement->FirstChildElement(
"cell"); cellElement; cellElement = cellElement->NextSiblingElement(
"cell")) {
484 int success = cellElement->QueryIntAttribute(
"x", &cellX);
485 success &= cellElement->QueryIntAttribute(
"y", &cellY);
486 if (success == TIXML_SUCCESS) {
490 const std::string* cellVisual = cellElement->Attribute(std::string(
"state"));
493 if (*cellVisual ==
"concealed") {
495 }
else if (*cellVisual ==
"masked") {
501 const std::string* cellBlocker = cellElement->Attribute(std::string(
"blocker_type"));
503 if (*cellBlocker ==
"no_blocker") {
506 }
else if (*cellBlocker ==
"blocker") {
512 double cellCost = 1.0;
513 double cellSpeed = 1.0;
514 success = cellElement->QueryDoubleAttribute(
"default_cost", &cellCost);
515 if (success == TIXML_SUCCESS) {
518 success = cellElement->QueryDoubleAttribute(
"default_speed", &cellSpeed);
519 if (success == TIXML_SUCCESS) {
525 cellElement->QueryIntAttribute(
"narrow", &isNarrow);
530 for (
const TiXmlElement* costElement = cellElement->FirstChildElement(
"cost"); costElement; costElement = costElement->NextSiblingElement(
"cost")) {
531 const std::string* costId = costElement->Attribute(std::string(
"id"));
533 success = costElement->QueryDoubleAttribute(
"value", &cost);
534 if (costId && success == TIXML_SUCCESS) {
540 for (
const TiXmlElement* areaElement = cellElement->FirstChildElement(
"area"); areaElement; areaElement = areaElement->NextSiblingElement(
"area")) {
541 const std::string* areaId = areaElement->Attribute(std::string(
"id"));
556 for (
const TiXmlElement* cacheElements = root->FirstChildElement(
"cellcaches"); cacheElements; cacheElements = cacheElements->NextSiblingElement(
"cellcaches")) {
557 for (
const TiXmlElement* cacheElement = cacheElements->FirstChildElement(
"cellcache"); cacheElement; cacheElement = cacheElement->NextSiblingElement(
"cellcache")) {
558 const std::string* layerId = cacheElement->Attribute(std::string(
"id"));
564 for (
const TiXmlElement* cellElement = cacheElement->FirstChildElement(
"cell"); cellElement; cellElement = cellElement->NextSiblingElement(
"cell")) {
567 int success = cellElement->QueryIntAttribute(
"x", &cellX);
568 success &= cellElement->QueryIntAttribute(
"y", &cellY);
569 if (success == TIXML_SUCCESS) {
575 for (
const TiXmlElement* transitionElement = cellElement->FirstChildElement(
"transition"); transitionElement; transitionElement = transitionElement->NextSiblingElement(
"transition")) {
579 success = transitionElement->QueryIntAttribute(
"x", &targetX);
580 success &= transitionElement->QueryIntAttribute(
"y", &targetY);
581 transitionElement->QueryIntAttribute(
"z", &targetZ);
582 if (success == TIXML_SUCCESS) {
584 Layer* targetLayer = NULL;
585 const std::string* targetLayerId = transitionElement->Attribute(std::string(
"id"));
587 targetLayer = map->
getLayer(*targetLayerId);
594 transitionElement->QueryIntAttribute(
"immediate", &immediate);
606 for (
const TiXmlElement* cameraElement = root->FirstChildElement(
"camera"); cameraElement; cameraElement = cameraElement->NextSiblingElement(
"camera")) {
607 const std::string* cameraId = cameraElement->Attribute(std::string(
"id"));
608 const std::string* refLayerId = cameraElement->Attribute(std::string(
"ref_layer_id"));
610 int refCellWidth = 0;
611 int refCellHeight = 0;
612 int success = cameraElement->QueryIntAttribute(
"ref_cell_width", &refCellWidth);
613 success &= cameraElement->QueryIntAttribute(
"ref_cell_height", &refCellHeight);
615 if (cameraId && refLayerId && success == TIXML_SUCCESS) {
618 double rotation = 0.0;
620 cameraElement->QueryDoubleAttribute(
"tilt", &tilt);
621 cameraElement->QueryDoubleAttribute(
"zoom", &zoom);
622 cameraElement->QueryDoubleAttribute(
"rotation", &rotation);
623 success = cameraElement->QueryDoubleAttribute(
"ztoy", &zToY);
625 const std::string* viewport = cameraElement->Attribute(std::string(
"viewport"));
643 if (viewportParameters.size() == 4) {
644 Rect rect(viewportParameters[0], viewportParameters[1],
645 viewportParameters[2], viewportParameters[3]);
648 cam = map->
addCamera(*cameraId, layer, rect);
660 cam = map->
addCamera(*cameraId, layer, rect);
674 if (success == TIXML_SUCCESS) {
680 if (instanceRenderer)
698 assert(objectLoader);
705 assert(animationLoader);
717 bfs::path mapPath(filename);
719 TiXmlDocument mapFile;
721 std::string mapFilename = mapPath.string();
730 if (mapFile.Error()) {
734 const TiXmlElement* root = mapFile.RootElement();
737 const std::string* loaderName = root->Attribute(std::string(
"loader"));
743 if (!loaderName || (loaderName && *loaderName ==
getLoaderName())) {
754 catch (NotFound& e) {
765 bfs::path importFilePath(directory);
766 importFilePath /= file;
768 std::string importFileString = importFilePath.string();
779 if (!directory.empty()) {
780 bfs::path importDirectory(directory);
781 std::string importDirectoryString = importDirectory.string();
783 std::set<std::string> files =
m_vfs->
listFiles(importDirectoryString);
786 std::set<std::string>::iterator iter;
787 for (iter = files.begin(); iter != files.end(); ++iter) {
790 std::string ext = bfs::extension(*iter);
791 if (ext ==
".xml" || ext ==
".zip") {
797 for (iter = nestedDirectories.begin(); iter != nestedDirectories.end(); ++iter) {
799 if ((*iter).find(
".svn") == std::string::npos) {
816 return (
new MapLoader(model, vfs, imageManager, renderBackend));
std::list< std::string > getNamespaces() const
Get a list of namespaces currently referenced by objects in the metamodel.
void setZScale(const double scale)
Set the cellgrid z-scaling.
static InstanceVisual * create(Instance *instance)
Constructs and assigns it to the passed item.
Abstract interface for all the renderbackends.
void setZToY(double zToY)
Sets zToY value for the camera and enables their use.
std::set< std::string > listFiles(const std::string &path) const
Get a filelist of the given directory.
uint32_t getDataLength() const
get the complete datalength
uint32_t getScreenHeight() const
void addPercentDoneListener(PercentDoneListener *listener)
allows adding a listener to the map loader for percent completed events
Map * load(const std::string &filename)
Layer * getLayer(const std::string &identifier)
Get the layer with the given id.
Camera * addCamera(const std::string &id, Layer *layer, const Rect &viewport)
Adds camera to the map.
Instance visual contains data that is needed to visualize the instance on screen. ...
void setZShift(const double zshift)
Set the cellgrid z shift.
void activateAllLayers(Map *elevation)
Activates all layers from given elevation.
void setSearchNarrowCells(bool search)
Sets if narrow cells should be searched automatic.
void reset(T *ptr=0)
reset this pointer to a null shared pointer this can be used to lower the reference count of the shar...
void setAnimationLoader(const FIFE::AnimationLoaderPtr &animationLoader)
A CellCache is an abstract depiction of one or a few layers and contains additional information...
MapLoader(Model *model, VFS *vfs, ImageManager *imageManager, RenderBackend *renderBackend)
void setSortingStrategy(SortingStrategy strategy)
Sets sorting strategy for the layer.
void setTilt(double tilt)
Sets tilt for the camera.
void setDefaultCostMultiplier(double multi)
Sets default cost for this CellCache.
void setSpeedMultiplier(double multi)
Changes the cell speed.
void addCellToCost(const std::string &costId, Cell *cell)
Assigns a cell to a cost identifier.
RawData * open(const std::string &path)
Open a file.
CellCache * getCellCache()
Returns the CellCache of this layer.
void setCellType(CellTypeInfo type)
Sets blocker type.
void setAtlasLoader(const FIFE::AtlasLoaderPtr &atlasLoader)
Instance * createInstance(Object *object, const ModelCoordinate &p, const std::string &id="")
Add an instance of an object at a specific position.
static Logger _log(LM_AUDIO)
void setVisitorRadius(uint16_t radius)
Sets the range for a visitor.
void registerCost(const std::string &costId, double cost)
Adds a cost with the given id and value.
void loadImportFile(const std::string &file, const std::string &directory="")
used to load an object file if directory is provided then file is assumed relative to directory if re...
void setXShift(const double &xshift)
Set the cellgrid x shift.
void setRotation(double rotation)
Sets rotation for the camera.
MapLoader * createDefaultMapLoader(Model *model, VFS *vfs, ImageManager *imageManager, RenderBackend *renderBackend)
convenience function for creating the default fife map loader deleting the object returned from this ...
Camera describes properties of a view port shown in the main screen Main screen can have multiple cam...
void setYScale(const double scale)
Set the cellgrid y-scaling.
void setObjectLoader(const FIFE::ObjectLoaderPtr &objectLoader)
virtual void load(const std::string &filename)=0
responsible for loading the object resource and populating the engine
void setXScale(const double scale)
Set the cellgrid x-scaling.
#define FL_ERR(logger, msg)
void setPathingStrategy(PathingStrategy strategy)
Sets pathing strategy for the layer.
PercentDoneCallback m_percentDoneListener
virtual bool isLoadable(const std::string &filename)=0
determines whether the resource is in the correct format for this loader
bool HasParentPath(const bfs::path &path)
Helper function to determine if a path object has a parent path.
void setMultiPart(bool part)
Sets the object as a part of a multi object.
std::vector< int32_t > IntVector
bfs::path GetParentPath(const bfs::path &path)
Helper function to retrieve a parent path object from a path object.
void setYShift(const double yshift)
Set the cellgrid y shift.
virtual bool isLoadable(const std::string &filename) const =0
determines whether the resource is in the correct format for this loader
Cell * getCell(const ModelCoordinate &mc)
Returns cell on this coordinate.
ObjectLoaderPtr m_objectLoader
virtual AtlasPtr load(const std::string &filename)=0
responsible for loading the atlas returns a shared pointer to an image resource
void getStaticImageAngles(std::vector< int32_t > &angles)
Returns list of available static image angles for this object.
uint32_t getScreenWidth() const
const std::string & getLoaderName() const
returns the loader name associated with this map file loader, this will only be populated after the l...
Layer * createLayer(const std::string &identifier, CellGrid *grid)
Add a Layer to this Map.
ImageManager * m_imageManager
A model is a facade for everything in the model.
RenderBackend * m_renderBackend
A basic cell on a CellCache.
void setInteract(bool interact, const std::string &id)
Sets interact for the layer.
void act(const std::string &actionName, const Location &direction, bool repeating=false)
Performs given named action to the instance.
void setDefaultSpeedMultiplier(double multi)
Sets default speed for this CellCache.
void setCellStackPosition(uint8_t stack)
Sets the cell stack position.
void setWalkable(bool walkable)
Sets walkable for the layer.
Object visual contains data that is needed for visualizing objects.
std::string readString(size_t len)
read a string with len bytes, not assuming a terminating 0 Appends a null terminator character to the...
DoublePoint3D ExactModelCoordinate
virtual void setAnimationLoader(const AnimationLoaderPtr &animationLoader)=0
allows setting which animation loader will be used to load animation files
CellGrid * getCellGrid(const std::string &gridtype)
Returns new copy of cellgrid corresponding given name.
void setFoWType(CellVisualEffect type)
Sets the cell visual.
void addCellToArea(const std::string &id, Cell *cell)
Adds a cell to a specific area group.
IntVector tokenize(const std::string &str, char delim, char group)
void setCostMultiplier(double multi)
Changes the cell cost.
std::string m_mapDirectory
Action * getAction(const std::string &identifier) const
Gets action with given id.
PathingStrategy
Defines how pathing can be performed on this layer.
the main VFS (virtual file system) class
void setStackPosition(int32_t stackposition)
Sets stack position of the instance Stack position is used to define the order in which instances res...
void finalizeCellCaches()
Creates cellcaches for this map.
void setRotation(const double rotation)
Set the cellgrid rotation.
void createTransition(Layer *layer, const ModelCoordinate &mc, bool immediate=false)
Creates a transistion from this cell to the given layer and coordinates.
void setRotation(int32_t rotation)
Set the rotation offset of this instance.
Cell * createCell(const ModelCoordinate &mc)
Creates cell on this CellCache.
void addNarrowCell(Cell *cell)
Adds cell to narrow cells.
Object * getObject(const std::string &id, const std::string &name_space)
Get an object by its id.
AtlasLoaderPtr m_atlasLoader
void loadImportDirectory(const std::string &directory)
used to load a directory of object files recursively if relativeToMap is true then the directory is a...
void setTotalNumberOfElements(unsigned int totalElements)
void initializeCellCaches()
Creates cellcaches for this map.
void addListener(PercentDoneListener *listener)
void setCellImageDimensions(uint32_t width, uint32_t height)
Sets screen cell image dimensions.
static InstanceRenderer * getInstance(IRendererContainer *cnt)
Gets instance for interface access.
An Instance is an "instantiation" of an Object at a Location.
std::list< Object * > getObjects(const std::string &name_space) const
Get all the objects in the given namespace.
bool isLoadable(const std::string &filename) const
void setFilename(const std::string &file)
Map * createMap(const std::string &identifier)
Add a map this model, and get a pointer to it.
void setCost(const std::string &id, double cost)
Sets for the given cost id a cost.
Used to access diffrent kinds of data.
void setZoom(double zoom)
Sets zoom for the camera.
std::set< std::string > listDirectories(const std::string &path) const
Get a directorylist of the given directory.
void setVisitor(bool visit)
Marks this instance as a visitor.
void setVisitorShape(VisitorShapeInfo info)
Sets the shape type for a visitor.