Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 9791 in orxonox.OLD


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

orxonox/new_class_id: resourceManager splitted away

Location:
branches/new_class_id/src
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • branches/new_class_id/src/lib/graphics/importer/resource_texture.cc

    r9790 r9791  
    88    : NewResource(&ResourceTexture::type)
    99{
    10   NewResource::StorePointer* ptr = this->acquireResource(imageName + ',' + "TEST");
     10  Resources::StorePointer* ptr = this->acquireResource(imageName + ',' + "TEST");
    1111
    1212  if (ptr)
     
    2020    std::string fileName = this->NewResource::locateFile(imageName);
    2121    this->Texture::loadImage(fileName, target);
    22     this->NewResource::addResource(new ResourceTexture::TextureResourcePointer(imageName + ',' + "TEST", KeepLevel(0), this->Texture::dataPointer()));
     22    this->NewResource::addResource(new ResourceTexture::TextureResourcePointer(imageName + ',' + "TEST", Resources::KeepLevel(0), this->Texture::dataPointer()));
    2323  }
    2424}
    2525
    2626
    27 NewResource::Type ResourceTexture::type(Texture::staticClassID());
     27Resources::Type ResourceTexture::type(Texture::staticClassID());
    2828
    2929
     
    3131
    3232
    33 ResourceTexture::TextureResourcePointer::TextureResourcePointer(const std::string& loadString, const NewResource::KeepLevel& keepLevel, const TextureData::Pointer& data)
    34     : NewResource::StorePointer(loadString, keepLevel) , pointer(data)
     33ResourceTexture::TextureResourcePointer::TextureResourcePointer(const std::string& loadString, const Resources::KeepLevel& keepLevel, const TextureData::Pointer& data)
     34    : Resources::StorePointer(loadString, keepLevel) , pointer(data)
    3535{}
    3636
  • branches/new_class_id/src/lib/graphics/importer/resource_texture.h

    r9789 r9791  
    1919
    2020private:
    21 class TextureResourcePointer : public NewResource::StorePointer
     21class TextureResourcePointer : public Resources::StorePointer
    2222  {
    2323  public:
    24     TextureResourcePointer(const std::string& loadString, const NewResource::KeepLevel& keepLevel, const TextureData::Pointer& data);
     24    TextureResourcePointer(const std::string& loadString, const Resources::KeepLevel& keepLevel, const TextureData::Pointer& data);
    2525    inline const TextureData::Pointer& ptr() const { return pointer; }
    2626  private:
     
    2929
    3030private:
    31   static NewResource::Type type;
     31  static Resources::Type type;
    3232};
    3333
  • branches/new_class_id/src/lib/util/loading/new_resource_manager.cc

    r9790 r9791  
    2222#include <assert.h>
    2323
    24 ObjectListDefinition(NewResourceManager);
     24//ObjectListDefinition(NewResourceManager);
     25
     26
     27//! Singleton Reference to the NewResourceManager
     28NewResourceManager* NewResourceManager::_singletonRef = NULL;
     29
    2530
    2631/**
     
    2934NewResourceManager::NewResourceManager ()
    3035{
    31   this->registerObject(this, NewResourceManager::_objectList);
     36//  this->registerObject(this, NewResourceManager::_objectList);
    3237  this->setName("NewResourceManager");
    3338
    3439  //this->dataDir = "./";
    35   this->tryDataDir("./data");
    3640}
    3741
    38 //! Singleton Reference to the NewResourceManager
    39 NewResourceManager* NewResourceManager::singletonRef = NULL;
    4042
    4143/**
     
    5052//     PRINTF(1)("Not removed all Resources, since there are still %d resources registered\n", this->resourceList.size());
    5153
    52   NewResourceManager::singletonRef = NULL;
     54  NewResourceManager::_singletonRef = NULL;
    5355}
    5456
     57
     58
     59
     60void NewResourceManager::registerType(Resources::Type* type)
     61{
     62  if(type->id() == -1)
     63  {
     64    type->setID(this->_resourceTypes.size());
     65    this->_resourceTypes.push_back(type);
     66  }
     67}
     68
     69void NewResourceManager::setMainGlobalPath(const Directory& directory)
     70{
     71  this->_mainGlobalPath = directory;
     72  this->_mainGlobalPath.open();
     73}
     74
     75void NewResourceManager::addGlobalPath(const Directory& directory)
     76{
     77  std::vector<Directory>::const_iterator it = std::find(this->_globalPaths.begin(), this->_globalPaths.end(), directory);
     78  if (it == this->_globalPaths.end())
     79    this->_globalPaths.push_back(directory);
     80}
     81
     82
     83bool NewResourceManager::addResourcePath(const std::string& resourceName, const std::string& pathName)
     84{
     85  std::vector<Resources::Type*>::iterator it;
     86  for (it = this->_resourceTypes.begin(); it != this->_resourceTypes.end(); ++it)
     87    if (*(*it) == resourceName)
     88      return (*it)->addResourcePath(pathName);
     89  PRINTF(2)("ResourcePath %s could not be added to the ResourceType %s\n", pathName.c_str(), resourceName.c_str());
     90  return false;
     91}
     92
     93bool NewResourceManager::addResourceSubPath(const std::string& resourceName, const std::string& pathName)
     94{
     95  std::vector<Resources::Type*>::iterator it;
     96  for (it = this->_resourceTypes.begin(); it != this->_resourceTypes.end(); ++it)
     97    if (*(*it) == resourceName)
     98      return (*it)->addResourceSubPath(pathName);
     99  PRINTF(2)("ResourceSubPath %s could not be added to the ResourceType %s\n", pathName.c_str(), resourceName.c_str());
     100  return false;
     101}
    55102
    56103
     
    63110  PRINT(0)("= RESOURCE-MANAGER DEBUG INFORMATION =\n");
    64111  PRINT(0)("======================================\n");
     112  PRINT(0)("Listing %d Types: \n", this->_resourceTypes.size());
     113  std::vector<Resources::Type*>::const_iterator it;
     114  for (it = this->_resourceTypes.begin(); it != this->_resourceTypes.end(); ++it)
     115    PRINT(0)("ResourceType '%s'\n", (*it)->storedClassID().name().c_str());
    65116
    66117  PRINT(0)("==================================RM==\n");
  • branches/new_class_id/src/lib/util/loading/new_resource_manager.h

    r9790 r9791  
    1212class NewResourceManager : public BaseObject
    1313{
    14   ObjectListDeclaration(NewResourceManager);
     14//  ObjectListDeclaration(NewResourceManager);
    1515public:
    1616  virtual ~NewResourceManager();
    1717  /** @returns a Pointer to the only object of this Class */
    18   inline static NewResourceManager* getInstance() { if (!singletonRef) singletonRef = new NewResourceManager();  return singletonRef; };
     18  inline static NewResourceManager* getInstance() { if (!_singletonRef) _singletonRef = new NewResourceManager();  return _singletonRef; };
    1919
    20   bool tryDataDir(const std::string& dataDir);
     20
     21  void setMainGlobalPath(const Directory& directory);
     22  void addGlobalPath(const Directory& directory);
     23
     24  bool addResourcePath(const std::string& resourceName, const std::string& pathName);
     25  bool addResourceSubPath(const std::string& resourceName, const std::string& pathName);
     26  void registerType(Resources::Type* type);
     27
     28
     29  const std::vector<Resources::Type*> resourceTypes() const { return _resourceTypes; };
     30  const Directory& mainGlobalPath() const { return _mainGlobalPath; };
     31  /** @returns all global paths without mainGlobalPath */
     32  const std::vector<Directory>& globalPaths() const { return _globalPaths; };
     33
     34
    2135  bool verifyDataDir(const std::string& fileInside);
    2236
     
    2842  static std::string getFullName(const std::string& fileName);
    2943  static bool isInDataDir(const std::string& fileName);
    30 
    3144private:
    3245  NewResourceManager();
    3346
    3447private:
    35   static NewResourceManager*    singletonRef;       //!< singleton Reference
     48  static NewResourceManager*       _singletonRef;       //!< singleton Reference
     49
     50  std::vector<Resources::Type*>    _resourceTypes;
     51  //! GLOBALS
     52  Directory                        _mainGlobalPath;
     53  std::vector<Directory>           _globalPaths;
     54
    3655
    3756};
  • branches/new_class_id/src/lib/util/loading/resource.cc

    r9790 r9791  
    1717
    1818#include "resource.h"
    19 #include "filesys/file.h"
     19#include "new_resource_manager.h"
     20
    2021#include "debug.h"
    2122
    2223ObjectListDefinition(NewResource);
    23 std::vector<NewResource::Type*>    NewResource::_resourceTypes;
    24 
    25 //! GLOBALS
    26 Directory NewResource::_mainGlobalPath;
    27 std::vector<Directory>        NewResource::_globalPaths;
    2824
    2925
     
    3127 * standard constructor
    3228*/
    33 NewResource::NewResource (NewResource::Type* type)
     29NewResource::NewResource (Resources::Type* type)
    3430    : _pointer(NULL), _type(type)
    3531{
     
    5046  if (File(fileName).exists())
    5147    return fileName;
    52   else if ((NewResource::_mainGlobalPath + File(fileName)).exists() )
    53     return (NewResource::_mainGlobalPath + File(fileName)).name();
     48  else if ((NewResourceManager::getInstance()->mainGlobalPath() + File(fileName)).exists() )
     49    return (NewResourceManager::getInstance()->mainGlobalPath() + File(fileName)).name();
    5450
    5551  printf("LOCATED %s\n", locateFileInSubDir(Directory("/home/bensch/svn/orxonox/data/"), fileName).c_str());
     
    8076
    8177
    82 NewResource::StorePointer* NewResource::acquireResource(const std::string& loadString)
     78Resources::StorePointer* NewResource::acquireResource(const std::string& loadString)
    8379{
    84   //const NewResource::Type* const type = NewResource::_resourceTypes[this->_type->id()];
     80  //const Resources::Type* const type = Resources::_resourceTypes[this->_type->id()];
    8581
    8682  for (unsigned int i = 0; i < _type->storedResources().size(); ++i)
     
    9389}
    9490
    95 void NewResource::setMainGlobalPath(const Directory& directory)
    96 {
    97   NewResource::_mainGlobalPath = directory;
    98   NewResource::_mainGlobalPath.open();
    99 }
    10091
    101 void NewResource::addGlobalPath(const Directory& directory)
    102 {
    103   std::vector<Directory>::const_iterator it = std::find(NewResource::_globalPaths.begin(), NewResource::_globalPaths.end(), directory);
    104   if (it == NewResource::_globalPaths.end())
    105     NewResource::_globalPaths.push_back(directory);
    106 }
    107 
    108 
    109 
    110 void NewResource::addResource(NewResource::StorePointer* pointer)
     92void NewResource::addResource(Resources::StorePointer* pointer)
    11193{
    11294  this->_type->addResource(pointer);
    113 }
    114 
    115 
    116 void 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 
    127 bool 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 
    137 bool 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 
    149 void 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 
    16295}
    16396
     
    16699
    167100
    168 std::vector<std::string> NewResource::KeepLevel::_keepLevelNames;
    169 void NewResource::KeepLevel::defineKeepLevelName(unsigned int level, const std::string& name)
     101
     102///////////////////
     103//// KEEPLEVEL ////
     104///////////////////
     105std::vector<std::string> Resources::KeepLevel::_keepLevelNames;
     106void Resources::KeepLevel::defineKeepLevelName(unsigned int level, const std::string& name)
    170107{
    171108  if (_keepLevelNames.size() <= level)
     
    175112
    176113
    177 NewResource::Type::Type(const ClassID& classID)
     114///////////////////////
     115//// STORE POINTER ////
     116///////////////////////
     117Resources::StorePointer::StorePointer(const std::string& loadString, const Resources::KeepLevel& keeplevel)
     118  : _loadString(loadString), _keepLevel(keeplevel)
     119{}
     120
     121
     122
     123
     124//////////////
     125//// TYPE ////
     126//////////////
     127Resources::Type::Type(const ClassID& classID)
    178128    : _id(-1), _classID(classID)
    179129{
    180   NewResource::registerType(this);
     130  NewResourceManager::getInstance()->registerType(this);
    181131}
    182132
    183 void NewResource::Type::addResource(NewResource::StorePointer* resource)
     133void Resources::Type::addResource(Resources::StorePointer* resource)
    184134{
    185135  this->_storedResources.push_back(resource);
     
    187137}
    188138
    189 bool NewResource::Type::addResourcePath(const std::string& path)
     139bool Resources::Type::addResourcePath(const std::string& path)
    190140{
    191141  std::vector<Directory>::const_iterator it;
     
    198148}
    199149
    200 bool NewResource::Type::addResourceSubPath(const std::string& subPath)
     150bool Resources::Type::addResourceSubPath(const std::string& subPath)
    201151{
    202152  std::vector<Directory>::const_iterator it;
     
    209159
    210160
    211 
    212 NewResource::StorePointer::StorePointer(const std::string& loadString, const NewResource::KeepLevel& keeplevel)
    213     : _loadString(loadString), _keepLevel(keeplevel)
    214 {}
    215 
    216 
    217 void NewResource::Type::setID(int id)
     161void Resources::Type::setID(int id)
    218162{
    219163  this->_id = id;
  • branches/new_class_id/src/lib/util/loading/resource.h

    r9790 r9791  
    1414#include "filesys/directory.h"
    1515
    16 //! A NewResource is an Object, that can be loaded from Disk
    17 /**
    18  *
    19  */
    20 class NewResource : virtual public BaseObject
     16namespace Resources
    2117{
    22   ObjectListDeclaration(NewResource);
    23 public:
    2418  class KeepLevel
    2519  {
     
    3529  };
    3630
    37 
    38 protected:
    3931  class StorePointer
    4032  {
    41   public:
    42     StorePointer(const std::string& loadString, const NewResource::KeepLevel& keeplevel);
    43     const std::string& loadString() const { return _loadString; };
    44     const NewResource::KeepLevel& keepLevel() const { return _keepLevel; };
     33    public:
     34      StorePointer(const std::string& loadString, const Resources::KeepLevel& keeplevel);
     35      const std::string& loadString() const { return _loadString; };
     36      const Resources::KeepLevel& keepLevel() const { return _keepLevel; };
    4537
    46   private:
    47     std::string                 _loadString;             //!< An identifier, to match when loading a File.
    48     NewResource::KeepLevel      _keepLevel;              //!< The Priority of this resource. (can only be increased, so none else will delete this)
     38    private:
     39      std::string                 _loadString;             //!< An identifier, to match when loading a File.
     40      Resources::KeepLevel        _keepLevel;              //!< The Priority of this resource. (can only be increased, so none else will delete this)
    4941  };
    50 
    5142
    5243  class Type
     
    6758    const std::vector<Directory>& resourcePaths() const { return _resourcePaths; };
    6859    const std::vector<Directory>& resourceSubPaths() const { return _resourceSubPaths; };
    69     const std::vector<NewResource::StorePointer*>& storedResources() const { return _storedResources; };
     60    const std::vector<Resources::StorePointer*>& storedResources() const { return _storedResources; };
    7061
    7162    void setID(int id);
    72     void addResource(NewResource::StorePointer* resource);
     63    void addResource(Resources::StorePointer* resource);
    7364
    7465  private:
     
    7970    std::vector<std::string>        _fileExtensions;
    8071
    81     std::vector<NewResource::StorePointer*> _storedResources;
     72    std::vector<Resources::StorePointer*> _storedResources;
    8273  };
     74}
    8375
     76//! A NewResource is an Object, that can be loaded from Disk
     77/**
     78 *
     79 */
     80class NewResource : virtual public BaseObject
     81{
     82  ObjectListDeclaration(NewResource);
    8483
    8584public:
    86   NewResource(NewResource::Type* type);
     85  NewResource(Resources::Type* type);
    8786  virtual ~NewResource();
    8887
     
    9493
    9594public:
    96   static void setMainGlobalPath(const Directory& directory);
    97   static void addGlobalPath(const Directory& directory);
    98 
    99   static bool addResourcePath(const std::string& resourceName, const std::string& pathName);
    100   static bool addResourceSubPath(const std::string& resourceName, const std::string& pathName);
    101 
    102   static void registerType(NewResource::Type* type);
    103 
    104   static void debug();
    10595protected:
    106   NewResource::StorePointer* acquireResource(const std::string& loadString);
    107   void addResource(NewResource::StorePointer* pointer);
     96  Resources::StorePointer* acquireResource(const std::string& loadString);
     97  void addResource(Resources::StorePointer* pointer);
    10898
    10999private:
     
    111101
    112102private:
    113   NewResource::StorePointer*       _pointer;                         //!< Virtual Pointer to the ResourceData.
    114   NewResource::Type*               _type;                            //!< Type of the NewResource.
    115 
    116 
    117   static std::vector<NewResource::Type*>  _resourceTypes;
    118 
    119   //! GLOBALS
    120   static Directory                       _mainGlobalPath;
    121   static std::vector<Directory>          _globalPaths;
     103  Resources::StorePointer*       _pointer;                         //!< Virtual Pointer to the ResourceData.
     104  Resources::Type*               _type;                            //!< Type of the NewResource.
    122105};
    123106
  • branches/new_class_id/src/orxonox.cc

    r9790 r9791  
    327327
    328328//#include "util/loading/dynamic_loader.h"
    329 #include "loading/resource.h"
     329#include "loading/new_resource_manager.h"
    330330/**
    331331 * initializes and loads resource files
     
    367367  }
    368368
    369   NewResource::debug();
    370369  //! @todo this is a hack and should be loadable
    371   NewResource::addResourceSubPath("Texture", "maps");
    372   NewResource::addResourceSubPath("Texture", "pictures");
     370  NewResourceManager::getInstance()->addResourceSubPath("Texture", "maps");
     371  NewResourceManager::getInstance()->addResourceSubPath("Texture", "pictures");
    373372
    374373  //  DynamicLoader::loadDyLib("libtest.so");
Note: See TracChangeset for help on using the changeset viewer.