Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: Fixed a reversive BUG in the ResourceManager:
Since resources, that depend on each other are loaded left tgo right they must be unlinked right to left… this cost me 3 hours.
What a luck i found this :)

File size: 24.1 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      tmpResource->count++;
254      if(tmpResource->prio < prio)
255        tmpResource->prio = prio;
256    }
257  else
258    {
259      // Setting up the new Resource
260      tmpResource = new Resource;
261      tmpResource->count = 1;
262      tmpResource->type = type;
263      tmpResource->prio = prio;
264      tmpResource->pointer = NULL;
265      tmpResource->name = new char[strlen(fileName)+1];
266      strcpy(tmpResource->name, fileName);
267
268      // creating the full name. (directoryName + FileName)
269      char* fullName = ResourceManager::getFullName(fileName);
270      // Checking for the type of resource \see ResourceType
271      switch(type)
272        {
273#ifndef NO_MODEL
274        case OBJ:
275          if (param1)
276            tmpResource->modelSize = *(float*)param1;
277          else
278            tmpResource->modelSize = 1.0;
279
280          if(ResourceManager::isFile(fullName))
281            tmpResource->pointer = new OBJModel(fullName, tmpResource->modelSize);
282          else
283            {
284              PRINTF(2)("Sorry, %s does not exist. Loading a cube-Model instead\n", fullName);
285              tmpResource->pointer = ResourceManager::load("cube", PRIM, prio, &tmpResource->modelSize);
286            }
287          break;
288        case PRIM:
289          if (param1)
290            tmpResource->modelSize = *(float*)param1;
291          else
292            tmpResource->modelSize = 1.0;
293
294          if (!strcmp(tmpResource->name, "cube"))
295            tmpResource->pointer = new PrimitiveModel(PRIM_CUBE, tmpResource->modelSize);
296          else if (!strcmp(tmpResource->name, "sphere"))
297            tmpResource->pointer = new PrimitiveModel(PRIM_SPHERE, tmpResource->modelSize);
298          else if (!strcmp(tmpResource->name, "plane"))
299            tmpResource->pointer = new PrimitiveModel(PRIM_PLANE, tmpResource->modelSize);
300          else if (!strcmp(tmpResource->name, "cylinder"))
301            tmpResource->pointer = new PrimitiveModel(PRIM_CYLINDER, tmpResource->modelSize);
302          else if (!strcmp(tmpResource->name, "cone"))
303            tmpResource->pointer = new PrimitiveModel(PRIM_CONE, tmpResource->modelSize);
304          break;
305        case MD2:
306          if(ResourceManager::isFile(fullName))
307            {
308              if (param1 != NULL)
309                {
310                  tmpResource->skinFileName = new char[strlen((const char*)param1)+1];
311                  strcpy(tmpResource->skinFileName, (const char*) param1);
312                }
313              else
314                tmpResource->skinFileName = NULL;
315              tmpResource->pointer = new MD2Data(fullName, tmpResource->skinFileName);
316            }
317              break;
318#endif /* NO_MODEL */
319#ifndef NO_TEXT
320        case TTF:
321            if (param1 != NULL)
322              tmpResource->ttfSize = *(unsigned int*)param1;
323            else
324              tmpResource->ttfSize = FONT_DEFAULT_SIZE;
325
326          if(isFile(fullName))
327            tmpResource->pointer = new Font(fullName, tmpResource->ttfSize);
328          else
329            PRINTF(2)("Sorry, %s does not exist. Not loading Font\n", fullName);
330          break;
331#endif /* NO_TEXT */
332#ifndef NO_AUDIO
333        case WAV:
334          if(isFile(fullName))
335            tmpResource->pointer = new SoundBuffer(fullName);
336          break;
337        case OGG:
338          if (isFile(fullName))
339            tmpResource->pointer = new OggPlayer(fullName);
340          break;
341#endif /* NO_AUDIO */
342#ifndef NO_TEXTURES
343        case IMAGE:
344          if(isFile(fullName))
345            {
346              PRINTF(4)("Image %s resides to %s\n", fileName, fullName);
347              tmpResource->pointer = new Texture(fullName);
348            }
349          else
350            {
351              char* tmpDir;
352              tIterator<char>* iterator = imageDirs->getIterator();
353              tmpDir = iterator->firstElement();
354              while(tmpDir)
355                {
356                  char* imgName = new char[strlen(tmpDir)+strlen(fileName)+1];
357                  sprintf(imgName, "%s%s", tmpDir, fileName);
358                  if(isFile(imgName))
359                    {
360                      PRINTF(4)("Image %s resides to %s\n", fileName, imgName);
361                      tmpResource->pointer = new Texture(imgName);
362                      delete[] imgName;
363                      break;
364                    }
365                  delete[] imgName;
366                  tmpDir = iterator->nextElement();
367                }
368              delete iterator;
369            }
370          if(!tmpResource)
371             PRINTF(2)("!!Image %s not Found!!\n", fileName);
372          break;
373#endif /* NO_TEXTURES */
374        default:
375          tmpResource->pointer = NULL;
376          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);
377          break;
378        }
379      if (tmpResource->pointer != NULL)
380        this->resourceList->add(tmpResource);
381      delete[] fullName;
382    }
383  if (tmpResource->pointer != NULL)
384    return tmpResource->pointer;
385  else
386    {
387      PRINTF(2)("Resource %s could not be loaded\n", fileName);
388      delete[] tmpResource->name;
389      delete tmpResource;
390      return NULL;
391    }
392}
393
394/**
395 * unloads a Resource
396 * @param pointer: The pointer to free
397 * @param prio: the PriorityLevel to unload this resource
398 * @returns true if successful (pointer found, and deleted), false otherwise
399*/
400bool ResourceManager::unload(void* pointer, ResourcePriority prio)
401{
402  // if pointer is existent. and only one resource of this type exists.
403  Resource* tmpResource = this->locateResourceByPointer(pointer);
404  if (tmpResource == NULL)
405    {
406      PRINTF(2)("Resource not Found %p\n", pointer);
407      return false;
408    }
409  else
410    return unload(tmpResource, prio);
411}
412
413/**
414 * unloads a Resource
415 * @param resource: The resource to unloade
416 * @param prio the PriorityLevel to unload this resource
417 * @returns true on success, false otherwise.
418*/
419bool ResourceManager::unload(Resource* resource, ResourcePriority prio)
420{
421  if (resource == NULL)
422    return false;
423  if (resource->count > 0)
424    resource->count--;
425
426  if (resource->prio <= prio)
427    {
428      if (resource->count == 0)
429        {
430          // deleting the Resource
431          switch(resource->type)
432            {
433#ifndef NO_MODEL
434            case OBJ:
435            case PRIM:
436              delete (Model*)resource->pointer;
437              break;
438            case MD2:
439              delete (MD2Data*)resource->pointer;
440              break;
441#endif /* NO_MODEL */
442#ifndef NO_AUDIO
443            case WAV:
444              delete (SoundBuffer*)resource->pointer;
445              break;
446            case OGG:
447              delete (OggPlayer*)resource->pointer;
448              break;
449#endif /* NO_AUDIO */
450#ifndef NO_TEXT
451            case TTF:
452              delete (Font*)resource->pointer;
453              break;
454#endif /* NO_TEXT */
455#ifndef NO_TEXTURES
456            case IMAGE:
457              delete (Texture*)resource->pointer;
458              break;
459#endif /* NO_TEXTURES */
460            default:
461              PRINTF(2)("NOT YET IMPLEMENTED !!FIX FIX!!\n");
462              return false;
463              break;
464            }
465          // deleting the List Entry:
466          PRINTF(4)("Resource %s safely removed.\n", resource->name);
467          delete[] resource->name;
468          this->resourceList->remove(resource);
469          delete resource;
470        }
471      else
472        PRINTF(4)("Resource %s not removed, because there are still %d References to it.\n", resource->name, resource->count);
473    }
474  else
475    PRINTF(4)("not deleting resource %s because DeleteLevel to high\n", resource->name);
476  return true;
477}
478
479
480/**
481 * unloads all alocated Memory of Resources with a pririty lower than prio
482 * @param prio The priority to delete
483*/
484bool ResourceManager::unloadAllByPriority(ResourcePriority prio)
485{
486  tIterator<Resource>* iterator = resourceList->getIterator();
487  Resource* enumRes = iterator->lastElement();
488  while (enumRes)
489    {
490      if (enumRes->prio <= prio)
491        if (enumRes->count == 0)
492          unload(enumRes, prio);
493        else
494          PRINTF(2)("unable to unload %s because there are still %d references to it\n",
495                   enumRes->name, enumRes->count);
496      //enumRes = resourceList->nextElement();
497      enumRes = iterator->prevElement();
498    }
499  delete iterator;
500}
501
502/**
503 * Searches for a Resource by some information
504 * @param fileName: The name to look for
505 * @param type the Type of resource to locate.
506 * @param param1: an additional option to parse (see the constuctors for more help)
507 * @param param2: an additional option to parse (see the constuctors for more help)
508 * @param param3: an additional option to parse (see the constuctors for more help)
509 * @returns a Pointer to the Resource if found, NULL otherwise.
510*/
511Resource* ResourceManager::locateResourceByInfo(const char* fileName, ResourceType type,
512                                                void* param1, void* param2, void* param3)
513{
514  //  Resource* enumRes = resourceList->enumerate();
515  tIterator<Resource>* iterator = resourceList->getIterator();
516  Resource* enumRes = iterator->firstElement();
517  while (enumRes)
518    {
519      if (enumRes->type == type && !strcmp(fileName, enumRes->name))
520        {
521          bool match = false;
522
523          switch (type)
524            {
525#ifndef NO_MODEL
526            case PRIM:
527            case OBJ:
528              if (!param1)
529                {
530                  if (enumRes->modelSize == 1.0)
531                    match = true;
532                }
533              else if (enumRes->modelSize == *(float*)param1)
534                match = true;
535              break;
536            case MD2:
537              if (!param1)
538                {
539                  if (enumRes->skinFileName == NULL)
540                    match = true;
541                }
542              else if (!strcmp(enumRes->skinFileName, (const char*)param1))
543                match = true;
544              break;
545#endif /* NO_MODEL */
546#ifndef NO_TEXT
547            case TTF:
548              if (param1 == NULL)
549                {
550                  if (enumRes->ttfSize == FONT_DEFAULT_SIZE)
551                    match = true;
552                }
553              else if (enumRes->ttfSize == *(unsigned int*)param1)
554                match = true;
555              break;
556#endif /* NO_TEXT */
557            default:
558              match = true;
559              break;
560            }
561          if (match)
562            {
563              delete iterator;
564              return enumRes;
565            }
566        }
567      enumRes = iterator->nextElement();
568    }
569  delete iterator;
570  return NULL;
571}
572
573/**
574 * Searches for a Resource by Pointer
575 * @param pointer the Pointer to search for
576 * @returns a Pointer to the Resource if found, NULL otherwise.
577*/
578Resource* ResourceManager::locateResourceByPointer(const void* pointer)
579{
580  //  Resource* enumRes = resourceList->enumerate();
581  tIterator<Resource>* iterator = resourceList->getIterator();
582  Resource* enumRes = iterator->firstElement();
583  while (enumRes)
584    {
585      if (pointer == enumRes->pointer)
586        {
587          delete iterator;
588          return enumRes;
589        }
590      enumRes = iterator->nextElement();
591    }
592  delete iterator;
593  return NULL;
594}
595
596/**
597 * Checks if it is a Directory
598 * @param directoryName the Directory to check for
599 * @returns true if it is a directory/symlink false otherwise
600*/
601bool ResourceManager::isDir(const char* directoryName)
602{
603  if (directoryName == NULL)
604    return false;
605
606  char* tmpDirName = NULL;
607  struct stat status;
608
609  // checking for the termination of the string given. If there is a "/" at the end cut it away
610  if (directoryName[strlen(directoryName)-1] == '/' ||
611      directoryName[strlen(directoryName)-1] == '\\')
612    {
613      tmpDirName = new char[strlen(directoryName)+1];
614      strncpy(tmpDirName, directoryName, strlen(directoryName)-1);
615      tmpDirName[strlen(directoryName)-1] = '\0';
616    }
617  else
618    {
619      tmpDirName = new char[strlen(directoryName)+1];
620      strcpy(tmpDirName, directoryName);
621    }
622
623  if(!stat(tmpDirName, &status))
624    {
625      if (status.st_mode & (S_IFDIR
626#ifndef __WIN32__
627                            | S_IFLNK
628#endif
629                            ))
630        {
631          delete[] tmpDirName;
632          return true;
633        }
634      else
635        {
636          delete[] tmpDirName;
637          return false;
638        }
639    }
640  else
641  {
642    delete[] tmpDirName;
643    return false;
644  }
645}
646
647/**
648 * Checks if the file is either a Regular file or a Symlink
649 * @param fileName the File to check for
650 * @returns true if it is a regular file/symlink, false otherwise
651*/
652bool ResourceManager::isFile(const char* fileName)
653{
654  if (fileName == NULL)
655    return false;
656  char* tmpFileName = ResourceManager::homeDirCheck(fileName);
657  // actually checks the File
658  struct stat status;
659  if (!stat(tmpFileName, &status))
660    {
661      if (status.st_mode & (S_IFREG
662#ifndef __WIN32__
663                            | S_IFLNK
664#endif
665                            ))
666        {
667          delete[] tmpFileName;
668          return true;
669        }
670      else
671        {
672          delete[] tmpFileName;
673          return false;
674        }
675    }
676  else
677    {
678      delete[] tmpFileName;
679      return false;
680    }
681}
682
683/**
684 * touches a File on the disk (thereby creating it)
685 * @param fileName The file to touch
686*/
687bool ResourceManager::touchFile(const char* fileName)
688{
689  char* tmpName = ResourceManager::homeDirCheck(fileName);
690  if (tmpName == NULL)
691    return false;
692  FILE* stream;
693  if( (stream = fopen (tmpName, "w")) == NULL)
694    {
695      PRINTF(1)("could not open %s fro writing\n", fileName);
696      delete[] tmpName;
697      return false;
698    }
699  fclose(stream);
700
701  delete[] tmpName;
702}
703
704/**
705 * deletes a File from disk
706 * @param fileName the File to delete
707*/
708bool ResourceManager::deleteFile(const char* fileName)
709{
710  if (fileName == NULL)
711    return false;
712  char* tmpName = ResourceManager::homeDirCheck(fileName);
713  unlink(tmpName);
714  delete[] tmpName;
715}
716
717/**
718 * @param name the Name of the file to check
719 * @returns The name of the file, including the HomeDir
720 * IMPORTANT: this has to be deleted from the outside
721 */
722char* ResourceManager::homeDirCheck(const char* name)
723{
724  if (name == NULL)
725    return NULL;
726  char* retName;
727  if (!strncmp(name, "~/", 2))
728    {
729      char tmpFileName[500];
730#ifdef __WIN32__
731      strcpy(tmpFileName, getenv("USERPROFILE"));
732#else
733      strcpy(tmpFileName, getenv("HOME"));
734#endif
735      retName = new char[strlen(tmpFileName)+strlen(name)];
736      sprintf(retName, "%s%s", tmpFileName, name+1);
737    }
738  else
739    {
740      retName = new char[strlen(name)+1];
741      strcpy(retName, name);
742    }
743  return retName;
744}
745
746/**
747 * @param fileName the Name of the File to check
748 * @returns The full name of the file, including the DataDir, and NULL if the file does not exist
749 * !!IMPORTANT: this has to be deleted from the outside!!
750*/
751char* ResourceManager::getFullName(const char* fileName)
752{
753  if (fileName == NULL)
754    return NULL;
755
756  char* retName = new char[strlen(ResourceManager::getInstance()->getDataDir())
757                           + strlen(fileName) + 1];
758  sprintf(retName, "%s%s", ResourceManager::getInstance()->getDataDir(), fileName);
759  if (ResourceManager::isFile(retName) || ResourceManager::isDir(retName))
760    return retName;
761  else
762    {
763      delete[] retName;
764      return NULL;
765    }
766}
767
768
769/**
770 * outputs debug information about the ResourceManager
771*/
772void ResourceManager::debug() const
773{
774  PRINT(0)("=RM===================================\n");
775  PRINT(0)("= RESOURCE-MANAGER DEBUG INFORMATION =\n");
776  PRINT(0)("======================================\n");
777  // if it is not initialized
778  PRINT(0)(" Reference is: %p\n", ResourceManager::singletonRef);
779  PRINT(0)(" Data-Directory is: %s\n", this->dataDir);
780  PRINT(0)(" List of Image-Directories: ");
781  tIterator<char>* tmpIt = imageDirs->getIterator();
782  char* tmpDir = tmpIt->firstElement();
783  while(tmpDir)
784    {
785      PRINT(0)("%s ",tmpDir);
786      tmpDir = tmpIt->nextElement();
787    }
788  delete tmpIt;
789  PRINT(0)("\n");
790
791  PRINT(0)("List of all stored Resources:\n");
792  tIterator<Resource>* iterator = resourceList->getIterator();
793  Resource* enumRes = iterator->firstElement();
794  while (enumRes)
795    {
796      PRINT(0)("-----------------------------------------\n");
797      PRINT(0)("Name: %s; References: %d; Type: %s ", enumRes->name, enumRes->count, ResourceManager::ResourceTypeToChar(enumRes->type));
798
799      PRINT(0)("gets deleted at ");
800      switch(enumRes->prio)
801        {
802        default:
803        case RP_NO:
804          PRINT(0)("first posibility (0)\n");
805          break;
806        case RP_LEVEL:
807          PRINT(0)("the end of the Level (1)\n");
808          break;
809        case RP_CAMPAIGN:
810          PRINT(0)("the end of the campaign (2)\n");
811          break;
812        case RP_GAME:
813          PRINT(0)("when leaving the game (3)\n");
814          break;
815        }
816      enumRes = iterator->nextElement();
817    }
818  delete iterator;
819
820
821
822  PRINT(0)("==================================RM==\n");
823}
824
825
826/**
827 * converts a ResourceType into the corresponding String
828 * @param type the ResourceType to translate
829 * @returns the converted String.
830 */
831const char* ResourceManager::ResourceTypeToChar(ResourceType type)
832{
833  switch (type)
834  {
835#ifndef NO_MODEL
836    case OBJ:
837      return "ObjectModel";
838      break;
839    case PRIM:
840      return "PrimitiveModel";
841      break;
842    case MD2:
843      return "MD2-Data";
844      break;
845#endif
846#ifndef NO_TEXTURES
847    case IMAGE:
848      return "ImageFile (Texture)";
849      break;
850#endif
851#ifndef NO_AUDIO
852    case WAV:
853      return "SoundFile";
854      break;
855    case OGG:
856      return "MusicFile";
857      break;
858#endif
859#ifndef NO_TEXT
860    case TTF:
861      return "Font (TTF)";
862      break;
863#endif
864    default:
865      return "unknown Format";
866      break;
867  }
868}
Note: See TracBrowser for help on using the repository browser.