54 : m_model(model), m_vfs(vfs), m_imageManager(imageManager), m_animationManager(animationManager) {
57 if (animationLoader) {
77 assert(animationLoader);
97 bfs::path objectPath(filename);
99 TiXmlDocument objectFile;
108 if (objectFile.Error()) {
109 std::ostringstream oss;
110 oss <<
" Failed to load" 111 << objectPath.string()
113 <<
" [" << __LINE__ <<
"]" 121 std::ostringstream oss;
122 oss <<
" Failed to load" 123 << objectPath.string()
125 <<
" [" << __LINE__ <<
"]" 137 std::ostringstream oss;
138 oss <<
" Failed to load" 139 << objectPath.string()
141 <<
" [" << __LINE__ <<
"]" 149 std::ostringstream oss;
150 oss <<
" Failed to load" 151 << objectPath.string()
153 <<
" [" << __LINE__ <<
"]" 165 TiXmlElement* root = objectFile.RootElement();
167 if (root && root->ValueStr() ==
"assets") {
168 if (root->FirstChildElement(
"object")) {
177 bfs::path objectPath(filename);
179 TiXmlDocument objectFile;
188 if (objectFile.Error()) {
199 std::ostringstream oss;
200 oss <<
" Failed to load" 201 << objectPath.string()
203 <<
" [" << __LINE__ <<
"]" 213 std::string objectDirectory =
"";
219 TiXmlElement* root = objectFile.RootElement();
221 for (
const TiXmlElement *importElement = root->FirstChildElement(
"import"); importElement; importElement = importElement->NextSiblingElement(
"import")) {
222 const std::string* importDir = importElement->Attribute(std::string(
"dir"));
223 const std::string* importFile = importElement->Attribute(std::string(
"file"));
225 std::string directory =
"";
227 directory = *importDir;
230 std::string file =
"";
235 if (importDir && !importFile) {
236 bfs::path fullPath(objectDirectory);
237 fullPath /= directory;
239 }
else if (importFile) {
240 bfs::path fullFilePath(file);
241 bfs::path fullDirPath(directory);
243 fullDirPath = bfs::path(objectDirectory);
244 fullDirPath /= directory;
246 fullFilePath = bfs::path(objectDirectory);
247 fullFilePath /= file;
254 if (root && root->ValueStr() ==
"assets") {
255 for (TiXmlElement* objectElem = root->FirstChildElement(
"object"); objectElem; objectElem = objectElem->NextSiblingElement(
"object")) {
256 const std::string* objectId = objectElem->Attribute(std::string(
"id"));
257 const std::string* namespaceId = objectElem->Attribute(std::string(
"namespace"));
260 if (objectId && namespaceId) {
261 const std::string* parentId = objectElem->Attribute(std::string(
"parent"));
280 catch (NameClash &e) {
295 objectElem->QueryIntAttribute(
"blocking", &isBlocking);
299 objectElem->QueryIntAttribute(
"static", &isStatic);
302 const std::string* pather = objectElem->Attribute(std::string(
"pather"));
311 const std::string* costId = objectElem->Attribute(std::string(
"cost_id"));
315 int success = objectElem->QueryDoubleAttribute(
"cost", &cost);
316 if (success == TIXML_SUCCESS) {
321 const std::string* areaId = objectElem->Attribute(std::string(
"area_id"));
327 int success = root->QueryDoubleAttribute(
"speed", &speed);
328 if (success == TIXML_SUCCESS) {
333 for (TiXmlElement* walkableElement = objectElem->FirstChildElement(
"walkable_area"); walkableElement; walkableElement = walkableElement->NextSiblingElement(
"walkable_area")) {
334 const std::string* walkableId = walkableElement->Attribute(std::string(
"id"));
341 objectElem->QueryIntAttribute(
"cellstack", &cellStack);
348 int xRetVal = objectElem->QueryValueAttribute(
"anchor_x", &ax);
349 int yRetVal = objectElem->QueryValueAttribute(
"anchor_y", &ay);
350 if (xRetVal == TIXML_SUCCESS && yRetVal == TIXML_SUCCESS) {
354 int isRestrictedRotation = 0;
355 objectElem->QueryIntAttribute(
"restricted_rotation", &isRestrictedRotation);
359 int zRetVal = objectElem->QueryIntAttribute(
"z_step_limit", &zStep);
360 if (zRetVal == TIXML_SUCCESS) {
365 for (TiXmlElement* multiElement = objectElem->FirstChildElement(
"multipart"); multiElement; multiElement = multiElement->NextSiblingElement(
"multipart")) {
366 const std::string* partId = multiElement->Attribute(std::string(
"id"));
370 for (TiXmlElement* multiRotation = multiElement->FirstChildElement(
"rotation"); multiRotation; multiRotation = multiRotation->NextSiblingElement(
"rotation")) {
372 multiRotation->QueryIntAttribute(
"rot", &rotation);
374 for (TiXmlElement* multiCoordinate = multiRotation->FirstChildElement(
"occupied_coord"); multiCoordinate; multiCoordinate = multiCoordinate->NextSiblingElement(
"occupied_coord")) {
377 xRetVal = multiCoordinate->QueryValueAttribute(
"x", &x);
378 yRetVal = multiCoordinate->QueryValueAttribute(
"y", &y);
379 if (xRetVal == TIXML_SUCCESS && yRetVal == TIXML_SUCCESS) {
381 multiCoordinate->QueryIntAttribute(
"z", &z);
389 for (TiXmlElement* imageElement = objectElem->FirstChildElement(
"image"); imageElement; imageElement = imageElement->NextSiblingElement(
"image")) {
390 const std::string* sourceId = imageElement->Attribute(std::string(
"source"));
393 bfs::path imagePath(filename);
398 imagePath = bfs::path(*sourceId);
401 if (!bfs::exists(imagePath)) {
402 imagePath= bfs::path(*sourceId);
415 int success = imageElement->QueryIntAttribute(
"x_offset", &xOffset);
417 if (success == TIXML_SUCCESS) {
422 success = imageElement->QueryIntAttribute(
"y_offset", &yOffset);
424 if (success == TIXML_SUCCESS) {
429 success = imageElement->QueryIntAttribute(
"direction", &direction);
431 if (success == TIXML_SUCCESS) {
442 for (TiXmlElement* actionElement = objectElem->FirstChildElement(
"action"); actionElement; actionElement = actionElement->NextSiblingElement(
"action")) {
443 const std::string* actionId = actionElement->Attribute(std::string(
"id"));
447 actionElement->QueryIntAttribute(
"default", &isDefault);
451 TiXmlElement* soundElement = actionElement->FirstChildElement(
"sound");
453 const std::string* clip = soundElement->Attribute(std::string(
"source"));
459 const std::string* group = soundElement->Attribute(std::string(
"group"));
465 int success = soundElement->QueryValueAttribute(
"volume", &value);
466 if (success == TIXML_SUCCESS)
468 success = soundElement->QueryValueAttribute(
"max_volume", &value);
469 if (success == TIXML_SUCCESS)
471 success = soundElement->QueryValueAttribute(
"min_volume", &value);
472 if (success == TIXML_SUCCESS)
474 success = soundElement->QueryValueAttribute(
"ref_distance", &value);
475 if (success == TIXML_SUCCESS)
477 success = soundElement->QueryValueAttribute(
"max_distance", &value);
478 if (success == TIXML_SUCCESS)
480 success = soundElement->QueryValueAttribute(
"rolloff", &value);
481 if (success == TIXML_SUCCESS)
483 success = soundElement->QueryValueAttribute(
"pitch", &value);
484 if (success == TIXML_SUCCESS)
486 success = soundElement->QueryValueAttribute(
"cone_inner_angle", &value);
487 if (success == TIXML_SUCCESS)
489 success = soundElement->QueryValueAttribute(
"cone_outer_angle", &value);
490 if (success == TIXML_SUCCESS)
492 success = soundElement->QueryValueAttribute(
"cone_outer_gain", &value);
493 if (success == TIXML_SUCCESS)
497 success = soundElement->QueryIntAttribute(
"looping", &boolValue);
498 if (success == TIXML_SUCCESS)
500 success = soundElement->QueryIntAttribute(
"relative_position", &boolValue);
501 if (success == TIXML_SUCCESS)
503 success = soundElement->QueryIntAttribute(
"direction", &boolValue);
504 if (success == TIXML_SUCCESS)
510 if (soundElement->QueryValueAttribute(
"x_velocity", &vx) == TIXML_SUCCESS && soundElement->QueryValueAttribute(
"y_velocity", &vy) == TIXML_SUCCESS) {
511 soundElement->QueryValueAttribute(
"z_velocity", &vz);
520 for (TiXmlElement* animElement = actionElement->FirstChildElement(
"animation"); animElement; animElement = animElement->NextSiblingElement(
"animation")) {
522 const std::string* animationId = animElement->Attribute(std::string(
"animation_id"));
536 const std::string* sourceId = animElement->Attribute(std::string(
"atlas"));
538 bfs::path atlasPath(filename);
543 atlasPath = bfs::path(*sourceId);
561 animElement->QueryValueAttribute(
"width", &frameWidth);
562 animElement->QueryValueAttribute(
"height", &frameHeight);
563 animElement->QueryValueAttribute(
"frames", &animFrames);
564 animElement->QueryValueAttribute(
"delay", &animDelay);
565 animElement->QueryValueAttribute(
"x_offset", &animXoffset);
566 animElement->QueryValueAttribute(
"y_offset", &animYoffset);
569 for (TiXmlElement* dirElement = animElement->FirstChildElement(
"direction");
570 dirElement; dirElement = dirElement->NextSiblingElement(
"direction")) {
572 dirElement->QueryIntAttribute(
"dir", &dir);
575 snprintf(tmp, 64,
"%03d", dir);
576 std::string aniId = *objectId +
":" + *actionId +
":" + std::string(tmp);
580 int success = dirElement->QueryValueAttribute(
"frames", &frames);
581 if(success != TIXML_SUCCESS) {
586 success = dirElement->QueryValueAttribute(
"delay", &delay);
587 if(success != TIXML_SUCCESS) {
592 success = dirElement->QueryValueAttribute(
"x_offset", &xoffset);
593 if(success != TIXML_SUCCESS) {
594 xoffset = animXoffset;
598 success = dirElement->QueryValueAttribute(
"y_offset", &yoffset);
599 if(success != TIXML_SUCCESS) {
600 yoffset = animYoffset;
604 success = dirElement->QueryValueAttribute(
"action_frame", &action_frame);
605 if(success == TIXML_SUCCESS) {
609 for (
int iframe = 0; iframe < frames; ++iframe) {
610 static char tmpBuf[64];
611 snprintf(tmpBuf, 64,
"%03d:%04d", dir, iframe);
613 std::string frameId = *objectId +
":" + *actionId +
":" + std::string(tmpBuf);
614 Rect region(frameWidth * iframe, frameHeight * nDir, frameWidth, frameHeight);
624 animation->
addFrame(framePtr, delay);
638 sourceId = animElement->Attribute(std::string(
"source"));
641 int success = animElement->QueryValueAttribute(
"direction", &direction);
643 bfs::path animPath(filename);
648 animPath = bfs::path(*sourceId);
656 if (action && animation) {
657 if (success != TIXML_SUCCESS) {
677 bfs::path importFilePath(directory);
678 importFilePath /= file;
680 std::string importFileString = importFilePath.string();
688 load(importFileString);
694 if (!directory.empty()) {
695 bfs::path importDirectory(directory);
696 std::string importDirectoryString = importDirectory.string();
698 std::set<std::string> files =
m_vfs->
listFiles(importDirectoryString);
701 std::set<std::string>::iterator iter;
702 for (iter = files.begin(); iter != files.end(); ++iter) {
705 std::string ext = bfs::extension(*iter);
706 if (ext ==
".xml" || ext ==
".zip") {
712 for (iter = nestedDirectories.begin(); iter != nestedDirectories.end(); ++iter) {
714 if ((*iter).find(
".svn") == std::string::npos) {
virtual ImagePtr create(IResourceLoader *loader=0)
Creates a blank Image but does not load it immediately.
void setRolloff(float rolloff)
Sets the AL_ROLEOFF_FACTOR.
void setGroupName(const std::string &name)
Sets the name of the group to which the emitter is added.
virtual bool exists(const std::string &name)
Checks to see if an Image exists.
virtual bool isLoadable(const std::string &filename) const
void setXShift(int32_t xshift)
uint32_t getDirection() const
Gets the animation direction.
void setDirection(bool direction)
Sets if the sound should use the instance direction.
void setArea(const std::string &id)
Sets the area id that the instances of this object adds to their cells.
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.
void setMaxGain(float gain)
Sets the max.
Action visual contains data that is needed to visualize different actions on screen.
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.
void setReferenceDistance(float distance)
Sets the distance under which the volume for the SoundEmitter would normally drop by half (before bei...
RawData * open(const std::string &path)
Open a file.
void setRelativePositioning(bool relative)
Sets Positioning-Type Default is false.
void setPitch(float pitch)
Sets pitch multiplier.
DoublePoint3D AudioSpaceCoordinate
static Logger _log(LM_AUDIO)
virtual AnimationPtr getPtr(const std::string &name)
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 AnimationLoaderPtr getAnimationLoader()
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.
void loadImportFile(const std::string &file, const std::string &directory="")
used to load an object, atlas or animation file if directory is provided then file is assumed relativ...
virtual ImagePtr getPtr(const std::string &name)
virtual void load(const std::string &filename)
#define FL_ERR(logger, msg)
AtlasLoaderPtr m_atlasLoader
uint32_t getDataLength() const
get the complete datalength
virtual AnimationPtr create(IResourceLoader *loader=0)
Creates a blank Animation but does not load it immediately.
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.
bfs::path GetParentPath(const bfs::path &path)
Helper function to retrieve a parent path object from a path object.
void setConeOuterGain(float gain)
Sets the gain when outside the oriented cone.
void setMinGain(float gain)
Sets the min.
void setGain(float gain)
Sets the gain of the emitter.
The class for holding audio data per Action.
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)
void setSoundFileName(const std::string &name)
Sets the name of the sound file.
void setVelocity(const AudioSpaceCoordinate &velocity)
Sets the velocity of the SoundEmitter in the virtual audio space.
A model is a facade for everything in the model.
void adoptAudio(ActionAudio *audio)
Sets audio to be used.
void setCost(double cost)
Sets the cost.
void loadImportDirectory(const std::string &directory)
used to load a directory of object, atlas or animation files recursively
void setConeInnerAngle(float inner)
Sets inner angle of the sound cone, in degrees.
void setMaxDistance(float distance)
Sets the max distance used with the Inverse Clamped Distance Model to set the distance where there wi...
void setConeOuterAngle(float outer)
Sets outer angle of the sound cone, in degrees.
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
virtual AtlasLoaderPtr getAtlasLoader()
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
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 ...
virtual void setAtlasLoader(const AtlasLoaderPtr &atlasLoader)
void setStatic(bool stat)
Set to true, if object is such that it doesn't move.
ObjectLoader(Model *model, VFS *vfs, ImageManager *imageManager, AnimationManager *animationManager, const AnimationLoaderPtr &animationLoader=AnimationLoaderPtr(), const AtlasLoaderPtr &atlasLoader=AtlasLoaderPtr())
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.
AnimationManager * m_animationManager
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.
T * getVisual() const
Gets used visualization.
void setBlocking(bool blocking)
Sets if object blocks movement.
T * getVisual() const
Gets used visualization.
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
uint32_t getDuration() const
Gets the total duration for the whole animation.
void setCostId(const std::string &cost)
Sets the cost id.
void setLooping(bool loop)
Sets the playing mode.
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 ...
Used to access diffrent kinds of data.