Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/util/resource_manager.cc @ 5306

Last change on this file since 5306 was 5306, checked in by bensch, 19 years ago

orxonox/trunk: ResourceManage-fixes

File size: 24.3 KB
Line 
1/*
2   orxonox - the future of 3D-vertical-scrollers
3
4   Copyright (C) 2004 orx
5
6   This program is free software; you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation; either version 2, or (at your option)
9   any later version.
10
11   ### File Specific:
12   main-programmer: Benjamin Grauer
13   co-programmer: Patrick Boenzli
14*/
15
16#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_LOAD
17
18#include "resource_manager.h"
19
20#include "debug.h"
21
22// different resource Types
23#ifndef NO_MODEL
24#include "objModel.h"
25#include "primitive_model.h"
26#include "md2Model.h"
27#endif /* NO_MODEL */
28#ifndef NO_TEXTURES
29#include "texture.h"
30#endif /* NO_TEXTURES */
31#ifndef NO_TEXT
32#include "text_engine.h"
33#endif /* NO_TEXT */
34#ifndef NO_AUDIO
35#include "sound_engine.h"
36#include "ogg_player.h"
37#endif /* NO_AUDIO */
38
39#include "list.h"
40#include "sdlincl.h"
41
42// File Handling Includes
43#include <sys/types.h>
44#include <sys/stat.h>
45#include <unistd.h>
46
47using namespace std;
48
49/**
50 *  standard constructor
51*/
52ResourceManager::ResourceManager ()
53{
54  this->setClassID(CL_RESOURCE_MANAGER, "ResourceManager");
55  this->setName("ResourceManager");
56
57  this->dataDir = NULL;
58  this->setDataDir("./");
59  this->imageDirs = new tList<char>();
60  this->resourceList = new tList<Resource>();
61}
62
63//! Singleton Reference to the ResourceManager
64ResourceManager* ResourceManager::singletonRef = NULL;
65
66/**
67 *  standard destructor
68*/
69ResourceManager::~ResourceManager ()
70{
71  // deleting the Resources-List
72  this->unloadAllByPriority(RP_GAME);
73
74  if (this->resourceList->getSize() > 0)
75    PRINTF(1)("Not removed all Resources, since there are still %d resources registered\n", this->resourceList->getSize());
76
77  delete this->resourceList;
78  // deleting the Directorie Lists
79  tIterator<char>* tmpIt = imageDirs->getIterator();
80  char* tmpDir = tmpIt->firstElement();
81  while(tmpDir)
82    {
83      delete[] tmpDir;
84      tmpDir = tmpIt->nextElement();
85    }
86  delete tmpIt;
87  delete this->imageDirs;
88
89  delete[] this->dataDir;
90
91  ResourceManager::singletonRef = NULL;
92}
93
94/**
95 *  sets the data main directory
96 * @param dataDir the DataDirectory.
97*/
98bool ResourceManager::setDataDir(const char* dataDir)
99{
100  char* realDir = ResourceManager::homeDirCheck(dataDir);
101  if (isDir(realDir))
102    {
103      delete[] this->dataDir;
104      this->dataDir = new char[strlen(realDir)+1];
105      strcpy(this->dataDir, realDir);
106      delete[] realDir;
107      return true;
108    }
109  else
110    {
111      PRINTF(1)("%s is not a Directory, and can not be the Data Directory, leaving as %s \n", realDir, this->dataDir);
112      delete[] realDir;
113      return false;
114    }
115}
116
117/**
118 *  checks for the DataDirectory, by looking if
119 * @param fileInside is inisde??
120*/
121bool ResourceManager::checkDataDir(const char* fileInside)
122{
123  bool retVal;
124  if (!isDir(this->dataDir))
125    {
126      PRINTF(1)("%s is not a directory\n", this->dataDir);
127      return false;
128    }
129
130  char* testFile = new char[strlen(this->dataDir)+strlen(fileInside)+1];
131  sprintf(testFile, "%s%s", this->dataDir, fileInside);
132  retVal = isFile(testFile);
133  delete[] testFile;
134  return retVal;
135}
136
137#ifndef NO_TEXTURES
138/**
139 *  adds a new Path for Images
140 * @param imageDir The path to insert
141 * @returns true, if the Path was well and injected (or already existent within the list)
142   false otherwise
143*/
144bool ResourceManager::addImageDir(const char* imageDir)
145{
146  // check if the param is a Directory
147  if (isDir(imageDir))
148    {
149      // check if the Directory has been added before
150      tIterator<char>* tmpImageDirs = imageDirs->getIterator();
151      char* tmpDir = tmpImageDirs->firstElement();
152      while(tmpDir)
153        {
154          if (!strcmp(tmpDir, imageDir))
155            {
156              PRINTF(4)("Path %s already loaded\n", imageDir);
157              delete tmpImageDirs;
158              return true;
159            }
160          tmpDir = tmpImageDirs->nextElement();
161        }
162      delete tmpImageDirs;
163
164      // adding the directory to the List
165      tmpDir  = new char[strlen(imageDir)+1];
166      strcpy(tmpDir, imageDir);
167      this->imageDirs->add(tmpDir);
168      return true;
169    }
170  else
171    {
172      PRINTF(1)("%s is not a Directory, and can not be added to the Paths of Images\n", dataDir);
173      return false;
174    }
175}
176#endif /* NO_TEXTURES */
177
178/**
179 *  loads resources
180 * @param fileName: The fileName of the resource to load
181 * @param prio: The ResourcePriority of this resource (will only be increased)
182 * @param param1: an additional option to parse (see the constuctors for more help)
183 * @param param2: an additional option to parse (see the constuctors for more help)
184 * @param param3: an additional option to parse (see the constuctors for more help)
185 * @returns a pointer to a desired Resource.
186*/
187BaseObject* ResourceManager::load(const char* fileName, ResourcePriority prio, void* param1, void* param2, void* param3)
188{
189  ResourceType tmpType;
190#ifndef NO_MODEL
191#define __IF_OK
192  if (!strncmp(fileName+(strlen(fileName)-4), ".obj", 4))
193    tmpType = OBJ;
194  else if (!strncmp(fileName+(strlen(fileName)-4), ".md2", 4))
195    tmpType = MD2;
196  else if (!strcmp(fileName, "cube") ||
197           !strcmp(fileName, "sphere") ||
198           !strcmp(fileName, "plane") ||
199           !strcmp(fileName, "cylinder") ||
200           !strcmp(fileName, "cone"))
201    tmpType = PRIM;
202#endif /* NO_MODEL */
203#ifndef NO_AUDIO
204#ifdef __IF_OK
205  else
206#endif
207#define __IF_OK
208  if (!strncmp(fileName+(strlen(fileName)-4), ".wav", 4))
209    tmpType = WAV;
210  else if (!strncmp(fileName+(strlen(fileName)-4), ".mp3", 4))
211    tmpType = MP3;
212  else if (!strncmp(fileName+(strlen(fileName)-4), ".ogg", 4))
213    tmpType = OGG;
214#endif /* NO_AUDIO */
215#ifndef NO_TEXT
216#ifdef __IF_OK
217  else
218#endif
219#define __IF_OK
220 if (!strncmp(fileName+(strlen(fileName)-4), ".ttf", 4))
221    tmpType = TTF;
222#endif /* NO_TEXT */
223#ifndef NO_TEXTURES
224#ifdef __IF_OK
225  else
226#else
227  if
228#endif
229   tmpType = IMAGE;
230#endif /* NO_TEXTURES */
231#undef __IF_OK
232  return this->load(fileName, tmpType, prio, param1, param2, param3);
233}
234
235/**
236 * loads resources
237 * @param fileName: The fileName of the resource to load
238 * @param type: The Type of Resource to load.
239 * @param prio: The ResourcePriority of this resource (will only be increased)
240 * @param param1: an additional option to parse (see the constuctors for more help)
241 * @param param2: an additional option to parse (see the constuctors for more help)
242 * @param param3: an additional option to parse (see the constuctors for more help)
243 * @returns a pointer to a desired Resource.
244*/
245BaseObject* ResourceManager::load(const char* fileName, ResourceType type, ResourcePriority prio,
246                            void* param1, void* param2, void* param3)
247{
248  // searching 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.
251    {
252      PRINTF(4)("not loading cached resource %s\n", tmpResource->name);
253      printf("adding %s count: %d\n", tmpResource->pointer->getName(),  tmpResource->count);
254      tmpResource->count++;
255      if(tmpResource->prio < prio)
256        tmpResource->prio = prio;
257    }
258  else
259    {
260      char* tmpDir;
261      // Setting up the new Resource
262      tmpResource = new Resource;
263      tmpResource->count = 1;
264      tmpResource->type = type;
265      tmpResource->prio = prio;
266      tmpResource->pointer = NULL;
267      tmpResource->name = new char[strlen(fileName)+1];
268      strcpy(tmpResource->name, fileName);
269
270      // creating the full name. (directoryName + FileName)
271      char* fullName = ResourceManager::getFullName(fileName);
272      // Checking for the type of resource \see ResourceType
273      switch(type)
274        {
275#ifndef NO_MODEL
276        case OBJ:
277          if (param1)
278            tmpResource->modelSize = *(float*)param1;
279          else
280            tmpResource->modelSize = 1.0;
281
282          if(ResourceManager::isFile(fullName))
283            tmpResource->pointer = new OBJModel(fullName, tmpResource->modelSize);
284          else
285            {
286              PRINTF(2)("Sorry, %s does not exist. Loading a cube-Model instead\n", fullName);
287              tmpResource->pointer = ResourceManager::load("cube", PRIM, prio, &tmpResource->modelSize);
288            }
289          break;
290        case PRIM:
291          if (param1)
292            tmpResource->modelSize = *(float*)param1;
293          else
294            tmpResource->modelSize = 1.0;
295
296          if (!strcmp(tmpResource->name, "cube"))
297            tmpResource->pointer = new PrimitiveModel(PRIM_CUBE, tmpResource->modelSize);
298          else if (!strcmp(tmpResource->name, "sphere"))
299            tmpResource->pointer = new PrimitiveModel(PRIM_SPHERE, tmpResource->modelSize);
300          else if (!strcmp(tmpResource->name, "plane"))
301            tmpResource->pointer = new PrimitiveModel(PRIM_PLANE, tmpResource->modelSize);
302          else if (!strcmp(tmpResource->name, "cylinder"))
303            tmpResource->pointer = new PrimitiveModel(PRIM_CYLINDER, tmpResource->modelSize);
304          else if (!strcmp(tmpResource->name, "cone"))
305            tmpResource->pointer = new PrimitiveModel(PRIM_CONE, tmpResource->modelSize);
306          break;
307        case MD2:
308          if(ResourceManager::isFile(fullName))
309            {
310              if (param1 != NULL)
311                {
312                  tmpResource->skinFileName = new char[strlen((const char*)param1)+1];
313                  strcpy(tmpResource->skinFileName, (const char*) param1);
314                }
315              else
316                tmpResource->skinFileName = NULL;
317              tmpResource->pointer = new MD2Data(fullName, tmpResource->skinFileName);
318            }
319              break;
320#endif /* NO_MODEL */
321#ifndef NO_TEXT
322        case TTF:
323            if (param1)
324              tmpResource->ttfSize = *(unsigned int*)param1;
325            else
326              tmpResource->ttfSize = FONT_DEFAULT_SIZE;
327
328          if(isFile(fullName))
329            tmpResource->pointer = new Font(fullName, tmpResource->ttfSize);
330          else
331            PRINTF(2)("Sorry, %s does not exist. Not loading Font\n", fullName);
332          break;
333#endif /* NO_TEXT */
334#ifndef NO_AUDIO
335        case WAV:
336          if(isFile(fullName))
337            tmpResource->pointer = new SoundBuffer(fullName);
338          break;
339        case OGG:
340          if (isFile(fullName))
341            tmpResource->pointer = new OggPlayer(fullName);
342          break;
343#endif /* NO_AUDIO */
344#ifndef NO_TEXTURES
345        case IMAGE:
346          if(isFile(fullName))
347            {
348              PRINTF(4)("Image %s resides to %s\n", fileName, fullName);
349              tmpResource->pointer = new Texture(fullName);
350            }
351          else
352            {
353              tIterator<char>* iterator = imageDirs->getIterator();
354              tmpDir = iterator->firstElement();
355              while(tmpDir)
356                {
357                  char* imgName = new char[strlen(tmpDir)+strlen(fileName)+1];
358                  sprintf(imgName, "%s%s", tmpDir, fileName);
359                  if(isFile(imgName))
360                    {
361                      PRINTF(4)("Image %s resides to %s\n", fileName, imgName);
362                      tmpResource->pointer = new Texture(imgName);
363                      delete[] imgName;
364                      break;
365                    }
366                  delete[] imgName;
367                  tmpDir = iterator->nextElement();
368                }
369              delete iterator;
370            }
371          if(!tmpResource)
372             PRINTF(2)("!!Image %s not Found!!\n", fileName);
373          break;
374#endif /* NO_TEXTURES */
375        default:
376          tmpResource->pointer = NULL;
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);
378          break;
379        }
380      if (tmpResource->pointer != NULL)
381        this->resourceList->add(tmpResource);
382      delete[] fullName;
383    }
384  if (tmpResource->pointer != NULL)
385    return tmpResource->pointer;
386  else
387    {
388      PRINTF(2)("Resource %s could not be loaded\n", fileName);
389      delete[] tmpResource->name;
390      delete tmpResource;
391      return NULL;
392    }
393}
394
395/**
396 * unloads a Resource
397 * @param pointer: The pointer to free
398 * @param prio: the PriorityLevel to unload this resource
399 * @returns true if successful (pointer found, and deleted), false otherwise
400*/
401bool ResourceManager::unload(void* pointer, ResourcePriority prio)
402{
403  // if pointer is existent. and only one resource of this type exists.
404  Resource* tmpResource = this->locateResourceByPointer(pointer);
405  if (tmpResource == NULL)
406    {
407      PRINTF(2)("Resource not Found %p\n", pointer);
408      return false;
409    }
410  else
411    unload(tmpResource, prio);
412}
413
414/**
415 * unloads a Resource
416 * @param resource: The resource to unloade
417 * @param prio the PriorityLevel to unload this resource
418*/
419bool ResourceManager::unload(Resource* resource, ResourcePriority prio)
420{
421  if (resource == NULL)
422    return false;
423  printf("removing %s count: %d\n", resource->pointer->getName(),  resource->count);
424  if (resource->count > 0)
425    resource->count--;
426
427  if (resource->prio <= prio)
428    {
429      if (resource->count <= 0)
430        {
431          // deleting the Resource
432          switch(resource->type)
433            {
434#ifndef NO_MODEL
435            case OBJ:
436            case PRIM:
437              delete (Model*)resource->pointer;
438              break;
439            case MD2:
440              delete (MD2Data*)resource->pointer;
441              break;
442#endif /* NO_MODEL */
443#ifndef NO_AUDIO
444            case WAV:
445              delete (SoundBuffer*)resource->pointer;
446              break;
447            case OGG:
448              delete (OggPlayer*)resource->pointer;
449              break;
450#endif /* NO_AUDIO */
451#ifndef NO_TEXT
452            case TTF:
453              delete (Font*)resource->pointer;
454              break;
455#endif /* NO_TEXT */
456#ifndef NO_TEXTURES
457            case IMAGE:
458              delete (Texture*)resource->pointer;
459              break;
460#endif /* NO_TEXTURES */
461            default:
462              PRINTF(2)("NOT YET IMPLEMENTED !!FIX FIX!!\n");
463              return false;
464              break;
465            }
466          // deleting the List Entry:
467          PRINTF(4)("Resource %s safely removed.\n", resource->name);
468          delete[] resource->name;
469          this->resourceList->remove(resource);
470          delete resource;
471        }
472      else
473        PRINTF(4)("Resource %s not removed, because there are still %d References to it.\n", resource->name, resource->count);
474    }
475  else
476    PRINTF(4)("not deleting resource %s because DeleteLevel to high\n", resource->name);
477  return true;
478}
479
480
481/**
482 *  unloads all alocated Memory of Resources with a pririty lower than prio
483 * @param prio The priority to delete
484*/
485bool ResourceManager::unloadAllByPriority(ResourcePriority prio)
486{
487  tIterator<Resource>* iterator = resourceList->getIterator();
488  Resource* enumRes = iterator->firstElement();
489  while (enumRes)
490    {
491      if (enumRes->prio <= prio)
492        if (enumRes->count == 0)
493          unload(enumRes, prio);
494        else
495          PRINTF(2)("unable to unload %s because there are still %d references to it\n",
496                   enumRes->name, enumRes->count);
497      //enumRes = resourceList->nextElement();
498      enumRes = iterator->nextElement();
499    }
500  delete iterator;
501}
502
503/**
504 * Searches for a Resource by some information
505 * @param fileName: The name to look for
506 * @param type the Type of resource to locate.
507 * @param param1: an additional option to parse (see the constuctors for more help)
508 * @param param2: an additional option to parse (see the constuctors for more help)
509 * @param param3: an additional option to parse (see the constuctors for more help)
510 * @returns a Pointer to the Resource if found, NULL otherwise.
511*/
512Resource* ResourceManager::locateResourceByInfo(const char* fileName, ResourceType type,
513                                                void* param1, void* param2, void* param3)
514{
515  //  Resource* enumRes = resourceList->enumerate();
516  tIterator<Resource>* iterator = resourceList->getIterator();
517  Resource* enumRes = iterator->firstElement();
518  while (enumRes)
519    {
520      if (enumRes->type == type && !strcmp(fileName, enumRes->name))
521        {
522          bool match = false;
523          bool subMatch = false;
524
525          switch (type)
526            {
527#ifndef NO_MODEL
528            case PRIM:
529            case OBJ:
530              if (!param1)
531                {
532                  if (enumRes->modelSize == 1.0)
533                    match = true;
534                }
535              else if (enumRes->modelSize == *(float*)param1)
536                match = true;
537              break;
538            case MD2:
539              if (!param1)
540                {
541                  if (enumRes->skinFileName == NULL)
542                    match = true;
543                }
544              else if (enumRes->skinFileName!= NULL && !strcmp(enumRes->skinFileName, (const char*) param1))
545                match = true;
546              break;
547#endif /* NO_MODEL */
548#ifndef NO_TEXT
549            case TTF:
550              if (!param1)
551                {
552                  if (enumRes->ttfSize == FONT_DEFAULT_SIZE)
553                    subMatch = true;
554                }
555              else if (enumRes->ttfSize == *(unsigned int*)param1)
556                subMatch = true;
557              break;
558#endif /* NO_TEXT */
559            default:
560              match = true;
561              break;
562            }
563          if (match)
564            {
565              delete iterator;
566              return enumRes;
567            }
568        }
569      enumRes = iterator->nextElement();
570    }
571  delete iterator;
572  return NULL;
573}
574
575/**
576 * Searches for a Resource by Pointer
577 * @param pointer the Pointer to search for
578 * @returns a Pointer to the Resource if found, NULL otherwise.
579*/
580Resource* ResourceManager::locateResourceByPointer(const void* pointer)
581{
582  //  Resource* enumRes = resourceList->enumerate();
583  tIterator<Resource>* iterator = resourceList->getIterator();
584  Resource* enumRes = iterator->firstElement();
585  while (enumRes)
586    {
587      if (pointer == enumRes->pointer)
588        {
589          delete iterator;
590          return enumRes;
591        }
592      enumRes = iterator->nextElement();
593    }
594  delete iterator;
595  return NULL;
596}
597
598/**
599 * Checks if it is a Directory
600 * @param directoryName the Directory to check for
601 * @returns true if it is a directory/symlink false otherwise
602*/
603bool ResourceManager::isDir(const char* directoryName)
604{
605  if (directoryName == NULL)
606    return false;
607
608  char* tmpDirName = NULL;
609  struct stat status;
610
611  // checking for the termination of the string given. If there is a "/" at the end cut it away
612  if (directoryName[strlen(directoryName)-1] == '/' ||
613      directoryName[strlen(directoryName)-1] == '\\')
614    {
615      tmpDirName = new char[strlen(directoryName)+1];
616      strncpy(tmpDirName, directoryName, strlen(directoryName)-1);
617      tmpDirName[strlen(directoryName)-1] = '\0';
618    }
619  else
620    {
621      tmpDirName = new char[strlen(directoryName)+1];
622      strcpy(tmpDirName, directoryName);
623    }
624
625  if(!stat(tmpDirName, &status))
626    {
627      if (status.st_mode & (S_IFDIR
628#ifndef __WIN32__
629                            | S_IFLNK
630#endif
631                            ))
632        {
633          delete[] tmpDirName;
634          return true;
635        }
636      else
637        {
638          delete[] tmpDirName;
639          return false;
640        }
641    }
642  else
643  {
644    delete[] tmpDirName;
645    return false;
646  }
647}
648
649/**
650 * Checks if the file is either a Regular file or a Symlink
651 * @param fileName the File to check for
652 * @returns true if it is a regular file/symlink, false otherwise
653*/
654bool ResourceManager::isFile(const char* fileName)
655{
656  if (fileName == NULL)
657    return false;
658  char* tmpFileName = ResourceManager::homeDirCheck(fileName);
659  // actually checks the File
660  struct stat status;
661  if (!stat(tmpFileName, &status))
662    {
663      if (status.st_mode & (S_IFREG
664#ifndef __WIN32__
665                            | S_IFLNK
666#endif
667                            ))
668        {
669          delete[] tmpFileName;
670          return true;
671        }
672      else
673        {
674          delete[] tmpFileName;
675          return false;
676        }
677    }
678  else
679    {
680      delete[] tmpFileName;
681      return false;
682    }
683}
684
685/**
686 * touches a File on the disk (thereby creating it)
687 * @param fileName The file to touch
688*/
689bool ResourceManager::touchFile(const char* fileName)
690{
691  char* tmpName = ResourceManager::homeDirCheck(fileName);
692  if (tmpName == NULL)
693    return false;
694  FILE* stream;
695  if( (stream = fopen (tmpName, "w")) == NULL)
696    {
697      PRINTF(1)("could not open %s fro writing\n", fileName);
698      delete[] tmpName;
699      return false;
700    }
701  fclose(stream);
702
703  delete[] tmpName;
704}
705
706/**
707 * deletes a File from disk
708 * @param fileName the File to delete
709*/
710bool ResourceManager::deleteFile(const char* fileName)
711{
712  if (fileName == NULL)
713    return false;
714  char* tmpName = ResourceManager::homeDirCheck(fileName);
715  unlink(tmpName);
716  delete[] tmpName;
717}
718
719/**
720 * @param name the Name of the file to check
721 * @returns The name of the file, including the HomeDir
722 * IMPORTANT: this has to be deleted from the outside
723 */
724char* ResourceManager::homeDirCheck(const char* name)
725{
726  if (name == NULL)
727    return NULL;
728  char* retName;
729  if (!strncmp(name, "~/", 2))
730    {
731      char tmpFileName[500];
732#ifdef __WIN32__
733      strcpy(tmpFileName, getenv("USERPROFILE"));
734#else
735      strcpy(tmpFileName, getenv("HOME"));
736#endif
737      retName = new char[strlen(tmpFileName)+strlen(name)];
738      sprintf(retName, "%s%s", tmpFileName, name+1);
739    }
740  else
741    {
742      retName = new char[strlen(name)+1];
743      strcpy(retName, name);
744    }
745  return retName;
746}
747
748/**
749 * @param fileName the Name of the File to check
750 * @returns The full name of the file, including the DataDir, and NULL if the file does not exist
751 * !!IMPORTANT: this has to be deleted from the outside!!
752*/
753char* ResourceManager::getFullName(const char* fileName)
754{
755  if (fileName == NULL)
756    return NULL;
757
758  char* retName = new char[strlen(ResourceManager::getInstance()->getDataDir())
759                           + strlen(fileName) + 1];
760  sprintf(retName, "%s%s", ResourceManager::getInstance()->getDataDir(), fileName);
761  if (ResourceManager::isFile(retName) || ResourceManager::isDir(retName))
762    return retName;
763  else
764    {
765      delete[] retName;
766      return NULL;
767    }
768}
769
770
771/**
772 * outputs debug information about the ResourceManager
773*/
774void ResourceManager::debug() const
775{
776  PRINT(0)("=RM===================================\n");
777  PRINT(0)("= RESOURCE-MANAGER DEBUG INFORMATION =\n");
778  PRINT(0)("======================================\n");
779  // if it is not initialized
780  PRINT(0)(" Reference is: %p\n", ResourceManager::singletonRef);
781  PRINT(0)(" Data-Directory is: %s\n", this->dataDir);
782  PRINT(0)(" List of Image-Directories: ");
783  tIterator<char>* tmpIt = imageDirs->getIterator();
784  char* tmpDir = tmpIt->firstElement();
785  while(tmpDir)
786    {
787      PRINT(0)("%s ",tmpDir);
788      tmpDir = tmpIt->nextElement();
789    }
790  delete tmpIt;
791  PRINT(0)("\n");
792
793  PRINT(0)("List of all stored Resources:\n");
794  tIterator<Resource>* iterator = resourceList->getIterator();
795  Resource* enumRes = iterator->firstElement();
796  while (enumRes)
797    {
798      PRINT(0)("-----------------------------------------\n");
799      PRINT(0)("Name: %s; References: %d; Type: %s ", enumRes->name, enumRes->count, ResourceManager::ResourceTypeToChar(enumRes->type));
800
801      PRINT(0)("gets deleted at ");
802      switch(enumRes->prio)
803        {
804        default:
805        case RP_NO:
806          PRINT(0)("first posibility (0)\n");
807          break;
808        case RP_LEVEL:
809          PRINT(0)("the end of the Level (1)\n");
810          break;
811        case RP_CAMPAIGN:
812          PRINT(0)("the end of the campaign (2)\n");
813          break;
814        case RP_GAME:
815          PRINT(0)("when leaving the game (3)\n");
816          break;
817        }
818      enumRes = iterator->nextElement();
819    }
820  delete iterator;
821
822
823
824  PRINT(0)("==================================RM==\n");
825}
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}
Note: See TracBrowser for help on using the repository browser.