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) {
260 int success = root->QueryDoubleAttribute(
"speed", &speed);
261 if (success == TIXML_SUCCESS) {
265 const std::string* areaId = root->Attribute(std::string(
"area_id"));
271 for (TiXmlElement* walkableElement = root->FirstChildElement(
"walkable_area"); walkableElement; walkableElement = walkableElement->NextSiblingElement(
"walkable_area")) {
272 const std::string* walkableId = walkableElement->Attribute(std::string(
"id"));
279 root->QueryIntAttribute(
"cellstack", &cellStack);
286 int xRetVal = root->QueryValueAttribute(
"anchor_x", &ax);
287 int yRetVal = root->QueryValueAttribute(
"anchor_y", &ay);
288 if (xRetVal == TIXML_SUCCESS && yRetVal == TIXML_SUCCESS) {
292 int isRestrictedRotation = 0;
293 root->QueryIntAttribute(
"restricted_rotation", &isRestrictedRotation);
297 int zRetVal = root->QueryIntAttribute(
"z_step_limit", &zStep);
298 if (zRetVal == TIXML_SUCCESS) {
303 for (TiXmlElement* multiElement = root->FirstChildElement(
"multipart"); multiElement; multiElement = multiElement->NextSiblingElement(
"multipart")) {
304 const std::string* partId = multiElement->Attribute(std::string(
"id"));
308 for (TiXmlElement* multiRotation = multiElement->FirstChildElement(
"rotation"); multiRotation; multiRotation = multiRotation->NextSiblingElement(
"rotation")) {
310 multiRotation->QueryIntAttribute(
"rot", &rotation);
312 for (TiXmlElement* multiCoordinate = multiRotation->FirstChildElement(
"occupied_coord"); multiCoordinate; multiCoordinate = multiCoordinate->NextSiblingElement(
"occupied_coord")) {
315 xRetVal = multiCoordinate->QueryValueAttribute(
"x", &x);
316 yRetVal = multiCoordinate->QueryValueAttribute(
"y", &y);
317 if (xRetVal == TIXML_SUCCESS && yRetVal == TIXML_SUCCESS) {
319 multiCoordinate->QueryIntAttribute(
"z", &z);
327 for (TiXmlElement* imageElement = root->FirstChildElement(
"image"); imageElement; imageElement = imageElement->NextSiblingElement(
"image")) {
328 const std::string* sourceId = imageElement->Attribute(std::string(
"source"));
331 bfs::path imagePath(filename);
336 imagePath = bfs::path(*sourceId);
349 int success = imageElement->QueryIntAttribute(
"x_offset", &xOffset);
351 if (success == TIXML_SUCCESS) {
356 success = imageElement->QueryIntAttribute(
"y_offset", &yOffset);
358 if (success == TIXML_SUCCESS) {
363 success = imageElement->QueryIntAttribute(
"direction", &direction);
365 if (success == TIXML_SUCCESS) {
376 for (TiXmlElement* actionElement = root->FirstChildElement(
"action"); actionElement; actionElement = actionElement->NextSiblingElement(
"action")) {
377 const std::string* actionId = actionElement->Attribute(std::string(
"id"));
383 for (TiXmlElement* animElement = actionElement->FirstChildElement(
"animation"); animElement; animElement = animElement->NextSiblingElement(
"animation")) {
384 const std::string* sourceId = animElement->Attribute(std::string(
"atlas"));
386 bfs::path atlasPath(filename);
391 atlasPath = bfs::path(*sourceId);
410 animElement->QueryValueAttribute(
"width", &frameWidth);
411 animElement->QueryValueAttribute(
"height", &frameHeight);
412 animElement->QueryValueAttribute(
"frames", &animFrames);
413 animElement->QueryValueAttribute(
"delay", &animDelay);
414 animElement->QueryValueAttribute(
"x_offset", &animXoffset);
415 animElement->QueryValueAttribute(
"y_offset", &animYoffset);
418 for (TiXmlElement* dirElement = animElement->FirstChildElement(
"direction");
419 dirElement; dirElement = dirElement->NextSiblingElement(
"direction")) {
423 dirElement->QueryIntAttribute(
"dir", &dir);
428 success = dirElement->QueryValueAttribute(
"frames", &frames);
429 if(success != TIXML_SUCCESS) {
434 success = dirElement->QueryValueAttribute(
"delay", &delay);
435 if(success != TIXML_SUCCESS) {
440 success = dirElement->QueryValueAttribute(
"x_offset", &xoffset);
441 if(success != TIXML_SUCCESS) {
442 xoffset = animXoffset;
446 success = dirElement->QueryValueAttribute(
"y_offset", &yoffset);
447 if(success != TIXML_SUCCESS) {
448 yoffset = animYoffset;
452 success = dirElement->QueryValueAttribute(
"action", &action_frame);
453 if(success == TIXML_SUCCESS) {
457 for (
int iframe = 0; iframe < frames; ++iframe) {
458 static char tmpBuf[64];
459 sprintf(tmpBuf,
"%03d:%04d", dir, iframe);
461 std::string frameId = *objectId +
":" + *actionId +
":" + std::string(tmpBuf);
467 frameWidth * iframe, frameHeight * nDir, frameWidth, frameHeight
476 animation->
addFrame(framePtr, delay);
488 sourceId = animElement->Attribute(std::string(
"source"));
490 bfs::path animPath(filename);
495 animPath = bfs::path(*sourceId);
504 animElement->QueryIntAttribute(
"direction", &direction);
506 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()
void setSpeed(double cost)
Sets the speed modifier.
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.