Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6185 in orxonox.OLD for branches/christmas_branche/src/util/loading


Ignore:
Timestamp:
Dec 20, 2005, 2:04:28 PM (19 years ago)
Author:
bensch
Message:

christmas: resourceManager uses std::list

Location:
branches/christmas_branche/src/util/loading
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/christmas_branche/src/util/loading/resource_manager.cc

    r6169 r6185  
    1919
    2020#include "debug.h"
     21
     22#include <algorithm>
    2123
    2224// different resource Types
     
    6163  strcpy(this->dataDir, "./");
    6264  this->tryDataDir("./data");
    63   this->imageDirs = new tList<char>;
    64   this->resourceList = new tList<Resource>;
    6565}
    6666
     
    7676  this->unloadAllByPriority(RP_GAME);
    7777
    78   if (this->resourceList->getSize() > 0)
    79     PRINTF(1)("Not removed all Resources, since there are still %d resources registered\n", this->resourceList->getSize());
    80 
    81   delete this->resourceList;
     78  if (!this->resourceList.empty())
     79    PRINTF(1)("Not removed all Resources, since there are still %d resources registered\n", this->resourceList.size());
     80
    8281  // deleting the Directorie Lists
    83   tIterator<char>* tmpIt = imageDirs->getIterator();
    84   char* tmpDir = tmpIt->firstElement();
    85   while(tmpDir)
    86     {
    87       delete[] tmpDir;
    88       tmpDir = tmpIt->nextElement();
    89     }
    90   delete tmpIt;
    91   delete this->imageDirs;
     82  while (!this->imageDirs.empty())
     83    {
     84      delete[] this->imageDirs.front();
     85      this->imageDirs.pop_front();
     86    }
    9287
    9388  delete[] this->dataDir;
     
    211206    {
    212207      // check if the Directory has been added before
    213       tIterator<char>* tmpImageDirs = imageDirs->getIterator();
    214       char* tmpDir = tmpImageDirs->firstElement();
    215       while(tmpDir)
    216         {
    217           if (!strcmp(tmpDir, newDir))
    218             {
    219               PRINTF(3)("Path %s already loaded\n", newDir);
    220               delete[] newDir;
    221               delete tmpImageDirs;
    222               return true;
    223             }
    224           tmpDir = tmpImageDirs->nextElement();
    225         }
    226       delete tmpImageDirs;
    227 
     208      std::list<char*>::const_iterator imageDir;
     209      for (imageDir = this->imageDirs.begin(); imageDir != this->imageDirs.end(); imageDir++)
     210      {
     211         if (!strcmp(*imageDir, newDir))
     212         {
     213           PRINTF(3)("Path %s already loaded\n", newDir);
     214           delete[] newDir;
     215           return true;
     216         }
     217      }
    228218      // adding the directory to the List
    229       this->imageDirs->add(newDir);
     219      this->imageDirs.push_back(newDir);
    230220      return true;
    231221    }
     
    427417          else
    428418            {
    429               char* tmpDir;
    430               tIterator<char>* iterator = imageDirs->getIterator();
    431               tmpDir = iterator->firstElement();
    432               while(tmpDir)
     419              std::list<char*>::iterator imageDir;
     420              for (imageDir = this->imageDirs.begin(); imageDir != this->imageDirs.end(); imageDir++)
    433421                {
    434                   char* imgName = new char[strlen(tmpDir)+strlen(fileName)+1];
    435                   sprintf(imgName, "%s%s", tmpDir, fileName);
     422                  char* imgName = new char[strlen(*imageDir)+strlen(fileName)+1];
     423                  sprintf(imgName, "%s%s", *imageDir, fileName);
    436424                  if(isFile(imgName))
    437425                    {
     
    442430                    }
    443431                  delete[] imgName;
    444                   tmpDir = iterator->nextElement();
    445432                }
    446               delete iterator;
    447433            }
    448434          if(!tmpResource)
     
    479465        }
    480466      if (tmpResource->pointer != NULL)
    481         this->resourceList->add(tmpResource);
     467        this->resourceList.push_back(tmpResource);
    482468      delete[] fullName;
    483469    }
     
    574560          PRINTF(4)("Resource %s safely removed.\n", resource->name);
    575561          delete[] resource->name;
    576           this->resourceList->remove(resource);
     562          std::list<Resource*>::iterator resourceIT = std::find(this->resourceList.begin(), this->resourceList.end(), resource);
     563          this->resourceList.erase(resourceIT);
    577564          delete resource;
    578565        }
     
    592579bool ResourceManager::unloadAllByPriority(ResourcePriority prio)
    593580{
    594   tIterator<Resource>* iterator = resourceList->getIterator();
    595   Resource* enumRes = iterator->lastElement();
    596   while (enumRes)
    597     {
    598       if (enumRes->prio <= prio)
    599         if (enumRes->count == 0)
    600           unload(enumRes, prio);
     581  std::list<Resource*>::iterator resource, pre;
     582  pre = this->resourceList.begin();
     583  while (pre != resourceList.end())
     584  {
     585    resource = pre;
     586    pre++;
     587      if ((*resource)->prio <= prio)
     588        if ((*resource)->count == 0)
     589          unload((*resource), prio);
    601590        else
    602591          PRINTF(2)("unable to unload %s because there are still %d references to it\n",
    603                    enumRes->name, enumRes->count);
    604       //enumRes = resourceList->nextElement();
    605       enumRes = iterator->prevElement();
    606     }
    607   delete iterator;
     592                   (*resource)->name, (*resource)->count);
     593    }
    608594}
    609595
     
    621607                                                void* param1, void* param2, void* param3) const
    622608{
    623   //  Resource* enumRes = resourceList->enumerate();
    624   tIterator<Resource>* iterator = resourceList->getIterator();
    625   Resource* enumRes = iterator->firstElement();
    626   while (enumRes)
    627     {
    628       if (enumRes->type == type && !strcmp(fileName, enumRes->name))
     609  std::list<Resource*>::const_iterator resource;
     610  for (resource = this->resourceList.begin(); resource != this->resourceList.end(); resource++)
     611  {
     612    if ((*resource)->type == type && !strcmp(fileName, (*resource)->name))
    629613        {
    630614          bool match = false;
     
    637621              if (!param1)
    638622                {
    639                   if (enumRes->modelSize == 1.0)
     623                  if ((*resource)->modelSize == 1.0)
    640624                    match = true;
    641625                }
    642               else if (enumRes->modelSize == *(float*)param1)
     626              else if ((*resource)->modelSize == *(float*)param1)
    643627                match = true;
    644628              break;
     
    646630              if (!param1)
    647631                {
    648                   if (enumRes->secFileName == NULL)
     632                  if ((*resource)->secFileName == NULL)
    649633                    match = true;
    650634                }
    651               else if (!strcmp(enumRes->secFileName, (const char*)param1))
     635              else if (!strcmp((*resource)->secFileName, (const char*)param1))
    652636                match = true;
    653637              break;
     
    657641              if (param1 == NULL)
    658642                {
    659                   if (enumRes->ttfSize == FONT_DEFAULT_RENDER_SIZE)
     643                  if ((*resource)->ttfSize == FONT_DEFAULT_RENDER_SIZE)
    660644                    match = true;
    661645                }
    662               else if (enumRes->ttfSize == *(unsigned int*)param1)
     646              else if ((*resource)->ttfSize == *(unsigned int*)param1)
    663647                match = true;
    664648              break;
     
    668652                if (!param1)
    669653                {
    670                   if (enumRes->secFileName == NULL)
     654                  if ((*resource)->secFileName == NULL)
    671655                    match = true;
    672656                }
    673                 else if (!strcmp(enumRes->secFileName, (const char*)param1))
     657                else if (!strcmp((*resource)->secFileName, (const char*)param1))
    674658                  match = true;
    675659#endif /* NO_SHADERS */
     
    680664          if (match)
    681665            {
    682               delete iterator;
    683               return enumRes;
     666              return (*resource);
    684667            }
    685668        }
    686       enumRes = iterator->nextElement();
    687     }
    688   delete iterator;
     669    }
    689670  return NULL;
    690671}
     
    698679{
    699680  //  Resource* enumRes = resourceList->enumerate();
    700   tIterator<Resource>* iterator = resourceList->getIterator();
    701   Resource* enumRes = iterator->firstElement();
    702   while (enumRes)
    703     {
    704       if (pointer == enumRes->pointer)
    705         {
    706           delete iterator;
    707           return enumRes;
    708         }
    709       enumRes = iterator->nextElement();
    710     }
    711   delete iterator;
     681  std::list<Resource*>::const_iterator resource;
     682  for (resource = this->resourceList.begin(); resource != this->resourceList.end(); resource++)
     683    if (pointer == (*resource)->pointer)
     684        return (*resource);
    712685  return NULL;
    713686}
     
    922895  PRINT(0)(" Data-Directory is: %s\n", this->dataDir);
    923896  PRINT(0)(" List of Image-Directories: ");
    924   tIterator<char>* tmpIt = imageDirs->getIterator();
    925   char* tmpDir = tmpIt->firstElement();
    926   while(tmpDir)
    927     {
    928       PRINT(0)("%s ",tmpDir);
    929       tmpDir = tmpIt->nextElement();
    930     }
    931   delete tmpIt;
     897  std::list<char*>::const_iterator imageDir;
     898  for (imageDir = this->imageDirs.begin(); imageDir != this->imageDirs.end(); imageDir++)
     899      PRINT(0)("%s ", (*imageDir));
    932900  PRINT(0)("\n");
    933901
    934902  PRINT(0)("List of all stored Resources:\n");
    935   tIterator<Resource>* iterator = resourceList->getIterator();
    936   Resource* enumRes = iterator->firstElement();
    937   while (enumRes)
     903  std::list<Resource*>::const_iterator resource;
     904  for (resource = this->resourceList.begin(); resource != this->resourceList.end(); resource++)
     905
    938906    {
    939907      PRINT(0)("-----------------------------------------\n");
    940       PRINT(0)("Name: %s; References: %d; Type: %s ", enumRes->name, enumRes->count, ResourceManager::ResourceTypeToChar(enumRes->type));
     908      PRINT(0)("Name: %s; References: %d; Type: %s ", (*resource)->name, (*resource)->count, ResourceManager::ResourceTypeToChar((*resource)->type));
    941909
    942910      PRINT(0)("gets deleted at ");
    943       switch(enumRes->prio)
     911      switch((*resource)->prio)
    944912        {
    945913        default:
     
    957925          break;
    958926        }
    959       enumRes = iterator->nextElement();
    960     }
    961   delete iterator;
     927    }
    962928
    963929
  • branches/christmas_branche/src/util/loading/resource_manager.h

    r5994 r6185  
    2222
    2323#include "stdlibincl.h"
    24 
    25 // FORWARD DECLARATION
    26 template<class T> class tList;
     24#include <list>
    2725
    2826//! An eumerator for different fileTypes the resourceManager supports
     
    144142
    145143  char*                    dataDir;            //!< The Data Directory, where all relevant Data is stored.
    146   tList<Resource>*         resourceList;       //!< The List of Resources, that has already been loaded.
    147   tList<char>*             imageDirs;          //!< A list of directories in which images are stored.
     144  std::list<Resource*>     resourceList;       //!< The List of Resources, that has already been loaded.
     145  std::list<char*>         imageDirs;          //!< A list of directories in which images are stored.
    148146
    149147};
Note: See TracChangeset for help on using the changeset viewer.