Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 9790 in orxonox.OLD for branches/new_class_id/src


Ignore:
Timestamp:
Sep 23, 2006, 10:34:42 AM (18 years ago)
Author:
bensch
Message:

added new_resource_manager

Location:
branches/new_class_id/src
Files:
6 edited
2 copied

Legend:

Unmodified
Added
Removed
  • branches/new_class_id/src/lib/coord/p_node.cc

    r9783 r9790  
    8181  // remove the Node, delete it's children (if required).
    8282  PNode* last = NULL;
    83   this->debugNode(0);
     83  //this->debugNode(0);
    8484
    8585  while(!this->children.empty())
  • branches/new_class_id/src/lib/graphics/importer/resource_texture.cc

    r9789 r9790  
    22
    33#include "resource_texture.h"
    4 
     4#include "debug.h"
    55
    66
     
    1212  if (ptr)
    1313  {
    14     printf("FOUNT TEXTURE: %s\n", imageName.c_str());
     14    PRINTF(5)("FOUNT TEXTURE: %s\n", imageName.c_str());
    1515    this->acquireData(static_cast<ResourceTexture::TextureResourcePointer*>(ptr)->ptr());
    1616  }
    1717  else
    1818  {
    19     printf("NOT FOUNT TEXTURE: %s\n", imageName.c_str());
     19    PRINTF(5)("NOT FOUNT TEXTURE: %s\n", imageName.c_str());
    2020    std::string fileName = this->NewResource::locateFile(imageName);
    2121    this->Texture::loadImage(fileName, target);
  • branches/new_class_id/src/lib/util/Makefile.am

    r9777 r9790  
    1616                \
    1717                loading/resource_manager.cc \
     18                loading/new_resource_manager.cc \
    1819                loading/resource.cc \
    1920                loading/game_loader.cc \
     
    6667                \
    6768                loading/resource_manager.h \
     69                loading/new_resource_manager.h \
    6870                loading/resource.h \
    6971                loading/game_loader.h \
  • branches/new_class_id/src/lib/util/loading/new_resource_manager.cc

    r9789 r9790  
    1616#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_LOAD
    1717
    18 #include "util/loading/resource_manager.h"
    19 #include "substring.h"
     18#include "new_resource_manager.h"
    2019#include "debug.h"
    2120
     
    2322#include <assert.h>
    2423
    25 // different resource Types
    26 #ifndef NO_MODEL
    27 #include "objModel.h"
    28 #include "primitive_model.h"
    29 #include "md2/md2Model.h"
    30 #include "md3/md3_data.h"
    31 #include "md3/md3_animation_cfg.h"
    32 #endif /* NO_MODEL */
    33 #ifndef NO_TEXTURES
    34 #include "texture.h"
    35 #endif /* NO_TEXTURES */
    36 #ifndef NO_TEXT
    37 #include "font.h"
    38 #endif /* NO_TEXT */
    39 #ifndef NO_AUDIO
    40 #include "sound_buffer.h"
    41 #include "ogg_player.h"
    42 #endif /* NO_AUDIO */
    43 #ifndef NO_SHADERS
    44 #include "shader.h"
    45 #endif /* NO_SHADERS */
    46 
    47 // File Handling Includes
    48 #include <sys/types.h>
    49 #include <sys/stat.h>
    50 #include <unistd.h>
    51 
    52 ObjectListDefinition(ResourceManager);
     24ObjectListDefinition(NewResourceManager);
    5325
    5426/**
    5527 * @brief standard constructor
    5628*/
    57 ResourceManager::ResourceManager ()
     29NewResourceManager::NewResourceManager ()
    5830{
    59   this->registerObject(this, ResourceManager::_objectList);
    60   this->setName("ResourceManager");
     31  this->registerObject(this, NewResourceManager::_objectList);
     32  this->setName("NewResourceManager");
    6133
    62   this->dataDir = "./";
     34  //this->dataDir = "./";
    6335  this->tryDataDir("./data");
    6436}
    6537
    66 //! Singleton Reference to the ResourceManager
    67 ResourceManager* ResourceManager::singletonRef = NULL;
     38//! Singleton Reference to the NewResourceManager
     39NewResourceManager* NewResourceManager::singletonRef = NULL;
    6840
    6941/**
    7042 * @brief standard destructor
    7143*/
    72 ResourceManager::~ResourceManager ()
     44NewResourceManager::~NewResourceManager ()
    7345{
    7446  // deleting the Resources-List
    75   this->unloadAllByPriority(RP_GAME);
     47  //this->unloadAllByPriority(RP_GAME);
    7648
    77   if (!this->resourceList.empty())
    78     PRINTF(1)("Not removed all Resources, since there are still %d resources registered\n", this->resourceList.size());
     49//   if (!this->resourceList.empty())
     50//     PRINTF(1)("Not removed all Resources, since there are still %d resources registered\n", this->resourceList.size());
    7951
    80   ResourceManager::singletonRef = NULL;
    81 }
    82 
    83 /**
    84  * @brief sets the data main directory
    85  * @param dataDir the DataDirectory.
    86  */
    87 bool ResourceManager::setDataDir(const std::string& dataDir)
    88 {
    89   File dataDirectory(dataDir);
    90   if (dataDirectory.isDirectory())
    91   {
    92     this->dataDir = dataDirectory.name();
    93 
    94     if (dataDir[dataDir.size()-1] != '/' && dataDir[dataDir.size()-1] != '\\')
    95     {
    96       this->dataDir += '/';
    97     }
    98     return true;
    99   }
    100   else
    101   {
    102     PRINTF(1)("%s is not a Directory, and can not be the Data Directory, leaving as %s \n", dataDir.c_str(), this->dataDir.c_str());
    103     return false;
    104   }
    105 }
    106 
    107 /**
    108  * @brief sets the data main directory
    109  * @param dataDir the DataDirectory.
    110  *
    111  * this is essentially the same as setDataDir, but it ommits the error-message
    112  */
    113 bool ResourceManager::tryDataDir(const std::string& dataDir)
    114 {
    115   File dataDirectory(dataDir);
    116   if (dataDirectory.isDirectory())
    117   {
    118     this->dataDir = dataDirectory.name();
    119 
    120     if (dataDir[dataDir.size()-1] != '/' && dataDir[dataDir.size()-1] != '\\')
    121     {
    122       this->dataDir += '/';
    123     }
    124     return true;
    125   }
    126   return false;
     52  NewResourceManager::singletonRef = NULL;
    12753}
    12854
    12955
    130 /**
    131  * @brief checks for the DataDirectory, by looking if
    132  * @param fileInside is iniside of the given directory.
    133 */
    134 bool ResourceManager::verifyDataDir(const std::string& fileInside)
    135 {
    136   File dataDirectory(this->dataDir);
    137   if (!dataDirectory.isDirectory())
    138   {
    139     PRINTF(1)("'%s' is not a directory\n", this->dataDir.c_str());
    140     return false;
    141   }
    142 
    143   File testFile(this->dataDir + fileInside);
    144   return testFile.isFile();
    145 }
    146 
    147 #ifndef NO_TEXTURES
    148 /**
    149  * @brief adds a new Path for Images
    150  * @param imageDir The path to insert
    151  * @returns true, if the Path was well and injected (or already existent within the list)
    152    false otherwise
    153 */
    154 bool ResourceManager::addImageDir(const std::string& imageDir)
    155 {
    156   std::string newDir = imageDir;
    157   if (imageDir[imageDir.size()-1] != '/' && imageDir[imageDir.size()-1] != '\\')
    158   {
    159     newDir += '/';
    160   }
    161   // check if the param is a Directory
    162   if (File(newDir).isDirectory())
    163   {
    164     // check if the Directory has been added before
    165     std::vector<std::string>::const_iterator imageDir;
    166     for (imageDir = this->imageDirs.begin(); imageDir != this->imageDirs.end(); imageDir++)
    167     {
    168       if (*imageDir == newDir)
    169       {
    170         PRINTF(3)("Path %s already loaded\n", newDir.c_str());
    171         return true;
    172       }
    173     }
    174     // adding the directory to the List
    175     this->imageDirs.push_back(newDir);
    176     return true;
    177   }
    178   else
    179   {
    180     PRINTF(1)("%s is not a Directory, and can not be added to the Paths of Images\n", newDir.c_str());
    181     return false;
    182   }
    183 }
    184 #endif /* NO_TEXTURES */
    18556
    18657/**
    187  * @brief loads resources
    188  * @param fileName: The fileName of the resource to load
    189  * @param prio: The ResourcePriority of this resource (will only be increased)
    190  * @param param0: an additional option to parse (see the constuctors for more help)
    191  * @param param1: an additional option to parse (see the constuctors for more help)
    192  * @param param2: an additional option to parse (see the constuctors for more help)
    193  * @returns a pointer to a desired Resource.
    194 */
    195 BaseObject* ResourceManager::load(const std::string& fileName, ResourcePriority prio,
    196                                   const MultiType& param0, const MultiType& param1, const MultiType& param2)
    197 {
    198   ResourceType tmpType;
    199 #ifndef NO_MODEL
    200 #define __IF_OK
    201   if (!strncasecmp(fileName.c_str()+(fileName.size()-4), ".obj", 4))
    202     tmpType = OBJ;
    203   else if (!strncmp(fileName.c_str()+(fileName.size()-4), ".md2", 4))
    204     tmpType = MD2;
    205   else if (!strncmp(fileName.c_str()+(fileName.size()-4), ".md3", 4))
    206     tmpType = MD3;
    207   else if (!strncmp(fileName.c_str()+(fileName.size()-4), ".cfg", 4))
    208     tmpType = MD3_CONFIG;
    209   else if (!strcasecmp(fileName.c_str(), "cube") ||
    210             !strcasecmp(fileName.c_str(), "sphere") ||
    211             !strcasecmp(fileName.c_str(), "plane") ||
    212             !strcasecmp(fileName.c_str(), "cylinder") ||
    213             !strcasecmp(fileName.c_str(), "cone"))
    214     tmpType = PRIM;
    215 #endif /* NO_MODEL */
    216 #ifndef NO_AUDIO
    217 #ifdef __IF_OK
    218   else
    219 #endif
    220 #define __IF_OK
    221     if (!strncasecmp(fileName.c_str()+(fileName.size()-4), ".wav", 4))
    222       tmpType = WAV;
    223     else if (!strncasecmp(fileName.c_str()+(fileName.size()-4), ".mp3", 4))
    224       tmpType = MP3;
    225     else if (!strncasecmp(fileName.c_str()+(fileName.size()-4), ".ogg", 4))
    226       tmpType = OGG;
    227 #endif /* NO_AUDIO */
    228 #ifndef NO_TEXT
    229 #ifdef __IF_OK
    230     else
    231 #endif
    232 #define __IF_OK
    233       if (!strncasecmp(fileName.c_str()+(fileName.size()-4), ".ttf", 4))
    234         tmpType = TTF;
    235 #endif /* NO_TEXT */
    236 #ifndef NO_SHADERS
    237 #ifdef __IF_OK
    238       else
    239 #endif
    240 #define __IF_OK
    241         if (!strncasecmp(fileName.c_str()+(fileName.size()-5), ".vert", 5))
    242           tmpType = SHADER;
    243 #endif /* NO_SHADERS */
    244 #ifndef NO_TEXTURES
    245 #ifdef __IF_OK
    246         else
    247 #else
    248   if
    249 #endif
    250           tmpType = IMAGE;
    251 #endif /* NO_TEXTURES */
    252 #undef __IF_OK
    253   return this->load(fileName, tmpType, prio, param0, param1, param2);
    254 }
    255 
    256 /**
    257  * @brief caches a Resource
    258  *
    259  * @see load;
    260  *
    261  * @brief returns true if ok, false otherwise.
    262  * This function loads a Resource without applying it to an Object.
    263  * This is for loading purposes, e.g, when the user is loading a Resource
    264  * during the initialisation instead of at Runtime.
     58 * @brief outputs debug information about the NewResourceManager
    26559 */
    266 bool ResourceManager::cache(const std::string& fileName, ResourceType type, ResourcePriority prio,
    267                             const MultiType& param0, const MultiType& param1, const MultiType& param2)
    268 {
    269   // searching if the resource was loaded before.
    270   Resource* tmpResource;
    271   // check if we already loaded this Resource
    272   tmpResource = this->locateResourceByInfo(fileName, type, param0, param1, param2);
    273   // otherwise load it
    274   if (tmpResource == NULL)
    275     tmpResource = this->loadResource(fileName, type, prio, param0, param1, param2);
    276   // return cached pointer.
    277   if (tmpResource != NULL) // if the resource was loaded before.
    278   {
    279     if(tmpResource->prio < prio)
    280       tmpResource->prio = prio;
    281     return true;
    282   }
    283   else
    284     return false;
    285 }
    286 
    287 /**
    288  * tells the ResourceManager to generate a Copy of the Resource.
    289  * @brief resourcePointer: The Pointer to the resource to copy
    290  * @returns the Resource pointed to resourcePointer.
    291  */
    292 BaseObject* ResourceManager::copy(BaseObject* resourcePointer)
    293 {
    294   Resource* tmp = locateResourceByPointer(resourcePointer);
    295   if (tmp!=NULL)
    296   {
    297     tmp->count++;
    298     return tmp->pointer;
    299   }
    300   else
    301     return NULL;
    302 }
    303 
    304 
    305 /**
    306  * @brief loads resources
    307  * @param fileName: The fileName of the resource to load
    308  * @param type: The Type of Resource to load.
    309  * @param prio: The ResourcePriority of this resource (will only be increased)
    310  * @param param0: an additional option to parse (see the constuctors for more help)
    311  * @param param1: an additional option to parse (see the constuctors for more help)
    312  * @param param2: an additional option to parse (see the constuctors for more help)
    313  * @returns a pointer to a desired Resource.
    314 */
    315 BaseObject* ResourceManager::load(const std::string& fileName, ResourceType type, ResourcePriority prio,
    316                                   const MultiType& param0, const MultiType& param1, const MultiType& param2)
    317 {
    318 
    319   // searching if the resource was loaded before.
    320   Resource* tmpResource;
    321   // check if we already loaded this Resource
    322   tmpResource = this->locateResourceByInfo(fileName, type, param0, param1, param2);
    323   // otherwise load it
    324   if (tmpResource == NULL)
    325   {
    326     tmpResource = this->loadResource(fileName, type, prio, param0, param1, param2);
    327   }
    328   // return cached pointer.
    329   if (tmpResource != NULL) // if the resource was loaded before.
    330   {
    331     tmpResource->count++;
    332     if(tmpResource->prio < prio)
    333       tmpResource->prio = prio;
    334 
    335     return tmpResource->pointer;
    336   }
    337   else
    338     return NULL;
    339 }
    340 
    341 
    342 /**
    343  * @brief loads resources for internal purposes
    344  * @param fileName: The fileName of the resource to load
    345  * @param type: The Type of Resource to load.
    346  * @param prio: The ResourcePriority of this resource (will only be increased)
    347  * @param param0: an additional option to parse (see the constuctors for more help)
    348  * @param param1: an additional option to parse (see the constuctors for more help)
    349  * @param param2: an additional option to parse (see the constuctors for more help)
    350  * @returns a pointer to a desired Resource.
    351  */
    352 Resource* ResourceManager::loadResource(const std::string& fileName, ResourceType type, ResourcePriority prio,
    353                                         const MultiType& param0, const MultiType& param1, const MultiType& param2)
    354 {
    355   // Setting up the new Resource
    356   Resource* tmpResource = new Resource;
    357   tmpResource->count = 0;
    358   tmpResource->type = type;
    359   tmpResource->prio = prio;
    360   tmpResource->pointer = NULL;
    361   tmpResource->name = fileName;
    362 
    363   // creating the full name. (directoryName + FileName)
    364   std::string fullName = ResourceManager::getFullName(fileName);
    365   // Checking for the type of resource \see ResourceType
    366   switch(type)
    367   {
    368 #ifndef NO_MODEL
    369     case OBJ:
    370       if (param0.getType() != MT_NULL)
    371         tmpResource->param[0] = param0;
    372       else
    373         tmpResource->param[0] = 1.0f;
    374 
    375       if(File(fullName).isFile())
    376         tmpResource->pointer = new OBJModel(fullName, tmpResource->param[0].getFloat());
    377       else
    378       {
    379         PRINTF(2)("File %s in %s does not exist. Loading a cube-Model instead\n", fileName.c_str(), dataDir.c_str());
    380         tmpResource->pointer = ResourceManager::load("cube", PRIM, prio, tmpResource->param[0].getFloat());
    381       }
    382       break;
    383     case PRIM:
    384       if (param0 != MT_NULL)
    385         tmpResource->param[0] = param0;
    386       else
    387         tmpResource->param[0] = 1.0f;
    388 
    389       if (tmpResource->name == "cube")
    390         tmpResource->pointer = new PrimitiveModel(PRIM_CUBE, tmpResource->param[0].getFloat());
    391       else if (tmpResource->name == "sphere")
    392         tmpResource->pointer = new PrimitiveModel(PRIM_SPHERE, tmpResource->param[0].getFloat());
    393       else if (tmpResource->name == "plane")
    394         tmpResource->pointer = new PrimitiveModel(PRIM_PLANE, tmpResource->param[0].getFloat());
    395       else if (tmpResource->name == "cylinder")
    396         tmpResource->pointer = new PrimitiveModel(PRIM_CYLINDER, tmpResource->param[0].getFloat());
    397       else if (tmpResource->name == "cone")
    398         tmpResource->pointer = new PrimitiveModel(PRIM_CONE, tmpResource->param[0].getFloat());
    399       break;
    400     case MD2:
    401       if(File(fullName).isFile())
    402       {
    403         tmpResource->param[0] = param0;
    404         tmpResource->param[1] = param1;
    405         tmpResource->pointer = new MD2Data(fullName, tmpResource->param[0].getCString(), tmpResource->param[1].getFloat());
    406       }
    407       break;
    408     case MD3:
    409       if(File(fullName).isFile())
    410       {
    411         tmpResource->param[0] = param0;
    412         tmpResource->param[1] = param1;
    413         tmpResource->pointer = new md3::MD3Data(fullName, tmpResource->param[0].getCString(), tmpResource->param[1].getFloat());
    414       }
    415       break;
    416     case MD3_CONFIG:
    417       if(File(fullName).isFile())
    418       {
    419         tmpResource->param[0] = param0;
    420         tmpResource->param[1] = param1;
    421         tmpResource->pointer = new md3::MD3AnimationCfg(fullName);
    422       }
    423       break;
    424 #endif /* NO_MODEL */
    425 #ifndef NO_TEXT
    426     case TTF:
    427       if (param0 != MT_NULL)
    428       {
    429         assert(param0.getInt() >= 0);
    430         tmpResource->param[0] = param0;
    431       }
    432       else
    433         tmpResource->param[0] = FONT_DEFAULT_RENDER_SIZE;
    434 
    435       if(File(fullName).isFile())
    436         tmpResource->pointer = new Font(fullName, (unsigned int) tmpResource->param[0].getInt());
    437       else
    438         PRINTF(2)("%s does not exist in %s. Not loading Font\n", fileName.c_str(), this->dataDir.c_str());
    439       break;
    440 #endif /* NO_TEXT */
    441 #ifndef NO_AUDIO
    442     case WAV:
    443       if(File(fullName).isFile())
    444         tmpResource->pointer = new OrxSound::SoundBuffer(fullName);
    445       break;
    446     case OGG:
    447       if (File(fullName).isFile())
    448         tmpResource->pointer = new OrxSound::OggPlayer(fullName);
    449       break;
    450 #endif /* NO_AUDIO */
    451 #ifndef NO_TEXTURES
    452     case IMAGE:
    453       if (param0 != MT_NULL)
    454         tmpResource->param[0] = param0;
    455       else
    456         tmpResource->param[0] = GL_TEXTURE_2D;
    457       if(File(fullName).isFile())
    458       {
    459         PRINTF(4)("Image %s resides to %s\n", fileName.c_str(), fullName.c_str());
    460         tmpResource->pointer = new Texture(fullName, tmpResource->param[0].getInt());
    461       }
    462       else
    463       {
    464         std::vector<std::string>::iterator imageDir;
    465         for (imageDir = this->imageDirs.begin(); imageDir != this->imageDirs.end(); imageDir++)
    466         {
    467           std::string imgName = *imageDir + fileName;
    468           if(File(imgName).isFile())
    469           {
    470             PRINTF(4)("Image %s resides to %s\n", fileName.c_str(), imgName.c_str());
    471             tmpResource->pointer = new Texture(imgName, tmpResource->param[0].getInt());
    472             break;
    473           }
    474         }
    475       }
    476       if(!tmpResource)
    477         PRINTF(2)("!!Image %s not Found!!\n", fileName.c_str());
    478       break;
    479 #endif /* NO_TEXTURES */
    480 #ifndef NO_SHADERS
    481     case SHADER:
    482       if(File(fullName).isFile())
    483       {
    484         if (param0 != MT_NULL)
    485         {
    486           MultiType param = param0; /// HACK
    487           std::string secFullName = ResourceManager::getFullName(param.getCString());
    488           if (File(secFullName).isFile())
    489           {
    490             tmpResource->param[0] = secFullName;
    491             tmpResource->pointer = new Shader(fullName, secFullName);
    492           }
    493         }
    494         else
    495         {
    496           tmpResource->param[0] = param0;
    497           tmpResource->pointer = new Shader(fullName, "");
    498         }
    499       }
    500       break;
    501 #endif /* NO_SHADERS */
    502     default:
    503       tmpResource->pointer = NULL;
    504       PRINTF(1)("No type found for %s.\n   !!This should not happen unless the Type is not supported yet. JUST DO IT!!\n", tmpResource->name.c_str());
    505       break;
    506   }
    507   if (tmpResource->pointer != NULL)
    508     this->resourceList.push_back(tmpResource);
    509 
    510   if (tmpResource->pointer != NULL)
    511     return tmpResource;
    512   else
    513   {
    514     PRINTF(2)("Resource %s could not be loaded\n", fileName.c_str());
    515     delete tmpResource;
    516     return NULL;
    517   }
    518 }
    519 
    520 /**
    521  * @brief unloads a Resource
    522  * @param pointer: The pointer to free
    523  * @param prio: the PriorityLevel to unload this resource
    524  * @returns true if successful (pointer found, and deleted), false otherwise
    525 */
    526 bool ResourceManager::unload(BaseObject* pointer, ResourcePriority prio)
    527 {
    528   if (pointer == NULL)
    529     return false;
    530   // if pointer is existent. and only one resource of this type exists.
    531   Resource* tmpResource = this->locateResourceByPointer(pointer);
    532   if (tmpResource != NULL)
    533     return unload(tmpResource, prio);
    534   else
    535   {
    536     PRINTF(2)("Resource not Found %p\n", pointer);
    537     return false;
    538   }
    539 }
    540 
    541 /**
    542  * @brief unloads a Resource
    543  * @param resource: The resource to unloade
    544  * @param prio the PriorityLevel to unload this resource
    545  * @returns true on success, false otherwise.
    546 */
    547 bool ResourceManager::unload(Resource* resource, ResourcePriority prio)
    548 {
    549   if (resource == NULL)
    550     return false;
    551   if (resource->count > 0)
    552     resource->count--;
    553 
    554   if (resource->prio <= prio)
    555   {
    556     if (resource->count == 0)
    557     {
    558       delete resource->pointer;
    559       // deleting the List Entry:
    560       PRINTF(4)("Resource %s safely removed.\n", resource->name.c_str());
    561       std::vector<Resource*>::iterator resourceIT = std::find(this->resourceList.begin(), this->resourceList.end(), resource);
    562       this->resourceList.erase(resourceIT);
    563       delete resource;
    564     }
    565     else
    566       PRINTF(4)("Resource %s not removed, because there are still %d References to it.\n", resource->name.c_str(), resource->count);
    567   }
    568   else
    569     PRINTF(4)("not deleting resource %s because DeleteLevel to high\n", resource->name.c_str());
    570   return true;
    571 }
    572 
    573 
    574 /**
    575  * @brief unloads all alocated Memory of Resources with a pririty lower than prio
    576  * @param prio The priority to delete
    577 */
    578 bool ResourceManager::unloadAllByPriority(ResourcePriority prio)
    579 {
    580   bool removedAll = true;
    581   unsigned int removeCount;
    582   for (unsigned int round = 0; round < 3; round++)
    583   {
    584     int index = this->resourceList.size() - 1;
    585     removeCount = 0;
    586     while (index >= 0)
    587     {
    588       if (this->resourceList[index]->prio <= prio)
    589       {
    590         if (this->resourceList[index]->count == 0)
    591           unload(this->resourceList[index], prio);
    592         else
    593         {
    594           if (round == 3)
    595           {
    596             PRINTF(2)("unable to unload %s because there are still %d references to it\n",
    597                       this->resourceList[index]->name.c_str(), this->resourceList[index]->count);
    598             removedAll = false;
    599           }
    600           removeCount++;
    601         }
    602       }
    603       index--;
    604     }
    605     if (removeCount == 0) break;
    606   }
    607   return removedAll;
    608 }
    609 
    610 
    611 /**
    612  * @brief Searches for a Resource by some information
    613  * @param fileName: The name to look for
    614  * @param type the Type of resource to locate.
    615  * @param param0: an additional option to parse (see the constuctors for more help)
    616  * @param param1: an additional option to parse (see the constuctors for more help)
    617  * @param param2: an additional option to parse (see the constuctors for more help)
    618  * @returns a Pointer to the Resource if found, NULL otherwise.
    619 */
    620 Resource* ResourceManager::locateResourceByInfo(const std::string& fileName, ResourceType type,
    621     const MultiType& param0, const MultiType& param1, const MultiType& param2) const
    622 {
    623   std::vector<Resource*>::const_iterator resource;
    624   for (resource = this->resourceList.begin(); resource != this->resourceList.end(); resource++)
    625   {
    626     if ((*resource)->type == type && fileName == (*resource)->name)
    627     {
    628       bool match = false;
    629       switch (type)
    630       {
    631 #ifndef NO_MODEL
    632         case PRIM:
    633         case OBJ:
    634           if (param0 == MT_NULL)
    635           {
    636             if ((*resource)->param[0] == 1.0f)
    637               match = true;
    638           }
    639           else if ((*resource)->param[0] == param0.getFloat())
    640             match = true;
    641           break;
    642         case MD2:
    643           if (param0 == MT_NULL && ((*resource)->param[0] == "") && param1 == MT_NULL && ((*resource)->param[0] == 1.0f))
    644               match = true;
    645           else if ((*resource)->param[0] == ((MultiType)param0).getString() && (*resource)->param[1] == ((MultiType)param1).getFloat())
    646             match = true;
    647           break;
    648         case MD3:
    649           if (param0 == MT_NULL && ((*resource)->param[0] == "") && param1 == MT_NULL && ((*resource)->param[0] == 1.0f))
    650             match = true;
    651           else if ((*resource)->param[0] == ((MultiType)param0).getString() && (*resource)->param[1] == ((MultiType)param1).getFloat())
    652             match = true;
    653           break;
    654         case MD3_CONFIG:
    655           if (param0 == MT_NULL && ((*resource)->param[0] == ""))
    656             match = true;
    657           else if ((*resource)->param[0] == ((MultiType)param0).getString())
    658             match = true;
    659           break;
    660 
    661 #endif /* NO_MODEL */
    662 #ifndef NO_TEXT
    663         case TTF:
    664           if (param0 == MT_NULL)
    665           {
    666             if ((*resource)->param[0] == FONT_DEFAULT_RENDER_SIZE)
    667               match = true;
    668           }
    669           else if ((*resource)->param[0] == param0.getInt())
    670             match = true;
    671           break;
    672 #endif /* NO_TEXT */
    673 #ifndef NO_SHADERS
    674         case SHADER:
    675           if (param0 == MT_NULL)
    676           {
    677             if ((*resource)->param[0] == "")
    678               match = true;
    679           }
    680           else if ((*resource)->param[0] == ((MultiType)param0).getString())
    681             match = true;
    682           break;
    683 #endif /* NO_SHADERS */
    684 #ifndef NO_TEXTURES
    685         case IMAGE:
    686           if (param0 == MT_NULL)
    687           {
    688             if ((*resource)->param[0] == GL_TEXTURE_2D)
    689               match = true;
    690           }
    691           else if ((*resource)->param[0] ==  param0.getInt())
    692             match = true;
    693           break;
    694 #endif /* NO_TEXTURES */
    695         default:
    696           match = true;
    697           break;
    698       }
    699       if (match)
    700       {
    701         return (*resource);
    702       }
    703     }
    704   }
    705   return NULL;
    706 }
    707 
    708 /**
    709  * @brief Searches for a Resource by Pointer
    710  * @param pointer the Pointer to search for
    711  * @returns a Pointer to the Resource if found, NULL otherwise.
    712  */
    713 Resource* ResourceManager::locateResourceByPointer(const void* pointer) const
    714 {
    715   //  Resource* enumRes = resourceList->enumerate();
    716   std::vector<Resource*>::const_iterator resource;
    717   for (resource = this->resourceList.begin(); resource != this->resourceList.end(); resource++)
    718     if (pointer == (*resource)->pointer)
    719       return (*resource);
    720   return NULL;
    721 }
    722 
    723 std::string ResourceManager::toResourcableString(unsigned int i)
    724 {
    725 /*  int len = strlen(ResourceManager::ResourceTypeToChar(this->resourceList[i]->type));
    726   len += this->resourceList[i]->name.size();
    727   if (this->resourceList[i]->param[0].getCString()) len += strlen(this->resourceList[i]->param[0].getCString()) +1;
    728   if (this->resourceList[i]->param[1].getCString()) len += strlen(this->resourceList[i]->param[1].getCString()) +1;
    729   if (this->resourceList[i]->param[2].getCString()) len += strlen(this->resourceList[i]->param[2].getCString()) +1;
    730   len += 10;
    731   std::string tmp = new char[len];
    732   tmp[0] = '\0';
    733   strcat(tmp, ResourceManager::ResourceTypeToChar(this->resourceList[i]->type));
    734   strcat(tmp,",");
    735   strcat (tmp, this->resourceList[i]->name);
    736   if (this->resourceList[i]->param[0].getCString() && this->resourceList[i]->param[0].getCString() != '\0')
    737   {
    738     strcat(tmp,",");
    739     strcat( tmp, this->resourceList[i]->param[0].getCString());
    740   }
    741   if (this->resourceList[i]->param[1].getCString() && this->resourceList[i]->param[1].getCString() != '\0')
    742   {
    743     strcat(tmp,",");
    744     strcat( tmp, this->resourceList[i]->param[1].getCString());
    745   }
    746   if (this->resourceList[i]->param[2].getCString() && this->resourceList[i]->param[2].getCString() != '\0')
    747   {
    748     strcat(tmp,",");
    749     strcat( tmp, this->resourceList[i]->param[2].getCString());
    750   }
    751   return tmp;*/
    752   return "";
    753 }
    754 
    755 /**
    756  * @brief caches a Resource from a ResourceableString created with the toResourcableString-function
    757  * @param resourceableString the String to cache the resource from.
    758  */
    759 bool ResourceManager::fromResourceableString(const std::string& resourceableString)
    760 {
    761 /*  SubString splits(resourceableString, ',');
    762   splits.debug();
    763   if (splits.getCount() == 2)
    764     this->cache(splits[1], ResourceManager::stringToResourceType(splits[0]),
    765                 RP_LEVEL);
    766   else if (splits.getCount() == 3)
    767     return this->cache(splits[1], ResourceManager::stringToResourceType(splits[0]),
    768                 RP_LEVEL, splits[2]);
    769   else if (splits.getCount() == 4)
    770     return this->cache(splits[1], ResourceManager::stringToResourceType(splits[0]),
    771                 RP_LEVEL, splits[2], splits[3]);
    772   else if (splits.getCount() == 5)
    773     return this->cache(splits[1], ResourceManager::stringToResourceType(splits[0]),
    774                 RP_LEVEL, splits[2], splits[3], splits[4]);*/
    775   return false;
    776 }
    777 
    778 
    779 /**
    780  * @param fileName the Name of the File to check
    781  * @returns The full name of the file, including the DataDir, and NULL if the file does not exist
    782  * !!IMPORTANT: this has to be deleted from the outside!!
    783 */
    784 std::string ResourceManager::getFullName(const std::string& fileName)
    785 {
    786   if (fileName.empty() || ResourceManager::getInstance()->getDataDir().empty())
    787     return "";
    788 
    789   std::string retName = ResourceManager::getInstance()->getDataDir() +fileName;
    790   if (File(retName).isFile() || File(retName).isDirectory())
    791     return retName;
    792   else
    793     return "";
    794 }
    795 
    796 
    797 /**
    798  * @brief checks wether a file is in the DataDir.
    799  * @param fileName the File to check if it is in the Data-Dir structure.
    800  * @returns true if the file exists, false otherwise
    801  */
    802 bool ResourceManager::isInDataDir(const std::string& fileName)
    803 {
    804   if (fileName.empty() || ResourceManager::getInstance()->getDataDir().empty())
    805     return false;
    806 
    807   bool retVal = false;
    808   std::string checkFile = ResourceManager::getInstance()->getDataDir() + fileName;
    809 
    810   if (File(checkFile).exists())
    811     retVal = true;
    812   else
    813     retVal = false;
    814   return retVal;
    815 }
    816 
    817 
    818 /**
    819  * @brief outputs debug information about the ResourceManager
    820  */
    821 void ResourceManager::debug() const
     60void NewResourceManager::debug() const
    82261{
    82362  PRINT(0)("=RM===================================\n");
    82463  PRINT(0)("= RESOURCE-MANAGER DEBUG INFORMATION =\n");
    82564  PRINT(0)("======================================\n");
    826   // if it is not initialized
    827   PRINT(0)(" Reference is: %p\n", ResourceManager::singletonRef);
    828   PRINT(0)(" Data-Directory is: %s\n", this->dataDir.c_str());
    829   PRINT(0)(" List of Image-Directories: ");
    830   std::vector<std::string>::const_iterator imageDir;
    831   for (imageDir = this->imageDirs.begin(); imageDir != this->imageDirs.end(); imageDir++)
    832     PRINT(0)("%s ", (*imageDir).c_str());
    833   PRINT(0)("\n");
    834 
    835   PRINT(0)("List of all stored Resources:\n");
    836   std::vector<Resource*>::const_iterator resource;
    837   for (resource = this->resourceList.begin(); resource != this->resourceList.end(); resource++)
    838 
    839   {
    840     PRINT(0)("-----------------------------------------\n");
    841     PRINT(0)("(%p) Name: %s; References: %d; Type: %s ", (*resource)->pointer, (*resource)->name.c_str(), (*resource)->count, ResourceManager::ResourceTypeToChar((*resource)->type));
    842 
    843     PRINT(0)("gets deleted at ");
    844     switch((*resource)->prio)
    845     {
    846       default:
    847       case RP_NO:
    848         PRINT(0)("first posibility (0)\n");
    849         break;
    850       case RP_LEVEL:
    851         PRINT(0)("the end of the Level (1)\n");
    852         break;
    853       case RP_CAMPAIGN:
    854         PRINT(0)("the end of the campaign (2)\n");
    855         break;
    856       case RP_GAME:
    857         PRINT(0)("when leaving the game (3)\n");
    858         break;
    859     }
    860   }
    861 
    862 
    86365
    86466  PRINT(0)("==================================RM==\n");
    86567}
    866 
    867 
    868 /**
    869  * @brief converts a ResourceType into the corresponding String
    870  * @param type the ResourceType to translate
    871  * @returns the converted String.
    872  */
    873 const char* ResourceManager::ResourceTypeToChar(ResourceType type)
    874 {
    875   return ResourceManager::resourceNames[type];
    876 }
    877 
    878 /**
    879  * @brief converts a String into a ResourceType (good for loading)
    880  * @param resourceType the name of the Type
    881  * @returns the Number of the Type, or 0 (defautl) if not found.
    882  */
    883 ResourceType ResourceManager::stringToResourceType(const std::string& resourceType)
    884 {
    885   for (unsigned int i = 0; i < RESOURCE_TYPE_SIZE; i++)
    886     if (resourceType == ResourceManager::resourceNames[i])
    887       return (ResourceType)i;
    888   return (ResourceType)0;
    889 }
    890 
    891 /**
    892  * The Names of the ResourceTypes
    893  */
    894 const char* ResourceManager::resourceNames[] =
    895   {
    896 #ifndef NO_MODEL
    897     "ObjectModel",
    898     "PrimitiveModel",
    899     "MD2-Data",
    900     "MD3-Data",
    901     "MD3-Config"
    902 #endif
    903 #ifndef NO_TEXT
    904     "Font",
    905 #endif
    906 #ifndef NO_AUDIO
    907     "Wav",
    908     "mp3",
    909     "ogg",
    910 #endif
    911 #ifndef NO_TEXTURES
    912     "Texture",
    913 #endif
    914 #ifndef NO_SHADERS
    915     "Shader",
    916 #endif
    917 
    918   };
  • branches/new_class_id/src/lib/util/loading/new_resource_manager.h

    r9789 r9790  
    11/*!
    2  * @file resource_manager.h
    3   *  The Resource Manager checks if a file/resource is loaded.
     2 * @file new_resource_manager.h
     3 */
    44
    5     If a file/resource was already loaded the resourceManager will
    6     return a void pointer to the desired resource.
    7     Otherwise it will instruct the coresponding resource-loader to load,
    8     and receive a pointer to it.
     5#ifndef _NEW_RESOURCE_MANAGER_H
     6#define _NEW_RESOURCE_MANAGER_H
    97
    10     it is possible to compile the resource Manager without some modules by
    11     just adding the compile flag -D....
    12     (NO_MODEL)
    13     (NO_AUDIO)
    14     (NO_TEXT)
    15     (NO_TEXTURES)
    16     (NO_SHADERS)
    17 */
     8#include "resource.h"
     9#include "filesys/file.h"
     10#include "filesys/directory.h"
    1811
    19 #ifndef _RESOURCE_MANAGER_H
    20 #define _RESOURCE_MANAGER_H
    21 
    22 #include "base_object.h"
    23 #include "filesys/file.h"
    24 
    25 #include "multi_type.h"
    26 #include <vector>
    27 
    28 //! An eumerator for different fileTypes the resourceManager supports
    29 typedef enum ResourceType
     12class NewResourceManager : public BaseObject
    3013{
    31 #ifndef NO_MODEL
    32   OBJ,                  //!< loading .obj file
    33   PRIM,                 //!< loading primitive model
    34   MD2,                  //!< loading md2-file
    35   MD3,                  //!< loading md3-file
    36   MD3_CONFIG,           //!< the md3 config file
    37 #endif /* NO_MODEL */
    38 #ifndef NO_TEXT
    39   TTF,                  //!< loading a TrueTypeFont
    40 #endif /* NO_TEXT */
    41 #ifndef NO_AUDIO
    42   WAV,                  //!< loading wav
    43   MP3,                  //!< loading mp3
    44   OGG,                  //!< loading ogg
    45 #endif /* NO_AUDIO */
    46 #ifndef NO_TEXTURES
    47   IMAGE,                //!< loading an image
    48 #endif /* NO_TEXTURES */
    49 #ifndef NO_SHADERS
    50   SHADER,               //!< openGL-shader program
    51 #endif /* NO_SHADERS */
    52   RESOURCE_TYPE_SIZE
    53 };
    54 
    55 //! An enumerator for different UNLOAD-types.
    56 /**
    57    RP_NO:        will be unloaded on request
    58    RP_LEVEL:     will be unloaded at the end of a Level
    59    RP_CAMPAIGN:  will be unloaded at the end of a Campaign
    60    RP_GAME:      will be unloaded at the end of the whole Game (when closing orxonox)
    61 */
    62 typedef enum ResourcePriority
    63 {
    64   RP_NO        =   0,
    65   RP_LEVEL     =   1,
    66   RP_CAMPAIGN  =   2,
    67   RP_GAME      =   4
    68 };
    69 
    70 //! A Struct that keeps track about a resource its name its Type, and so on
    71 struct Resource
    72 {
    73   BaseObject*       pointer;           //!< Pointer to the Resource.
    74   unsigned int      count;             //!< How many times this Resource has been loaded.
    75 
    76   std::string       name;              //!< Name of the Resource.
    77   ResourceType      type;              //!< ResourceType of this Resource.
    78   ResourcePriority  prio;              //!< The Priority of this resource. (This will only be increased)
    79 
    80   MultiType         param[3];          //!< The Parameters given to this Resource.
    81 };
    82 
    83 
    84 //! The ResourceManager is a class, that decides if a file/resource should be loaded
    85 /**
    86  * If a file/resource was already loaded the resourceManager will
    87  * return a pointer to the desired resource.
    88  * Otherwise it will instruct the corresponding resource-loader to load,
    89  * and receive the pointer to it.
    90  *
    91  * It does it by looking, if a desired file has already been loaded.
    92  * There is also the possibility to check for some variables
    93  */
    94 class ResourceManager : public BaseObject
    95 {
    96   ObjectListDeclaration(ResourceManager);
     14  ObjectListDeclaration(NewResourceManager);
    9715public:
    98   virtual ~ResourceManager();
     16  virtual ~NewResourceManager();
    9917  /** @returns a Pointer to the only object of this Class */
    100   inline static ResourceManager* getInstance() { if (!singletonRef) singletonRef = new ResourceManager();  return singletonRef; };
    101 
    102   bool setDataDir(const std::string& dataDir);
    103   /** @returns the Name of the data directory */
    104 inline const std::string& getDataDir() const { return this->dataDir; };
    105 
     18  inline static NewResourceManager* getInstance() { if (!singletonRef) singletonRef = new NewResourceManager();  return singletonRef; };
    10619
    10720  bool tryDataDir(const std::string& dataDir);
    10821  bool verifyDataDir(const std::string& fileInside);
    109   bool addImageDir(const std::string& imageDir);
    11022
    111   bool cache(const std::string& fileName, ResourceType type, ResourcePriority prio = RP_NO,
    112              const MultiType& param0 = MultiType(), const MultiType& param1 = MultiType(), const MultiType& param2 = MultiType());
    113   BaseObject* copy(BaseObject* resourcePointer);
    114 
    115   BaseObject* load(const std::string& fileName, ResourcePriority prio = RP_NO,
    116                    const MultiType& param0 = MultiType(), const MultiType& param1 = MultiType(), const MultiType& param2 = MultiType());
    117   BaseObject* load(const std::string& fileName, ResourceType type, ResourcePriority prio = RP_NO,
    118                    const MultiType& param0 = MultiType(), const MultiType& param1 = MultiType(), const MultiType& param2 = MultiType());
    119   bool unload(BaseObject* pointer, ResourcePriority prio = RP_NO);
    120   bool unload(Resource* resource, ResourcePriority = RP_NO);
    121   bool unloadAllByPriority(ResourcePriority prio);
    122 
    123   Resource* locateResourceByInfo(const std::string& fileName, ResourceType type,
    124                                  const MultiType& param0 = MultiType(), const MultiType& param1 = MultiType(), const MultiType& param2 = MultiType()) const;
    125   Resource* locateResourceByPointer(const void* pointer) const;
    126 
    127   std::string toResourcableString(unsigned int i);
    128   bool fromResourceableString(const std::string& resourceableString);
    129   /** @returns the Count of Resources the ResourceManager handles */
    130   unsigned int resourceCount() const { return this->resourceList.size(); }
     23  bool unloadAllByPriority();
    13124
    13225  void debug() const;
    133 
    13426
    13527  // utility functions for handling files in and around the data-directory
     
    13729  static bool isInDataDir(const std::string& fileName);
    13830
    139   static const char* ResourceTypeToChar(ResourceType type);
    140   static ResourceType stringToResourceType(const std::string& resourceType);
     31private:
     32  NewResourceManager();
    14133
    14234private:
    143   ResourceManager();
    144   Resource* loadResource(const std::string& fileName, ResourceType type, ResourcePriority prio,
    145                          const MultiType& param0, const MultiType& param1, const MultiType& param2);
     35  static NewResourceManager*    singletonRef;       //!< singleton Reference
    14636
    147 private:
    148   static ResourceManager*    singletonRef;       //!< singleton Reference
    149 
    150   std::string                dataDir;            //!< The Data Directory, where all relevant Data is stored.
    151   std::vector<std::string>   imageDirs;          //!< A list of directories in which images are stored.
    152 
    153   std::vector<Resource*>     resourceList;       //!< The List of Resources, that has already been loaded.
    154 
    155   static const char*         resourceNames[RESOURCE_TYPE_SIZE];
    15637};
    15738
  • branches/new_class_id/src/lib/util/loading/resource.cc

    r9789 r9790  
    1414*/
    1515
    16 #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_LOADING
     16#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_LOAD
    1717
    1818#include "resource.h"
    1919#include "filesys/file.h"
     20#include "debug.h"
    2021
    2122ObjectListDefinition(NewResource);
    22 
    23 
    2423std::vector<NewResource::Type*>    NewResource::_resourceTypes;
    2524
     
    3635{
    3736  this->registerObject(this, NewResource::_objectList);
    38 
    39   if(this->_type->id() == -1)
    40   {
    41     NewResource::_resourceTypes.push_back(this->_type);
    42     this->_type->setID(NewResource::_resourceTypes.size()-1);
    43   }
    4437}
    4538
     
    5346
    5447
    55 std::string NewResource::locateFile(const std::string& fileName)
     48std::string NewResource::locateFile(const std::string& fileName) const
    5649{
    5750  if (File(fileName).exists())
    5851    return fileName;
    59   else if ((NewResource::_mainGlobalPath+File(fileName)) . exists() )
     52  else if ((NewResource::_mainGlobalPath + File(fileName)).exists() )
    6053    return (NewResource::_mainGlobalPath + File(fileName)).name();
    6154
     55  printf("LOCATED %s\n", locateFileInSubDir(Directory("/home/bensch/svn/orxonox/data/"), fileName).c_str());
     56
    6257  return std::string("/home/bensch/svn/orxonox/data/") + fileName;
    63 
    64 }
     58}
     59
     60/**
     61 * @brief tests in all the SubDirectories defined in Resource under Directory if the fileName exists.
     62 * @param directory the directory to in what to search for all subdirectories for.
     63 * @param fileName the Name of the File to query for
     64 * @return true on success.
     65 */
     66std::string NewResource::locateFileInSubDir(const Directory& directory, const std::string& fileName) const
     67{
     68  std::vector<Directory>::const_iterator it;
     69  for (it = this->_type->resourceSubPaths().begin(); it != this->_type->resourceSubPaths().end(); ++it)
     70  {
     71    Directory dir = directory + (*it);
     72    File file = dir + File(fileName);
     73    printf("Testing %s (from %s in directory %s)\n", file.name().c_str(), fileName.c_str(), dir.name().c_str());
     74    if ((dir+ File(fileName)).exists())
     75      return (dir+File(fileName)).name();
     76  }
     77  return "";
     78}
     79
    6580
    6681
     
    99114
    100115
    101 
    102 
    103 
    104 
    105 
    106 
    107 
    108 std::vector<std::string>  NewResource::KeepLevel::_keepLevelNames;
     116void NewResource::registerType(NewResource::Type* type)
     117{
     118  NewResource::debug();
     119  if(type->id() == -1)
     120  {
     121    NewResource::_resourceTypes.push_back(type);
     122    type->setID(NewResource::_resourceTypes.size()-1);
     123  }
     124  NewResource::debug();
     125}
     126
     127bool NewResource::addResourcePath(const std::string& resourceName, const std::string& pathName)
     128{
     129  std::vector<NewResource::Type*>::iterator it;
     130  for (it = NewResource::_resourceTypes.begin(); it != NewResource::_resourceTypes.end(); ++it)
     131    if (*(*it) == resourceName)
     132      return (*it)->addResourcePath(pathName);
     133  PRINTF(2)("ResourcePath %s could not be added to the ResourceType %s\n", pathName.c_str(), resourceName.c_str());
     134  return false;
     135}
     136
     137bool NewResource::addResourceSubPath(const std::string& resourceName, const std::string& pathName)
     138{
     139  std::vector<NewResource::Type*>::iterator it;
     140  for (it = NewResource::_resourceTypes.begin(); it != NewResource::_resourceTypes.end(); ++it)
     141    if (*(*it) == resourceName)
     142      return (*it)->addResourceSubPath(pathName);
     143  PRINTF(2)("ResourceSubPath %s could not be added to the ResourceType %s\n", pathName.c_str(), resourceName.c_str());
     144  return false;
     145}
     146
     147
     148
     149void NewResource::debug()
     150{
     151  PRINT(0)("==================================\n");
     152  PRINT(0)("DEBUG output for all Resources\n");
     153  PRINT(0)("==================================\n");
     154
     155  PRINT(0)("Listing %d Types: \n", NewResource::_resourceTypes.size());
     156  std::vector<NewResource::Type*>::iterator it;
     157  for (it = NewResource::_resourceTypes.begin(); it != NewResource::_resourceTypes.end(); ++it)
     158    PRINT(0)("ResourceType '%s'\n", (*it)->storedClassID().name().c_str());
     159
     160  PRINT(0)("==================================\n");
     161
     162}
     163
     164
     165
     166
     167
     168std::vector<std::string> NewResource::KeepLevel::_keepLevelNames;
    109169void NewResource::KeepLevel::defineKeepLevelName(unsigned int level, const std::string& name)
    110170{
     
    115175
    116176
     177NewResource::Type::Type(const ClassID& classID)
     178    : _id(-1), _classID(classID)
     179{
     180  NewResource::registerType(this);
     181}
    117182
    118183void NewResource::Type::addResource(NewResource::StorePointer* resource)
     
    121186
    122187}
     188
     189bool NewResource::Type::addResourcePath(const std::string& path)
     190{
     191  std::vector<Directory>::const_iterator it;
     192  for (it = this->_resourcePaths.begin(); it != this->_resourcePaths.end(); ++it)
     193    if ((*it) == path)
     194      return false;
     195  this->_resourcePaths.push_back(path);
     196  return true;
     197
     198}
     199
     200bool NewResource::Type::addResourceSubPath(const std::string& subPath)
     201{
     202  std::vector<Directory>::const_iterator it;
     203  for (it = this->_resourceSubPaths.begin(); it != this->_resourceSubPaths.end(); ++it)
     204    if ((*it) == subPath)
     205      return false;
     206  this->_resourceSubPaths.push_back(subPath);
     207  return true;
     208}
     209
    123210
    124211
  • branches/new_class_id/src/lib/util/loading/resource.h

    r9789 r9790  
    5353  {
    5454  public:
    55     Type(const ClassID& classID) : _id(-1), _classID(classID) { };
     55    Type(const ClassID& classID);
     56    bool operator==(const ClassID& classID) const { return this->_classID == classID; };
     57    bool operator==(const std::string& resourceName) const { return this->_classID.name() == resourceName; };
    5658
    5759    void addExtension(const std::string& extension);
    5860
    59     void addResourcePath(const std::string& path);
    60     void addResourceSubPath(const std::string& subPath);
     61    bool addResourcePath(const std::string& path);
     62    bool addResourceSubPath(const std::string& subPath);
    6163
    6264    /// Retrieve Functions
    6365    const ClassID& storedClassID() const { return _classID; };
    6466    int id() const { return _id; };
    65     const std::vector<std::string>& resourcePaths() const { return _resourcePaths; };
    66     const std::vector<std::string>& resourceSubPaths() const { return _resourceSubPaths; };
     67    const std::vector<Directory>& resourcePaths() const { return _resourcePaths; };
     68    const std::vector<Directory>& resourceSubPaths() const { return _resourceSubPaths; };
    6769    const std::vector<NewResource::StorePointer*>& storedResources() const { return _storedResources; };
    6870
     
    7375    int                             _id;
    7476    const ClassID&                  _classID;
    75     std::vector<std::string>        _resourcePaths;
    76     std::vector<std::string>        _resourceSubPaths;
     77    std::vector<Directory>          _resourcePaths;
     78    std::vector<Directory>          _resourceSubPaths;
    7779    std::vector<std::string>        _fileExtensions;
    7880
     
    8890  virtual bool unload() { return false; };
    8991
    90   std::string locateFile(const std::string& fileName);
     92  std::string locateFile(const std::string& fileName) const;
    9193
    9294
     
    9597  static void addGlobalPath(const Directory& directory);
    9698
     99  static bool addResourcePath(const std::string& resourceName, const std::string& pathName);
     100  static bool addResourceSubPath(const std::string& resourceName, const std::string& pathName);
    97101
     102  static void registerType(NewResource::Type* type);
     103
     104  static void debug();
    98105protected:
    99106  NewResource::StorePointer* acquireResource(const std::string& loadString);
     
    101108
    102109private:
     110  std::string locateFileInSubDir(const Directory& directory, const std::string& fileName) const;
     111
     112private:
    103113  NewResource::StorePointer*       _pointer;                         //!< Virtual Pointer to the ResourceData.
    104   NewResource::Type*          _type;                            //!< Type of the NewResource.
     114  NewResource::Type*               _type;                            //!< Type of the NewResource.
    105115
    106116
    107   static std::vector<NewResource::Type*>    _resourceTypes;
     117  static std::vector<NewResource::Type*>  _resourceTypes;
    108118
    109119  //! GLOBALS
  • branches/new_class_id/src/orxonox.cc

    r9789 r9790  
    367367  }
    368368
    369 
     369  NewResource::debug();
    370370  //! @todo this is a hack and should be loadable
    371   std::string imageDir = ResourceManager::getInstance()->getFullName("maps");
    372   ResourceManager::getInstance()->addImageDir(imageDir);
    373   imageDir = ResourceManager::getInstance()->getFullName("pictures");
    374   ResourceManager::getInstance()->addImageDir(imageDir);
     371  NewResource::addResourceSubPath("Texture", "maps");
     372  NewResource::addResourceSubPath("Texture", "pictures");
    375373
    376374  //  DynamicLoader::loadDyLib("libtest.so");
Note: See TracChangeset for help on using the changeset viewer.