Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5306 in orxonox.OLD


Ignore:
Timestamp:
Oct 7, 2005, 6:17:49 PM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: ResourceManage-fixes

Location:
trunk/src
Files:
7 edited

Legend:

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

    r5303 r5306  
    3131
    3232/**
    33  *  creates a Material.
     33 * creates a Material.
    3434 * @param mtlName Name of the Material to be added to the Material List
    35 */
     35 */
    3636Material::Material (const char* mtlName)
    3737{
     
    105105    glShadeModel(GL_SMOOTH);
    106106
    107   if (this->diffuseTexture)
     107  if (this->diffuseTexture != NULL)
    108108    {
    109109      glEnable(GL_TEXTURE_2D);
  • trunk/src/lib/graphics/importer/texture.cc

    r5305 r5306  
    3333{
    3434  this->setClassID(CL_TEXTURE, "Texture");
     35  this->setName(imageName);
    3536
    3637  this->bAlpha = false;
  • trunk/src/lib/graphics/text_engine.cc

    r5290 r5306  
    4242/// TEXT ///
    4343////////////
     44
     45/**
     46 *  creates a new Text Element
     47 * @param fontFile the Font to render this text in
     48 * @param type The renderType to display this font in
     49 */
     50Text::Text(const char* fontFile, unsigned int fontSize, TEXT_RENDER_TYPE type)
     51{
     52  this->init();
     53
     54  if (fontFile != NULL)
     55    this->setFont(fontFile, fontSize);
     56  this->setType(type);
     57}
     58
    4459/**
    4560 *  creates a new Text Element
    4661 * @param font the Font to render this text in
    4762 * @param type The renderType to display this font in
    48 
    49    this constructor is private, because the user should initialize
    50    a text with the TextEngine.
    51 */
     63 *
     64 * this constructor is private, because the user should initialize
     65 * a text with the TextEngine.
     66 */
    5267Text::Text(Font* font, TEXT_RENDER_TYPE type)
    5368{
     69  this->init();
     70
     71  this->font = font;
     72  this->setType(type);
     73}
     74
     75/**
     76 *  deletes a Text out of memory
     77 *
     78 * This also ereases the text from the textList of the TextEngine
     79*/
     80Text::~Text()
     81{
     82  if (this->font != NULL)
     83    ResourceManager::getInstance()->unload(this->font);
     84
     85  if (this->text)
     86    delete[] this->text;
     87}
     88
     89void Text::init()
     90{
    5491  this->setClassID(CL_TEXT, "Text");
    5592
    5693  // initialize this Text
    57   this->font = font;
     94  this->font = NULL;
    5895  this->text = NULL;
    5996  this->externText = NULL;
     
    6299  this->blending = TEXT_DEFAULT_BLENDING;
    63100  this->color = TEXT_DEFAULT_COLOR;
    64   this->setType(type);
     101  this->setType(TEXT_RENDER_DYNAMIC);
    65102
    66103  this->setText(NULL);
    67 }
    68 
    69 /**
    70  *  deletes a Text out of memory
    71  *
    72  * This also ereases the text from the textList of the TextEngine
    73 */
    74 Text::~Text()
    75 {
    76   if (this->font != NULL)
    77     ResourceManager::getInstance()->unload(this->font);
    78 
    79   if (this->text)
    80     delete[] this->text;
    81104}
    82105
  • trunk/src/lib/graphics/text_engine.h

    r5275 r5306  
    105105class Text : public Element2D
    106106{
     107  friend class TextEngine;
    107108 public:
    108    Text(Font* font = NULL, TEXT_RENDER_TYPE type = TEXT_RENDER_DYNAMIC);
     109   Text(const char* fontFile, unsigned int fontSize = FONT_DEFAULT_SIZE, TEXT_RENDER_TYPE type = TEXT_RENDER_DYNAMIC);
    109110  ~Text();
    110111
    111   void setFont(Font* font);
     112  void init();
     113
    112114  void setFont(const char* fontFile, unsigned int fontSize);
    113115  void setType(TEXT_RENDER_TYPE type);
     
    128130
    129131 private:
    130   static GLuint loadTexture(SDL_Surface* surface, TexCoord* texCoord);
    131   static int powerOfTwo(int input);
     132   Text(Font* font = NULL, TEXT_RENDER_TYPE type = TEXT_RENDER_DYNAMIC);
     133   void setFont(Font* font);
     134
     135   static GLuint loadTexture(SDL_Surface* surface, TexCoord* texCoord);
     136   static int powerOfTwo(int input);
    132137
    133138 private:
  • trunk/src/lib/shell/shell_input.cc

    r5254 r5306  
    4141 * this also generates a ShellCompletion automatically.
    4242*/
    43 ShellInput::ShellInput ()
     43ShellInput::ShellInput () : Text ((const char*)NULL)
    4444{
    4545  this->pressedKey = SDLK_FIRST;
  • trunk/src/util/resource_manager.cc

    r5304 r5306  
    236236 * loads resources
    237237 * @param fileName: The fileName of the resource to load
    238  * @param type: The Type of Resource to load (\see ResourceType)
     238 * @param type: The Type of Resource to load.
    239239 * @param prio: The ResourcePriority of this resource (will only be increased)
    240240 * @param param1: an additional option to parse (see the constuctors for more help)
     
    247247{
    248248  // searching if the resource was loaded before.
    249   Resource* tmpResource = this->locateResourceByInfo(fileName, type, param1, param2,param3);
    250   if (tmpResource) // if the resource was loaded before.
     249  Resource* tmpResource = this->locateResourceByInfo(fileName, type, param1, param2, param3);
     250  if (tmpResource != NULL) // if the resource was loaded before.
    251251    {
    252252      PRINTF(4)("not loading cached resource %s\n", tmpResource->name);
     253      printf("adding %s count: %d\n", tmpResource->pointer->getName(),  tmpResource->count);
    253254      tmpResource->count++;
    254255      if(tmpResource->prio < prio)
     
    307308          if(ResourceManager::isFile(fullName))
    308309            {
    309               if (param1)
     310              if (param1 != NULL)
    310311                {
    311312                  tmpResource->skinFileName = new char[strlen((const char*)param1)+1];
     
    321322        case TTF:
    322323            if (param1)
    323               tmpResource->ttfSize = *(int*)param1;
     324              tmpResource->ttfSize = *(unsigned int*)param1;
    324325            else
    325326              tmpResource->ttfSize = FONT_DEFAULT_SIZE;
    326327
    327328          if(isFile(fullName))
    328             tmpResource->pointer = new Font(fullName,
    329                                             tmpResource->ttfSize);
     329            tmpResource->pointer = new Font(fullName, tmpResource->ttfSize);
    330330          else
    331331            PRINTF(2)("Sorry, %s does not exist. Not loading Font\n", fullName);
     
    375375        default:
    376376          tmpResource->pointer = NULL;
    377           PRINTF(1)("No type found for %s.\n   !!This should not happen unless the Type is not supported yet.!!\n", tmpResource->name);
     377          PRINTF(1)("No type found for %s.\n   !!This should not happen unless the Type is not supported yet. JUST DO IT!!\n", tmpResource->name);
    378378          break;
    379379        }
     
    419419bool ResourceManager::unload(Resource* resource, ResourcePriority prio)
    420420{
     421  if (resource == NULL)
     422    return false;
     423  printf("removing %s count: %d\n", resource->pointer->getName(),  resource->count);
    421424  if (resource->count > 0)
    422425    resource->count--;
     426
    423427  if (resource->prio <= prio)
    424428    {
     
    538542                    match = true;
    539543                }
    540               else if (!strcmp(enumRes->skinFileName, (const char*) param1))
     544              else if (enumRes->skinFileName!= NULL && !strcmp(enumRes->skinFileName, (const char*) param1))
    541545                match = true;
    542546              break;
     
    549553                    subMatch = true;
    550554                }
    551               else if (enumRes->ttfSize == *(int*)param1)
     555              else if (enumRes->ttfSize == *(unsigned int*)param1)
    552556                subMatch = true;
    553557              break;
     
    793797    {
    794798      PRINT(0)("-----------------------------------------\n");
    795       PRINT(0)("Name: %s; References: %d; Type:", enumRes->name, enumRes->count);
    796       switch (enumRes->type)
    797         {
    798 #ifndef NO_MODEL
    799           case OBJ:
    800           PRINT(0)("ObjectModel\n");
    801           break;
    802         case PRIM:
    803           PRINT(0)("PrimitiveModel\n");
    804           break;
    805 #endif
    806 #ifndef NO_TEXTURES
    807         case IMAGE:
    808           PRINT(0)("ImageFile (Texture)\n");
    809           break;
    810 #endif
    811 #ifndef NO_AUDIO
    812         case WAV:
    813           PRINT(0)("SoundFile\n");
    814           break;
    815         case OGG:
    816           PRINT(0)("MusicFile\n");
    817           break;
    818 #endif
    819         default:
    820           PRINT(0)("Do not know this format\n");
    821           break;
    822         }
     799      PRINT(0)("Name: %s; References: %d; Type: %s ", enumRes->name, enumRes->count, ResourceManager::ResourceTypeToChar(enumRes->type));
     800
    823801      PRINT(0)("gets deleted at ");
    824802      switch(enumRes->prio)
     
    846824  PRINT(0)("==================================RM==\n");
    847825}
     826
     827
     828/**
     829 * converts a ResourceType into the corresponding String
     830 * @param type the ResourceType to translate
     831 * @returns the converted String.
     832 */
     833const char* ResourceManager::ResourceTypeToChar(ResourceType type)
     834{
     835  switch (type)
     836  {
     837#ifndef NO_MODEL
     838    case OBJ:
     839      return "ObjectModel";
     840      break;
     841    case PRIM:
     842      return "PrimitiveModel";
     843      break;
     844    case MD2:
     845      return "MD2-Data";
     846      break;
     847#endif
     848#ifndef NO_TEXTURES
     849    case IMAGE:
     850      return "ImageFile (Texture)";
     851      break;
     852#endif
     853#ifndef NO_AUDIO
     854    case WAV:
     855      return "SoundFile";
     856      break;
     857    case OGG:
     858      return "MusicFile";
     859      break;
     860#endif
     861#ifndef NO_TEXT
     862    case TTF:
     863      return "Font (TTF)";
     864      break;
     865#endif
     866    default:
     867      return "unknown Format";
     868      break;
     869  }
     870}
  • trunk/src/util/resource_manager.h

    r5304 r5306  
    106106  bool addImageDir(const char* imageDir);
    107107  BaseObject* load(const char* fileName, ResourcePriority prio = RP_NO,
    108              void* param1 = NULL, void* param2 = NULL, void* param3 = NULL);
     108               void* param1 = NULL, void* param2 = NULL, void* param3 = NULL);
    109109  BaseObject* load(const char* fileName, ResourceType type, ResourcePriority prio = RP_NO,
    110              void* param1 = NULL, void* param2 = NULL, void* param3 = NULL);
     110               void* param1 = NULL, void* param2 = NULL, void* param3 = NULL);
    111111  bool unload(void* pointer, ResourcePriority prio = RP_NO);
    112112  bool unload(Resource* resource, ResourcePriority = RP_NO);
     
    123123  static char* homeDirCheck(const char* fileName);
    124124  static char* getFullName(const char* fileName);
     125
     126  static const char* ResourceTypeToChar(ResourceType type);
    125127
    126128 private:
Note: See TracChangeset for help on using the changeset viewer.