30 #include "ext/tinyxml/fife_tinyxml.h"
51 : m_model(model), m_vfs(vfs), m_imageManager(imageManager) {
54 if (animationLoader) {
67 assert(animationLoader);
73 bfs::path objectPath(filename);
75 TiXmlDocument objectFile;
84 if (objectFile.Error()) {
85 std::ostringstream oss;
86 oss <<
" Failed to load"
87 << objectPath.string()
89 <<
" [" << __LINE__ <<
"]"
97 std::ostringstream oss;
98 oss <<
" Failed to load"
99 << objectPath.string()
101 <<
" [" << __LINE__ <<
"]"
113 std::ostringstream oss;
114 oss <<
" Failed to load"
115 << objectPath.string()
117 <<
" [" << __LINE__ <<
"]"
125 std::ostringstream oss;
126 oss <<
" Failed to load"
127 << objectPath.string()
129 <<
" [" << __LINE__ <<
"]"
141 TiXmlElement* root = objectFile.RootElement();
143 if (root && root->ValueStr() ==
"object") {
152 bfs::path objectPath(filename);
154 TiXmlDocument objectFile;
163 if (objectFile.Error()) {
174 std::ostringstream oss;
175 oss <<
" Failed to load"
176 << objectPath.string()
178 <<
" [" << __LINE__ <<
"]"
190 TiXmlElement* root = objectFile.RootElement();
192 if (root && root->ValueStr() ==
"object") {
193 const std::string* objectId = root->Attribute(std::string(
"id"));
194 const std::string* namespaceId = root->Attribute(std::string(
"namespace"));
197 if (objectId && namespaceId) {
198 const std::string* parentId = root->Attribute(std::string(
"parent"));
218 catch (NameClash &e) {
233 root->QueryIntAttribute(
"blocking", &isBlocking);
237 root->QueryIntAttribute(
"static", &isStatic);
240 const std::string* pather = root->Attribute(std::string(
"pather"));
249 const std::string* costId = root->Attribute(std::string(
"cost_id"));
253 int success = root->QueryDoubleAttribute(
"cost", &cost);
254 if (success == TIXML_SUCCESS) {
259 const std::string* areaId = root->Attribute(std::string(
"area_id"));
265 for (TiXmlElement* walkableElement = root->FirstChildElement(
"walkable_area"); walkableElement; walkableElement = walkableElement->NextSiblingElement(
"walkable_area")) {
266 const std::string* walkableId = walkableElement->Attribute(std::string(
"id"));
273 root->QueryIntAttribute(
"cellstack", &cellStack);
280 int xRetVal = root->QueryValueAttribute(
"anchor_x", &ax);
281 int yRetVal = root->QueryValueAttribute(
"anchor_y", &ay);
282 if (xRetVal == TIXML_SUCCESS && yRetVal == TIXML_SUCCESS) {
286 int isRestrictedRotation = 0;
287 root->QueryIntAttribute(
"restricted_rotation", &isRestrictedRotation);
291 int zRetVal = root->QueryIntAttribute(
"z_step_limit", &zStep);
292 if (zRetVal == TIXML_SUCCESS) {
297 for (TiXmlElement* multiElement = root->FirstChildElement(
"multipart"); multiElement; multiElement = multiElement->NextSiblingElement(
"multipart")) {
298 const std::string* partId = multiElement->Attribute(std::string(
"id"));
302 for (TiXmlElement* multiRotation = multiElement->FirstChildElement(
"rotation"); multiRotation; multiRotation = multiRotation->NextSiblingElement(
"rotation")) {
304 multiRotation->QueryIntAttribute(
"rot", &rotation);
306 for (TiXmlElement* multiCoordinate = multiRotation->FirstChildElement(
"occupied_coord"); multiCoordinate; multiCoordinate = multiCoordinate->NextSiblingElement(
"occupied_coord")) {
309 xRetVal = multiCoordinate->QueryValueAttribute(
"x", &x);
310 yRetVal = multiCoordinate->QueryValueAttribute(
"y", &y);
311 if (xRetVal == TIXML_SUCCESS && yRetVal == TIXML_SUCCESS) {
313 multiCoordinate->QueryIntAttribute(
"z", &z);
321 for (TiXmlElement* imageElement = root->FirstChildElement(
"image"); imageElement; imageElement = imageElement->NextSiblingElement(
"image")) {
322 const std::string* sourceId = imageElement->Attribute(std::string(
"source"));
325 bfs::path imagePath(filename);
330 imagePath = bfs::path(*sourceId);
343 int success = imageElement->QueryIntAttribute(
"x_offset", &xOffset);
345 if (success == TIXML_SUCCESS) {
350 success = imageElement->QueryIntAttribute(
"y_offset", &yOffset);
352 if (success == TIXML_SUCCESS) {
357 success = imageElement->QueryIntAttribute(
"direction", &direction);
359 if (success == TIXML_SUCCESS) {
370 for (TiXmlElement* actionElement = root->FirstChildElement(
"action"); actionElement; actionElement = actionElement->NextSiblingElement(
"action")) {
371 const std::string* actionId = actionElement->Attribute(std::string(
"id"));
377 for (TiXmlElement* animElement = actionElement->FirstChildElement(
"animation"); animElement; animElement = animElement->NextSiblingElement(
"animation")) {
378 const std::string* sourceId = animElement->Attribute(std::string(
"atlas"));
380 bfs::path atlasPath(filename);
385 atlasPath = bfs::path(*sourceId);
404 animElement->QueryValueAttribute(
"width", &frameWidth);
405 animElement->QueryValueAttribute(
"height", &frameHeight);
406 animElement->QueryValueAttribute(
"frames", &animFrames);
407 animElement->QueryValueAttribute(
"delay", &animDelay);
408 animElement->QueryValueAttribute(
"x_offset", &animXoffset);
409 animElement->QueryValueAttribute(
"y_offset", &animYoffset);
412 for (TiXmlElement* dirElement = animElement->FirstChildElement(
"direction");
413 dirElement; dirElement = dirElement->NextSiblingElement(
"direction")) {
417 dirElement->QueryIntAttribute(
"dir", &dir);
422 success = dirElement->QueryValueAttribute(
"frames", &frames);
423 if(success != TIXML_SUCCESS) {
428 success = dirElement->QueryValueAttribute(
"delay", &delay);
429 if(success != TIXML_SUCCESS) {
434 success = dirElement->QueryValueAttribute(
"x_offset", &xoffset);
435 if(success != TIXML_SUCCESS) {
436 xoffset = animXoffset;
440 success = dirElement->QueryValueAttribute(
"y_offset", &yoffset);
441 if(success != TIXML_SUCCESS) {
442 yoffset = animYoffset;
446 success = dirElement->QueryValueAttribute(
"action", &action_frame);
447 if(success == TIXML_SUCCESS) {
451 for (
int iframe = 0; iframe < frames; ++iframe) {
452 static char tmpBuf[64];
453 sprintf(tmpBuf,
"%03d:%04d", dir, iframe);
455 std::string frameId = *objectId +
":" + *actionId +
":" + std::string(tmpBuf);
461 frameWidth * iframe, frameHeight * nDir, frameWidth, frameHeight
470 animation->
addFrame(framePtr, delay);
482 sourceId = animElement->Attribute(std::string(
"source"));
484 bfs::path animPath(filename);
489 animPath = bfs::path(*sourceId);
498 animElement->QueryIntAttribute(
"direction", &direction);
500 if (action && animation) {
virtual ImagePtr create(IResourceLoader *loader=0)
Creates a blank Image but does not load it immediately.
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 * getVisual() const
Gets used visualization.
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.
Action visual contains data that is needed to visualize different actions on screen.
uint32_t getDuration() const
Gets the total duration for the whole animation.
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.
static ActionVisual * create(Action *action)
Constructs and assigns it to the passed item.
RawData * open(const std::string &path)
Open a file.
virtual bool isLoadable(const std::string &filename) const
static Logger _log(LM_AUDIO)
void setZStepRange(int32_t zRange)
Sets z-step range for object.
ImageManager * m_imageManager
void setActionFrame(int32_t num)
Sets the action frame.
void setFilename(const std::string &file)
virtual ImagePtr getPtr(const std::string &name)
virtual void load(const std::string &filename)
#define FL_ERR(logger, msg)
bool HasParentPath(const bfs::path &path)
Helper function to determine if a path object has a parent path.
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 setRestrictedRotation(bool restrict)
Sets the rotation to restricted.
void addMultiPartCoordinate(int32_t rotation, ModelCoordinate coord)
Adds rotationally dependent coordinates for this object part.
void addAnimation(uint32_t angle, AnimationPtr animationptr)
Adds new animation with given angle (degrees)
virtual void setAnimationLoader(const AnimationLoaderPtr &animationLoader)
A model is a facade for everything in the model.
void setCost(double cost)
Sets the cost.
ObjectLoader(Model *model, VFS *vfs, ImageManager *imageManager, const AnimationLoaderPtr &animationLoader=AnimationLoaderPtr())
Action * createAction(const std::string &identifier, bool is_default=false)
Adds new action with given id.
Object visual contains data that is needed for visualizing objects.
AnimationLoaderPtr m_animationLoader
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.
void addFrame(ImagePtr image, uint32_t duration)
Adds new frame into animation Frames must be added starting from first frame.
the main VFS (virtual file system) class
IPather * getPather(const std::string &pathername)
Returns pather corresponding given name.
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.
virtual AnimationPtr load(const std::string &filename)=0
responsible for loading the animation returns a shared pointer to an animation resource ...
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 setDuration(uint32_t duration)
Sets the duration for this action.
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()
virtual bool isLoadable(const std::string &filename)=0
determines whether the resource is in the correct format for this loader
void setCostId(const std::string &cost)
Sets the cost id.
Used to access diffrent kinds of data.