Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: ResourceManager removed obsolete subMatch. This was a Bug

File size: 24.2 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      // Setting up the new Resource
261      tmpResource = new Resource;
262      tmpResource->count = 1;
263      tmpResource->type = type;
264      tmpResource->prio = prio;
265      tmpResource->pointer = NULL;
266      tmpResource->name = new char[strlen(fileName)+1];
267      strcpy(tmpResource->name, fileName);
268
269      // creating the full name. (directoryName + FileName)
270      char* fullName = ResourceManager::getFullName(fileName);
271      // Checking for the type of resource \see ResourceType
272      switch(type)
273        {
274#ifndef NO_MODEL
275        case OBJ:
276          if (param1)
277            tmpResource->modelSize = *(float*)param1;
278          else
279            tmpResource->modelSize = 1.0;
280
281          if(ResourceManager::isFile(fullName))
282            tmpResource->pointer = new OBJModel(fullName, tmpResource->modelSize);
283          else
284            {
285              PRINTF(2)("Sorry, %s does not exist. Loading a cube-Model instead\n", fullName);
286              tmpResource->pointer = ResourceManager::load("cube", PRIM, prio, &tmpResource->modelSize);
287            }
288          break;
289        case PRIM:
290          if (param1)
291            tmpResource->modelSize = *(float*)param1;
292          else
293            tmpResource->modelSize = 1.0;
294
295          if (!strcmp(tmpResource->name, "cube"))
296            tmpResource->pointer = new PrimitiveModel(PRIM_CUBE, tmpResource->modelSize);
297          else if (!strcmp(tmpResource->name, "sphere"))
298            tmpResource->pointer = new PrimitiveModel(PRIM_SPHERE, tmpResource->modelSize);
299          else if (!strcmp(tmpResource->name, "plane"))
300            tmpResource->pointer = new PrimitiveModel(PRIM_PLANE, tmpResource->modelSize);
301          else if (!strcmp(tmpResource->name, "cylinder"))
302            tmpResource->pointer = new PrimitiveModel(PRIM_CYLINDER, tmpResource->modelSize);
303          else if (!strcmp(tmpResource->name, "cone"))
304            tmpResource->pointer = new PrimitiveModel(PRIM_CONE, tmpResource->modelSize);
305          break;
306        case MD2:
307          if(ResourceManager::isFile(fullName))
308            {
309              if (param1 != NULL)
310                {
311                  tmpResource->skinFileName = new char[strlen((const char*)param1)+1];
312                  strcpy(tmpResource->skinFileName, (const char*) param1);
313                }
314              else
315                tmpResource->skinFileName = NULL;
316              tmpResource->pointer = new MD2Data(fullName, tmpResource->skinFileName);
317            }
318              break;
319#endif /* NO_MODEL */
320#ifndef NO_TEXT
321        case TTF:
322            if (param1 != NULL)
323              tmpResource->ttfSize = *(unsigned int*)param1;
324            else
325              tmpResource->ttfSize = FONT_DEFAULT_SIZE;
326
327          if(isFile(fullName))
328            tmpResource->pointer = new Font(fullName, tmpResource->ttfSize);
329          else
330            PRINTF(2)("Sorry, %s does not exist. Not loading Font\n", fullName);
331          break;
332#endif /* NO_TEXT */
333#ifndef NO_AUDIO
334        case WAV:
335          if(isFile(fullName))
336            tmpResource->pointer = new SoundBuffer(fullName);
337          break;
338        case OGG:
339          if (isFile(fullName))
340            tmpResource->pointer = new OggPlayer(fullName);
341          break;
342#endif /* NO_AUDIO */
343#ifndef NO_TEXTURES
344        case IMAGE:
345          if(isFile(fullName))
346            {
347              PRINTF(4)("Image %s resides to %s\n", fileName, fullName);
348              tmpResource->pointer = new Texture(fullName);
349            }
350          else
351            {
352              char* tmpDir;
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
524          switch (type)
525            {
526#ifndef NO_MODEL
527            case PRIM:
528            case OBJ:
529              if (!param1)
530                {
531                  if (enumRes->modelSize == 1.0)
532                    match = true;
533                }
534              else if (enumRes->modelSize == *(float*)param1)
535                match = true;
536              break;
537            case MD2:
538              if (!param1)
539                {
540                  if (enumRes->skinFileName == NULL)
541                    match = true;
542                }
543              else if (!strcmp(enumRes->skinFileName, (const char*)param1))
544                match = true;
545              break;
546#endif /* NO_MODEL */
547#ifndef NO_TEXT
548            case TTF:
549              if (param1 == NULL)
550                {
551                  if (enumRes->ttfSize == FONT_DEFAULT_SIZE)
552                    match = true;
553                }
554              else if (enumRes->ttfSize == *(unsigned int*)param1)
555                match = true;
556              break;
557#endif /* NO_TEXT */
558            default:
559              match = true;
560              break;
561            }
562          if (match)
563            {
564              delete iterator;
565              return enumRes;
566            }
567        }
568      enumRes = iterator->nextElement();
569    }
570  delete iterator;
571  return NULL;
572}
573
574/**
575 * Searches for a Resource by Pointer
576 * @param pointer the Pointer to search for
577 * @returns a Pointer to the Resource if found, NULL otherwise.
578*/
579Resource* ResourceManager::locateResourceByPointer(const void* pointer)
580{
581  //  Resource* enumRes = resourceList->enumerate();
582  tIterator<Resource>* iterator = resourceList->getIterator();
583  Resource* enumRes = iterator->firstElement();
584  while (enumRes)
585    {
586      if (pointer == enumRes->pointer)
587        {
588          delete iterator;
589          return enumRes;
590        }
591      enumRes = iterator->nextElement();
592    }
593  delete iterator;
594  return NULL;
595}
596
597/**
598 * Checks if it is a Directory
599 * @param directoryName the Directory to check for
600 * @returns true if it is a directory/symlink false otherwise
601*/
602bool ResourceManager::isDir(const char* directoryName)
603{
604  if (directoryName == NULL)
605    return false;
606
607  char* tmpDirName = NULL;
608  struct stat status;
609
610  // checking for the termination of the string given. If there is a "/" at the end cut it away
611  if (directoryName[strlen(directoryName)-1] == '/' ||
612      directoryName[strlen(directoryName)-1] == '\\')
613    {
614      tmpDirName = new char[strlen(directoryName)+1];
615      strncpy(tmpDirName, directoryName, strlen(directoryName)-1);
616      tmpDirName[strlen(directoryName)-1] = '\0';
617    }
618  else
619    {
620      tmpDirName = new char[strlen(directoryName)+1];
621      strcpy(tmpDirName, directoryName);
622    }
623
624  if(!stat(tmpDirName, &status))
625    {
626      if (status.st_mode & (S_IFDIR
627#ifndef __WIN32__
628                            | S_IFLNK
629#endif
630                            ))
631        {
632          delete[] tmpDirName;
633          return true;
634        }
635      else
636        {
637          delete[] tmpDirName;
638          return false;
639        }
640    }
641  else
642  {
643    delete[] tmpDirName;
644    return false;
645  }
646}
647
648/**
649 * Checks if the file is either a Regular file or a Symlink
650 * @param fileName the File to check for
651 * @returns true if it is a regular file/symlink, false otherwise
652*/
653bool ResourceManager::isFile(const char* fileName)
654{
655  if (fileName == NULL)
656    return false;
657  char* tmpFileName = ResourceManager::homeDirCheck(fileName);
658  // actually checks the File
659  struct stat status;
660  if (!stat(tmpFileName, &status))
661    {
662      if (status.st_mode & (S_IFREG
663#ifndef __WIN32__
664                            | S_IFLNK
665#endif
666                            ))
667        {
668          delete[] tmpFileName;
669          return true;
670        }
671      else
672        {
673          delete[] tmpFileName;
674          return false;
675        }
676    }
677  else
678    {
679      delete[] tmpFileName;
680      return false;
681    }
682}
683
684/**
685 * touches a File on the disk (thereby creating it)
686 * @param fileName The file to touch
687*/
688bool ResourceManager::touchFile(const char* fileName)
689{
690  char* tmpName = ResourceManager::homeDirCheck(fileName);
691  if (tmpName == NULL)
692    return false;
693  FILE* stream;
694  if( (stream = fopen (tmpName, "w")) == NULL)
695    {
696      PRINTF(1)("could not open %s fro writing\n", fileName);
697      delete[] tmpName;
698      return false;
699    }
700  fclose(stream);
701
702  delete[] tmpName;
703}
704
705/**
706 * deletes a File from disk
707 * @param fileName the File to delete
708*/
709bool ResourceManager::deleteFile(const char* fileName)
710{
711  if (fileName == NULL)
712    return false;
713  char* tmpName = ResourceManager::homeDirCheck(fileName);
714  unlink(tmpName);
715  delete[] tmpName;
716}
717
718/**
719 * @param name the Name of the file to check
720 * @returns The name of the file, including the HomeDir
721 * IMPORTANT: this has to be deleted from the outside
722 */
723char* ResourceManager::homeDirCheck(const char* name)
724{
725  if (name == NULL)
726    return NULL;
727  char* retName;
728  if (!strncmp(name, "~/", 2))
729    {
730      char tmpFileName[500];
731#ifdef __WIN32__
732      strcpy(tmpFileName, getenv("USERPROFILE"));
733#else
734      strcpy(tmpFileName, getenv("HOME"));
735#endif
736      retName = new char[strlen(tmpFileName)+strlen(name)];
737      sprintf(retName, "%s%s", tmpFileName, name+1);
738    }
739  else
740    {
741      retName = new char[strlen(name)+1];
742      strcpy(retName, name);
743    }
744  return retName;
745}
746
747/**
748 * @param fileName the Name of the File to check
749 * @returns The full name of the file, including the DataDir, and NULL if the file does not exist
750 * !!IMPORTANT: this has to be deleted from the outside!!
751*/
752char* ResourceManager::getFullName(const char* fileName)
753{
754  if (fileName == NULL)
755    return NULL;
756
757  char* retName = new char[strlen(ResourceManager::getInstance()->getDataDir())
758                           + strlen(fileName) + 1];
759  sprintf(retName, "%s%s", ResourceManager::getInstance()->getDataDir(), fileName);
760  if (ResourceManager::isFile(retName) || ResourceManager::isDir(retName))
761    return retName;
762  else
763    {
764      delete[] retName;
765      return NULL;
766    }
767}
768
769
770/**
771 * outputs debug information about the ResourceManager
772*/
773void ResourceManager::debug() const
774{
775  PRINT(0)("=RM===================================\n");
776  PRINT(0)("= RESOURCE-MANAGER DEBUG INFORMATION =\n");
777  PRINT(0)("======================================\n");
778  // if it is not initialized
779  PRINT(0)(" Reference is: %p\n", ResourceManager::singletonRef);
780  PRINT(0)(" Data-Directory is: %s\n", this->dataDir);
781  PRINT(0)(" List of Image-Directories: ");
782  tIterator<char>* tmpIt = imageDirs->getIterator();
783  char* tmpDir = tmpIt->firstElement();
784  while(tmpDir)
785    {
786      PRINT(0)("%s ",tmpDir);
787      tmpDir = tmpIt->nextElement();
788    }
789  delete tmpIt;
790  PRINT(0)("\n");
791
792  PRINT(0)("List of all stored Resources:\n");
793  tIterator<Resource>* iterator = resourceList->getIterator();
794  Resource* enumRes = iterator->firstElement();
795  while (enumRes)
796    {
797      PRINT(0)("-----------------------------------------\n");
798      PRINT(0)("Name: %s; References: %d; Type: %s ", enumRes->name, enumRes->count, ResourceManager::ResourceTypeToChar(enumRes->type));
799
800      PRINT(0)("gets deleted at ");
801      switch(enumRes->prio)
802        {
803        default:
804        case RP_NO:
805          PRINT(0)("first posibility (0)\n");
806          break;
807        case RP_LEVEL:
808          PRINT(0)("the end of the Level (1)\n");
809          break;
810        case RP_CAMPAIGN:
811          PRINT(0)("the end of the campaign (2)\n");
812          break;
813        case RP_GAME:
814          PRINT(0)("when leaving the game (3)\n");
815          break;
816        }
817      enumRes = iterator->nextElement();
818    }
819  delete iterator;
820
821
822
823  PRINT(0)("==================================RM==\n");
824}
825
826
827/**
828 * converts a ResourceType into the corresponding String
829 * @param type the ResourceType to translate
830 * @returns the converted String.
831 */
832const char* ResourceManager::ResourceTypeToChar(ResourceType type)
833{
834  switch (type)
835  {
836#ifndef NO_MODEL
837    case OBJ:
838      return "ObjectModel";
839      break;
840    case PRIM:
841      return "PrimitiveModel";
842      break;
843    case MD2:
844      return "MD2-Data";
845      break;
846#endif
847#ifndef NO_TEXTURES
848    case IMAGE:
849      return "ImageFile (Texture)";
850      break;
851#endif
852#ifndef NO_AUDIO
853    case WAV:
854      return "SoundFile";
855      break;
856    case OGG:
857      return "MusicFile";
858      break;
859#endif
860#ifndef NO_TEXT
861    case TTF:
862      return "Font (TTF)";
863      break;
864#endif
865    default:
866      return "unknown Format";
867      break;
868  }
869}
Note: See TracBrowser for help on using the repository browser.