Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 9784 in orxonox.OLD


Ignore:
Timestamp:
Sep 22, 2006, 12:19:51 AM (18 years ago)
Author:
bensch
Message:

orxonox/new_class_id: new Resources stuff

Location:
branches/new_class_id/src/lib
Files:
5 edited

Legend:

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

    r9781 r9784  
    55
    66
     7ResourceTexture::ResourceTexture(const std::string& imageName, GLenum target)
     8{
     9  Resource::Pointer* ptr = this->acquireResource(ResourceTexture::type, imageName + ',' + "TEST");
    710
    8 ResourceTexture::TextureResourcePointer::TextureResourcePointer(TextureData* data)
    9 {
    10   this->pointer = new TextureData::Pointer(data);
     11  if (ptr)
     12    this->acquireData(static_cast<ResourceTexture::TextureResourcePointer*>(ptr)->ptr());
     13  else
     14  {
     15    this->loadImage(imageName, target);
     16  }
    1117}
    1218
    1319
    1420Resource::Type ResourceTexture::type(Texture::staticClassID());
     21
     22
     23
     24
     25
     26ResourceTexture::TextureResourcePointer::TextureResourcePointer(const std::string& loadString, const Resource::KeepLevel& keepLevel, TextureData* data)
     27    : Resource::Pointer(loadString, keepLevel) , pointer(data)
     28{
     29}
     30
     31
  • branches/new_class_id/src/lib/graphics/importer/resource_texture.h

    r9781 r9784  
    1818
    1919private:
    20   class TextureResourcePointer
     20  class TextureResourcePointer : public Resource::Pointer
    2121  {
    2222  public:
    23     TextureResourcePointer(TextureData* data);
     23    TextureResourcePointer(const std::string& loadString, const Resource::KeepLevel& keepLevel, TextureData* data);
     24    inline const TextureData::Pointer& ptr() const { return pointer; }
    2425  private:
    25     TextureData::Pointer* pointer;
     26    TextureData::Pointer pointer;
    2627  };
    2728
  • branches/new_class_id/src/lib/graphics/importer/texture.h

    r9719 r9784  
    3030  Texture& operator=(const Texture& texture);
    3131  Texture& operator=(const TextureData::Pointer& textureDataPointer);
     32  void acquireData(const TextureData::Pointer& textureDataPointer) { this->data = textureDataPointer; };
     33  const TextureData::Pointer& dataPointer() const { return data; }
    3234
    3335  virtual ~Texture();
  • branches/new_class_id/src/lib/util/loading/resource.cc

    r9783 r9784  
    2424 * standard constructor
    2525*/
    26 Resource::Resource (const std::string& fileName)
     26Resource::Resource ()
     27    : _pointer(NULL)
    2728{
    2829  this->registerObject(this, Resource::_objectList);
     
    4041
    4142
     43Resource::Pointer* Resource::acquireResource(Resource::Type& resourceType, const std::string& loadString)
     44{
     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()];
     51
     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;
     55
     56  return NULL;
     57}
     58
    4259
    4360
  • branches/new_class_id/src/lib/util/loading/resource.h

    r9783 r9784  
    3737    void addExtension(const std::string& extension);
    3838
     39    void addResourcePath(const std::string& path);
     40    void addResourceSubPath(const std::string& subPath);
     41
     42    /// Retrieve Functions
    3943    const ClassID& storedClassID() const { return _classID; };
    4044    int id() const { return _id; };
    4145    const std::vector<std::string>& resourcePaths() const { return _resourcePaths; };
    42 
     46    const std::vector<std::string>& resourceSubPaths() const { return _resourceSubPaths; };
     47    const std::vector<Resource*>& storedResources() const { return _storedResources; };
    4348
    4449    void setID(int id);
     
    5055    std::vector<std::string>      _resourceSubPaths;
    5156    std::vector<std::string>      _fileExtensions;
     57
     58    std::vector<Resource*>        _storedResources;
    5259  };
    5360
    54   class Pointer {};
     61  class Pointer
     62  {
     63  public:
     64    Pointer(const std::string& loadString, const Resource::KeepLevel& keeplevel);
     65    const std::string& loadString() const { return _loadString; };
     66    const Resource::KeepLevel& keepLevel() const { return _keepLevel; };
     67
     68  private:
     69    std::string              _loadString;             //!< An identifier, to match when loading a File.
     70    Resource::KeepLevel      _keepLevel;              //!< The Priority of this resource. (can only be increased, so none else will delete this)
     71  };
    5572
    5673
    5774public:
    58   Resource(const std::string& fileName);
     75  Resource();
    5976  virtual ~Resource();
    6077
    61   bool loadResource(std::string& fileName, Resource::Pointer* ptr);
    6278  virtual bool reload();
    6379  virtual bool unload();
    6480
     81protected:
     82  Resource::Pointer* acquireResource(Resource::Type& resourceType, const std::string& loadString);
     83
     84private:
     85  Resource::Pointer*       _pointer;                //!< Virtual Pointer to the ResourceData.
    6586
    6687
    67 private:
    68   std::string              _loadString;             //!< An identifier, to match when loading a File.
    69   std::string              _fileName;
    70   MultiType                _parameters[3];          //!< The Parameters given to this Resource.
    71   Resource::KeepLevel      _keepLevel;              //!< The Priority of this resource. (can only be increased, so noone else will delete this)
    72 
    73 
    74   static std::vector<Resource::Type>     _resourceTypes;
     88  static std::vector<Resource::Type*>    _resourceTypes;
    7589
    7690  //! GLOBALS
Note: See TracChangeset for help on using the changeset viewer.