Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: ResourceManager should now be able to compile without some modules

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