Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 9785 in orxonox.OLD for branches/new_class_id/src/lib/util


Ignore:
Timestamp:
Sep 22, 2006, 3:40:06 PM (18 years ago)
Author:
bensch
Message:

some implementations of the new self sustained Resources. It works, but does not yet load the correct stuff

Location:
branches/new_class_id/src/lib/util
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/new_class_id/src/lib/util/filesys/directory.cc

    r9719 r9785  
    212212
    213213}
     214
     215File operator+(const Directory& dir, const File& file)
     216{
     217   return File(dir.name() + '/' + file.name());
     218}
  • branches/new_class_id/src/lib/util/filesys/directory.h

    r9719 r9785  
    7777};
    7878
     79File operator+(const Directory& dir, const File& file);
     80
    7981#endif /* __DIRECTORY_H_ */
    8082
  • branches/new_class_id/src/lib/util/loading/resource.cc

    r9784 r9785  
    1717
    1818#include "resource.h"
     19#include "filesys/file.h"
    1920
    2021ObjectListDefinition(Resource);
     22
     23
     24std::vector<Resource::Type*>    Resource::_resourceTypes;
     25
     26//! GLOBALS
     27Directory Resource::_mainGlobalPath;
     28std::vector<Directory>        Resource::_globalPaths;
    2129
    2230
     
    2432 * standard constructor
    2533*/
    26 Resource::Resource ()
    27     : _pointer(NULL)
     34Resource::Resource (Resource::Type* type)
     35    : _pointer(NULL), _type(type)
    2836{
    2937  this->registerObject(this, Resource::_objectList);
     38
     39  if(this->_type->id() == -1)
     40  {
     41    Resource::_resourceTypes.push_back(this->_type);
     42    this->_type->setID(Resource::_resourceTypes.size()-1);
     43  }
    3044
    3145}
     
    4054
    4155
     56std::string Resource::locateFile(const std::string& fileName)
     57{
     58  if (File(fileName).exists())
     59    return fileName;
     60  else if ((Resource::_mainGlobalPath+File(fileName)) . exists() )
     61    return (Resource::_mainGlobalPath + File(fileName)).name();
    4262
    43 Resource::Pointer* Resource::acquireResource(Resource::Type& resourceType, const std::string& loadString)
     63
     64  return std::string("/home/bensch/svn/orxonox/data/") + fileName;
     65
     66}
     67
     68
     69Resource::Pointer* Resource::acquireResource(const std::string& loadString)
    4470{
    45   if(resourceType.id() == -1)
    46   {
    47     Resource::_resourceTypes.push_back(&resourceType);
    48     resourceType.setID(Resource::_resourceTypes.size());
    49   }
    50   const Resource::Type* const type = Resource::_resourceTypes[resourceType.id()];
     71  //const Resource::Type* const type = Resource::_resourceTypes[this->_type->id()];
    5172
    52   for (unsigned int i = 0; i < type->storedResources().size(); ++i)
    53     if (type->storedResources()[i]->_pointer->loadString() == loadString)
    54       return type->storedResources()[i]->_pointer;
     73  for (unsigned int i = 0; i < _type->storedResources().size(); ++i)
     74    if (_type->storedResources()[i]->_pointer->loadString() == loadString)
     75      return _type->storedResources()[i]->_pointer;
    5576
    5677  return NULL;
    5778}
     79
     80void Resource::setMainGlobalPath(const Directory& directory)
     81{
     82  Resource::_mainGlobalPath = directory;
     83  Resource::_mainGlobalPath.open();
     84}
     85
     86void Resource::addGlobalPath(const Directory& directory)
     87{
     88  std::vector<Directory>::const_iterator it = std::find(Resource::_globalPaths.begin(), Resource::_globalPaths.end(), directory);
     89  if (it == Resource::_globalPaths.end())
     90    Resource::_globalPaths.push_back(directory);
     91}
     92
     93
     94
     95void Resource::addResource(Resource::Pointer* pointer)
     96{}
     97
     98
     99
     100
    58101
    59102
     
    68111  _keepLevelName[level] = name;
    69112}
     113
     114
     115
     116
     117
     118
     119
     120
     121
     122
     123Resource::Pointer::Pointer(const std::string& loadString, const Resource::KeepLevel& keeplevel)
     124{
     125}
     126
     127void Resource::Type::setID(int id)
     128{
     129  this->_id = id;
     130}
  • branches/new_class_id/src/lib/util/loading/resource.h

    r9784 r9785  
    1212#include <vector>
    1313#include <set>
     14
     15#include "filesys/directory.h"
    1416
    1517//! A Resource is an Object, that can be loaded from Disk
     
    4850
    4951    void setID(int id);
     52    void addResource(Resource* resource);
    5053
    5154  private:
     
    7376
    7477public:
    75   Resource();
     78  Resource(Resource::Type* type);
    7679  virtual ~Resource();
    7780
    78   virtual bool reload();
    79   virtual bool unload();
     81  virtual bool reload() { return false; };
     82  virtual bool unload() { return false; };
     83
     84  std::string locateFile(const std::string& fileName);
     85
     86
     87  public:
     88    static void setMainGlobalPath(const Directory& directory);
     89    static void addGlobalPath(const Directory& directory);
     90
    8091
    8192protected:
    82   Resource::Pointer* acquireResource(Resource::Type& resourceType, const std::string& loadString);
     93  Resource::Pointer* acquireResource(const std::string& loadString);
     94  void addResource(Resource::Pointer* pointer);
    8395
    8496private:
    8597  Resource::Pointer*       _pointer;                //!< Virtual Pointer to the ResourceData.
     98  Resource::Type*          _type;                   //!< Type of the Resource.
    8699
    87100
     
    89102
    90103  //! GLOBALS
    91   static std::string                     _mainGlobalPath;
    92   static std::vector<std::string>        _globalPaths;
     104  static Directory                       _mainGlobalPath;
     105  static std::vector<Directory>          _globalPaths;
    93106};
    94107
Note: See TracChangeset for help on using the changeset viewer.