Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5335 in orxonox.OLD


Ignore:
Timestamp:
Oct 9, 2005, 1:27:58 AM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: more fool-proov loading of important paths (data and image)

Location:
trunk/src
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/graphics/shader.cc

    r5333 r5335  
    234234void Shader::deleteProgram(SHADER_TYPE type)
    235235{
    236   GLint status;
     236  GLint status = 0;
    237237  if (type == SHADER_VERTEX && this->vertexShader != 0)
    238238  {
  • trunk/src/lib/shell/shell.cc

    r5329 r5335  
    5656  this->setName("Shell");
    5757
    58   // register the shell at the ShellBuffer
    59   ShellBuffer::getInstance()->registerShell(this);
    6058  // EVENT-Handler subscription of '`' to all States.
    6159  EventHandler::getInstance()->subscribe(this, ES_ALL, SDLK_BACKQUOTE);
     
    8280
    8381  this->rebuildText();
     82
     83  // register the shell at the ShellBuffer
     84  ShellBuffer::getInstance()->registerShell(this);
    8485}
    8586
     
    8990Shell::~Shell ()
    9091{
     92  ShellBuffer::getInstance()->unregisterShell(this);
     93
    9194  // delete the displayable Buffers
    9295  for (unsigned int i = 0; i < this->bufferDisplaySize; i++)
     
    97100  // delete the inputLine
    98101  delete this->shellInput;
    99 
    100   ShellBuffer::getInstance()->unregisterShell(this);
    101102}
    102103
     
    158159void Shell::setFont(const char* fontFile)
    159160{
     161//   if (!ResourceManager::isInDataDir(fontFile))
     162//     return false;
     163
    160164  if (this->fontFile != NULL)
    161165    delete[] this->fontFile;
  • trunk/src/orxonox.cc

    r5332 r5335  
    282282  }
    283283   //! @todo this is a hack and should be loadable
    284   char* imageDir = ResourceManager::getInstance()->getFullName("maps/");
     284  char* imageDir = ResourceManager::getInstance()->getFullName("maps");
    285285  ResourceManager::getInstance()->addImageDir(imageDir);
    286286  delete[] imageDir;
  • trunk/src/util/resource_manager.cc

    r5334 r5335  
    6060  this->dataDir = NULL;
    6161  this->setDataDir("./");
    62   this->imageDirs = new tList<char>();
    63   this->resourceList = new tList<Resource>();
     62  this->imageDirs = new tList<char>;
     63  this->resourceList = new tList<Resource>;
    6464}
    6565
     
    105105    {
    106106      delete[] this->dataDir;
    107       this->dataDir = new char[strlen(realDir)+1];
    108       strcpy(this->dataDir, realDir);
     107      if (dataDir[strlen(dataDir)-1] == '/' || dataDir[strlen(dataDir)-1] == '\\')
     108      {
     109        this->dataDir = new char[strlen(realDir)+1];
     110        strcpy(this->dataDir, realDir);
     111      }
     112      else
     113      {
     114        this->dataDir = new char[strlen(realDir)+2];
     115        strcpy(this->dataDir, realDir);
     116        this->dataDir[strlen(realDir)] = '/';
     117        this->dataDir[strlen(realDir)+1] = '\0';
     118      }
    109119      delete[] realDir;
    110120      return true;
     
    147157bool ResourceManager::addImageDir(const char* imageDir)
    148158{
     159  if (imageDir == NULL)
     160    return false;
     161
     162  char* newDir;
     163  if (imageDir[strlen(imageDir)-1] == '/' || imageDir[strlen(imageDir)-1] == '\\')
     164  {
     165    newDir = new char[strlen(imageDir)+1];
     166    strcpy(newDir, imageDir);
     167  }
     168  else
     169  {
     170    newDir = new char[strlen(imageDir)+2];
     171    strcpy(newDir, imageDir);
     172    newDir[strlen(imageDir)] = '/';
     173    newDir[strlen(imageDir)+1] = '\0';
     174  }
    149175  // check if the param is a Directory
    150   if (isDir(imageDir))
     176  if (isDir(newDir))
    151177    {
    152178      // check if the Directory has been added before
     
    155181      while(tmpDir)
    156182        {
    157           if (!strcmp(tmpDir, imageDir))
     183          if (!strcmp(tmpDir, newDir))
    158184            {
    159               PRINTF(4)("Path %s already loaded\n", imageDir);
     185              PRINTF(3)("Path %s already loaded\n", newDir);
     186              delete[] newDir;
    160187              delete tmpImageDirs;
    161188              return true;
     
    166193
    167194      // adding the directory to the List
    168       tmpDir  = new char[strlen(imageDir)+1];
    169       strcpy(tmpDir, imageDir);
    170       this->imageDirs->add(tmpDir);
     195      this->imageDirs->add(newDir);
    171196      return true;
    172197    }
    173198  else
    174199    {
    175       PRINTF(1)("%s is not a Directory, and can not be added to the Paths of Images\n", dataDir);
     200      PRINTF(1)("%s is not a Directory, and can not be added to the Paths of Images\n", newDir);
     201      delete[] newDir;
    176202      return false;
    177203    }
     
    660686      directoryName[strlen(directoryName)-1] == '\\')
    661687    {
    662       tmpDirName = new char[strlen(directoryName)+1];
     688      tmpDirName = new char[strlen(directoryName)];
    663689      strncpy(tmpDirName, directoryName, strlen(directoryName)-1);
    664690      tmpDirName[strlen(directoryName)-1] = '\0';
     
    800826char* ResourceManager::getFullName(const char* fileName)
    801827{
    802   if (fileName == NULL)
     828  if (fileName == NULL || ResourceManager::getInstance()->getDataDir() == NULL)
    803829    return NULL;
    804830
     
    813839      return NULL;
    814840    }
     841}
     842
     843
     844/**
     845 * checks wether a file is in the DataDir.
     846 * @param fileName the File to check if it is in the Data-Dir structure.
     847 * @returns true if the file exists, false otherwise
     848 */
     849bool ResourceManager::isInDataDir(const char* fileName)
     850{
     851  if (fileName == NULL || ResourceManager::getInstance()->getDataDir() == NULL)
     852    return false;
     853
     854  bool retVal = false;
     855  char* checkFile = new char[strlen(ResourceManager::getInstance()->getDataDir())
     856      + strlen(fileName) + 1];
     857  sprintf(checkFile, "%s%s", ResourceManager::getInstance()->getDataDir(), fileName);
     858
     859  if (ResourceManager::isFile(checkFile) || ResourceManager::isDir(checkFile))
     860    retVal = true;
     861  else
     862    retVal = false;
     863  delete[] checkFile;
     864  return retVal;
    815865}
    816866
  • trunk/src/util/resource_manager.h

    r5323 r5335  
    108108
    109109  bool checkDataDir(const char* fileInside);
    110   bool addImageDir(const char* imageDir);
     110 bool addImageDir(const char* imageDir);
    111111  BaseObject* load(const char* fileName, ResourcePriority prio = RP_NO,
    112112               void* param1 = NULL, void* param2 = NULL, void* param3 = NULL);
     
    127127  static char* homeDirCheck(const char* fileName);
    128128  static char* getFullName(const char* fileName);
     129  static bool isInDataDir(const char* fileName);
    129130
    130131  static const char* ResourceTypeToChar(ResourceType type);
  • trunk/src/util/track/track_manager.cc

    r5313 r5335  
    900900 * @param count The count of Paths to join.
    901901 * @param trackIDs an Array with the trackID's to join
    902 
    903    \see void TrackManager::join(unsigned int count, ...)
     902 *
     903 * @see void TrackManager::join(unsigned int count, ...)
    904904*/
    905905void TrackManager::joinV(unsigned int count, int* trackIDs)
Note: See TracChangeset for help on using the changeset viewer.