Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 3775 in orxonox.OLD


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

Location:
orxonox/branches/textEngine/src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • orxonox/branches/textEngine/src/lib/graphics/font/text_engine.cc

    r3774 r3775  
    834834  Font* tmpFont;
    835835  Text* newText;
    836  
    837 
    838   tmpFont = (Font*)ResourceManager::getInstance()->load(fontFile, TTF, RP_GAME);
     836  Vector tmpVec;
     837
     838  tmpVec = Vector(r, g, b);
     839  tmpFont = (Font*)ResourceManager::getInstance()->load(fontFile, TTF, RP_GAME, &fontSize, &tmpVec);
    839840  if (!tmpFont)
    840841    {
     
    861862  ResourceManager::getInstance()->unload(text->font);
    862863  textList->remove(text);
    863 
    864864}
    865865
  • 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();
  • orxonox/branches/textEngine/src/lib/util/resource_manager.h

    r3769 r3775  
    3333{
    3434  void* pointer;             //!< Pointer to the Resource.
     35  int count;                 //!< How many times this Resource has been loaded.
    3536 
    3637  char* name;                //!< Name of the Resource.
    3738  ResourceType type;         //!< ResourceType of this Resource.
    3839  ResourcePriority prio;     //!< The Priority of this resource. (This will only be increased)
    39   int count;                 //!< How many times this Resource has been loaded.
     40
     41  // more specific
     42  float modelSize;
     43  unsigned int ttfSize;
     44  unsigned char ttfColorR;
     45  unsigned char ttfColorG;
     46  unsigned char ttfColorB;
    4047};
    4148
     
    6067  bool setDataDir(char* dataDir);
    6168  bool addImageDir(char* imageDir);
    62   void* load(const char* fileName, ResourcePriority prio = RP_NO);
    63   void* load(const char* fileName, ResourceType type, ResourcePriority prio = RP_NO);
     69  void* load(const char* fileName, ResourcePriority prio = RP_NO,
     70             void* param1 = NULL, void* param2 = NULL, void* param3 = NULL);
     71  void* load(const char* fileName, ResourceType type, ResourcePriority prio = RP_NO,
     72             void* param1 = NULL, void* param2 = NULL, void* param3 = NULL);
    6473  bool unload(void* pointer, ResourcePriority prio = RP_NO);
    6574  bool unload(Resource* resource, ResourcePriority = RP_NO);
     
    7685
    7786
    78   Resource* locateResourceByName(const char* fileName);
     87  Resource* locateResourceByInfo(const char* fileName, ResourceType type, void* param1, void* param2, void* param3);
    7988  Resource* locateResourceByPointer(const void* pointer);
    8089 
  • orxonox/branches/textEngine/src/story_entities/world.cc

    r3774 r3775  
    351351            trackManager->condition(2, LEFTRIGHT, this->localPlayer);
    352352            this->glmis->step();
    353             this->testText = TextEngine::getInstance()->createText("fonts/earth.ttf");
    354             testText->setText("test");
     353
     354            this->testText = TextEngine::getInstance()->createText("fonts/earth.ttf", 30, TEXT_DYNAMIC, 10, 100, 0);
     355            testText->setText("ORXONOX 123");
    355356            testText->setBindNode(tn);
    356357
Note: See TracChangeset for help on using the changeset viewer.