Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7229 in orxonox.OLD for branches/resources/src/lib


Ignore:
Timestamp:
Mar 21, 2006, 3:13:34 PM (19 years ago)
Author:
bensch
Message:

resources: some minor implementations

Location:
branches/resources/src/lib
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • branches/resources/src/lib/graphics/graphics_engine.cc

    r7221 r7229  
    357357
    358358#ifdef __WIN32__
     359  // renewing GL-settings
     360  glEnable(GL_DEPTH_TEST);
     361
    359362  // REBUILDING TEXTURES (ON WINDOWS CONTEXT SWITCH)
    360363  const std::list<BaseObject*>* texList = ClassList::getList(CL_TEXTURE);
  • branches/resources/src/lib/graphics/importer/material.cc

    r7221 r7229  
    8383    ResourceManager::getInstance()->unload(this->diffuseTexture);
    8484  if (m.diffuseTexture != NULL)
    85     this->diffuseTexture = (Texture*)ResourceManager::getInstance()->copy(m.diffuseTexture);
     85    this->diffuseTexture = dynamic_cast<Texture*>(ResourceManager::getInstance()->copy(m.diffuseTexture));
    8686  this->ambientTexture = NULL; /// FIXME
    8787  this->specularTexture = NULL; /// FIXME
     
    298298  //! @todo Textures from .mtl-file need special care.
    299299  if (!dMap.empty())
    300     this->diffuseTexture = (Texture*)ResourceManager::getInstance()->load(dMap, IMAGE, RP_GAME, (int)target);
     300    this->diffuseTexture = dynamic_cast<Texture*>(ResourceManager::getInstance()->load(dMap, IMAGE, RP_GAME, (int)target));
    301301  else
    302302    this->diffuseTexture = NULL;
  • branches/resources/src/lib/graphics/importer/texture.h

    r7221 r7229  
    88
    99#include "base_object.h"
     10#include "lib/util/loading/resource.h"
    1011
    1112#include "glincl.h"
     
    1516
    1617//! A Class, that reads in Textures from different fileformats.
    17   class Texture : public BaseObject
     18  class Texture : public Loading::Resource
    1819  {
    1920    public:
     
    4344
    4445    protected:
    45 
    4646      bool setSurface(SDL_Surface* newSurface);
    4747      bool setAlpha(bool hasAlpha) { this->bAlpha = hasAlpha; };
  • branches/resources/src/lib/graphics/text_engine/text.cc

    r7221 r7229  
    8888  if (!fontFile.empty())
    8989  {
    90     tmpFont = (Font*)ResourceManager::getInstance()->load(fontFile, TTF, RP_GAME, (int)fontSize);
     90    tmpFont = dynamic_cast<Font*>(ResourceManager::getInstance()->load(fontFile, TTF, RP_GAME, (int)fontSize));
    9191    if (tmpFont != NULL)
    9292      this->font = tmpFont;
  • branches/resources/src/lib/shell/shell_command.cc

    r7225 r7229  
    349349 * @returns the Name of the Parameter at Hand
    350350 */
    351 const char* ShellCommand::paramToString(long parameter)
     351const std::string& ShellCommand::paramToString(long parameter)
    352352{
    353353  return MultiType::MultiTypeToString((MT_Type)parameter);
  • branches/resources/src/lib/shell/shell_command.h

    r7225 r7229  
    8080
    8181    static bool isRegistered(const std::string& commandName, const std::string& className);
    82     static const char* paramToString(long parameter);
     82    static const std::string& paramToString(long parameter);
    8383
    8484  protected:
  • branches/resources/src/lib/sound/sound_buffer.cc

    r7221 r7229  
    9696  else if (stereo && !is16Bit)
    9797    return AL_FORMAT_STEREO8;
    98   else if (stereo && is16Bit)
     98  else /* if (stereo && is16Bit) */
    9999    return AL_FORMAT_STEREO16;
    100100}
  • branches/resources/src/lib/util/loading/resource.cc

    r7195 r7229  
    1818#include "resource.h"
    1919
    20 using namespace std;
    2120
     21namespace Loading
     22{
    2223
    23 /**
    24  * standard constructor
    25 */
    26 Resource::Resource (const std::string& fileName)
    27 {
    28    this->setClassID(CL_RESOURCE, "Resource");
     24  /**
     25   * standard constructor
     26  */
     27  Resource::Resource (const std::string& fileName, ResourcePriority prio)
     28  {
     29    this->setClassID(CL_RESOURCE, "Resource");
     30    this->resource = NULL;
    2931
     32  }
     33
     34  /**
     35   * standard deconstructor
     36   */
     37  Resource::~Resource ()
     38  {
     39    // delete what has to be deleted here
     40  }
     41
     42  Resource::SharedResource::SharedResource()
     43  {
     44    this->referenceCount = 1;
     45    this->type = CL_NULL;
     46    this->prio = RP_NO;
     47  }
    3048}
    31 
    32 /**
    33  * standard deconstructor
    34  */
    35 Resource::~Resource ()
    36 {
    37   // delete what has to be deleted here
    38 }
  • branches/resources/src/lib/util/loading/resource.h

    r7195 r7229  
    1010#include "multi_type.h"
    1111#include <string>
    12 
    13 // FORWARD DECLARATION
     12#include <map>
     13#include <vector>
    1414
    1515
     16namespace Loading
     17{
     18  // FORWARD DECLARATION
    1619
    17 //! An enumerator for different (UN)LOAD-types.
    18 /**
    19  * RP_NO:        will be unloaded on request
    20  * RP_LEVEL:     will be unloaded at the end of a Level
    21  * RP_CAMPAIGN:  will be unloaded at the end of a Campaign
    22  * RP_GAME:      will be unloaded at the end of the whole Game (when closing orxonox)
    23  */
    24 typedef enum ResourcePriority
    25 {
    26   RP_NO        =   0,
    27   RP_LEVEL     =   1,
    28   RP_CAMPAIGN  =   2,
    29   RP_GAME      =   3
    30 };
     20  //! An enumerator for different (UN)LOAD-types.
     21  /**
     22   * RP_NO:        will be unloaded on request
     23   * RP_LEVEL:     will be unloaded at the end of a Level
     24   * RP_CAMPAIGN:  will be unloaded at the end of a Campaign
     25   * RP_GAME:      will be unloaded at the end of the whole Game (when closing orxonox)
     26   */
     27  typedef enum ResourcePriority
     28  {
     29    RP_NO        =   0,
     30    RP_LEVEL     =   1,
     31    RP_CAMPAIGN  =   2,
     32    RP_GAME      =   3
     33  };
    3134
    3235
     36  //! A Resource is an Object, that can be loaded from Disk
     37  /**
     38   * A Resource can cahnge the internal type, meaning it is a
     39   * SmartPointer, that keeps track of the InternalCount of the
     40   * Resource (SharedResource).
     41   */
     42  class Resource : virtual public BaseObject
     43  {
     44  protected:
     45    /**
     46     * This is a Class for the internal handling of the Resource.
     47     * Any Resource keeps exactly one of these Classes, so it can
     48     * reference and move it around, and keep track of how many
     49     * references of it are stored.
     50     */
     51    class SharedResource
     52    {
     53    public:
     54      SharedResource();
     55      std::string       fileName;
    3356
    34 //! A Resource is an Object, that can be loaded from Disk
    35 /**
    36  *
    37  */
    38 class Resource : virtual public BaseObject {
     57      unsigned int      referenceCount;    //!< How many times this Resource has been loaded.
     58      ClassID           type;              //!< ResourceType of this Resource.
     59      ResourcePriority  prio;              //!< The Priority of this resource. (can only be increased, so noone else will delete this)
    3960
    40  public:
    41    Resource(const std::string& fileName);
    42   virtual ~Resource();
     61      MultiType         param[3];          //!< The Parameters given to this Resource.
     62    };
    4363
    44   virtual bool load(std::string& fileName, const MultiType& param1, const MultiType& param2);
    45   virtual bool reload();
    46   virtual bool unload();
    4764
    48  private:
    49    std::string       fileName;
     65  public:
     66    Resource(const std::string& fileName = "", ResourcePriority prio = RP_LEVEL);
     67    virtual ~Resource();
    5068
    51    unsigned int      referenceCount;    //!< How many times this Resource has been loaded.
    52 /// TODO REMOVE THIS:   ResourceType      type;              //!< ResourceType of this Resource.
    53    ResourcePriority  prio;              //!< The Priority of this resource. (can only be increased, so noone else will delete this)
     69    // looks if the resource was already loaded and (if not) loads it.
     70    virtual bool load(std::string& fileName = "",
     71                      ResourcePriority prio = RP_LEVEL,
     72                      const MultiType& param0 = MT_NULL,
     73                      const MultiType& param1 = MT_NULL,
     74                      const MultiType& param2 = MT_NULL);
     75    // reloads the resource.
     76    virtual bool reload() { };
     77    // unloads the sharedResource (from this Resource)
     78    virtual bool unload();
    5479
    55    MultiType         param[3];          //!< The Parameters given to this Resource.
    56 };
     80    // checks if a resource was already loaded.
     81    bool isLoaded(std::string& fileName,
     82                  const MultiType& param0 = MT_NULL,
     83                  const MultiType& param1 = MT_NULL,
     84                  const MultiType& param2 = MT_NULL);
    5785
     86    // raises the priority can only be raised
     87    void raisePriority(ResourcePriority prio);
     88    /** @returns the referenceCount of the shared resource behind this resource or 0 if no internal Resource is stored */
     89  unsigned int referenceCount() const { return (this->resource)? this->resource->referenceCount : 0; };
     90
     91  protected:
     92    const SharedResource* findResource(std::string& fileName,
     93                                       const MultiType& param0 = MT_NULL,
     94                                       const MultiType& param1 = MT_NULL,
     95                                       const MultiType& param2 = MT_NULL);
     96
     97  protected:
     98    SharedResource*     resource;          //!< The internal Resource, this Resource is keeping (at the moment).
     99
     100    static std::map<ClassID, std::vector<SharedResource> > storedResources;
     101  };
     102
     103}
    58104#endif /* _RESOURCE_H */
  • branches/resources/src/lib/util/multi_type.cc

    r7221 r7229  
    408408#endif
    409409  ("MultiType of Type '%s' :: Values: BOOL: '%d', INT: '%d', FLOAT: '%f', CHAR: '%c', STRING '%s'\n",
    410    MultiType::MultiTypeToString(this->type),
     410   MultiType::MultiTypeToString(this->type).c_str(),
    411411   this->getBool(),
    412412   this->getInt(),
     
    453453 * @returns: the Type as a constant String (do not delete)
    454454 */
    455 const char* MultiType::MultiTypeToString(MT_Type type)
     455const std::string& MultiType::MultiTypeToString(MT_Type type)
    456456{
    457457  switch ( type )
    458458  {
    459459    case MT_BOOL:
    460       return "bool";
     460      return MultiType::multiTypeNames[1];
    461461    case MT_INT:
    462       return "int";
     462      return MultiType::multiTypeNames[2];
    463463    case MT_FLOAT:
    464       return "float";
     464      return MultiType::multiTypeNames[3];
    465465    case MT_CHAR:
    466       return "char";
     466      return MultiType::multiTypeNames[4];
    467467    case MT_STRING:
    468       return "string";
    469   }
    470   return "NONE";
     468      return MultiType::multiTypeNames[5];
     469  }
     470  return MultiType::multiTypeNames[0];
    471471}
    472472
     
    478478MT_Type MultiType::StringToMultiType(const std::string& type)
    479479{
    480   if (type == "bool")
     480  if (type == MultiType::multiTypeNames[1])
    481481    return MT_BOOL;
    482   if (type == "int")
     482  if (type == MultiType::multiTypeNames[2])
    483483    return MT_INT;
    484   if (type, "float")
     484  if (type == MultiType::multiTypeNames[3])
    485485    return MT_FLOAT;
    486   if (type == "char")
     486  if (type == MultiType::multiTypeNames[4])
    487487    return MT_CHAR;
    488   if (type == "string")
     488  if (type == MultiType::multiTypeNames[5])
    489489    return MT_STRING;
    490490
    491491  return MT_NULL;
    492492}
     493
     494
     495const std::string MultiType::multiTypeNames[] =
     496{
     497  "none",
     498  "bool",
     499  "int",
     500  "float",
     501  "char",
     502  "string"
     503};
  • branches/resources/src/lib/util/multi_type.h

    r7225 r7229  
    9292    void debug() const;
    9393
    94     static const char* MultiTypeToString(MT_Type type);
     94    static const std::string& MultiTypeToString(MT_Type type);
    9595    static MT_Type StringToMultiType(const std::string& type);
    9696
    9797  private:
     98    /**
     99     * The stored internal Value of the MultiType is handled in this union
     100     * plus the string down below
     101     */
    98102    union MultiTypeValue
    99103    {
    100       bool              Bool;
    101       int               Int;
    102       float             Float;
    103       char              Char;
     104      bool              Bool;            //!< If Type == MT_BOOL this is the MultiType's value
     105      int               Int;             //!< If Type == MT_INT this is the MultiType's value
     106      float             Float;           //!< If Type == MT_FLOAT this is the MultiType's value
     107      char              Char;            //!< If Type == MT_CHAR this is the MultiType's value
    104108//      std::string*      String;
    105     }                   value;
    106     std::string         storedString;
    107     MT_Type             type;
     109    }                   value;           //!< The stored internal value.
     110    std::string         storedString;    //!< The String if either MT_TYPE == MT_STRING or if temporary requested
     111    MT_Type             type;            //!< The Type of the MultiString.
     112
     113    static const std::string multiTypeNames[]; //!< An array to convert from String to MT_TYPE and backwords.
    108114};
    109115
Note: See TracChangeset for help on using the changeset viewer.