30 #include "ext/tinyxml/fife_tinyxml.h"
63 return iter->second.image;
71 for(
uint32_t i = 0; i < index; ++i, ++iter);
72 return iter->second.image;
76 return m_subimages.insert(std::pair<std::string, AtlasData>(imagename, data)).second;
88 : m_model(model), m_vfs(vfs), m_imageManager(imageManager) {
95 bfs::path atlasPath(filename);
96 std::string atlasFilename = atlasPath.string();
97 TiXmlDocument atlasFile;
106 if (atlasFile.Error()) {
117 }
catch (NotFound&) {
122 TiXmlElement* root = atlasFile.RootElement();
124 if (root && root->ValueStr() ==
"atlas") {
133 bfs::path atlasPath(filename);
134 bfs::path atlasPathDirectory;
162 catch (NotFound& e) {
174 TiXmlElement* root = doc.RootElement();
176 if (root && root->ValueStr() ==
"atlas") {
177 const std::string* atlasName = root->Attribute(std::string(
"name"));
179 const std::string* namespaceId = root->Attribute(std::string(
"namespace"));
181 namespaceId = atlasName;
185 bfs::path atlasImagePath = atlasPathDirectory / *atlasName;
186 atlas.
reset(
new Atlas(atlasImagePath.string()));
205 bool subsExists =
true;
206 for (TiXmlElement* imageElem = root->FirstChildElement(
"image");
207 imageElem != 0; imageElem = imageElem->NextSiblingElement(
"image")) {
210 imageElem->QueryValueAttribute(
"xpos", ®ion.
x);
211 imageElem->QueryValueAttribute(
"ypos", ®ion.
y);
212 imageElem->QueryValueAttribute(
"width", ®ion.
w);
213 imageElem->QueryValueAttribute(
"height", ®ion.
h);
215 const std::string* subimageName = imageElem->Attribute(std::string(
"source"));
218 std::string finalname = *namespaceId +
":" +*subimageName;
231 AtlasData atlas_data = {region, subImage};
232 atlas->addImage(finalname, atlas_data);
235 subsExists = subsExists && atlasExists;
238 for(TiXmlElement* objElem = root->NextSiblingElement(
"object");
239 objElem != 0; objElem = objElem->NextSiblingElement(
"object"))
242 if(objElem->ValueStr() ==
"object") {
253 const std::string* objectId = root->Attribute(std::string(
"id"));
254 const std::string* namespaceId = root->Attribute(std::string(
"namespace"));
257 if (objectId && namespaceId) {
258 const std::string* parentId = root->Attribute(std::string(
"parent"));
283 }
else if (!exists) {
291 for (TiXmlElement* imageElement = root->FirstChildElement(
"image"); imageElement; imageElement = imageElement->NextSiblingElement(
"image")) {
292 const std::string* sourceId = imageElement->Attribute(std::string(
"source"));
295 std::string source = *namespaceId +
":" + *sourceId;
297 throw NotFound(source +
" couldn't be found.");
302 int success = imageElement->QueryIntAttribute(
"x_offset", &xOffset);
303 if (success == TIXML_SUCCESS) {
308 success = imageElement->QueryIntAttribute(
"y_offset", &yOffset);
309 if (success == TIXML_SUCCESS) {
314 success = imageElement->QueryIntAttribute(
"direction", &direction);
315 if (success == TIXML_SUCCESS) {
333 root->QueryIntAttribute(
"blocking", &isBlocking);
337 root->QueryIntAttribute(
"static", &isStatic);
340 const std::string* pather = root->Attribute(std::string(
"pather"));
349 const std::string* costId = root->Attribute(std::string(
"cost_id"));
353 int success = root->QueryDoubleAttribute(
"cost", &cost);
354 if (success == TIXML_SUCCESS) {
359 const std::string* areaId = root->Attribute(std::string(
"area_id"));
365 for (TiXmlElement* walkableElement = root->FirstChildElement(
"walkable_area"); walkableElement; walkableElement = walkableElement->NextSiblingElement(
"walkable_area")) {
366 const std::string* walkableId = walkableElement->Attribute(std::string(
"id"));
373 root->QueryIntAttribute(
"cellstack", &cellStack);
380 int xRetVal = root->QueryValueAttribute(
"anchor_x", &ax);
381 int yRetVal = root->QueryValueAttribute(
"anchor_y", &ay);
382 if (xRetVal == TIXML_SUCCESS && yRetVal == TIXML_SUCCESS) {
386 int isRestrictedRotation = 0;
387 root->QueryIntAttribute(
"restricted_rotation", &isRestrictedRotation);
391 int zRetVal = root->QueryIntAttribute(
"z_step_limit", &zStep);
392 if (zRetVal == TIXML_SUCCESS) {
397 for (TiXmlElement* multiElement = root->FirstChildElement(
"multipart"); multiElement; multiElement = multiElement->NextSiblingElement(
"multipart")) {
398 const std::string* partId = multiElement->Attribute(std::string(
"id"));
402 for (TiXmlElement* multiRotation = multiElement->FirstChildElement(
"rotation"); multiRotation; multiRotation = multiRotation->NextSiblingElement(
"rotation")) {
404 multiRotation->QueryIntAttribute(
"rot", &rotation);
406 for (TiXmlElement* multiCoordinate = multiRotation->FirstChildElement(
"occupied_coord"); multiCoordinate; multiCoordinate = multiCoordinate->NextSiblingElement(
"occupied_coord")) {
409 xRetVal = multiCoordinate->QueryValueAttribute(
"x", &x);
410 yRetVal = multiCoordinate->QueryValueAttribute(
"y", &y);
411 if (xRetVal == TIXML_SUCCESS && yRetVal == TIXML_SUCCESS) {
413 multiCoordinate->QueryIntAttribute(
"z", &z);
420 for (TiXmlElement* imageElement = root->FirstChildElement(
"image"); imageElement; imageElement = imageElement->NextSiblingElement(
"image")) {
421 const std::string* sourceId = imageElement->Attribute(std::string(
"source"));
424 std::string source = *namespaceId +
":" + *sourceId;
426 throw NotFound(source +
" couldn't be found.");
430 int success = imageElement->QueryIntAttribute(
"x_offset", &xOffset);
432 if (success == TIXML_SUCCESS) {
437 success = imageElement->QueryIntAttribute(
"y_offset", &yOffset);
439 if (success == TIXML_SUCCESS) {
444 success = imageElement->QueryIntAttribute(
"direction", &direction);
446 if (success == TIXML_SUCCESS) {
virtual ImagePtr create(IResourceLoader *loader=0)
Creates a blank Image but does not load it immediately.
T * get() const
allows direct access to underlying pointer
virtual bool exists(const std::string &name)
Checks to see if an Image exists.
uint32_t getDataLength() const
get the complete datalength
void setXShift(int32_t xshift)
void setArea(const std::string &id)
Sets the area id that the instances of this object adds to their cells.
T h
Height of the rectangle.
ImagePtr & getPackedImage()
Returns an (packed) Image for this atlas.
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 setRotationAnchor(const ExactModelCoordinate &anchor)
Sets the rotation anchor for this multi object.
virtual bool isLoadable(const std::string &filename)
Object * createObject(const std::string &identifier, const std::string &name_space, Object *parent=0)
Add an object to the metamodel.
void setCellStackPosition(uint8_t position)
Sets the cell stack position.
AtlasLoader(Model *model, VFS *vfs, ImageManager *imageManager)
RawData * open(const std::string &path)
Open a file.
static Logger _log(LM_AUDIO)
void setZStepRange(int32_t zRange)
Sets z-step range for object.
void setFilename(const std::string &file)
SharedPtr< Image > ImagePtr
virtual ImagePtr getPtr(const std::string &name)
#define FL_ERR(logger, msg)
AtlasLoader * createDefaultAtlasLoader(Model *model, VFS *vfs, ImageManager *imageManager)
convenience function for creating the default fife atlas loader deleting the object returned from thi...
bool HasParentPath(const bfs::path &path)
Helper function to determine if a path object has a parent path.
ImageManager * m_imageManager
bfs::path GetParentPath(const bfs::path &path)
Helper function to retrieve a parent path object from a path object.
T * getVisual() const
Gets used visualization.
void parseObject(Atlas *atlas, TiXmlElement *root, bool exists)
virtual AtlasPtr load(const std::string &filename)
void setRestrictedRotation(bool restrict)
Sets the rotation to restricted.
void addMultiPartCoordinate(int32_t rotation, ModelCoordinate coord)
Adds rotationally dependent coordinates for this object part.
void setPackedImage(const ImagePtr &image)
Sets the image for atlas to use it for rendering.
A model is a facade for everything in the model.
void setCost(double cost)
Sets the cost.
const std::string & getName() const
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
void addMultiPartId(const std::string &partId)
Adds a multi part identifier.
static ObjectVisual * create(Object *object)
Constructs and assigns it to the passed item.
void addStaticImage(uint32_t angle, int32_t image_index)
Adds new static image with given angle (degrees) Static images are used in case there are no actions ...
void setStatic(bool stat)
Set to true, if object is such that it doesn't move.
the main VFS (virtual file system) class
std::string m_atlasFilename
IPather * getPather(const std::string &pathername)
Returns pather corresponding given name.
ImagePtr getImage(const std::string &id)
Return an Image of given id.
virtual void useSharedImage(const ImagePtr &shared, const Rect ®ion)=0
After this call all image data will be taken from the given image and its subregion.
void addWalkableArea(const std::string &id)
Adds an area id to walkable area.
Object * getObject(const std::string &id, const std::string &name_space)
Get an object by its id.
void setPather(IPather *pather)
Sets pather used by instances created out of this object.
void setBlocking(bool blocking)
Sets if object blocks movement.
void setYShift(int32_t yshift)
ResourceHandle getHandle()
size_t getImageCount() const
Returns the number of subimages that belongs to this atlas.
T w
Width of the rectangle.
void setCostId(const std::string &cost)
Sets the cost id.
bool addImage(const std::string &imagename, const AtlasData &data)
Adds new information about subimage that belongs to this atlas.
Used to access diffrent kinds of data.