Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6645 in orxonox.OLD for trunk/src


Ignore:
Timestamp:
Jan 21, 2006, 4:56:43 PM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: totally remastered the ResourceManager.
Now it takes MultiTypes instead of (void*) as parameters

  1. This is TypeSafe
  2. This is easier to use
  3. This makes much more sense, and is objectOriented

also made some minor adjustments to the MultiType, some comparisons

also fixed the loading in all the Other classes like material md2 and so on

Location:
trunk/src
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/graphics/importer/material.cc

    r6622 r6645  
    303303  //! @todo Textures from .mtl-file need special care.
    304304  if (dMap != NULL)
    305     this->diffuseTexture = (Texture*)ResourceManager::getInstance()->load(dMap, IMAGE, RP_GAME, (void*)&target);
     305    this->diffuseTexture = (Texture*)ResourceManager::getInstance()->load(dMap, IMAGE, RP_GAME, (int)target);
    306306  else
    307307    this->diffuseTexture = NULL;
  • trunk/src/lib/graphics/importer/md2Model.cc

    r6222 r6645  
    7878{
    7979  /* this creates the data container via ressource manager */
    80   this->data = (MD2Data*)ResourceManager::getInstance()->load(modelFileName, MD2, RP_GAME, (void*)skinFileName);
     80  this->data = (MD2Data*)ResourceManager::getInstance()->load(modelFileName, MD2, RP_GAME, skinFileName);
    8181  if( unlikely(this->data == NULL))
    8282    PRINTF(0)("The model was not found, MD2Model Loader finished abnormaly. Update the data-repos\n");
  • trunk/src/lib/graphics/shader.cc

    r5390 r6645  
    106106Shader* Shader::getShader(const char* vertexShaderFile, const char* fragmentShaderFile)
    107107{
    108   return (Shader*)ResourceManager::getInstance()->load(vertexShaderFile, SHADER,  RP_LEVEL, (void*)fragmentShaderFile);
     108  return (Shader*)ResourceManager::getInstance()->load(vertexShaderFile, SHADER,  RP_LEVEL, fragmentShaderFile);
    109109}
    110110
  • trunk/src/lib/graphics/text_engine/text.cc

    r6349 r6645  
    9292  if (fontFile != NULL)
    9393  {
    94     tmpFont = (Font*)ResourceManager::getInstance()->load(fontFile, TTF, RP_GAME, &fontSize);
     94    tmpFont = (Font*)ResourceManager::getInstance()->load(fontFile, TTF, RP_GAME, (int)fontSize);
    9595    if (tmpFont != NULL)
    9696      this->font = tmpFont;
  • trunk/src/lib/util/executor/executor.cc

    r6222 r6645  
    6060  {
    6161    int type = va_arg(parameterList, int);
    62     this->defaultValue[i].setType(type);
     62    this->defaultValue[i].setType((MT_Type)type);
    6363  }
    6464}
  • trunk/src/lib/util/multi_type.cc

    r6643 r6645  
    187187 * @param type the new Type
    188188 */
    189 void MultiType::setType(int type)
     189void MultiType::setType(MT_Type type)
    190190{
    191191  if (this->type != type)
    192     this->type = (MT_Type)type;
     192    this->type = type;
    193193}
    194194
  • trunk/src/lib/util/multi_type.h

    r6644 r6645  
    3131 */
    3232class MultiType {
    33 
    3433  public:
    3534    MultiType();
     
    5554    bool operator==(char value) const { return (this->getChar() == value); };
    5655    bool operator==(const char* value) const;
     56    bool operator==(MT_Type type) const { return (this->type == type); }
     57    bool operator!=(MT_Type type) const { return (this->type != type); }
    5758
    58     void setType(int type);
     59    void setType(MT_Type type);
    5960
    6061    void setBool(bool value);
  • trunk/src/util/loading/resource_manager.cc

    r6642 r6645  
    230230 * @param fileName: The fileName of the resource to load
    231231 * @param prio: The ResourcePriority of this resource (will only be increased)
     232 * @param param0: an additional option to parse (see the constuctors for more help)
    232233 * @param param1: an additional option to parse (see the constuctors for more help)
    233234 * @param param2: an additional option to parse (see the constuctors for more help)
    234  * @param param3: an additional option to parse (see the constuctors for more help)
    235235 * @returns a pointer to a desired Resource.
    236236*/
    237 BaseObject* ResourceManager::load(const char* fileName, ResourcePriority prio, void* param1, void* param2, void* param3)
     237BaseObject* ResourceManager::load(const char* fileName, ResourcePriority prio,
     238                                   const MultiType& param0, const MultiType& param1, const MultiType& param2)
    238239{
    239240  if (fileName == NULL)
     
    290291#endif /* NO_TEXTURES */
    291292#undef __IF_OK
    292   return this->load(fileName, tmpType, prio, param1, param2, param3);
     293  return this->load(fileName, tmpType, prio, param0, param1, param2);
    293294}
    294295
     
    303304 */
    304305void ResourceManager::cache(const char* fileName, ResourceType type, ResourcePriority prio,
    305              void* param1, void* param2, void* param3)
     306                            const MultiType& param0, const MultiType& param1, const MultiType& param2)
    306307{
    307308  assert(fileName != NULL);
     
    310311  Resource* tmpResource;
    311312  // check if we already loaded this Resource
    312   tmpResource = this->locateResourceByInfo(fileName, type, param1, param2, param3);
     313  tmpResource = this->locateResourceByInfo(fileName, type, param0, param1, param2);
    313314  // otherwise load it
    314315  if (tmpResource == NULL)
    315     tmpResource = this->loadResource(fileName, type, prio, param1, param2, param3);
     316    tmpResource = this->loadResource(fileName, type, prio, param0, param1, param2);
    316317  // return cached pointer.
    317318  if (tmpResource != NULL) // if the resource was loaded before.
     
    326327 * @param type: The Type of Resource to load.
    327328 * @param prio: The ResourcePriority of this resource (will only be increased)
     329 * @param param0: an additional option to parse (see the constuctors for more help)
    328330 * @param param1: an additional option to parse (see the constuctors for more help)
    329331 * @param param2: an additional option to parse (see the constuctors for more help)
    330  * @param param3: an additional option to parse (see the constuctors for more help)
    331332 * @returns a pointer to a desired Resource.
    332333*/
    333334BaseObject* ResourceManager::load(const char* fileName, ResourceType type, ResourcePriority prio,
    334                                   void* param1, void* param2, void* param3)
     335                                  const MultiType& param0, const MultiType& param1, const MultiType& param2)
    335336{
    336337  assert(fileName != NULL);
     
    339340  Resource* tmpResource;
    340341  // check if we already loaded this Resource
    341   tmpResource = this->locateResourceByInfo(fileName, type, param1, param2, param3);
     342  tmpResource = this->locateResourceByInfo(fileName, type, param0, param1, param2);
    342343  // otherwise load it
    343344  if (tmpResource == NULL)
    344     tmpResource = this->loadResource(fileName, type, prio, param1, param2, param3);
     345    tmpResource = this->loadResource(fileName, type, prio, param0, param1, param2);
    345346  // return cached pointer.
    346347  if (tmpResource != NULL) // if the resource was loaded before.
     
    361362 * @param type: The Type of Resource to load.
    362363 * @param prio: The ResourcePriority of this resource (will only be increased)
     364 * @param param0: an additional option to parse (see the constuctors for more help)
    363365 * @param param1: an additional option to parse (see the constuctors for more help)
    364366 * @param param2: an additional option to parse (see the constuctors for more help)
    365  * @param param3: an additional option to parse (see the constuctors for more help)
    366367 * @returns a pointer to a desired Resource.
    367368 */
    368369Resource* ResourceManager::loadResource(const char* fileName, ResourceType type, ResourcePriority prio,
    369     void* param1, void* param2, void* param3)
     370                                        const MultiType& param0, const MultiType& param1, const MultiType& param2)
    370371{
    371372  // Setting up the new Resource
     
    385386#ifndef NO_MODEL
    386387  case OBJ:
    387     if (param1)
    388       tmpResource->modelSize = *(float*)param1;
    389     else
    390       tmpResource->modelSize = 1.0;
     388    if (param0.getType() != MT_NULL)
     389      tmpResource->param[0] = param0;
     390    else
     391      tmpResource->param[0] = 1.0f;
    391392
    392393    if(ResourceManager::isFile(fullName))
    393       tmpResource->pointer = new OBJModel(fullName, tmpResource->modelSize);
     394      tmpResource->pointer = new OBJModel(fullName, tmpResource->param[0].getFloat());
    394395    else
    395396    {
    396397      PRINTF(2)("File %s in %s does not exist. Loading a cube-Model instead\n", fileName, dataDir);
    397       tmpResource->pointer = ResourceManager::load("cube", PRIM, prio, &tmpResource->modelSize);
     398      tmpResource->pointer = ResourceManager::load("cube", PRIM, prio, tmpResource->param[0].getFloat());
    398399    }
    399400    break;
    400401  case PRIM:
    401     if (param1)
    402       tmpResource->modelSize = *(float*)param1;
    403     else
    404       tmpResource->modelSize = 1.0;
     402    if (param0 != MT_NULL)
     403      tmpResource->param[0] = param0;
     404    else
     405      tmpResource->param[0] = 1.0f;
    405406
    406407    if (!strcmp(tmpResource->name, "cube"))
    407       tmpResource->pointer = new PrimitiveModel(PRIM_CUBE, tmpResource->modelSize);
     408      tmpResource->pointer = new PrimitiveModel(PRIM_CUBE, tmpResource->param[0].getFloat());
    408409    else if (!strcmp(tmpResource->name, "sphere"))
    409       tmpResource->pointer = new PrimitiveModel(PRIM_SPHERE, tmpResource->modelSize);
     410      tmpResource->pointer = new PrimitiveModel(PRIM_SPHERE, tmpResource->param[0].getFloat());
    410411    else if (!strcmp(tmpResource->name, "plane"))
    411       tmpResource->pointer = new PrimitiveModel(PRIM_PLANE, tmpResource->modelSize);
     412      tmpResource->pointer = new PrimitiveModel(PRIM_PLANE, tmpResource->param[0].getFloat());
    412413    else if (!strcmp(tmpResource->name, "cylinder"))
    413       tmpResource->pointer = new PrimitiveModel(PRIM_CYLINDER, tmpResource->modelSize);
     414      tmpResource->pointer = new PrimitiveModel(PRIM_CYLINDER, tmpResource->param[0].getFloat());
    414415    else if (!strcmp(tmpResource->name, "cone"))
    415       tmpResource->pointer = new PrimitiveModel(PRIM_CONE, tmpResource->modelSize);
     416      tmpResource->pointer = new PrimitiveModel(PRIM_CONE, tmpResource->param[0].getFloat());
    416417    break;
    417418  case MD2:
    418419    if(ResourceManager::isFile(fullName))
    419420    {
    420       if (param1 != NULL)
    421       {
    422         tmpResource->secFileName = new char[strlen((const char*)param1)+1];
    423         strcpy(tmpResource->secFileName, (const char*) param1);
    424       }
    425       else
    426         tmpResource->secFileName = NULL;
    427       tmpResource->pointer = new MD2Data(fullName, tmpResource->secFileName);
     421      tmpResource->param[0] = param0;
     422      tmpResource->pointer = new MD2Data(fullName, tmpResource->param[0].getString());
    428423      //               tmpResource->pointer = new MD2Model(fullName, tmpResource->secFileName);
    429424
     
    433428#ifndef NO_TEXT
    434429  case TTF:
    435     if (param1 != NULL)
    436       tmpResource->ttfSize = *(unsigned int*)param1;
    437     else
    438       tmpResource->ttfSize = FONT_DEFAULT_RENDER_SIZE;
     430    if (param0 != MT_NULL)
     431    {
     432      assert(param0.getInt() >= 0);
     433      tmpResource->param[0] = param0;
     434    }
     435    else
     436      tmpResource->param[0] = FONT_DEFAULT_RENDER_SIZE;
    439437
    440438    if(isFile(fullName))
    441       tmpResource->pointer = new Font(fullName, tmpResource->ttfSize);
     439      tmpResource->pointer = new Font(fullName, (unsigned int) tmpResource->param[0].getInt());
    442440    else
    443441      PRINTF(2)("%s does not exist in %s. Not loading Font\n", fileName, this->dataDir);
     
    456454#ifndef NO_TEXTURES
    457455  case IMAGE:
    458     if (param1 != NULL)
    459       tmpResource->texTarget = *(GLenum*)param1;
    460     else
    461       tmpResource->texTarget = GL_TEXTURE_2D;
     456    if (param0 != MT_NULL)
     457      tmpResource->param[0] = param0;
     458    else
     459      tmpResource->param[0] = GL_TEXTURE_2D;
    462460    if(isFile(fullName))
    463461    {
     
    475473        {
    476474          PRINTF(4)("Image %s resides to %s\n", fileName, imgName);
    477           tmpResource->pointer = new Texture(imgName, tmpResource->texTarget);
     475          tmpResource->pointer = new Texture(imgName, tmpResource->param[0].getInt());
    478476          delete[] imgName;
    479477          break;
     
    490488    if(ResourceManager::isFile(fullName))
    491489    {
    492       if (param1 != NULL)
     490      if (param0 != MT_NULL)
    493491      {
    494         char* secFullName = ResourceManager::getFullName((const char*)param1);
     492        MultiType param = param0; /// HACK
     493        char* secFullName = ResourceManager::getFullName(param.getString());
    495494        if (ResourceManager::isFile(secFullName))
    496495        {
    497           tmpResource->secFileName = new char[strlen((const char*)param1)+1];
    498           strcpy(tmpResource->secFileName, (const char*) param1);
     496          tmpResource->param[0] = secFullName;
    499497          tmpResource->pointer = new Shader(fullName, secFullName);
    500498        }
     
    503501      else
    504502      {
    505         tmpResource->secFileName = NULL;
     503        tmpResource->param[0] = param0;
    506504        tmpResource->pointer = new Shader(fullName, NULL);
    507505      }
     
    659657 * @param fileName: The name to look for
    660658 * @param type the Type of resource to locate.
     659 * @param param0: an additional option to parse (see the constuctors for more help)
    661660 * @param param1: an additional option to parse (see the constuctors for more help)
    662661 * @param param2: an additional option to parse (see the constuctors for more help)
    663  * @param param3: an additional option to parse (see the constuctors for more help)
    664662 * @returns a Pointer to the Resource if found, NULL otherwise.
    665663*/
    666664Resource* ResourceManager::locateResourceByInfo(const char* fileName, ResourceType type,
    667     void* param1, void* param2, void* param3) const
     665        const MultiType& param0, const MultiType& param1, const MultiType& param2) const
    668666{
    669667  std::vector<Resource*>::const_iterator resource;
     
    679677      case PRIM:
    680678      case OBJ:
    681         if (!param1)
     679        if (param0 == MT_NULL)
    682680        {
    683           if ((*resource)->modelSize == 1.0)
     681          if ((*resource)->param[0] == 1.0f)
    684682            match = true;
    685683        }
    686         else if ((*resource)->modelSize == *(float*)param1)
     684        else if ((*resource)->param[0] == param0)
    687685          match = true;
    688686        break;
    689687      case MD2:
    690         if (!param1)
     688        if (param0 == MT_NULL)
    691689        {
    692           if ((*resource)->secFileName == NULL)
     690          if ((*resource)->param[0] == "")
    693691            match = true;
    694692        }
    695         else if (!strcmp((*resource)->secFileName, (const char*)param1))
     693        else if ((*resource)->param[0] == param0)
    696694          match = true;
    697695        break;
     
    699697#ifndef NO_TEXT
    700698      case TTF:
    701         if (param1 == NULL)
     699        if (param0 == MT_NULL)
    702700        {
    703           if ((*resource)->ttfSize == FONT_DEFAULT_RENDER_SIZE)
     701          if ((*resource)->param[0] == FONT_DEFAULT_RENDER_SIZE)
    704702            match = true;
    705703        }
    706         else if ((*resource)->ttfSize == *(unsigned int*)param1)
     704        else if ((*resource)->param[0] == param0)
    707705          match = true;
    708706        break;
     
    710708#ifndef NO_SHADERS
    711709      case SHADER:
    712         if (!param1)
     710        if (param0 == MT_NULL)
    713711        {
    714           if ((*resource)->secFileName == NULL)
     712          if ((*resource)->param[0] == "")
    715713            match = true;
    716714        }
    717         else if (!strcmp((*resource)->secFileName, (const char*)param1))
     715        else if ((*resource)->param[0] == param0)
    718716          match = true;
    719717#endif /* NO_SHADERS */
    720718#ifndef NO_TEXTURES
    721719      case IMAGE:
    722         if (!param1)
     720        if (param0 == MT_NULL)
    723721        {
    724           if ((*resource)->texTarget == GL_TEXTURE_2D)
     722          if ((*resource)->param[0] == GL_TEXTURE_2D)
    725723            match = true;
    726724        }
    727         else if ((*resource)->texTarget ==  *(GLenum*)param1)
     725        else if ((*resource)->param[0] ==  param0)
    728726          match = true;
    729727#endif /* NO_TEXTURES */
  • trunk/src/util/loading/resource_manager.h

    r6642 r6645  
    2121
    2222#include "base_object.h"
    23 
     23#include "multi_type.h"
    2424
    2525#include <vector>
     
    7474  ResourcePriority  prio;              //!< The Priority of this resource. (This will only be increased)
    7575
    76   // more specific
    77   union {
    78 #ifndef NO_MODEL
    79   float             modelSize;         //!< the size of the model (OBJ/PRIM)
    80   char*             secFileName;       //!< a seconf fileName
    81 #endif /* NO_MODEL */
    82 #ifndef NO_TEXT
    83   unsigned int      ttfSize;           //!< the size of the ttf-font (TTF)
    84 #endif /* NO_TEXT */
    85 #ifndef NO_TEXTURES
    86   GLenum            texTarget;
    87 #endif /* NO_TEXTURES */
    88   };
     76  MultiType         param[3];          //!< The Parameters given to this Resource.
    8977};
    9078
     
    117105
    118106  void cache(const char* fileName, ResourceType type, ResourcePriority prio = RP_NO,
    119              void* param1 = NULL, void* param2 = NULL, void* param3 = NULL);
     107             const MultiType& param0 = MultiType(), const MultiType& param1 = MultiType(), const MultiType& param2 = MultiType());
    120108
    121109  BaseObject* load(const char* fileName, ResourcePriority prio = RP_NO,
    122                void* param1 = NULL, void* param2 = NULL, void* param3 = NULL);
     110                   const MultiType& param0 = MultiType(), const MultiType& param1 = MultiType(), const MultiType& param2 = MultiType());
    123111  BaseObject* load(const char* fileName, ResourceType type, ResourcePriority prio = RP_NO,
    124                void* param1 = NULL, void* param2 = NULL, void* param3 = NULL);
     112                   const MultiType& param0 = MultiType(), const MultiType& param1 = MultiType(), const MultiType& param2 = MultiType());
    125113  bool unload(void* pointer, ResourcePriority prio = RP_NO);
    126114  bool unload(Resource* resource, ResourcePriority = RP_NO);
    127115  bool unloadAllByPriority(ResourcePriority prio);
    128116
    129   Resource* locateResourceByInfo(const char* fileName, ResourceType type, void* param1, void* param2, void* param3) const;
     117  Resource* locateResourceByInfo(const char* fileName, ResourceType type,
     118                                 const MultiType& param0 = MultiType(), const MultiType& param1 = MultiType(), const MultiType& param2 = MultiType()) const;
    130119  Resource* locateResourceByPointer(const void* pointer) const;
    131120
     
    148137  ResourceManager();
    149138  Resource* loadResource(const char* fileName, ResourceType type, ResourcePriority prio,
    150                      void* param1, void* param2, void* param3);
     139                         const MultiType& param0, const MultiType& param1, const MultiType& param2);
    151140
    152141 private:
  • trunk/src/world_entities/environments/water.cc

    r6610 r6645  
    5353  this->rebuildGrid();
    5454  this->waterMaterial = new Material();
    55   this->waterShader = (Shader*)ResourceManager::getInstance()->load("shaders/water.vert", SHADER, RP_GAME, (void*)"shaders/water.frag");
     55  this->waterShader = (Shader*)ResourceManager::getInstance()->load("shaders/water.vert", SHADER, RP_GAME, "shaders/water.frag");
    5656
    5757  this->grid->height(this->grid->columns()/2,this->grid->rows()/2) = 100;
Note: See TracChangeset for help on using the changeset viewer.