32 #include "ext/tinyxml/fife_tinyxml.h"
71 : m_model(model), m_vfs(vfs), m_imageManager(imageManager), m_renderBackend(renderBackend),
72 m_loaderName(
"fife"), m_mapDirectory(
"") {
89 bfs::path mapPath(filename);
98 TiXmlDocument mapFile;
100 std::string mapFilename = mapPath.string();
109 if (mapFile.Error()) {
110 std::ostringstream oss;
111 oss <<
" Failed to load"
114 <<
" [" << __LINE__ <<
"]"
140 const TiXmlElement* root = mapFile.RootElement();
143 const std::string* loaderName = root->Attribute(std::string(
"loaderName"));
150 root->QueryValueAttribute(
"elements", &numElements);
153 const std::string* mapName = root->Attribute(std::string(
"id"));
159 catch (NameClash& e) {
170 for (
const TiXmlElement *importElement = root->FirstChildElement(
"import"); importElement; importElement = importElement->NextSiblingElement(
"import")) {
171 const std::string* importDir = importElement->Attribute(std::string(
"dir"));
172 const std::string* importFile = importElement->Attribute(std::string(
"file"));
174 std::string directory =
"";
176 directory = *importDir;
179 std::string file =
"";
184 if (importDir && !importFile) {
186 fullPath /= directory;
189 else if (importFile) {
190 bfs::path fullFilePath(file);
191 bfs::path fullDirPath(directory);
194 fullDirPath /= directory;
198 fullFilePath /= file;
205 std::list<std::string>::iterator name_it = namespaces.begin();
206 for (; name_it != namespaces.end(); ++name_it) {
208 std::list<Object*>::iterator object_it = objects.begin();
209 for (; object_it != objects.end(); ++object_it) {
210 if ((*object_it)->isMultiObject()) {
211 const std::list<std::string>& multiParts = (*object_it)->getMultiPartIds();
212 std::list<std::string>::const_iterator multi_it = multiParts.begin();
213 for (; multi_it != multiParts.end(); ++multi_it) {
217 (*object_it)->addMultiPart(partObj);
225 for (
const TiXmlElement* layerElement = root->FirstChildElement(
"layer"); layerElement; layerElement = layerElement->NextSiblingElement(
"layer")) {
227 double xOffset = 0.0;
228 double yOffset = 0.0;
229 double zOffset = 0.0;
233 double rotation = 0.0;
235 int xOffsetRetVal = layerElement->QueryValueAttribute(
"x_offset", &xOffset);
236 int yOffsetRetVal = layerElement->QueryValueAttribute(
"y_offset", &yOffset);
237 layerElement->QueryValueAttribute(
"z_offset", &zOffset);
238 int xScaleRetVal = layerElement->QueryValueAttribute(
"x_scale", &xScale);
239 int yScaleRetVal = layerElement->QueryValueAttribute(
"y_scale", &yScale);
240 layerElement->QueryValueAttribute(
"z_scale", &zScale);
241 int rotationRetVal = layerElement->QueryValueAttribute(
"rotation", &rotation);
243 const std::string* layerName = layerElement->Attribute(std::string(
"id"));
244 const std::string* pathing = layerElement->Attribute(std::string(
"pathing"));
245 const std::string* sorting = layerElement->Attribute(std::string(
"sorting"));
246 const std::string* gridType = layerElement->Attribute(std::string(
"grid_type"));
247 const std::string* layerType = layerElement->Attribute(std::string(
"layer_type"));
248 const std::string* layerTypeName = layerElement->Attribute(std::string(
"layer_type_id"));
250 if (xOffsetRetVal == TIXML_SUCCESS &&
251 yOffsetRetVal == TIXML_SUCCESS &&
252 xScaleRetVal == TIXML_SUCCESS &&
253 yScaleRetVal == TIXML_SUCCESS &&
254 rotationRetVal == TIXML_SUCCESS &&
260 if (
"cell_edges_and_diagonals" == *pathing) {
266 if (*sorting ==
"location") {
268 }
else if (*sorting ==
"camera_and_location") {
303 if (*layerType ==
"walkable") {
305 }
else if (*layerType ==
"interact") {
313 for (
const TiXmlElement* instances = layerElement->FirstChildElement(
"instances"); instances; instances = instances->NextSiblingElement(
"instances")) {
314 for (
const TiXmlElement* instance = instances->FirstChildElement(
"i"); instance; instance = instance->NextSiblingElement(
"i")) {
321 int visitorRadius = 0;
323 const std::string* instanceId = instance->Attribute(std::string(
"id"));
324 const std::string* objectId = instance->Attribute(std::string(
"o"));
325 const std::string* costId = instance->Attribute(std::string(
"cost_id"));
328 objectId = instance->Attribute(std::string(
"object"));
332 objectId = instance->Attribute(std::string(
"obj"));
335 const std::string* namespaceId = instance->Attribute(std::string(
"ns"));
338 namespaceId = instance->Attribute(std::string(
"namespace"));
341 int xRetVal = instance->QueryValueAttribute(
"x", &x);
342 int yRetVal = instance->QueryValueAttribute(
"y", &y);
343 instance->QueryValueAttribute(
"z", &z);
344 int rRetVal = instance->QueryValueAttribute(
"r", &r);
346 if (xRetVal == TIXML_SUCCESS) {
353 if (yRetVal == TIXML_SUCCESS) {
360 if (rRetVal != TIXML_SUCCESS) {
361 rRetVal = instance->QueryValueAttribute(
"rotation", &r);
364 int stackRetVal = instance->QueryValueAttribute(
"stackpos", &stackpos);
365 int cellStackRetVal = instance->QueryValueAttribute(
"cellstack", &cellStack);
366 int visitorRetVal = instance->QueryValueAttribute(
"visitor_radius", &visitorRadius);
367 const std::string* shapeType = instance->Attribute(std::string(
"visitor_shape"));
370 if (
"quad" == *shapeType) {
372 }
else if (
"circle" == *shapeType) {
394 if (rRetVal != TIXML_SUCCESS) {
396 std::vector<int> angles;
398 if (!angles.empty()) {
407 if (instVisual && (stackRetVal == TIXML_SUCCESS)) {
411 if (cellStackRetVal == TIXML_SUCCESS) {
415 if (visitorRetVal == TIXML_SUCCESS) {
423 int costRetVal = instance->QueryValueAttribute(
"cost", &cost);
424 if (costRetVal == TIXML_SUCCESS) {
437 std::ostringstream oss;
438 oss <<
" Failed to create instance of object "
441 <<
" [" << __LINE__ <<
"]"
463 for (
const TiXmlElement* cacheElements = root->FirstChildElement(
"cellcaches"); cacheElements; cacheElements = cacheElements->NextSiblingElement(
"cellcaches")) {
464 for (
const TiXmlElement* cacheElement = cacheElements->FirstChildElement(
"cellcache"); cacheElement; cacheElement = cacheElement->NextSiblingElement(
"cellcache")) {
465 double cacheCost = 1.0;
466 double cacheSpeed = 1.0;
467 const std::string* layerId = cacheElement->Attribute(std::string(
"id"));
470 cacheElement->QueryDoubleAttribute(
"default_cost", &cacheCost);
471 cacheElement->QueryDoubleAttribute(
"default_speed", &cacheSpeed);
477 int searchNarrow = 0;
478 cacheElement->QueryIntAttribute(
"search_narrow", &searchNarrow);
483 for (
const TiXmlElement* cellElement = cacheElement->FirstChildElement(
"cell"); cellElement; cellElement = cellElement->NextSiblingElement(
"cell")) {
486 int success = cellElement->QueryIntAttribute(
"x", &cellX);
487 success &= cellElement->QueryIntAttribute(
"y", &cellY);
488 if (success == TIXML_SUCCESS) {
492 const std::string* cellVisual = cellElement->Attribute(std::string(
"state"));
495 if (*cellVisual ==
"concealed") {
497 }
else if (*cellVisual ==
"masked") {
503 const std::string* cellBlocker = cellElement->Attribute(std::string(
"blocker_type"));
505 if (*cellBlocker ==
"no_blocker") {
508 }
else if (*cellBlocker ==
"blocker") {
514 double cellCost = 1.0;
515 double cellSpeed = 1.0;
516 success = cellElement->QueryDoubleAttribute(
"default_cost", &cellCost);
517 if (success == TIXML_SUCCESS) {
520 success = cellElement->QueryDoubleAttribute(
"default_speed", &cellSpeed);
521 if (success == TIXML_SUCCESS) {
527 cellElement->QueryIntAttribute(
"narrow", &isNarrow);
532 for (
const TiXmlElement* costElement = cellElement->FirstChildElement(
"cost"); costElement; costElement = costElement->NextSiblingElement(
"cost")) {
533 const std::string* costId = costElement->Attribute(std::string(
"id"));
535 success = costElement->QueryDoubleAttribute(
"value", &cost);
536 if (costId && success == TIXML_SUCCESS) {
542 for (
const TiXmlElement* areaElement = cellElement->FirstChildElement(
"area"); areaElement; areaElement = areaElement->NextSiblingElement(
"area")) {
543 const std::string* areaId = areaElement->Attribute(std::string(
"id"));
558 for (
const TiXmlElement* cacheElements = root->FirstChildElement(
"cellcaches"); cacheElements; cacheElements = cacheElements->NextSiblingElement(
"cellcaches")) {
559 for (
const TiXmlElement* cacheElement = cacheElements->FirstChildElement(
"cellcache"); cacheElement; cacheElement = cacheElement->NextSiblingElement(
"cellcache")) {
560 const std::string* layerId = cacheElement->Attribute(std::string(
"id"));
566 for (
const TiXmlElement* cellElement = cacheElement->FirstChildElement(
"cell"); cellElement; cellElement = cellElement->NextSiblingElement(
"cell")) {
569 int success = cellElement->QueryIntAttribute(
"x", &cellX);
570 success &= cellElement->QueryIntAttribute(
"y", &cellY);
571 if (success == TIXML_SUCCESS) {
577 for (
const TiXmlElement* transitionElement = cellElement->FirstChildElement(
"transition"); transitionElement; transitionElement = transitionElement->NextSiblingElement(
"transition")) {
581 success = transitionElement->QueryIntAttribute(
"x", &targetX);
582 success &= transitionElement->QueryIntAttribute(
"y", &targetY);
583 transitionElement->QueryIntAttribute(
"z", &targetZ);
584 if (success == TIXML_SUCCESS) {
586 Layer* targetLayer = NULL;
587 const std::string* targetLayerId = transitionElement->Attribute(std::string(
"id"));
589 targetLayer = map->
getLayer(*targetLayerId);
596 transitionElement->QueryIntAttribute(
"immediate", &immediate);
608 for (
const TiXmlElement* triggerElements = root->FirstChildElement(
"triggers"); triggerElements; triggerElements = triggerElements->NextSiblingElement(
"triggers")) {
610 for (
const TiXmlElement* triggerElement = triggerElements->FirstChildElement(
"trigger"); triggerElement; triggerElement = triggerElement->NextSiblingElement(
"trigger")) {
611 const std::string* triggerName = triggerElement->Attribute(std::string(
"name"));
613 int allInstances = 0;
614 triggerElement->QueryIntAttribute(
"triggered", &triggered);
615 triggerElement->QueryIntAttribute(
"all_instances", &allInstances);
621 if (allInstances > 0) {
625 const std::string* instanceId = triggerElement->Attribute(std::string(
"attached_instance"));
626 const std::string* layerId = triggerElement->Attribute(std::string(
"attached_layer"));
627 if (instanceId && layerId) {
632 trigger->
attach(instance);
636 for (
const TiXmlElement* assignElement = triggerElement->FirstChildElement(
"assign"); assignElement; assignElement = assignElement->NextSiblingElement(
"assign")) {
637 layerId = assignElement->Attribute(std::string(
"layer_id"));
643 assignElement->QueryIntAttribute(
"x", &x);
644 assignElement->QueryIntAttribute(
"y", &y);
650 for (
const TiXmlElement* enabledElement = triggerElement->FirstChildElement(
"enabled"); enabledElement; enabledElement = enabledElement->NextSiblingElement(
"enabled")) {
651 layerId = enabledElement->Attribute(std::string(
"layer_id"));
652 instanceId = enabledElement->Attribute(std::string(
"instance_id"));
653 if (!instanceId || !layerId) {
664 for (
const TiXmlElement* conditionElement = triggerElement->FirstChildElement(
"condition"); conditionElement; conditionElement = conditionElement->NextSiblingElement(
"condition")) {
665 int conditionId = -1;
666 conditionElement->QueryIntAttribute(
"id", &conditionId);
667 if (conditionId != -1) {
675 for (
const TiXmlElement* cameraElement = root->FirstChildElement(
"camera"); cameraElement; cameraElement = cameraElement->NextSiblingElement(
"camera")) {
676 const std::string* cameraId = cameraElement->Attribute(std::string(
"id"));
677 const std::string* refLayerId = cameraElement->Attribute(std::string(
"ref_layer_id"));
679 int refCellWidth = 0;
680 int refCellHeight = 0;
681 int success = cameraElement->QueryIntAttribute(
"ref_cell_width", &refCellWidth);
682 success &= cameraElement->QueryIntAttribute(
"ref_cell_height", &refCellHeight);
684 if (cameraId && refLayerId && success == TIXML_SUCCESS) {
687 double rotation = 0.0;
689 cameraElement->QueryDoubleAttribute(
"tilt", &tilt);
690 cameraElement->QueryDoubleAttribute(
"zoom", &zoom);
691 cameraElement->QueryDoubleAttribute(
"rotation", &rotation);
692 success = cameraElement->QueryDoubleAttribute(
"ztoy", &zToY);
694 const std::string* viewport = cameraElement->Attribute(std::string(
"viewport"));
712 if (viewportParameters.size() == 4) {
713 Rect rect(viewportParameters[0], viewportParameters[1],
714 viewportParameters[2], viewportParameters[3]);
717 cam = map->
addCamera(*cameraId, layer, rect);
729 cam = map->
addCamera(*cameraId, layer, rect);
743 if (success == TIXML_SUCCESS) {
749 if (instanceRenderer)
767 assert(objectLoader);
774 assert(animationLoader);
786 bfs::path mapPath(filename);
788 TiXmlDocument mapFile;
790 std::string mapFilename = mapPath.string();
799 if (mapFile.Error()) {
803 const TiXmlElement* root = mapFile.RootElement();
806 const std::string* loaderName = root->Attribute(std::string(
"loader"));
812 if (!loaderName || (loaderName && *loaderName ==
getLoaderName())) {
823 catch (NotFound& e) {
834 bfs::path importFilePath(directory);
835 importFilePath /= file;
837 std::string importFileString = importFilePath.string();
848 if (!directory.empty()) {
849 bfs::path importDirectory(directory);
850 std::string importDirectoryString = importDirectory.string();
852 std::set<std::string> files =
m_vfs->
listFiles(importDirectoryString);
855 std::set<std::string>::iterator iter;
856 for (iter = files.begin(); iter != files.end(); ++iter) {
859 std::string ext = bfs::extension(*iter);
860 if (ext ==
".xml" || ext ==
".zip") {
866 for (iter = nestedDirectories.begin(); iter != nestedDirectories.end(); ++iter) {
868 if ((*iter).find(
".svn") == std::string::npos) {
885 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.
void attach(Instance *instance)
Attaches the trigger to the given instance.
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 enableForInstance(Instance *instance)
Enables trigger for given instance.
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)
void addTriggerCondition(TriggerCondition type)
Adds trigger condition.
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.
TriggerController * getTriggerController() const
#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
Instance * getInstance(const std::string &identifier)
Get the first instance on this layer with the given identifier.
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
void assign(Layer *layer, const ModelCoordinate &pt)
Assigns trigger on given layer and position.
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 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
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...
Trigger * createTrigger(const std::string &triggerName)
Creates a trigger.
void actRepeat(const std::string &actionName, const Location &direction)
Performs given named action to the instance, repeated.
Trigger get triggered when a specific set of criteria are met.
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...
Action * getAction(const std::string &identifier, bool deepsearch=true) const
Gets action with given id.
void setTotalNumberOfElements(unsigned int totalElements)
void enableForAllInstances()
Enables trigger for all instances.
void initializeCellCaches()
Creates cellcaches for this map.
void addListener(PercentDoneListener *listener)
This class serves as a central place to manage triggers for a Map.
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)
void setTriggered()
Sets the trigger to triggered and calls ITriggerListener->onTriggered()
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.