72 : m_model(model), m_vfs(vfs), m_imageManager(imageManager), m_animationManager(
AnimationManager::instance()), m_renderBackend(renderBackend),
73 m_loaderName(
"fife"), m_mapDirectory(
"") {
90 bfs::path mapPath(filename);
99 TiXmlDocument mapFile;
101 std::string mapFilename = mapPath.string();
110 if (mapFile.Error()) {
111 std::ostringstream oss;
112 oss <<
" Failed to load" 115 <<
" [" << __LINE__ <<
"]" 141 const TiXmlElement* root = mapFile.RootElement();
144 const std::string* loaderName = root->Attribute(std::string(
"loaderName"));
151 root->QueryValueAttribute(
"elements", &numElements);
154 const std::string* mapName = root->Attribute(std::string(
"id"));
160 catch (NameClash& e) {
171 for (
const TiXmlElement *importElement = root->FirstChildElement(
"import"); importElement; importElement = importElement->NextSiblingElement(
"import")) {
172 const std::string* importDir = importElement->Attribute(std::string(
"dir"));
173 const std::string* importFile = importElement->Attribute(std::string(
"file"));
175 std::string directory =
"";
177 directory = *importDir;
180 std::string file =
"";
185 if (importDir && !importFile) {
187 fullPath /= directory;
190 else if (importFile) {
191 bfs::path fullFilePath(file);
192 bfs::path fullDirPath(directory);
195 fullDirPath /= directory;
199 fullFilePath /= file;
206 std::list<std::string>::iterator name_it = namespaces.begin();
207 for (; name_it != namespaces.end(); ++name_it) {
209 std::list<Object*>::iterator object_it = objects.begin();
210 for (; object_it != objects.end(); ++object_it) {
211 if ((*object_it)->isMultiObject()) {
212 const std::list<std::string>& multiParts = (*object_it)->getMultiPartIds();
213 std::list<std::string>::const_iterator multi_it = multiParts.begin();
214 for (; multi_it != multiParts.end(); ++multi_it) {
218 (*object_it)->addMultiPart(partObj);
226 for (
const TiXmlElement* layerElement = root->FirstChildElement(
"layer"); layerElement; layerElement = layerElement->NextSiblingElement(
"layer")) {
228 double xOffset = 0.0;
229 double yOffset = 0.0;
230 double zOffset = 0.0;
234 double rotation = 0.0;
236 int xOffsetRetVal = layerElement->QueryValueAttribute(
"x_offset", &xOffset);
237 int yOffsetRetVal = layerElement->QueryValueAttribute(
"y_offset", &yOffset);
238 layerElement->QueryValueAttribute(
"z_offset", &zOffset);
239 int xScaleRetVal = layerElement->QueryValueAttribute(
"x_scale", &xScale);
240 int yScaleRetVal = layerElement->QueryValueAttribute(
"y_scale", &yScale);
241 layerElement->QueryValueAttribute(
"z_scale", &zScale);
242 int rotationRetVal = layerElement->QueryValueAttribute(
"rotation", &rotation);
244 const std::string* layerName = layerElement->Attribute(std::string(
"id"));
245 const std::string* pathing = layerElement->Attribute(std::string(
"pathing"));
246 const std::string* sorting = layerElement->Attribute(std::string(
"sorting"));
247 const std::string* gridType = layerElement->Attribute(std::string(
"grid_type"));
248 const std::string* layerType = layerElement->Attribute(std::string(
"layer_type"));
249 const std::string* layerTypeName = layerElement->Attribute(std::string(
"layer_type_id"));
251 if (xOffsetRetVal == TIXML_SUCCESS &&
252 yOffsetRetVal == TIXML_SUCCESS &&
253 xScaleRetVal == TIXML_SUCCESS &&
254 yScaleRetVal == TIXML_SUCCESS &&
255 rotationRetVal == TIXML_SUCCESS &&
261 if (
"cell_edges_and_diagonals" == *pathing) {
267 if (*sorting ==
"location") {
269 }
else if (*sorting ==
"camera_and_location") {
304 if (*layerType ==
"walkable") {
306 }
else if (*layerType ==
"interact") {
314 for (
const TiXmlElement* instances = layerElement->FirstChildElement(
"instances"); instances; instances = instances->NextSiblingElement(
"instances")) {
315 for (
const TiXmlElement* instance = instances->FirstChildElement(
"i"); instance; instance = instance->NextSiblingElement(
"i")) {
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);
384 if (rRetVal != TIXML_SUCCESS) {
386 std::vector<int> angles;
388 if (!angles.empty()) {
397 if (instVisual && (stackRetVal == TIXML_SUCCESS)) {
401 if (cellStackRetVal == TIXML_SUCCESS) {
407 int costRetVal = instance->QueryValueAttribute(
"cost", &cost);
408 if (costRetVal == TIXML_SUCCESS) {
421 std::ostringstream oss;
422 oss <<
" Failed to create instance of object " 425 <<
" [" << __LINE__ <<
"]" 447 for (
const TiXmlElement* cacheElements = root->FirstChildElement(
"cellcaches"); cacheElements; cacheElements = cacheElements->NextSiblingElement(
"cellcaches")) {
448 for (
const TiXmlElement* cacheElement = cacheElements->FirstChildElement(
"cellcache"); cacheElement; cacheElement = cacheElement->NextSiblingElement(
"cellcache")) {
449 double cacheCost = 1.0;
450 double cacheSpeed = 1.0;
451 const std::string* layerId = cacheElement->Attribute(std::string(
"id"));
454 cacheElement->QueryDoubleAttribute(
"default_cost", &cacheCost);
455 cacheElement->QueryDoubleAttribute(
"default_speed", &cacheSpeed);
461 int searchNarrow = 0;
462 cacheElement->QueryIntAttribute(
"search_narrow", &searchNarrow);
467 for (
const TiXmlElement* cellElement = cacheElement->FirstChildElement(
"cell"); cellElement; cellElement = cellElement->NextSiblingElement(
"cell")) {
470 int success = cellElement->QueryIntAttribute(
"x", &cellX);
471 success &= cellElement->QueryIntAttribute(
"y", &cellY);
472 if (success == TIXML_SUCCESS) {
476 const std::string* cellBlocker = cellElement->Attribute(std::string(
"blocker_type"));
478 if (*cellBlocker ==
"no_blocker") {
481 }
else if (*cellBlocker ==
"blocker") {
487 double cellCost = 1.0;
488 double cellSpeed = 1.0;
489 success = cellElement->QueryDoubleAttribute(
"default_cost", &cellCost);
490 if (success == TIXML_SUCCESS) {
493 success = cellElement->QueryDoubleAttribute(
"default_speed", &cellSpeed);
494 if (success == TIXML_SUCCESS) {
500 cellElement->QueryIntAttribute(
"narrow", &isNarrow);
505 for (
const TiXmlElement* costElement = cellElement->FirstChildElement(
"cost"); costElement; costElement = costElement->NextSiblingElement(
"cost")) {
506 const std::string* costId = costElement->Attribute(std::string(
"id"));
508 success = costElement->QueryDoubleAttribute(
"value", &cost);
509 if (costId && success == TIXML_SUCCESS) {
515 for (
const TiXmlElement* areaElement = cellElement->FirstChildElement(
"area"); areaElement; areaElement = areaElement->NextSiblingElement(
"area")) {
516 const std::string* areaId = areaElement->Attribute(std::string(
"id"));
531 for (
const TiXmlElement* cacheElements = root->FirstChildElement(
"cellcaches"); cacheElements; cacheElements = cacheElements->NextSiblingElement(
"cellcaches")) {
532 for (
const TiXmlElement* cacheElement = cacheElements->FirstChildElement(
"cellcache"); cacheElement; cacheElement = cacheElement->NextSiblingElement(
"cellcache")) {
533 const std::string* layerId = cacheElement->Attribute(std::string(
"id"));
539 for (
const TiXmlElement* cellElement = cacheElement->FirstChildElement(
"cell"); cellElement; cellElement = cellElement->NextSiblingElement(
"cell")) {
542 int success = cellElement->QueryIntAttribute(
"x", &cellX);
543 success &= cellElement->QueryIntAttribute(
"y", &cellY);
544 if (success == TIXML_SUCCESS) {
550 for (
const TiXmlElement* transitionElement = cellElement->FirstChildElement(
"transition"); transitionElement; transitionElement = transitionElement->NextSiblingElement(
"transition")) {
554 success = transitionElement->QueryIntAttribute(
"x", &targetX);
555 success &= transitionElement->QueryIntAttribute(
"y", &targetY);
556 transitionElement->QueryIntAttribute(
"z", &targetZ);
557 if (success == TIXML_SUCCESS) {
559 Layer* targetLayer = NULL;
560 const std::string* targetLayerId = transitionElement->Attribute(std::string(
"id"));
562 targetLayer = map->
getLayer(*targetLayerId);
569 transitionElement->QueryIntAttribute(
"immediate", &immediate);
581 for (
const TiXmlElement* triggerElements = root->FirstChildElement(
"triggers"); triggerElements; triggerElements = triggerElements->NextSiblingElement(
"triggers")) {
583 for (
const TiXmlElement* triggerElement = triggerElements->FirstChildElement(
"trigger"); triggerElement; triggerElement = triggerElement->NextSiblingElement(
"trigger")) {
584 const std::string* triggerName = triggerElement->Attribute(std::string(
"name"));
586 int allInstances = 0;
587 triggerElement->QueryIntAttribute(
"triggered", &triggered);
588 triggerElement->QueryIntAttribute(
"all_instances", &allInstances);
594 if (allInstances > 0) {
598 const std::string* instanceId = triggerElement->Attribute(std::string(
"attached_instance"));
599 const std::string* layerId = triggerElement->Attribute(std::string(
"attached_layer"));
600 if (instanceId && layerId) {
605 trigger->
attach(instance);
609 for (
const TiXmlElement* assignElement = triggerElement->FirstChildElement(
"assign"); assignElement; assignElement = assignElement->NextSiblingElement(
"assign")) {
610 layerId = assignElement->Attribute(std::string(
"layer_id"));
616 assignElement->QueryIntAttribute(
"x", &x);
617 assignElement->QueryIntAttribute(
"y", &y);
623 for (
const TiXmlElement* enabledElement = triggerElement->FirstChildElement(
"enabled"); enabledElement; enabledElement = enabledElement->NextSiblingElement(
"enabled")) {
624 layerId = enabledElement->Attribute(std::string(
"layer_id"));
625 instanceId = enabledElement->Attribute(std::string(
"instance_id"));
626 if (!instanceId || !layerId) {
637 for (
const TiXmlElement* conditionElement = triggerElement->FirstChildElement(
"condition"); conditionElement; conditionElement = conditionElement->NextSiblingElement(
"condition")) {
638 int conditionId = -1;
639 conditionElement->QueryIntAttribute(
"id", &conditionId);
640 if (conditionId != -1) {
648 for (
const TiXmlElement* cameraElement = root->FirstChildElement(
"camera"); cameraElement; cameraElement = cameraElement->NextSiblingElement(
"camera")) {
649 const std::string* cameraId = cameraElement->Attribute(std::string(
"id"));
651 int refCellWidth = 0;
652 int refCellHeight = 0;
653 int success = cameraElement->QueryIntAttribute(
"ref_cell_width", &refCellWidth);
654 success &= cameraElement->QueryIntAttribute(
"ref_cell_height", &refCellHeight);
656 if (cameraId && success == TIXML_SUCCESS) {
659 double rotation = 0.0;
661 cameraElement->QueryDoubleAttribute(
"tilt", &tilt);
662 cameraElement->QueryDoubleAttribute(
"zoom", &zoom);
663 cameraElement->QueryDoubleAttribute(
"rotation", &rotation);
664 success = cameraElement->QueryDoubleAttribute(
"ztoy", &zToY);
666 const std::string* viewport = cameraElement->Attribute(std::string(
"viewport"));
675 if (viewportParameters.size() == 4) {
676 Rect rect(viewportParameters[0], viewportParameters[1],
677 viewportParameters[2], viewportParameters[3]);
705 if (success == TIXML_SUCCESS) {
711 if (instanceRenderer)
729 assert(objectLoader);
739 assert(animationLoader);
765 bfs::path mapPath(filename);
767 TiXmlDocument mapFile;
769 std::string mapFilename = mapPath.string();
778 if (mapFile.Error()) {
782 const TiXmlElement* root = mapFile.RootElement();
785 const std::string* loaderName = root->Attribute(std::string(
"loader"));
791 if (!loaderName || (loaderName && *loaderName ==
getLoaderName())) {
802 catch (NotFound& e) {
813 bfs::path importFilePath(directory);
814 importFilePath /= file;
816 std::string importFileString = importFilePath.string();
830 if (!directory.empty()) {
831 bfs::path importDirectory(directory);
832 std::string importDirectoryString = importDirectory.string();
834 std::set<std::string> files =
m_vfs->
listFiles(importDirectoryString);
837 std::set<std::string>::iterator iter;
838 for (iter = files.begin(); iter != files.end(); ++iter) {
841 std::string ext = bfs::extension(*iter);
842 if (ext ==
".xml" || ext ==
".zip") {
848 for (iter = nestedDirectories.begin(); iter != nestedDirectories.end(); ++iter) {
850 if ((*iter).find(
".svn") == std::string::npos) {
867 return (
new MapLoader(model, vfs, imageManager, renderBackend));
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.
Action * getAction(const std::string &identifier, bool deepsearch=true) const
Gets action with given id.
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.
std::list< Object * > getObjects(const std::string &name_space) const
Get all the objects in the given namespace.
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.
virtual void setAtlasLoader(const AtlasLoaderPtr &atlasLoader)=0
allows setting which atlas loader will be used to load atlas files
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.
bool isLoadable(const std::string &filename) const
static Logger _log(LM_AUDIO)
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.
uint32_t getScreenWidth() const
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.
uint32_t getScreenHeight() const
void setObjectLoader(const FIFE::ObjectLoaderPtr &objectLoader)
virtual std::vector< AnimationPtr > loadMultiple(const std::string &filename)=0
responsible for loading all animations returns a vector of shared pointer to an animation resource ...
std::set< std::string > listFiles(const std::string &path) const
Get a filelist of the given directory.
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)
uint32_t getDataLength() const
get the complete datalength
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
void getStaticImageAngles(std::vector< int32_t > &angles)
Returns list of available static image angles for this object.
Instance * getInstance(const std::string &identifier)
Get the first instance on this layer with the given identifier.
Layer * createLayer(const std::string &identifier, CellGrid *grid)
Add a Layer to this Map.
FIFE::AnimationLoaderPtr getAnimationLoader()
virtual AnimationLoaderPtr getAnimationLoader()=0
const std::string & getLoaderName() const
returns the loader name associated with this map file loader, this will only be populated after the l...
ImageManager * m_imageManager
FIFE::ObjectLoaderPtr getObjectLoader()
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.
std::list< std::string > getNamespaces() const
Get a list of namespaces currently referenced by objects in the metamodel.
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...
std::set< std::string > listDirectories(const std::string &path) const
Get a directorylist of the given directory.
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 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...
SharedPtr< IAnimationLoader > AnimationLoaderPtr
Trigger * createTrigger(const std::string &triggerName)
Creates a trigger.
Camera * addCamera(const std::string &id, const Rect &viewport)
Adds camera to the map.
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.
FIFE::AtlasLoaderPtr getAtlasLoader()
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.
virtual AtlasLoaderPtr getAtlasLoader()=0
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.
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 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.
TriggerController * getTriggerController() const
virtual bool isLoadable(const std::string &filename)=0
determines whether the resource is in the correct format for this loader
AnimationManager * m_animationManager
An Instance is an "instantiation" of an Object at a Location.
void setFilename(const std::string &file)
void setTriggered()
Sets the trigger to triggered and calls ITriggerListener->onTriggered()
SharedPtr< FIFE::IAtlasLoader > AtlasLoaderPtr
virtual std::vector< AtlasPtr > loadMultiple(const std::string &filename)=0
responsible for loading the all atlases returns a vector of shared pointer to an image resource ...
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.