Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 3672 in orxonox.OLD


Ignore:
Timestamp:
Mar 30, 2005, 3:02:58 PM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: ResourceManager not totally static anymore, list-iterators, and so on

Location:
orxonox/trunk/src
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • orxonox/trunk/src/defs/debug.h

    r3668 r3672  
    5858// DEFINE MODULES \\
    5959#define DEBUG_MODULE_ORXONOX            0
    60 #define DEBUG_MODULE_WORLD              3
     60#define DEBUG_MODULE_WORLD              2
    6161#define DEBUG_MODULE_PNODE              0
    6262#define DEBUG_MODULE_WORLD_ENTITY       0
    6363#define DEBUG_MODULE_COMMAND_NODE       0
    6464#define DEBUG_MODULE_GRAPHICS           0
    65 #define DEBUG_MODULE_LOAD               0
     65#define DEBUG_MODULE_LOAD               4
    6666
    6767#define DEBUG_MODULE_IMPORTER           0
  • orxonox/trunk/src/lib/graphics/importer/material.cc

    r3658 r3672  
    6262    delete []this->name;
    6363  if (this->diffuseTexture)
    64     ResourceManager::unload(this->diffuseTexture);
     64    ResourceManager::getInstance()->unload(this->diffuseTexture);
    6565  if (this->nextMat)
    6666    delete this->nextMat;
     
    339339  //! \todo check if RESOURCE MANAGER is availiable
    340340  //! \todo Textures from .mtl-file need special care.
    341   this->diffuseTextureSet = this->diffuseTexture = (Texture*)ResourceManager::load(dMap, IMAGE);
     341  this->diffuseTextureSet = this->diffuseTexture = (Texture*)ResourceManager::getInstance()->load(dMap, IMAGE);
    342342}
    343343
  • orxonox/trunk/src/lib/util/resource_manager.cc

    r3667 r3672  
    1111   ### File Specific:
    1212   main-programmer: Benjamin Grauer
    13    co-programmer: ...
     13   co-programmer: Patrick Boenzli
    1414*/
    1515
     
    3838{
    3939   this->setClassName ("ResourceManager");
    40    dataDir = NULL;
    41    imageDirs = new tList<char>();
    42    resourceList = new tList<Resource>();
     40   this->dataDir = "./";
     41   this->imageDirs = new tList<char>();
     42   this->resourceList = new tList<Resource>();
    4343}
    4444
     
    5555//! Singleton Reference to the ResourceManager
    5656ResourceManager* ResourceManager::singletonRef = NULL;
    57 //! The List of Resources, that has already been loaded.
    58 tList<Resource>* ResourceManager::resourceList = NULL;
    59 //! The Data Directory, where all relevant Data is stored.
    60 char* ResourceManager::dataDir = NULL;
    61 //! A list of directories in which images are stored.
    62 tList<char>* ResourceManager::imageDirs = NULL;
    6357
    6458/**
     
    6862{
    6963  // deleting the Resources-List
    70   unloadAllByPriority(RP_GAME);
    71   delete resourceList;
    72   resourceList = NULL;
     64  this->unloadAllByPriority(RP_GAME);
     65  delete this->resourceList;
    7366  // deleting the Directorie Lists
    74   char* tmpDir = imageDirs->enumerate();
     67  tIterator<char>* tmpIt = imageDirs->getIterator();
     68  char* tmpDir = tmpIt->nextElement();
    7569  while(tmpDir)
    7670    {
    7771      delete []tmpDir;
    78       tmpDir = imageDirs->nextElement();
    79     }
    80 
    81   delete imageDirs;
    82   imageDirs = NULL;
     72      tmpDir = tmpIt->nextElement();
     73    }
     74  delete tmpIt;
     75
     76  delete this->imageDirs;
     77
    8378  ResourceManager::singletonRef = NULL;
    8479}
     
    9287  if (isDir(dataDir))
    9388    {
    94       ResourceManager::dataDir = new char[strlen(dataDir)+1];
    95       strcpy(ResourceManager::dataDir, dataDir);
     89      this->dataDir = new char[strlen(dataDir)+1];
     90      strcpy(this->dataDir, dataDir);
    9691    }
    9792  else
     
    113108    {
    114109      // check if the Directory has been added before
    115       char* tmpDir = imageDirs->enumerate();
     110      tIterator<char>* tmpImageDirs = imageDirs->getIterator();
     111      char* tmpDir = tmpImageDirs->nextElement();
    116112      while(tmpDir)
    117113        {
     
    119115            {
    120116              PRINTF(4)("Path %s already loaded\n", imageDir);
     117              delete tmpImageDirs;
    121118              return true;
    122119            }
    123           tmpDir = imageDirs->nextElement();
    124         }
     120          tmpDir = tmpImageDirs->nextElement();
     121        }
     122      delete tmpImageDirs;
     123
    125124      // adding the directory to the List
    126125      tmpDir  = new char[strlen(imageDir)+1];
    127126      strcpy(tmpDir, imageDir);
    128       imageDirs->add(tmpDir);
     127      this->imageDirs->add(tmpDir);
    129128      return true;
    130129    }
     
    162161    tmpType = IMAGE;
    163162
    164   return ResourceManager::load(fileName, tmpType, prio);
     163  return this->load(fileName, tmpType, prio);
    165164}
    166165
     
    175174{
    176175  // searching if the resource was loaded before.
    177   Resource* tmpResource = ResourceManager::locateResourceByName(fileName);
     176  Resource* tmpResource = this->locateResourceByName(fileName);
    178177  if (!tmpResource) // if the resource was not loaded before.
    179178    {
     
    189188      // creating the full name. (directoryName + FileName)
    190189      char* fullName = new char[strlen(dataDir)+strlen(fileName)+1];
    191       sprintf(fullName, "%s%s", dataDir, fileName);
     190      sprintf(fullName, "%s%s", this->dataDir, fileName);
    192191     
    193192      // Checking for the type of resource \see ResourceType
     
    251250          tmpResource->pointer = NULL;
    252251        }
    253       resourceList->add(tmpResource);
     252      this->resourceList->add(tmpResource);
    254253      delete []fullName;
    255254    }
     
    274273{
    275274  // if pointer is existent. and only one resource of this type exists.
    276   Resource* tmpResource =ResourceManager::locateResourceByPointer(pointer);
     275  Resource* tmpResource = this->locateResourceByPointer(pointer);
    277276  if (!tmpResource)
    278277    {
     
    310309          PRINTF(4)("Resource %s safely removed.\n", resource->name);
    311310          delete []resource->name;
    312           resourceList->remove(resource);
     311          this->resourceList->remove(resource);
    313312        }
    314313      else
     
    327326bool ResourceManager::unloadAllByPriority(ResourcePriority prio)
    328327{
    329 
    330328  tIterator<Resource>* iterator = resourceList->getIterator();
    331329  Resource* enumRes = iterator->nextElement();
  • orxonox/trunk/src/lib/util/resource_manager.h

    r3660 r3672  
    5656  virtual ~ResourceManager();
    5757
    58   static bool setDataDir(char* dataDir);
    59   static bool addImageDir(char* imageDir);
    60   static void* load(const char* fileName, ResourcePriority prio = RP_NO);
    61   static void* load(const char* fileName, ResourceType type, ResourcePriority prio = RP_NO);
    62   static bool unload(void* pointer, ResourcePriority prio = RP_NO);
    63   static bool unload(Resource* resource, ResourcePriority = RP_NO);
    64   static bool unloadAllByPriority(ResourcePriority prio);
     58  bool setDataDir(char* dataDir);
     59  bool addImageDir(char* imageDir);
     60  void* load(const char* fileName, ResourcePriority prio = RP_NO);
     61  void* load(const char* fileName, ResourceType type, ResourcePriority prio = RP_NO);
     62  bool unload(void* pointer, ResourcePriority prio = RP_NO);
     63  bool unload(Resource* resource, ResourcePriority = RP_NO);
     64  bool unloadAllByPriority(ResourcePriority prio);
    6565
    6666 private:
     
    6868  static ResourceManager* singletonRef;
    6969
    70   static tList<Resource>* resourceList;
    71   static char* dataDir;
    72   static tList<char>* imageDirs;
     70  tList<Resource>* resourceList;       //!< The List of Resources, that has already been loaded.
     71  char* dataDir;                       //!< The Data Directory, where all relevant Data is stored.
     72  tList<char>* imageDirs;              //!< A list of directories in which images are stored.
    7373
    74   static Resource* locateResourceByName(const char* fileName);
    75   static Resource* locateResourceByPointer(const void* pointer);
     74
     75  Resource* locateResourceByName(const char* fileName);
     76  Resource* locateResourceByPointer(const void* pointer);
    7677 
    77   static bool isDir(const char* directory);
    78   static bool isFile(const char* directory); 
     78  bool isDir(const char* directory);
     79  bool isFile(const char* directory); 
    7980};
    8081
  • orxonox/trunk/src/story_entities/world.cc

    r3670 r3672  
    146146  cn->reset();
    147147
    148   ResourceManager::unloadAllByPriority(RP_LEVEL);
     148  ResourceManager::getInstance()->unloadAllByPriority(RP_LEVEL);
    149149
    150150  delete WorldInterface::getInstance();
  • orxonox/trunk/src/world_entities/environment.cc

    r3658 r3672  
    2929Environment::Environment () : WorldEntity()
    3030{
    31   this->model = (Model*) ResourceManager::load("models/reaplow.obj", OBJ);
     31  this->model = (Model*) ResourceManager::getInstance()->load("models/reaplow.obj", OBJ);
    3232  //  this->model = new OBJModel("../data/models/fighter.obj");
    3333}
  • orxonox/trunk/src/world_entities/player.cc

    r3660 r3672  
    4545     the player.cc for debug also
    4646  */
    47   this->model = (Model*)ResourceManager::load("models/reaplow.obj", OBJ, RP_CAMPAIGN);
     47  this->model = (Model*)ResourceManager::getInstance()->load("models/reaplow.obj", OBJ, RP_CAMPAIGN);
    4848  travelSpeed = 15.0;
    4949  velocity = new Vector();
  • orxonox/trunk/src/world_entities/projectile.cc

    r3670 r3672  
    3333Projectile::Projectile () : WorldEntity()
    3434{
    35   //this->model = new OBJModel("");
    36   this->projectileModel = new Primitive(P_SPHERE);
     35  this->model = (Model*)ResourceManager::getInstance()->load("cube", PRIM, RP_LEVEL);
     36  //  this->projectileModel = new Primitive(P_SPHERE);
    3737  this->flightDirection = NULL;
    3838  this->currentLifeTime = 0.0f;
     
    137137  this->getAbsDir().matrix (matrix);
    138138  glMultMatrixf((float*)matrix); 
    139   //this->model->draw();
    140   this->projectileModel->draw();
     139  this->model->draw();
     140  //this->projectileModel->draw();
    141141
    142142  glPopMatrix();
  • orxonox/trunk/src/world_entities/world_entity.cc

    r3658 r3672  
    5151{
    5252  // if( collisioncluster != NULL) delete collisioncluster;
    53   ResourceManager::unload(this->model);
     53  if (this->model)
     54    ResourceManager::getInstance()->unload(this->model);
    5455}
    5556
Note: See TracChangeset for help on using the changeset viewer.