FIFE  be64c707dea6b3250bd4355bf5c825d25920087d
objectloader.cpp
Go to the documentation of this file.
1 /**************************************************************************
2 * Copyright (C) 2005-2019 by the FIFE team *
3 * http://www.fifengine.net *
4 * This file is part of FIFE. *
5 * *
6 * FIFE is free software; you can redistribute it and/or *
7 * modify it under the terms of the GNU Lesser General Public *
8 * License as published by the Free Software Foundation; either *
9 * version 2.1 of the License, or (at your option) any later version. *
10 * *
11 * This library is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
14 * Lesser General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU Lesser General Public *
17 * License along with this library; if not, write to the *
18 * Free Software Foundation, Inc., *
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
20 ***************************************************************************/
21 
22 // Standard C++ library includes
23 
24 // 3rd party library includes
25 #include <tinyxml.h>
26 
27 // FIFE includes
28 // These includes are split up in two parts, separated by one empty line
29 // First block: files included from the FIFE root src directory
30 // Second block: files included from the same folder
31 #include "audio/actionaudio.h"
32 #include "util/log/logger.h"
33 #include "model/model.h"
34 #include "model/metamodel/object.h"
35 #include "model/metamodel/action.h"
37 #include "vfs/vfs.h"
38 #include "vfs/raw/rawdata.h"
39 #include "view/visual.h"
40 #include "video/imagemanager.h"
41 #include "video/animationmanager.h"
42 
43 #include "atlasloader.h"
44 #include "objectloader.h"
45 #include "animationloader.h"
46 
47 namespace FIFE {
51  static Logger _log(LM_NATIVE_LOADERS);
52 
53  ObjectLoader::ObjectLoader(Model* model, VFS* vfs, ImageManager* imageManager, AnimationManager* animationManager, const AnimationLoaderPtr& animationLoader, const AtlasLoaderPtr& atlasLoader)
54  : m_model(model), m_vfs(vfs), m_imageManager(imageManager), m_animationManager(animationManager) {
56 
57  if (animationLoader) {
58  m_animationLoader = animationLoader;
59  }
60  else {
62  }
63 
64  if (atlasLoader) {
65  m_atlasLoader = atlasLoader;
66  }
67  else {
69  }
70  }
71 
73 
74  }
75 
77  assert(animationLoader);
78 
79  m_animationLoader = animationLoader;
80  }
81 
83  return m_animationLoader;
84  }
85 
86  void ObjectLoader::setAtlasLoader(const AtlasLoaderPtr& atlasLoader) {
87  assert(atlasLoader);
88 
89  m_atlasLoader = atlasLoader;
90  }
91 
93  return m_atlasLoader;
94  }
95 
96  bool ObjectLoader::isLoadable(const std::string& filename) const {
97  bfs::path objectPath(filename);
98 
99  TiXmlDocument objectFile;
100 
101  try {
102  RawData* data = m_vfs->open(objectPath.string());
103 
104  if (data) {
105  if (data->getDataLength() != 0) {
106  objectFile.Parse(data->readString(data->getDataLength()).c_str());
107 
108  if (objectFile.Error()) {
109  std::ostringstream oss;
110  oss << " Failed to load"
111  << objectPath.string()
112  << " : " << __FILE__
113  << " [" << __LINE__ << "]"
114  << std::endl;
115  FL_ERR(_log, oss.str());
116 
117  return false;
118  }
119  }
120  else {
121  std::ostringstream oss;
122  oss << " Failed to load"
123  << objectPath.string()
124  << " : " << __FILE__
125  << " [" << __LINE__ << "]"
126  << std::endl;
127  FL_ERR(_log, oss.str());
128 
129  return false;
130  }
131 
132  // done with data delete resource
133  delete data;
134  data = 0;
135  }
136  else {
137  std::ostringstream oss;
138  oss << " Failed to load"
139  << objectPath.string()
140  << " : " << __FILE__
141  << " [" << __LINE__ << "]"
142  << std::endl;
143  FL_ERR(_log, oss.str());
144 
145  return false;
146  }
147  }
148  catch (NotFound&) {
149  std::ostringstream oss;
150  oss << " Failed to load"
151  << objectPath.string()
152  << " : " << __FILE__
153  << " [" << __LINE__ << "]"
154  << std::endl;
155  FL_ERR(_log, oss.str());
156 
157  // TODO - should we abort here
158  // or rethrow the exception
159  // or just keep going
160 
161  return false;
162  }
163 
164  // if we get here then loading the file went well
165  TiXmlElement* root = objectFile.RootElement();
166 
167  if (root && root->ValueStr() == "assets") {
168  if (root->FirstChildElement("object")) {
169  return true;
170  }
171  }
172 
173  return false;
174  }
175 
176  void ObjectLoader::load(const std::string& filename) {
177  bfs::path objectPath(filename);
178 
179  TiXmlDocument objectFile;
180 
181  try {
182  RawData* data = m_vfs->open(objectPath.string());
183 
184  if (data) {
185  if (data->getDataLength() != 0) {
186  objectFile.Parse(data->readString(data->getDataLength()).c_str());
187 
188  if (objectFile.Error()) {
189  return;
190  }
191  }
192 
193  // done with data delete resource
194  delete data;
195  data = 0;
196  }
197  }
198  catch (NotFound&) {
199  std::ostringstream oss;
200  oss << " Failed to load"
201  << objectPath.string()
202  << " : " << __FILE__
203  << " [" << __LINE__ << "]"
204  << std::endl;
205  FL_ERR(_log, oss.str());
206 
207  // TODO - should we abort here
208  // or rethrow the exception
209  // or just keep going
210 
211  return;
212  }
213  std::string objectDirectory = "";
214  if (HasParentPath(objectPath)) {
215  objectDirectory = GetParentPath(objectPath).string();
216  }
217 
218  // if we get here then loading the file went well
219  TiXmlElement* root = objectFile.RootElement();
220  if (root) {
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"));
224 
225  std::string directory = "";
226  if (importDir) {
227  directory = *importDir;
228  }
229 
230  std::string file = "";
231  if (importFile) {
232  file = *importFile;
233  }
234 
235  if (importDir && !importFile) {
236  bfs::path fullPath(objectDirectory);
237  fullPath /= directory;
238  loadImportDirectory(fullPath.string());
239  } else if (importFile) {
240  bfs::path fullFilePath(file);
241  bfs::path fullDirPath(directory);
242  if (importDir) {
243  fullDirPath = bfs::path(objectDirectory);
244  fullDirPath /= directory;
245  } else {
246  fullFilePath = bfs::path(objectDirectory);
247  fullFilePath /= file;
248  }
249  loadImportFile(fullFilePath.string(), fullDirPath.string());
250  }
251  }
252  }
253 
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"));
258 
259  Object* obj = NULL;
260  if (objectId && namespaceId) {
261  const std::string* parentId = objectElem->Attribute(std::string("parent"));
262 
263  if (parentId) {
264  Object* parent = m_model->getObject(*parentId, *namespaceId);
265  if (parent) {
266  try {
267  obj = m_model->createObject(*objectId, *namespaceId, parent);
268  }
269  catch (NameClash&) {
270  // TODO - handle exception
271  assert(false);
272  }
273  }
274  } else {
275  // this will make sure the object has not already been loaded
276  if (m_model->getObject(*objectId, *namespaceId) == NULL) {
277  try {
278  obj = m_model->createObject(*objectId, *namespaceId);
279  }
280  catch (NameClash &e) {
281  FL_ERR(_log, e.what());
282 
283  // TODO - handle exception
284  assert(false);
285  }
286  }
287  }
288  }
289 
290  if (obj) {
291  obj->setFilename(objectPath.string());
293 
294  int isBlocking = 0;
295  objectElem->QueryIntAttribute("blocking", &isBlocking);
296  obj->setBlocking(isBlocking!=0);
297 
298  int isStatic = 0;
299  objectElem->QueryIntAttribute("static", &isStatic);
300  obj->setStatic(isStatic!=0);
301 
302  const std::string* pather = objectElem->Attribute(std::string("pather"));
303 
304  if (pather) {
305  obj->setPather(m_model->getPather(*pather));
306  }
307  else {
308  obj->setPather(m_model->getPather("RoutePather"));
309  }
310 
311  const std::string* costId = objectElem->Attribute(std::string("cost_id"));
312  if (costId) {
313  obj->setCostId(*costId);
314  double cost = 1.0;
315  int success = objectElem->QueryDoubleAttribute("cost", &cost);
316  if (success == TIXML_SUCCESS) {
317  obj->setCost(cost);
318  }
319  }
320 
321  const std::string* areaId = objectElem->Attribute(std::string("area_id"));
322  if (areaId) {
323  obj->setArea(*areaId);
324  }
325 
326  double speed = 1.0;
327  int success = root->QueryDoubleAttribute("speed", &speed);
328  if (success == TIXML_SUCCESS) {
329  obj->setSpeed(speed);
330  }
331 
332  // loop over all walkable areas
333  for (TiXmlElement* walkableElement = objectElem->FirstChildElement("walkable_area"); walkableElement; walkableElement = walkableElement->NextSiblingElement("walkable_area")) {
334  const std::string* walkableId = walkableElement->Attribute(std::string("id"));
335  if (walkableId) {
336  obj->addWalkableArea(*walkableId);
337  }
338  }
339 
340  int cellStack = 0;
341  objectElem->QueryIntAttribute("cellstack", &cellStack);
342  obj->setCellStackPosition(cellStack);
343 
344  double ax = 0;
345  double ay = 0;
346  double az = 0;
347 
348  int xRetVal = objectElem->QueryValueAttribute("anchor_x", &ax);
349  int yRetVal = objectElem->QueryValueAttribute("anchor_y", &ay);
350  if (xRetVal == TIXML_SUCCESS && yRetVal == TIXML_SUCCESS) {
351  obj->setRotationAnchor(ExactModelCoordinate(ax, ay, az));
352  }
353 
354  int isRestrictedRotation = 0;
355  objectElem->QueryIntAttribute("restricted_rotation", &isRestrictedRotation);
356  obj->setRestrictedRotation(isRestrictedRotation!=0);
357 
358  int zStep = 0;
359  int zRetVal = objectElem->QueryIntAttribute("z_step_limit", &zStep);
360  if (zRetVal == TIXML_SUCCESS) {
361  obj->setZStepRange(zStep);
362  }
363 
364  // loop over all multi parts
365  for (TiXmlElement* multiElement = objectElem->FirstChildElement("multipart"); multiElement; multiElement = multiElement->NextSiblingElement("multipart")) {
366  const std::string* partId = multiElement->Attribute(std::string("id"));
367  if (partId) {
368  obj->addMultiPartId(*partId);
369  }
370  for (TiXmlElement* multiRotation = multiElement->FirstChildElement("rotation"); multiRotation; multiRotation = multiRotation->NextSiblingElement("rotation")) {
371  int rotation = 0;
372  multiRotation->QueryIntAttribute("rot", &rotation);
373  // relative coordinates which are used to position the object
374  for (TiXmlElement* multiCoordinate = multiRotation->FirstChildElement("occupied_coord"); multiCoordinate; multiCoordinate = multiCoordinate->NextSiblingElement("occupied_coord")) {
375  int x = 0;
376  int y = 0;
377  xRetVal = multiCoordinate->QueryValueAttribute("x", &x);
378  yRetVal = multiCoordinate->QueryValueAttribute("y", &y);
379  if (xRetVal == TIXML_SUCCESS && yRetVal == TIXML_SUCCESS) {
380  int z = 0;
381  multiCoordinate->QueryIntAttribute("z", &z);
382  obj->addMultiPartCoordinate(rotation, ModelCoordinate(x, y, z));
383  }
384  }
385  }
386  }
387 
388  // loop over all image tags
389  for (TiXmlElement* imageElement = objectElem->FirstChildElement("image"); imageElement; imageElement = imageElement->NextSiblingElement("image")) {
390  const std::string* sourceId = imageElement->Attribute(std::string("source"));
391 
392  if (sourceId) {
393  bfs::path imagePath(filename);
394 
395  if (HasParentPath(imagePath)) {
396  imagePath = GetParentPath(imagePath) / *sourceId;
397  } else {
398  imagePath = bfs::path(*sourceId);
399  }
400 
401  if (!bfs::exists(imagePath)) {
402  imagePath= bfs::path(*sourceId);
403  }
404 
405  ImagePtr imagePtr;
406  if(!m_imageManager->exists(imagePath.string())) {
407  imagePtr = m_imageManager->create(imagePath.string());
408  }
409  else {
410  imagePtr = m_imageManager->getPtr(imagePath.string());
411  }
412 
413  if (imagePtr) {
414  int xOffset = 0;
415  int success = imageElement->QueryIntAttribute("x_offset", &xOffset);
416 
417  if (success == TIXML_SUCCESS) {
418  imagePtr->setXShift(xOffset);
419  }
420 
421  int yOffset = 0;
422  success = imageElement->QueryIntAttribute("y_offset", &yOffset);
423 
424  if (success == TIXML_SUCCESS) {
425  imagePtr->setYShift(yOffset);
426  }
427 
428  int direction = 0;
429  success = imageElement->QueryIntAttribute("direction", &direction);
430 
431  if (success == TIXML_SUCCESS) {
432  ObjectVisual* objVisual = obj->getVisual<ObjectVisual>();
433 
434  if (objVisual) {
435  objVisual->addStaticImage(direction, static_cast<int32_t>(imagePtr->getHandle()));
436  }
437  }
438  }
439  }
440  }
441 
442  for (TiXmlElement* actionElement = objectElem->FirstChildElement("action"); actionElement; actionElement = actionElement->NextSiblingElement("action")) {
443  const std::string* actionId = actionElement->Attribute(std::string("id"));
444 
445  if (actionId) {
446  int isDefault = 0;
447  actionElement->QueryIntAttribute("default", &isDefault);
448  Action* action = obj->createAction(*actionId, (isDefault != 0));
449 
450  // Fetch ActionAudio data
451  TiXmlElement* soundElement = actionElement->FirstChildElement("sound");
452  if (soundElement) {
453  const std::string* clip = soundElement->Attribute(std::string("source"));
454  if (clip) {
455  ActionAudio* audio = new ActionAudio();
456  action->adoptAudio(audio);
457  audio->setSoundFileName(*clip);
458 
459  const std::string* group = soundElement->Attribute(std::string("group"));
460  if (group) {
461  audio->setGroupName(*group);
462  }
463 
464  float value = 0;
465  int success = soundElement->QueryValueAttribute("volume", &value);
466  if (success == TIXML_SUCCESS)
467  audio->setGain(value);
468  success = soundElement->QueryValueAttribute("max_volume", &value);
469  if (success == TIXML_SUCCESS)
470  audio->setMaxGain(value);
471  success = soundElement->QueryValueAttribute("min_volume", &value);
472  if (success == TIXML_SUCCESS)
473  audio->setMinGain(value);
474  success = soundElement->QueryValueAttribute("ref_distance", &value);
475  if (success == TIXML_SUCCESS)
476  audio->setReferenceDistance(value);
477  success = soundElement->QueryValueAttribute("max_distance", &value);
478  if (success == TIXML_SUCCESS)
479  audio->setMaxDistance(value);
480  success = soundElement->QueryValueAttribute("rolloff", &value);
481  if (success == TIXML_SUCCESS)
482  audio->setRolloff(value);
483  success = soundElement->QueryValueAttribute("pitch", &value);
484  if (success == TIXML_SUCCESS)
485  audio->setPitch(value);
486  success = soundElement->QueryValueAttribute("cone_inner_angle", &value);
487  if (success == TIXML_SUCCESS)
488  audio->setConeInnerAngle(value);
489  success = soundElement->QueryValueAttribute("cone_outer_angle", &value);
490  if (success == TIXML_SUCCESS)
491  audio->setConeOuterAngle(value);
492  success = soundElement->QueryValueAttribute("cone_outer_gain", &value);
493  if (success == TIXML_SUCCESS)
494  audio->setConeOuterGain(value);
495 
496  int boolValue = 0;
497  success = soundElement->QueryIntAttribute("looping", &boolValue);
498  if (success == TIXML_SUCCESS)
499  audio->setLooping(boolValue != 0);
500  success = soundElement->QueryIntAttribute("relative_position", &boolValue);
501  if (success == TIXML_SUCCESS)
502  audio->setRelativePositioning(boolValue != 0);
503  success = soundElement->QueryIntAttribute("direction", &boolValue);
504  if (success == TIXML_SUCCESS)
505  audio->setDirection(boolValue != 0);
506 
507  double vx = 0;
508  double vy = 0;
509  double vz = 0;
510  if (soundElement->QueryValueAttribute("x_velocity", &vx) == TIXML_SUCCESS && soundElement->QueryValueAttribute("y_velocity", &vy) == TIXML_SUCCESS) {
511  soundElement->QueryValueAttribute("z_velocity", &vz);
512  audio->setVelocity(AudioSpaceCoordinate(vx, vy, vz));
513  }
514  }
515  }
516 
517  // Create and fetch ActionVisual
518  ActionVisual::create(action);
519 
520  for (TiXmlElement* animElement = actionElement->FirstChildElement("animation"); animElement; animElement = animElement->NextSiblingElement("animation")) {
521  // Fetch already created animation
522  const std::string* animationId = animElement->Attribute(std::string("animation_id"));
523  if (animationId) {
524  AnimationPtr animation = m_animationManager->getPtr(*animationId);
525  if (animation) {
526  ActionVisual* actionVisual = action->getVisual<ActionVisual>();
527  if (actionVisual) {
528  actionVisual->addAnimation(animation->getDirection(), animation);
529  action->setDuration(animation->getDuration());
530  continue;
531  }
532  }
533  }
534 
535  // Create animated spritesheet
536  const std::string* sourceId = animElement->Attribute(std::string("atlas"));
537  if (sourceId) {
538  bfs::path atlasPath(filename);
539 
540  if (HasParentPath(atlasPath)) {
541  atlasPath = GetParentPath(atlasPath) / *sourceId;
542  } else {
543  atlasPath = bfs::path(*sourceId);
544  }
545 
546  ImagePtr atlasImgPtr;
547  // we need to load this since its shared image
548  if (!m_imageManager->exists(atlasPath.string())) {
549  atlasImgPtr = m_imageManager->create(atlasPath.string());
550  } else {
551  atlasImgPtr = m_imageManager->getPtr(atlasPath.string());
552  }
553 
554  int animFrames = 0;
555  int animDelay = 0;
556  int animXoffset = 0;
557  int animYoffset = 0;
558  int frameWidth = 0;
559  int frameHeight = 0;
560 
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);
567  int nDir = 0;
568 
569  for (TiXmlElement* dirElement = animElement->FirstChildElement("direction");
570  dirElement; dirElement = dirElement->NextSiblingElement("direction")) {
571  int dir;
572  dirElement->QueryIntAttribute("dir", &dir);
573 
574  static char tmp[64];
575  snprintf(tmp, 64, "%03d", dir);
576  std::string aniId = *objectId + ":" + *actionId + ":" + std::string(tmp);
577  AnimationPtr animation = m_animationManager->create(aniId);
578 
579  int frames;
580  int success = dirElement->QueryValueAttribute("frames", &frames);
581  if(success != TIXML_SUCCESS) {
582  frames = animFrames;
583  }
584 
585  int delay;
586  success = dirElement->QueryValueAttribute("delay", &delay);
587  if(success != TIXML_SUCCESS) {
588  delay = animDelay;
589  }
590 
591  int xoffset;
592  success = dirElement->QueryValueAttribute("x_offset", &xoffset);
593  if(success != TIXML_SUCCESS) {
594  xoffset = animXoffset;
595  }
596 
597  int yoffset;
598  success = dirElement->QueryValueAttribute("y_offset", &yoffset);
599  if(success != TIXML_SUCCESS) {
600  yoffset = animYoffset;
601  }
602 
603  int action_frame;
604  success = dirElement->QueryValueAttribute("action_frame", &action_frame);
605  if(success == TIXML_SUCCESS) {
606  animation->setActionFrame(action_frame);
607  }
608 
609  for (int iframe = 0; iframe < frames; ++iframe) {
610  static char tmpBuf[64];
611  snprintf(tmpBuf, 64, "%03d:%04d", dir, iframe);
612 
613  std::string frameId = *objectId + ":" + *actionId + ":" + std::string(tmpBuf);
614  Rect region(frameWidth * iframe, frameHeight * nDir, frameWidth, frameHeight);
615  ImagePtr framePtr;
616  if (!m_imageManager->exists(frameId)) {
617  framePtr = m_imageManager->create(frameId);
618  framePtr->useSharedImage(atlasImgPtr, region);
619  framePtr->setXShift(xoffset);
620  framePtr->setYShift(yoffset);
621  } else {
622  framePtr = m_imageManager->getPtr(frameId);
623  }
624  animation->addFrame(framePtr, delay);
625  }
626 
627  ActionVisual* actionVisual = action->getVisual<ActionVisual>();
628  if(actionVisual) {
629  actionVisual->addAnimation(dir, animation);
630  action->setDuration(animation->getDuration());
631  }
632  ++nDir;
633  }
634  continue;
635  }
636 
637  // Load animation.xml with frames
638  sourceId = animElement->Attribute(std::string("source"));
639  if (sourceId) {
640  int direction = 0;
641  int success = animElement->QueryValueAttribute("direction", &direction);
642 
643  bfs::path animPath(filename);
644 
645  if (HasParentPath(animPath)) {
646  animPath = GetParentPath(animPath) / *sourceId;
647  } else {
648  animPath = bfs::path(*sourceId);
649  }
650 
651  AnimationPtr animation;
652  if (m_animationLoader && m_animationLoader->isLoadable(animPath.string())) {
653  animation = m_animationLoader->load(animPath.string());
654  }
655 
656  if (action && animation) {
657  if (success != TIXML_SUCCESS) {
658  direction = animation->getDirection();
659  }
660  ActionVisual* actionVisual = action->getVisual<ActionVisual>();
661  if (actionVisual) {
662  actionVisual->addAnimation(direction, animation);
663  action->setDuration(animation->getDuration());
664  }
665  }
666  }
667  }
668  }
669  }
670  }
671  }
672  }
673  }
674 
675  void ObjectLoader::loadImportFile(const std::string& file, const std::string& directory) {
676  if (!file.empty()) {
677  bfs::path importFilePath(directory);
678  importFilePath /= file;
679 
680  std::string importFileString = importFilePath.string();
681  if (m_atlasLoader && m_atlasLoader->isLoadable(importFileString)) {
682  m_atlasLoader->loadMultiple(importFileString);
683  }
684  if (m_animationLoader && m_animationLoader->isLoadable(importFileString)) {
685  m_animationLoader->loadMultiple(importFileString);
686  }
687  if (isLoadable(importFileString)) {
688  load(importFileString);
689  }
690  }
691  }
692 
693  void ObjectLoader::loadImportDirectory(const std::string& directory) {
694  if (!directory.empty()) {
695  bfs::path importDirectory(directory);
696  std::string importDirectoryString = importDirectory.string();
697 
698  std::set<std::string> files = m_vfs->listFiles(importDirectoryString);
699 
700  // load all xml files in the directory
701  std::set<std::string>::iterator iter;
702  for (iter = files.begin(); iter != files.end(); ++iter) {
703  // TODO - vtchill - may need a way to allow clients to load things other
704  // than .xml and .zip files
705  std::string ext = bfs::extension(*iter);
706  if (ext == ".xml" || ext == ".zip") {
707  loadImportFile(*iter, importDirectoryString);
708  }
709  }
710 
711  std::set<std::string> nestedDirectories = m_vfs->listDirectories(importDirectoryString);
712  for (iter = nestedDirectories.begin(); iter != nestedDirectories.end(); ++iter) {
713  // do not attempt to load anything from a .svn directory
714  if ((*iter).find(".svn") == std::string::npos) {
715  loadImportDirectory(importDirectoryString + "/" + *iter);
716  }
717  }
718  }
719  }
720 }
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.
Definition: actionaudio.cpp:72
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)
Definition: image.h:119
uint32_t getDirection() const
Gets the animation direction.
Definition: animation.h:134
void setDirection(bool direction)
Sets if the sound should use the instance direction.
ImageManager.
Definition: imagemanager.h:54
void setArea(const std::string &id)
Sets the area id that the instances of this object adds to their cells.
Definition: object.cpp:573
Object class.
Definition: object.h:51
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...
Definition: sharedptr.h:164
void setRotationAnchor(const ExactModelCoordinate &anchor)
Sets the rotation anchor for this multi object.
Definition: object.cpp:508
void setMaxGain(float gain)
Sets the max.
Definition: actionaudio.cpp:88
Action visual contains data that is needed to visualize different actions on screen.
Definition: visual.h:212
Object * createObject(const std::string &identifier, const std::string &name_space, Object *parent=0)
Add an object to the metamodel.
Definition: model.cpp:205
void setCellStackPosition(uint8_t position)
Sets the cell stack position.
Definition: object.cpp:258
static ActionVisual * create(Action *action)
Constructs and assigns it to the passed item.
Definition: visual.cpp:228
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.
Definition: vfs.cpp:172
void setRelativePositioning(bool relative)
Sets Positioning-Type Default is false.
void setPitch(float pitch)
Sets pitch multiplier.
DoublePoint3D AudioSpaceCoordinate
Definition: modelcoords.h:36
static Logger _log(LM_AUDIO)
virtual AnimationPtr getPtr(const std::string &name)
void setZStepRange(int32_t zRange)
Sets z-step range for object.
Definition: object.cpp:556
ImageManager * m_imageManager
Definition: objectloader.h:95
void setActionFrame(int32_t num)
Sets the action frame.
Definition: animation.h:114
void setFilename(const std::string &file)
Definition: object.cpp:250
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.
Definition: vfs.cpp:182
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)
Definition: logger.h:73
AtlasLoaderPtr m_atlasLoader
Definition: objectloader.h:98
uint32_t getDataLength() const
get the complete datalength
Definition: rawdata.cpp:75
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
AnimationManager.
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.
Definition: actionaudio.cpp:96
Point3D ModelCoordinate
Definition: modelcoords.h:38
void setGain(float gain)
Sets the gain of the emitter.
Definition: actionaudio.cpp:80
The class for holding audio data per Action.
Definition: actionaudio.h:41
void setRestrictedRotation(bool restrict)
Sets the rotation to restricted.
Definition: object.cpp:525
void addMultiPartCoordinate(int32_t rotation, ModelCoordinate coord)
Adds rotationally dependent coordinates for this object part.
Definition: object.cpp:442
void addAnimation(uint32_t angle, AnimationPtr animationptr)
Adds new animation with given angle (degrees)
Definition: visual.cpp:240
virtual void setAnimationLoader(const AnimationLoaderPtr &animationLoader)
void setSoundFileName(const std::string &name)
Sets the name of the sound file.
Definition: actionaudio.cpp:64
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.
Definition: model.h:54
void adoptAudio(ActionAudio *audio)
Sets audio to be used.
Definition: action.h:78
void setCost(double cost)
Sets the cost.
Definition: object.cpp:302
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.
Definition: object.cpp:92
Object visual contains data that is needed for visualizing objects.
Definition: visual.h:91
AnimationLoaderPtr m_animationLoader
Definition: objectloader.h:97
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...
Definition: rawdata.cpp:128
std::set< std::string > listDirectories(const std::string &path) const
Get a directorylist of the given directory.
Definition: vfs.cpp:198
DoublePoint3D ExactModelCoordinate
Definition: modelcoords.h:37
void addMultiPartId(const std::string &partId)
Adds a multi part identifier.
Definition: object.cpp:356
static ObjectVisual * create(Object *object)
Constructs and assigns it to the passed item.
Definition: visual.cpp:101
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 ...
Definition: visual.cpp:113
virtual void setAtlasLoader(const AtlasLoaderPtr &atlasLoader)
void setStatic(bool stat)
Set to true, if object is such that it doesn&#39;t move.
Definition: object.cpp:233
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.
Definition: animation.cpp:104
the main VFS (virtual file system) class
Definition: vfs.h:58
IPather * getPather(const std::string &pathername)
Returns pather corresponding given name.
Definition: model.cpp:111
AnimationManager * m_animationManager
Definition: objectloader.h:96
virtual void useSharedImage(const ImagePtr &shared, const Rect &region)=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.
Definition: object.cpp:590
Object * getObject(const std::string &id, const std::string &name_space)
Get an object by its id.
Definition: model.cpp:280
void setDuration(uint32_t duration)
Sets the duration for this action.
Definition: action.h:62
void setPather(IPather *pather)
Sets pather used by instances created out of this object.
Definition: object.cpp:188
T * getVisual() const
Gets used visualization.
Definition: action.h:74
void setBlocking(bool blocking)
Sets if object blocks movement.
Definition: object.cpp:216
T * getVisual() const
Gets used visualization.
Definition: object.h:122
void setYShift(int32_t yshift)
Definition: image.h:125
ResourceHandle getHandle()
Definition: resource.h:68
void setSpeed(double cost)
Sets the speed modifier.
Definition: object.cpp:329
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.
Definition: animation.h:138
void setCostId(const std::string &cost)
Sets the cost id.
Definition: object.cpp:285
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.
Definition: rawdata.h:48