Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 9854 in orxonox.OLD for branches


Ignore:
Timestamp:
Sep 28, 2006, 10:17:56 AM (18 years ago)
Author:
bensch
Message:

more nice comments, and also updated the KeepLevel loading (if you want to load a Resource to a KeepLevel just append it at loadtime:
eg.:
Texture tex = ResourceTexture(orxonox.png, GL_TEXTURE_2D, GameEnd);
where GameEnd is the KeepLevel as defined in orxonox.cc→initResources()

Location:
branches/new_class_id/src
Files:
18 edited

Legend:

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

    r9847 r9854  
    66
    77
    8 ResourceMD2::ResourceMD2(const std::string& modelName, const std::string& skinName, float scale)
     8ResourceMD2::ResourceMD2(const std::string& modelName, const std::string& skinName, float scale, const Resources::KeepLevel& keepLevel)
    99    : Resource(&ResourceMD2::type)
    1010{
     
    2222    //std::string skinFileName = this->Resource::locateFile(skinName);
    2323    this->MD2Model::load(modelFileName, skinName, scale);
    24     this->Resource::addResource(new ResourceMD2::MD2ResourcePointer(loadString(modelName, skinName, scale), Resources::KeepLevel(0), this->MD2Model::dataPointer()));
     24    this->Resource::addResource(new ResourceMD2::MD2ResourcePointer(loadString(modelName, skinName, scale), keepLevel, this->MD2Model::dataPointer()));
    2525  }
    2626
    2727}
    2828
    29 ResourceMD2 ResourceMD2::createFromString(const std::string& loadString)
     29ResourceMD2 ResourceMD2::createFromString(const std::string& loadString, const Resources::KeepLevel& keepLevel)
    3030{
    3131  SubString loadValues(loadString, ',');
     
    4040    scale = MultiType(loadValues[2]).getFloat();
    4141
    42   return ResourceMD2(modelName, skinName, scale);
     42  return ResourceMD2(modelName, skinName, scale, keepLevel);
    4343}
    4444
  • branches/new_class_id/src/lib/graphics/importer/md2/resource_md2.h

    r9847 r9854  
    1515{
    1616public:
    17   ResourceMD2(const std::string& modelName, const std::string& skinName = "", float scale = 1.0f);
    18   static ResourceMD2 createFromString(const std::string& loadString);
     17  ResourceMD2(const std::string& modelName,
     18              const std::string& skinName = "",
     19              float scale = 1.0f,
     20              const Resources::KeepLevel& keepLevel = Resources::KeepLevel());
     21  static ResourceMD2 createFromString(const std::string& loadString, const Resources::KeepLevel& keepLevel = Resources::KeepLevel());
    1922  static std::string loadString(const std::string& modelName, const std::string& skinName = "", float scale = 1.0f);
    2023
  • branches/new_class_id/src/lib/graphics/importer/resource_obj.cc

    r9847 r9854  
    66
    77
    8 ResourceOBJ::ResourceOBJ(const std::string& imageName, float scaling)
     8ResourceOBJ::ResourceOBJ(const std::string& imageName, float scaling, const Resources::KeepLevel& keepLevel)
    99    : Resource(&ResourceOBJ::type)
    1010{
     
    2121    std::string fileName = this->Resource::locateFile(imageName);
    2222    this->acquireData(OBJModel(fileName, scaling).dataPointer());
    23     this->Resource::addResource(new ResourceOBJ::OBJResourcePointer(imageName + ',' + MultiType(scaling).getString(), Resources::KeepLevel(0), this->StaticModel::dataPointer()));
     23    this->Resource::addResource(new ResourceOBJ::OBJResourcePointer(imageName + ',' + MultiType(scaling).getString(), keepLevel, this->StaticModel::dataPointer()));
    2424  }
    2525}
    2626
    27 ResourceOBJ ResourceOBJ::createFromString(const std::string& loadString)
     27ResourceOBJ ResourceOBJ::createFromString(const std::string& loadString, const Resources::KeepLevel& keepLevel)
    2828{
    2929  SubString loadValues(loadString, ',');
     
    3535    scaling = (GLenum)MultiType(loadValues[2]).getFloat();
    3636
    37   return ResourceOBJ(imageName, scaling);
     37  return ResourceOBJ(imageName, scaling, keepLevel);
    3838}
    3939
  • branches/new_class_id/src/lib/graphics/importer/resource_obj.h

    r9847 r9854  
    1414{
    1515public:
    16   ResourceOBJ(const std::string& imageName, float scaling = 1.0f);
    17   static ResourceOBJ createFromString(const std::string& loadString);
     16  ResourceOBJ(const std::string& imageName,
     17              float scaling = 1.0f,
     18              const Resources::KeepLevel& keepLevel = Resources::KeepLevel());
     19  static ResourceOBJ createFromString(const std::string& loadString,
     20                                      const Resources::KeepLevel& keepLevel = Resources::KeepLevel());
    1821
    1922private:
  • branches/new_class_id/src/lib/graphics/importer/resource_texture.cc

    r9847 r9854  
    66
    77
    8 ResourceTexture::ResourceTexture(const std::string& imageName, GLenum target)
     8ResourceTexture::ResourceTexture(const std::string& imageName, GLenum target, const Resources::KeepLevel& keepLevel)
    99    : Resource(&ResourceTexture::type)
    1010{
     
    2121    std::string fileName = this->Resource::locateFile(imageName);
    2222    this->Texture::loadImage(fileName, target);
    23     this->Resource::addResource(new ResourceTexture::TextureResourcePointer(imageName + ',' + MultiType((int)target).getString(), Resources::KeepLevel(0), this->Texture::dataPointer()));
     23    this->Resource::addResource(new ResourceTexture::TextureResourcePointer(imageName + ',' + MultiType((int)target).getString(), keepLevel, this->Texture::dataPointer()));
    2424  }
    2525}
    2626
    27 ResourceTexture ResourceTexture::createFromString(const std::string& loadString)
     27ResourceTexture ResourceTexture::createFromString(const std::string& loadString, const Resources::KeepLevel& keepLevel)
    2828{
    2929  SubString loadValues(loadString, ',');
     
    3535    target = (GLenum)MultiType(loadValues[2]).getInt();
    3636
    37   return ResourceTexture(imageName, target);
     37  return ResourceTexture(imageName, target, keepLevel);
    3838}
    3939
  • branches/new_class_id/src/lib/graphics/importer/resource_texture.h

    r9847 r9854  
    1515{
    1616public:
    17   ResourceTexture(const std::string& imageName, GLenum target = GL_TEXTURE_2D);
    18   static ResourceTexture createFromString(const std::string& loadString);
     17  ResourceTexture(const std::string& imageName,
     18                  GLenum target = GL_TEXTURE_2D,
     19                  const Resources::KeepLevel& keepLevel = Resources::KeepLevel());
     20  static ResourceTexture createFromString(const std::string& loadString,
     21                                          const Resources::KeepLevel& keepLevel = Resources::KeepLevel());
    1922
    2023private:
  • branches/new_class_id/src/lib/graphics/resource_shader.cc

    r9847 r9854  
    44#include "substring.h"
    55
    6 ResourceShader::ResourceShader(const std::string& vertexShaderName, const std::string& fragmentShaderName)
     6ResourceShader::ResourceShader(const std::string& vertexShaderName, const std::string& fragmentShaderName, const Resources::KeepLevel& keepLevel)
    77    : Resource(&ResourceShader::type)
    88{
     
    2323
    2424    this->Shader::load(vertexFileName, fragmentFileName);
    25     this->Resource::addResource(new ResourceShader::ShaderResourcePointer(vertexShaderName+','+fragmentShaderName, Resources::KeepLevel(0), this->Shader::dataPointer()));
     25    this->Resource::addResource(new ResourceShader::ShaderResourcePointer(vertexShaderName+','+fragmentShaderName, keepLevel, this->Shader::dataPointer()));
    2626  }
    2727}
    2828
    29 ResourceShader ResourceShader::createFromString(const std::string& loadString)
     29ResourceShader ResourceShader::createFromString(const std::string& loadString, const Resources::KeepLevel& keepLevel)
    3030{
    3131  std::string vertexShaderName;
     
    3838    fragmentShaderName = shaderNames[1];
    3939
    40   return ResourceShader(vertexShaderName, fragmentShaderName);
     40  return ResourceShader(vertexShaderName, fragmentShaderName, keepLevel);
    4141}
    4242
  • branches/new_class_id/src/lib/graphics/resource_shader.h

    r9847 r9854  
    1515{
    1616public:
    17   ResourceShader(const std::string& vertexShaderName, const std::string& fragmentShaderName);
    18   static ResourceShader createFromString(const std::string& loadString);
     17  ResourceShader(const std::string& vertexShaderName,
     18                 const std::string& fragmentShaderName,
     19                 const Resources::KeepLevel& keepLevel = Resources::KeepLevel());
     20  static ResourceShader createFromString(const std::string& loadString,
     21                                         const Resources::KeepLevel& keepLevel = Resources::KeepLevel());
    1922
    2023private:
  • branches/new_class_id/src/lib/graphics/text_engine/resource_font.cc

    r9847 r9854  
    66
    77
    8 ResourceFont::ResourceFont(const std::string& fontName, unsigned int renderSize)
     8ResourceFont::ResourceFont(const std::string& fontName, unsigned int renderSize, const Resources::KeepLevel& keepLevel)
    99  : Font(), Resource(&ResourceFont::type)
    1010{
     
    2525
    2626    this->Font::loadFontFromTTF(fileName, renderSize);
    27     this->Resource::addResource(new ResourceFont::FontResourcePointer(fontName + ',' + MultiType((int)renderSize).getString(), Resources::KeepLevel(0), this->Font::dataPointer()));
     27    this->Resource::addResource(new ResourceFont::FontResourcePointer(fontName + ',' + MultiType((int)renderSize).getString(), keepLevel, this->Font::dataPointer()));
    2828  }
    2929}
    3030
    31 ResourceFont ResourceFont::createFromString(const std::string& loadString)
     31ResourceFont ResourceFont::createFromString(const std::string& loadString, const Resources::KeepLevel& keepLevel)
    3232{
    3333  SubString loadValues(loadString, ',');
     
    3939    renderSize = (unsigned int)MultiType(loadValues[2]).getInt();
    4040
    41   return ResourceFont(fontName, renderSize);
     41  return ResourceFont(fontName, renderSize, keepLevel);
    4242}
    4343
  • branches/new_class_id/src/lib/graphics/text_engine/resource_font.h

    r9847 r9854  
    1515{
    1616public:
    17   ResourceFont(const std::string& fontName, unsigned int renderSize);
    18   static ResourceFont createFromString(const std::string& loadString);
     17  ResourceFont(const std::string& fontName, unsigned int renderSize, const Resources::KeepLevel& keepLevel = Resources::KeepLevel());
     18  static ResourceFont createFromString(const std::string& loadString, const Resources::KeepLevel& keepLevel = Resources::KeepLevel());
    1919
    2020private:
  • branches/new_class_id/src/lib/shell/some_shell_commands.cc

    r9851 r9854  
    5555namespace Resources {
    5656  SHELL_COMMAND(debug, ResourceManager, debug);
    57   SHELL_COMMAND(load, ResourceManager, loadFromLoadString);
     57  SHELL_COMMAND(load, ResourceManager, loadFromLoadStringHACK);
    5858  SHELL_COMMAND(unload, ResourceManager, unloadAllBelowKeepLevelINT);
    5959}
  • branches/new_class_id/src/lib/sound/resource_sound_buffer.cc

    r9847 r9854  
    88  ObjectListDefinition(ResourceSoundBuffer);
    99
    10   ResourceSoundBuffer::ResourceSoundBuffer(const std::string& soundName)
     10  ResourceSoundBuffer::ResourceSoundBuffer(const std::string& soundName, const Resources::KeepLevel& keepLevel)
    1111      : SoundBuffer(), Resource(&ResourceSoundBuffer::type)
    1212  {
     
    2525      std::string fileName = this->Resource::locateFile(soundName);
    2626      this->SoundBuffer::load(fileName);
    27       this->Resource::addResource(new ResourceSoundBuffer::SoundBufferResourcePointer(soundName, Resources::KeepLevel(0), this->SoundBuffer::dataPointer()));
     27      this->Resource::addResource(new ResourceSoundBuffer::SoundBufferResourcePointer(soundName, keepLevel, this->SoundBuffer::dataPointer()));
    2828    }
    2929  }
  • branches/new_class_id/src/lib/sound/resource_sound_buffer.h

    r9847 r9854  
    1717    ObjectListDeclaration(ResourceSoundBuffer);
    1818  public:
    19     ResourceSoundBuffer(const std::string& soundName);
    20     static ResourceSoundBuffer createFromString(const std::string& loadString) { return ResourceSoundBuffer(loadString); };
     19    ResourceSoundBuffer(const std::string& soundName,
     20                        const Resources::KeepLevel& keepLevel = Resources::KeepLevel());
     21    static ResourceSoundBuffer createFromString(const std::string& loadString, const Resources::KeepLevel& keepLevel = Resources::KeepLevel())
     22    { return ResourceSoundBuffer(loadString, keepLevel); };
    2123
    2224  private:
  • branches/new_class_id/src/lib/util/loading/resource.cc

    r9851 r9854  
    134134  //// KEEPLEVEL ////
    135135  ///////////////////
     136
     137  //! Constructs a default KeepLevel as Set in the ResourceManager via setDefaultKeepLevel.
     138  KeepLevel::KeepLevel()
     139  {
     140    this->_keepLevel = ResourceManager::getInstance()->defaultKeepLevel().keepLevel();
     141  }
     142  /**
     143   * @param keepLevel the level to set.
     144   */
     145  KeepLevel::KeepLevel(unsigned int keepLevel)
     146  {
     147    _keepLevel = keepLevel;
     148  }
     149
    136150  /**
    137151   * @brief constructor of a KeepLevel.
  • branches/new_class_id/src/lib/util/loading/resource.h

    r9852 r9854  
    2626  {
    2727  public:
    28     /** @param keepLevel the level to set. */
    29     inline KeepLevel(unsigned int keepLevel) { _keepLevel = keepLevel; };
     28    KeepLevel();
     29    KeepLevel(unsigned int keepLevel);
    3030    KeepLevel(const std::string& keepLevelName);
    3131
     
    9393    bool operator==(const std::string& typeName) const { return this->_typeName == typeName; };
    9494
     95    ////////////////////
     96    //// EXTENSIONS ////
    9597    void addExtension(const std::string& extension);
    9698
     99    ///////////////
     100    //// PATHS ////
    97101    bool addResourcePath(const std::string& path);
    98102    bool addResourceSubPath(const std::string& subPath);
     
    109113    const std::vector<Resources::StorePointer*>& storedResources() const { return _storedResources; };
    110114
    111     virtual void createFromString(const std::string& loadString) = 0;
    112 
     115    ///////////////////////////////
     116    //// LOADING AND UNLOADING ////
     117    virtual void createFromString(const std::string& loadString, const KeepLevel& keepLevel = KeepLevel()) = 0;
    113118    void unloadAllBelowKeepLevel(const Resources::KeepLevel& keepLevel);
    114119
     120    ///////////////////
     121    //// INTERNALS ////
    115122    void addResource(Resources::StorePointer* resource);
    116123
     124    ///////////////
     125    //// DEBUG ////
    117126    void debug() const;
    118127
     
    144153    tType(const std::string& typeName) : Type(typeName) {};
    145154    /** @param loadString the String to load a Resource with @brief tries to create a Resource of Type T with a loadString */
    146     virtual void createFromString(const std::string& loadString) { T::createFromString(loadString); }
     155    virtual void createFromString(const std::string& loadString, const KeepLevel& keepLevel = KeepLevel()) { T::createFromString(loadString, keepLevel); }
    147156  };
    148157
  • branches/new_class_id/src/lib/util/loading/resource_manager.cc

    r9853 r9854  
    3535  */
    3636  ResourceManager::ResourceManager ()
     37  : _defaultKeepLevel(0)
    3738  {
    3839    this->registerObject(this, ResourceManager::_objectList);
     
    4748  ResourceManager::~ResourceManager ()
    4849  {
    49     // deleting the Resources-List
    50     //this->unloadAllByPriority(RP_GAME);
    51 
    52     //   if (!this->resourceList.empty())
    53     //     PRINTF(1)("Not removed all Resources, since there are still %d resources registered\n", this->resourceList.size());
    54 
    5550    ResourceManager::_singletonRef = NULL;
    5651  }
     
    195190   * @param loadString the loadString to load in the Type.
    196191   */
    197   void ResourceManager::loadFromLoadString(const std::string& resourceTypeName, const std::string& loadString)
     192  void ResourceManager::loadFromLoadString(const std::string& resourceTypeName, const std::string& loadString, const KeepLevel& keepLevel)
    198193  {
    199194    std::vector<Resources::Type*>::const_iterator it;
     
    202197      if (*(*it) == resourceTypeName)
    203198      {
    204         (*it)->createFromString(loadString);
     199        (*it)->createFromString(loadString, keepLevel);
    205200        /// TODO check if the resource was allocated!!
    206201        return ;
  • branches/new_class_id/src/lib/util/loading/resource_manager.h

    r9851 r9854  
    1717    ObjectListDeclaration(ResourceManager);
    1818  public:
     19    ///////////////////////
     20    //// INSTANZIATION ////
    1921    /** @returns a Pointer to the only object of this Class */
    2022    inline static ResourceManager* getInstance() { if (!_singletonRef) _singletonRef = new ResourceManager();  return _singletonRef; };
     
    2224    inline static void deleteInstance() { if (_singletonRef) delete _singletonRef; };
    2325
    24 
     26    ////////////////////////
     27    //// RESOURCE PATHS ////
    2528    void setMainGlobalPath(const Directory& directory);
    2629    void addGlobalPath(const Directory& directory);
     
    3134    void unregisterType(Resources::Type* type);
    3235
    33     unsigned int addKeepLevelName(const std::string& keepLevelName);
    34     unsigned int getKeepLevelID(const std::string& keepLevelName) const;
    35     const std::string& getKeepLevelName(unsigned int keepLevelID) const;
    36 
    37     /** @returns the Types of Resources */
    38     const std::vector<Resources::Type*> resourceTypes() const { return _resourceTypes; };
    3936    /** @returns the main global search Path */
    4037    const Directory& mainGlobalPath() const { return _mainGlobalPath; };
     
    4239    const std::vector<Directory>& globalPaths() const { return _globalPaths; };
    4340
     41    ////////////////////
     42    //// KEEPLEVELS ////
     43    unsigned int addKeepLevelName(const std::string& keepLevelName);
     44    unsigned int getKeepLevelID(const std::string& keepLevelName) const;
     45    const std::string& getKeepLevelName(unsigned int keepLevelID) const;
     46    void setDefaultKeepLevel(const KeepLevel& keepLevel) { this->_defaultKeepLevel = keepLevel; };
     47    const KeepLevel& defaultKeepLevel() const { return this->_defaultKeepLevel; };
     48
     49    //////////////////////////
     50    //// GENERAL QUERIES ////
     51    /** @returns the Types of Resources */
     52    const std::vector<Resources::Type*> resourceTypes() const { return _resourceTypes; };
    4453
    4554    bool checkFileInMainPath(const File& fileInside);
    4655    std::string prependAbsoluteMainPath(const std::string& fileName);
    4756
     57    ////////////////////////////////////////
     58    //// RESOURCE LOADING AND UNLOADING ////
     59    void loadFromLoadString(const std::string& resourceTypeName, const std::string& loadString, const KeepLevel& keepLevel = KeepLevel());
     60    void loadFromLoadStringHACK(const std::string& resourceTypeName, const std::string& loadString) { this->loadFromLoadString(resourceTypeName, loadString); };
     61
    4862    void unloadAllBelowKeepLevel(const Resources::KeepLevel& keepLevel);
    4963    void unloadAllBelowKeepLevelINT(unsigned int level) { unloadAllBelowKeepLevel(level); };
    50     void loadFromLoadString(const std::string& resourceTypeName, const std::string& loadString);
    5164
     65    ///////////////
     66    //// DEBUG ////
    5267    void debug() const;
    5368
    54     // utility functions for handling files in and around the data-directory
    55     static std::string getFullName(const std::string& fileName);
    56     static bool isInDataDir(const std::string& fileName);
    5769  private:
    5870    ResourceManager();
     
    6678
    6779    std::vector<Resources::Type*>      _resourceTypes;      //!< A Vector of all the stored ResourceTypes @see Resources::Type
     80
    6881    std::vector<std::string>           _keepLevelNames;     //!< Names of KeepLevels @see Resources::KeepLevel
     82    KeepLevel                          _defaultKeepLevel;   //!< The default KeepLevel.
    6983  };
    7084
  • branches/new_class_id/src/orxonox.cc

    r9845 r9854  
    377377  Resources::ResourceManager::getInstance()->addKeepLevelName("CampaignEnd");
    378378  Resources::ResourceManager::getInstance()->addKeepLevelName("GameEnd");
    379 
    380   //  DynamicLoader::loadDyLib("libtest.so");
     379  Resources::ResourceManager::getInstance()->setDefaultKeepLevel(std::string("GameEnd"));
     380
    381381  return 0;
    382382}
Note: See TracChangeset for help on using the changeset viewer.