Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Apr 11, 2005, 4:16:57 PM (19 years ago)
Author:
bensch
Message:

orxonox/branches/textEngine: now the Resource Manager also checks for special parameters

File:
1 edited

Legend:

Unmodified
Added
Removed
  • orxonox/branches/textEngine/src/lib/util/resource_manager.cc

    r3773 r3775  
    142142   \returns a pointer to a desired Resource.
    143143*/
    144 void* ResourceManager::load(const char* fileName, ResourcePriority prio)
     144void* ResourceManager::load(const char* fileName, ResourcePriority prio, void* param1, void* param2, void* param3)
    145145{
    146146  ResourceType tmpType;
     
    164164    tmpType = IMAGE;
    165165
    166   return this->load(fileName, tmpType, prio);
     166  return this->load(fileName, tmpType, prio, param1, param2, param3);
    167167}
    168168
     
    174174   \returns a pointer to a desired Resource.
    175175*/
    176 void* ResourceManager::load(const char* fileName, ResourceType type, ResourcePriority prio)
     176void* ResourceManager::load(const char* fileName, ResourceType type, ResourcePriority prio, void* param1, void* param2, void* param3)
    177177{
    178178  // searching if the resource was loaded before.
    179   Resource* tmpResource = this->locateResourceByName(fileName);
     179  Resource* tmpResource = this->locateResourceByInfo(fileName, type, param1, param2,param3);
    180180  if (tmpResource) // if the resource was not loaded before.
    181181    {
     
    204204        {
    205205        case OBJ:
     206          if (param1)
     207            tmpResource->modelSize = *(float*)param1;
     208          else
     209            tmpResource->modelSize = 1.0;
     210
    206211          if(isFile(fullName))
    207             tmpResource->pointer = new OBJModel(fullName);
     212            tmpResource->pointer = new OBJModel(fullName, tmpResource->modelSize);
    208213          else
    209214            {
    210215              PRINTF(2)("Sorry, %s does not exist. Loading a cube-Model instead\n", fullName);
    211               tmpResource->pointer = ResourceManager::load("cube", PRIM);
     216              tmpResource->pointer = ResourceManager::load("cube", PRIM, prio, &tmpResource->modelSize);
    212217            }
    213218          break;
    214219        case PRIM:
     220          if (param1)
     221            tmpResource->modelSize = *(float*)param1;
     222          else
     223            tmpResource->modelSize = 1.0;
     224
    215225          if (!strcmp(tmpResource->name, "cube"))
    216             tmpResource->pointer = new PrimitiveModel(CUBE);
     226            tmpResource->pointer = new PrimitiveModel(CUBE, tmpResource->modelSize);
    217227          else if (!strcmp(tmpResource->name, "sphere"))
    218             tmpResource->pointer = new PrimitiveModel(SPHERE);
     228            tmpResource->pointer = new PrimitiveModel(SPHERE, tmpResource->modelSize);
    219229          else if (!strcmp(tmpResource->name, "plane"))
    220             tmpResource->pointer = new PrimitiveModel(PLANE);
     230            tmpResource->pointer = new PrimitiveModel(PLANE, tmpResource->modelSize);
    221231          else if (!strcmp(tmpResource->name, "cylinder"))
    222             tmpResource->pointer = new PrimitiveModel(CYLINDER);
     232            tmpResource->pointer = new PrimitiveModel(CYLINDER, tmpResource->modelSize);
    223233          else if (!strcmp(tmpResource->name, "cone"))
    224             tmpResource->pointer = new PrimitiveModel(CONE);
     234            tmpResource->pointer = new PrimitiveModel(CONE, tmpResource->modelSize);
    225235          break;
    226236        case TTF:
     237            if (param1)
     238              tmpResource->ttfSize = *(int*)param1;
     239            else
     240              tmpResource->ttfSize = FONT_DEFAULT_SIZE;
     241            if (param2)
     242              {
     243                Vector* tmpVec = (Vector*)param2;
     244                tmpResource->ttfColorR = (int)tmpVec->x;
     245                tmpResource->ttfColorG = (int)tmpVec->y;
     246                tmpResource->ttfColorB = (int)tmpVec->z;
     247              }
     248            else
     249              {
     250                tmpResource->ttfColorR = FONT_DEFAULT_COLOR_R;
     251                tmpResource->ttfColorG = FONT_DEFAULT_COLOR_G;
     252                tmpResource->ttfColorB = FONT_DEFAULT_COLOR_B;
     253              }
     254           
    227255          if(isFile(fullName))
    228             tmpResource->pointer = new Font(fullName);
     256            tmpResource->pointer = new Font(fullName,
     257                                            tmpResource->ttfSize,
     258                                            tmpResource->ttfColorR,
     259                                            tmpResource->ttfColorG,
     260                                            tmpResource->ttfColorB);
    229261          else
    230262            PRINTF(2)("Sorry, %s does not exist. Not loading Font\n", fullName);
     
    268300      delete []fullName;
    269301    }
    270 
    271   return tmpResource->pointer;
     302  if (tmpResource->pointer)
     303    return tmpResource->pointer;
     304  else
     305    {
     306      PRINTF(2)("Resource %s could not be loaded\n", fileName);
     307      delete tmpResource;
     308      return NULL;
     309    }
    272310}
    273311
     
    354392
    355393/**
    356    \brief Searches for a Resource by Name
     394   \brief Searches for a Resource by some information
    357395   \param fileName The name to look for
    358396   \returns a Pointer to the Resource if found, NULL otherwise.
    359397*/
    360 Resource* ResourceManager::locateResourceByName(const char* fileName)
     398Resource* ResourceManager::locateResourceByInfo(const char* fileName, ResourceType type, void* param1, void* param2, void* param3)
    361399{
    362400  //  Resource* enumRes = resourceList->enumerate();
     
    365403  while (enumRes)
    366404    {
    367       if (!strcmp(fileName, enumRes->name))
    368         {
    369           delete iterator;
    370           return enumRes;
     405      if (enumRes->type == type && !strcmp(fileName, enumRes->name))
     406        {
     407          bool match = false;
     408          bool subMatch = false;
     409          switch (type)
     410            {
     411            case PRIM:
     412            case OBJ:
     413              if (!param1)
     414                {
     415                  if (enumRes->modelSize == 1.0)
     416                    match = true;
     417                }
     418              else if (enumRes->modelSize == *(float*)param1)
     419                match = true;
     420              break;
     421            case TTF:
     422              if (!param1)
     423                {
     424                  if (enumRes->ttfSize == FONT_DEFAULT_SIZE)
     425                    subMatch = true;
     426                }
     427              else if (enumRes->modelSize =- *(int*)param1)
     428                subMatch = true;
     429              if(subMatch)
     430                {
     431                  Vector* tmpVec = (Vector*)param2;
     432                  if (!param2)
     433                    {
     434                      if(enumRes->ttfColorR == FONT_DEFAULT_COLOR_R &&
     435                         enumRes->ttfColorG == FONT_DEFAULT_COLOR_G &&
     436                         enumRes->ttfColorB == FONT_DEFAULT_COLOR_B )
     437                        match = true;
     438                    }
     439                  else if (enumRes->ttfColorR == (int)tmpVec->x &&
     440                           enumRes->ttfColorG == (int)tmpVec->y &&
     441                           enumRes->ttfColorB == (int)tmpVec->z )
     442                    match = true;
     443                }
     444
     445              break;
     446            default:
     447              match = true;
     448              break;
     449            }
     450          if (match)
     451            {
     452              delete iterator;
     453              return enumRes;
     454            }
    371455        }
    372456      enumRes = iterator->nextElement();
Note: See TracChangeset for help on using the changeset viewer.