Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 3658 in orxonox.OLD for orxonox


Ignore:
Timestamp:
Mar 27, 2005, 7:44:39 PM (20 years ago)
Author:
bensch
Message:

orxonox/trunk: resource manager working, player uses it.

Location:
orxonox/trunk/src
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • orxonox/trunk/src/glmenu/glmenu_imagescreen.cc

    r3544 r3658  
    8181  // Select Our VU Meter Background Texture
    8282  this->backMat = new Material("load_screen");
    83   this->backMat->setDiffuseMap("../data/pictures/load_screen.jpg");
     83  this->backMat->setDiffuseMap("pictures/load_screen.jpg");
    8484  this->maxValue = 10;
    8585  this->currentValue = 0;
  • orxonox/trunk/src/lib/graphics/importer/Makefile.am

    r3657 r3658  
    3333                  $(MAINSRCDIR)/lib/graphics/graphics_engine.cc \
    3434                  $(MAINSRCDIR)/lib/lang/base_object.cc \
    35                   $(MAINSRCDIR)/lib/math/vector.cc
     35                  $(MAINSRCDIR)/lib/math/vector.cc \
     36                  $(MAINSRCDIR)/lib/util/resource_manager.cc
    3637
    3738noinst_HEADERS= framework.h \
  • orxonox/trunk/src/lib/graphics/importer/Makefile.in

    r3657 r3658  
    5757        array.$(OBJEXT) material.$(OBJEXT) texture.$(OBJEXT) \
    5858        graphics_engine.$(OBJEXT) base_object.$(OBJEXT) \
    59         vector.$(OBJEXT)
     59        vector.$(OBJEXT) resource_manager.$(OBJEXT)
    6060importer_OBJECTS = $(am_importer_OBJECTS)
    6161importer_LDADD = $(LDADD)
     
    7070@AMDEP_TRUE@    ./$(DEPDIR)/objModel.Po \
    7171@AMDEP_TRUE@    ./$(DEPDIR)/primitive_model.Po \
     72@AMDEP_TRUE@    ./$(DEPDIR)/resource_manager.Po \
    7273@AMDEP_TRUE@    ./$(DEPDIR)/texture.Po ./$(DEPDIR)/vector.Po \
    7374@AMDEP_TRUE@    ./$(DEPDIR)/windowHandler.Po
     
    204205                  $(MAINSRCDIR)/lib/graphics/graphics_engine.cc \
    205206                  $(MAINSRCDIR)/lib/lang/base_object.cc \
    206                   $(MAINSRCDIR)/lib/math/vector.cc
     207                  $(MAINSRCDIR)/lib/math/vector.cc \
     208                  $(MAINSRCDIR)/lib/util/resource_manager.cc
    207209
    208210noinst_HEADERS = framework.h \
     
    289291@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/objModel.Po@am__quote@
    290292@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/primitive_model.Po@am__quote@
     293@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/resource_manager.Po@am__quote@
    291294@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/texture.Po@am__quote@
    292295@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/vector.Po@am__quote@
     
    356359@AMDEP_TRUE@@am__fastdepCXX_FALSE@      $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
    357360@am__fastdepCXX_FALSE@  $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o vector.obj `if test -f '$(MAINSRCDIR)/lib/math/vector.cc'; then $(CYGPATH_W) '$(MAINSRCDIR)/lib/math/vector.cc'; else $(CYGPATH_W) '$(srcdir)/$(MAINSRCDIR)/lib/math/vector.cc'; fi`
     361
     362resource_manager.o: $(MAINSRCDIR)/lib/util/resource_manager.cc
     363@am__fastdepCXX_TRUE@   if $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT resource_manager.o -MD -MP -MF "$(DEPDIR)/resource_manager.Tpo" -c -o resource_manager.o `test -f '$(MAINSRCDIR)/lib/util/resource_manager.cc' || echo '$(srcdir)/'`$(MAINSRCDIR)/lib/util/resource_manager.cc; \
     364@am__fastdepCXX_TRUE@   then mv -f "$(DEPDIR)/resource_manager.Tpo" "$(DEPDIR)/resource_manager.Po"; else rm -f "$(DEPDIR)/resource_manager.Tpo"; exit 1; fi
     365@AMDEP_TRUE@@am__fastdepCXX_FALSE@      source='$(MAINSRCDIR)/lib/util/resource_manager.cc' object='resource_manager.o' libtool=no @AMDEPBACKSLASH@
     366@AMDEP_TRUE@@am__fastdepCXX_FALSE@      depfile='$(DEPDIR)/resource_manager.Po' tmpdepfile='$(DEPDIR)/resource_manager.TPo' @AMDEPBACKSLASH@
     367@AMDEP_TRUE@@am__fastdepCXX_FALSE@      $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
     368@am__fastdepCXX_FALSE@  $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o resource_manager.o `test -f '$(MAINSRCDIR)/lib/util/resource_manager.cc' || echo '$(srcdir)/'`$(MAINSRCDIR)/lib/util/resource_manager.cc
     369
     370resource_manager.obj: $(MAINSRCDIR)/lib/util/resource_manager.cc
     371@am__fastdepCXX_TRUE@   if $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT resource_manager.obj -MD -MP -MF "$(DEPDIR)/resource_manager.Tpo" -c -o resource_manager.obj `if test -f '$(MAINSRCDIR)/lib/util/resource_manager.cc'; then $(CYGPATH_W) '$(MAINSRCDIR)/lib/util/resource_manager.cc'; else $(CYGPATH_W) '$(srcdir)/$(MAINSRCDIR)/lib/util/resource_manager.cc'; fi`; \
     372@am__fastdepCXX_TRUE@   then mv -f "$(DEPDIR)/resource_manager.Tpo" "$(DEPDIR)/resource_manager.Po"; else rm -f "$(DEPDIR)/resource_manager.Tpo"; exit 1; fi
     373@AMDEP_TRUE@@am__fastdepCXX_FALSE@      source='$(MAINSRCDIR)/lib/util/resource_manager.cc' object='resource_manager.obj' libtool=no @AMDEPBACKSLASH@
     374@AMDEP_TRUE@@am__fastdepCXX_FALSE@      depfile='$(DEPDIR)/resource_manager.Po' tmpdepfile='$(DEPDIR)/resource_manager.TPo' @AMDEPBACKSLASH@
     375@AMDEP_TRUE@@am__fastdepCXX_FALSE@      $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
     376@am__fastdepCXX_FALSE@  $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o resource_manager.obj `if test -f '$(MAINSRCDIR)/lib/util/resource_manager.cc'; then $(CYGPATH_W) '$(MAINSRCDIR)/lib/util/resource_manager.cc'; else $(CYGPATH_W) '$(srcdir)/$(MAINSRCDIR)/lib/util/resource_manager.cc'; fi`
    358377uninstall-info-am:
    359378
  • orxonox/trunk/src/lib/graphics/importer/material.cc

    r3655 r3658  
    2121#include "texture.h"
    2222#include "debug.h"
     23#include "resource_manager.h"
    2324#include <stdlib.h>
    2425#include <string.h>
     
    6162    delete []this->name;
    6263  if (this->diffuseTexture)
    63     this->diffuseTexture;
     64    ResourceManager::unload(this->diffuseTexture);
    6465  if (this->nextMat)
    6566    delete this->nextMat;
     
    9293  this->nextMat = NULL;
    9394  this->name ="";
    94   this->setIllum(1);
     95  this->setIllum(3);
    9596  this->setDiffuse(0,0,0);
    9697  this->setAmbient(0,0,0);
     
    168169}
    169170
    170 
    171171/**
    172172   \brief Set the Name of the Material. (Important for searching)
     
    322322void Material::addTexturePath(char* pathName)
    323323{
    324   PathList::getInstance()->addPath(pathName);
     324  ResourceManager::getInstance()->addImageDir(pathName);
    325325}
    326326
     
    334334{
    335335  PRINTF(4)("setting Diffuse Map %s\n", dMap);
    336     diffuseTexture = new Texture();
    337     this->diffuseTextureSet = diffuseTexture->loadImage(dMap);
     336  //    diffuseTexture = new Texture();
     337  //    this->diffuseTextureSet = diffuseTexture->loadImage(dMap);
    338338
    339339  //! \todo check if RESOURCE MANAGER is availiable
    340   //this->diffuseTextureSet = this->diffuseTexture = (Texture*)ResourceManager::load(dMap, IMAGE);
     340  //! \todo Textures from .mtl-file need special care.
     341  this->diffuseTextureSet = this->diffuseTexture = (Texture*)ResourceManager::load(dMap, IMAGE);
    341342}
    342343
  • orxonox/trunk/src/lib/graphics/importer/objModel.cc

    r3655 r3658  
    185185  delete []fileName;
    186186  return true;
    187 
    188187}
    189188
  • orxonox/trunk/src/lib/graphics/importer/primitive_model.cc

    r3657 r3658  
    2424using namespace std;
    2525
    26 
    27 /**
    28    \brief standard constructor
    29    \todo this constructor is not jet implemented - do it
    30 */
    31 PrimitiveModel::PrimitiveModel ()
    32 {
    33   this->initialize();
    34 
    35   this->cubeModel();
    36 
    37   this->importToGL ();
    38 
    39   this->cleanup();
    40 }
    41 
    4226/**
    4327   \brief Creates a 3D-Model of Primitive-Type type
     
    7559}
    7660
    77 
    7861/**
    7962   \brief standard deconstructor
     
    8366{
    8467  // delete what has to be deleted here
    85 }
    86 
    87 
    88 
    89 
    90 /**
    91    \brief Includes a default model
    92 
    93    This will inject a Cube, because this is the most basic model.
    94 */
    95 void PrimitiveModel::cubeModel(void)
    96 {
    97   this->addVertex (-0.5, -0.5, 0.5);
    98   this->addVertex (0.5, -0.5, 0.5);
    99   this->addVertex (-0.5, 0.5, 0.5);
    100   this->addVertex (0.5, 0.5, 0.5);
    101   this->addVertex (-0.5, 0.5, -0.5);
    102   this->addVertex (0.5, 0.5, -0.5);
    103   this->addVertex (-0.5, -0.5, -0.5);
    104   this->addVertex (0.5, -0.5, -0.5);
    105 
    106   this->addVertexTexture (0.0, 0.0);
    107   this->addVertexTexture (1.0, 0.0);
    108   this->addVertexTexture (0.0, 1.0);
    109   this->addVertexTexture (1.0, 1.0);
    110   this->addVertexTexture (0.0, 2.0);
    111   this->addVertexTexture (1.0, 2.0);
    112   this->addVertexTexture (0.0, 3.0);
    113   this->addVertexTexture (1.0, 3.0);
    114   this->addVertexTexture (0.0, 4.0);
    115   this->addVertexTexture (1.0, 4.0);
    116   this->addVertexTexture (2.0, 0.0);
    117   this->addVertexTexture (2.0, 1.0);
    118   this->addVertexTexture (-1.0, 0.0);
    119   this->addVertexTexture (-1.0, 1.0);
    120 
    121   this->addVertexNormal (0.0, 0.0, 1.0);
    122   this->addVertexNormal (0.0, 0.0, 1.0);
    123   this->addVertexNormal (0.0, 0.0, 1.0);
    124   this->addVertexNormal (0.0, 0.0, 1.0);
    125   this->addVertexNormal (0.0, 1.0, 0.0);
    126   this->addVertexNormal (0.0, 1.0, 0.0);
    127   this->addVertexNormal (0.0, 1.0, 0.0);
    128   this->addVertexNormal (0.0, 1.0, 0.0);
    129   this->addVertexNormal (0.0, 0.0, -1.0);
    130   this->addVertexNormal (0.0, 0.0, -1.0);
    131   this->addVertexNormal (0.0, 0.0, -1.0);
    132   this->addVertexNormal (0.0, 0.0, -1.0);
    133   this->addVertexNormal (0.0, -1.0, 0.0);
    134   this->addVertexNormal (0.0, -1.0, 0.0);
    135   this->addVertexNormal (0.0, -1.0, 0.0);
    136   this->addVertexNormal (0.0, -1.0, 0.0);
    137   this->addVertexNormal (1.0, 0.0, 0.0);
    138   this->addVertexNormal (1.0, 0.0, 0.0);
    139   this->addVertexNormal (1.0, 0.0, 0.0);
    140   this->addVertexNormal (1.0, 0.0, 0.0);
    141   this->addVertexNormal (-1.0, 0.0, 0.0);
    142   this->addVertexNormal (-1.0, 0.0, 0.0);
    143   this->addVertexNormal (-1.0, 0.0, 0.0);
    144   this->addVertexNormal (-1.0, 0.0, 0.0);
    145 
    146   /* normaleLess-testingMode
    147   this->addFace ("1 2 4 3");
    148   this->addFace ("3 4 6 5");
    149   this->addFace ("5 6 8 7");
    150   this->addFace ("7 8 2 1");
    151   this->addFace ("2 8 6 4");
    152   this->addFace ("7 1 3 5");
    153   */
    154 
    155   this->addFace (4, 3, 1,1,1, 2,2,2, 4,4,3, 3,3,4);
    156   this->addFace (4, 3, 3,3,5, 4,4,6, 6,6,7, 5,5,8);
    157   this->addFace (4, 3, 5,5,9, 6,6,10, 8,8,11, 7,7,12);
    158   this->addFace (4, 3, 7,7,13, 8,8,14, 2,10,15, 1,9,16);
    159   this->addFace (4, 3, 2,2,17, 8,11,18, 6,12,19, 4,4,20);
    160   this->addFace (4, 3, 7,13,21, 1,1,22, 3,3,23, 5,14,24);
    161 
    16268}
    16369
     
    247153  this->addVertex(0, 0, size);
    248154
    249  
    250155  if (count != detail)
    251156    PRINTF(1)("calculation error, count should be %d but is %d.\n", detail, count);
  • orxonox/trunk/src/lib/graphics/importer/primitive_model.h

    r3657 r3658  
    11/*!
    2     \file primitive_model.h
    3 
     2    \file primitive_model.h
     3    \brief a Class to handle different simple models like planes cubes spheres and so on.
     4    (cube is also an option of Model, but is extended here.
    45*/
    56
     
    1011
    1112//! Specification of different primitives the Model knows
    12 enum PRIMITIVE {PLANE, CUBE, SPHERE, CYLINDER, CONE};
     13enum PRIMITIVE {CUBE, SPHERE, PLANE, CYLINDER, CONE};
    1314
    1415// FORWARD DEFINITION \\
     
    1819
    1920 public:
    20   PrimitiveModel();
    2121  PrimitiveModel(PRIMITIVE type, float size = 1.0, unsigned int detail = 10);
    22 
    2322  virtual ~PrimitiveModel();
    2423
    2524 protected:
    26   void cubeModel(void);
    2725  void sphereModel(float size = 1.0, unsigned int detail = 10);
    2826  void cylinderModel(float size = 1.0, unsigned int detail = 10);
  • orxonox/trunk/src/lib/util/resource_manager.cc

    r3657 r3658  
    2323#include "texture.h"
    2424
     25#include "list.h"
     26
    2527// File Handling Includes
    2628#include <sys/types.h>
     
    2830#include <unistd.h>
    2931
    30 
    3132using namespace std;
    3233
    33 
    3434/**
    3535   \brief standard constructor
     
    3838{
    3939   this->setClassName ("ResourceManager");
    40    this->dataDir = NULL;
     40   dataDir = NULL;
     41   imageDirs = new tList<char>();
     42   resourceList = new tList<Resource>();
    4143}
    4244
     
    4850}
    4951
     52//! Singleton Reference to the ResourceManager
    5053ResourceManager* ResourceManager::singletonRef = NULL;
     54//! The List of Resources, that has already been loaded.
     55tList<Resource>* ResourceManager::resourceList = NULL;
     56//! The Data Directory, where all relevant Data is stored.
     57char* ResourceManager::dataDir = NULL;
     58//! A list of directories in which images are stored.
     59tList<char>* ResourceManager::imageDirs = NULL;
    5160
    5261/**
     
    5564ResourceManager::~ResourceManager (void)
    5665{
     66
     67  delete resourceList;
     68  resourceList = NULL;
    5769  ResourceManager::singletonRef = NULL;
    5870}
    59 
    60 
    6171
    6272/**
     
    6878  if (isDir(dataDir))
    6979    {
    70       this->dataDir = new char[strlen(dataDir)+1];
    71       strcpy(this->dataDir, dataDir);
     80      ResourceManager::dataDir = new char[strlen(dataDir)+1];
     81      strcpy(ResourceManager::dataDir, dataDir);
    7282    }
    7383  else
    7484    {
    7585      PRINTF(1)("%s is not a Directory, and can not be the Data Directory\n", dataDir);
     86    }
     87}
     88
     89bool ResourceManager::addImageDir(char* imageDir)
     90{
     91  if (isDir(imageDir))
     92    {
     93      char* tmpDir  = new char[strlen(imageDir)+1];
     94      strcpy(tmpDir, imageDir);
     95      imageDirs->add(tmpDir);
     96    }
     97  else
     98    {
     99      PRINTF(1)("%s is not a Directory, and can not be added to the Paths of Images\n", dataDir);
    76100    }
    77101}
     
    87111  if (!strncmp(fileName+(strlen(fileName)-4), ".obj", 4))
    88112    tmpType = OBJ;
     113  else if (!strncmp(fileName+(strlen(fileName)-4), ".wav", 4))
     114    tmpType = WAV;
     115  else if (!strncmp(fileName+(strlen(fileName)-4), ".mp3", 4))
     116    tmpType = MP3;
     117  else if (!strncmp(fileName+(strlen(fileName)-4), ".ogg", 4))
     118    tmpType = OGG;
     119  else if (!strcmp(fileName, "cube") ||
     120           !strcmp(fileName, "sphere") ||
     121           !strcmp(fileName, "plane") ||
     122           !strcmp(fileName, "cylinder") ||
     123           !strcmp(fileName, "cone"))
     124    tmpType = PRIM;
     125  else
     126    tmpType = IMAGE;
    89127
    90128  return ResourceManager::load(fileName, tmpType);
     
    99137void* ResourceManager::load(const char* fileName, ResourceType type)
    100138{
    101   void* tmpResource = NULL;
    102   char* tmpName = new char[strlen(fileName)+1];
    103   strcpy(tmpName, fileName);
    104   // Checking for the type of resource \see ResourceType
    105   switch(type)
    106     {
    107     case OBJ:
    108       if(isFile(tmpName))
    109         tmpResource = new OBJModel(tmpName);
    110       else
     139  // searching if the resource was loaded before.
     140  Resource* tmpResource = ResourceManager::locateResourceByName(fileName);
     141  char* tmpDir;
     142  if (!tmpResource) // if the resource was not loaded before.
     143    {
     144      // Setting up the new Resource
     145      tmpResource = new Resource;
     146      tmpResource->count = 1;
     147      tmpResource->type = type;
     148      tmpResource->name = new char[strlen(fileName)+1];
     149      strcpy(tmpResource->name, fileName);
     150
     151      // creating the full name. (directoryName + FileName)
     152      char* fullName = new char[strlen(dataDir)+strlen(fileName)+1];
     153      sprintf(fullName, "%s%s", dataDir, fileName);
     154     
     155      // Checking for the type of resource \see ResourceType
     156      switch(type)
    111157        {
    112           PRINTF(2)("Sorry, %s does not exist. Loading a cube-Model instead\n", tmpName);
    113           tmpResource = new PrimitiveModel(CUBE);
     158        case OBJ:
     159          if(isFile(fullName))
     160            tmpResource->pointer = new OBJModel(fullName);
     161          else
     162            {
     163              PRINTF(2)("Sorry, %s does not exist. Loading a cube-Model instead\n", fullName);
     164              tmpResource->pointer = ResourceManager::load("cube", PRIM);
     165            }
     166          break;
     167        case PRIM:
     168          if (!strcmp(tmpResource->name, "cube"))
     169            tmpResource->pointer = new PrimitiveModel(CUBE);
     170          else if (!strcmp(tmpResource->name, "sphere"))
     171            tmpResource->pointer = new PrimitiveModel(SPHERE);
     172          else if (!strcmp(tmpResource->name, "plane"))
     173            tmpResource->pointer = new PrimitiveModel(PLANE);
     174          else if (!strcmp(tmpResource->name, "cylinder"))
     175            tmpResource->pointer = new PrimitiveModel(CYLINDER);
     176          else if (!strcmp(tmpResource->name, "cone"))
     177            tmpResource->pointer = new PrimitiveModel(CONE);
     178          break;
     179        case IMAGE:
     180          if(isFile(fullName))
     181            {
     182              tmpResource->pointer = new Texture(fullName);
     183            }
     184          else
     185            {
     186              tmpDir = imageDirs->enumerate();
     187              while(tmpDir)
     188                {
     189                  char* imgName = new char[strlen(tmpDir)+strlen(fileName)+1];
     190                  sprintf(imgName, "%s%s", tmpDir, fileName);
     191                  if(isFile(imgName))
     192                    tmpResource->pointer = new Texture(imgName);
     193                  delete []imgName;
     194                  tmpDir = imageDirs->nextElement();
     195                }
     196            }
     197          if(!tmpResource)
     198             PRINTF(2)("!!Image %s not Found!!\n", fileName);
     199          break;
     200        default:
     201          tmpResource->pointer = NULL;
     202          PRINTF(1)("No type found for %s.\n   !!This should not happen unless the Type is not supported yet.!!\n", tmpResource->name);
     203          break;
    114204        }
    115       break;
    116     case IMAGE:
    117       if(isFile(tmpName))
     205     
     206      // checking if the File really exists.
     207      if(!isFile(fullName))
    118208        {
    119           tmpResource = new Texture(tmpName);
     209          PRINTF(2)("Sorry, %s is not a regular file.\n", fullName);
     210          tmpResource->pointer = NULL;
    120211        }
    121       else
    122         PRINTF(1)("!!Texture %s not Found!!\n", tmpName);
    123       break;
    124     default:
    125       tmpResource = NULL;
    126       PRINTF(2)("No type found for %s.\n   !!This should not happen unless the Type is not supported yet.!!\n", tmpName);
    127       break;
    128     }
    129 
    130   // checking if the File really exists.
    131   if(!isFile(tmpName))
    132     {
    133       PRINTF(2)("Sorry, %s is not a regular file.\n", tmpName);
    134       tmpResource = NULL;
    135     }
    136   return tmpResource;
     212      resourceList->add(tmpResource);
     213      delete []fullName;
     214
     215    }
     216  else
     217    {
     218      tmpResource->count++;
     219    }
     220
     221  return tmpResource->pointer;
     222}
     223
     224/**
     225   \brief unloads a Resource
     226   \param pointer The pointer to free
     227   \returns true if successful (pointer found, and deleted), false otherwise
     228   
     229*/
     230bool ResourceManager::unload(void* pointer)
     231{
     232  // if pointer is existent. and only one resource of this type exists.
     233  Resource* tmpResource = ResourceManager::locateResourceByPointer(pointer);
     234  if (!tmpResource)
     235    {
     236      PRINTF(2)("Resource not Found %p\n", pointer);
     237      return false;
     238    }
     239  tmpResource->count--;
     240  if (tmpResource->count <= 0)
     241    {
     242      // deleting the Resource
     243      switch(tmpResource->type)
     244        {
     245        case OBJ:
     246        case PRIM:
     247          delete (Model*)tmpResource->pointer;
     248          break;
     249        case IMAGE:
     250          delete (Texture*)tmpResource->pointer;
     251          break;
     252        default:
     253          PRINTF(1)("NOT YET IMPLEMENTED FIX FIX\n");
     254          return false;
     255          break;
     256        }
     257      // deleting the List Entry:
     258      PRINTF(4)("Resource %s Safely removed.\n", tmpResource->name);
     259      delete []tmpResource->name;
     260      resourceList->remove(tmpResource);
     261    }
     262  else
     263    PRINTF(4)("Resource not removed, because there are still %d References to it.\n", tmpResource->count);
     264  return true;
     265}
     266
     267/**
     268   \brief Searches for a Resource by Name
     269   \param fileName The name to look for
     270   \returns a Pointer to the Resource if found, NULL otherwise.
     271*/
     272Resource* ResourceManager::locateResourceByName(const char* fileName)
     273{
     274  Resource* enumRes = resourceList->enumerate();
     275  while (enumRes)
     276    {
     277      if (!strcmp(fileName, enumRes->name))
     278        return enumRes;
     279      enumRes = resourceList->nextElement();
     280    }
     281  return NULL;
     282}
     283
     284/**
     285   \brief Searches for a Resource by Pointer
     286   \param pointer the Pointer to search for
     287   \returns a Pointer to the Resource if found, NULL otherwise.
     288*/
     289Resource* ResourceManager::locateResourceByPointer(const void* pointer)
     290{
     291  Resource* enumRes = resourceList->enumerate();
     292  while (enumRes)
     293    {
     294      if (pointer == enumRes->pointer);
     295        return enumRes;
     296      enumRes = resourceList->nextElement();
     297    }
     298  return NULL;
    137299}
    138300
     
    148310  if (status.st_mode & (S_IFDIR | S_IFLNK))
    149311    return true;
    150   else 
     312  else
    151313    return false;
    152314}
  • orxonox/trunk/src/lib/util/resource_manager.h

    r3655 r3658  
    1515
    1616// FORWARD DEFINITION \\
     17//template<class T> class tList;
     18#include "list.h"                //! \todo do this by forward definition (ask Patrick)
     19enum ResourceType {OBJ, PRIM, WAV, MP3, OGG, IMAGE};
    1720
     21struct Resource
     22{
     23  void* pointer;             //!< Pointer to the Resource.
     24 
     25  char* name;                //!< Name of the Resource.
     26  ResourceType type;         //!< ResourceType of this Resource.
     27  int count;                 //!< How many times this Resource has been loaded.
     28};
    1829
    19 enum ResourceType {OBJ, WAV, MP3, OGG, IMAGE};
    2030
    2131//! The ResourceManager is a class, that decides if a file/resource should be loaded
     
    3444  virtual ~ResourceManager();
    3545
    36   bool setDataDir(char* dataDir);
     46  static bool setDataDir(char* dataDir);
     47  static bool addImageDir(char* imageDir);
    3748  static void* load(const char* fileName);
    3849  static void* load(const char* fileName, ResourceType type);
     50  static bool unload(void* pointer);
    3951
    4052 private:
     
    4254  static ResourceManager* singletonRef;
    4355
     56  static tList<Resource>* resourceList;
     57  static char* dataDir;
     58  static tList<char>* imageDirs;
    4459
    45   struct file;
    46   struct folder
    47   {
    48     char* name;
    49     folder** subfolders;             //!<
    50     file** files;                    //!< Files in the directory
    51   };
    52   struct file
    53   {
    54     char* name;                      //!< exact Name of a file
    55     void* pointer;
    56   };
    57 
    58   char* dataDir;                     //!< The main data directory
     60  static Resource* locateResourceByName(const char* fileName);
     61  static Resource* locateResourceByPointer(const void* pointer);
     62 
    5963
    6064  static bool isDir(const char* directory);
  • orxonox/trunk/src/orxonox.cc

    r3655 r3658  
    163163  PRINT(3)("initializing ResourceManager\n");
    164164  resourceManager = ResourceManager::getInstance();
    165   resourceManager->setDataDir("../data");
     165  resourceManager->setDataDir("../data/");
    166166  return 0;
    167167}
  • orxonox/trunk/src/world_entities/environment.cc

    r3578 r3658  
    2929Environment::Environment () : WorldEntity()
    3030{
    31   this->model = new OBJModel("../data/models/fighter.obj");
     31  this->model = (Model*) ResourceManager::load("models/reaplow.obj", OBJ);
     32  //  this->model = new OBJModel("../data/models/fighter.obj");
    3233}
    3334
  • orxonox/trunk/src/world_entities/player.cc

    r3655 r3658  
    4545     the player.cc for debug also
    4646  */
    47   this->model = (Model*) ResourceManager::load("../data/models/reaplow.obj", OBJ);
     47  this->model = (Model*)ResourceManager::load("models/reaplow.obj", OBJ);
    4848  travelSpeed = 15.0;
    4949  velocity = new Vector();
  • orxonox/trunk/src/world_entities/world_entity.cc

    r3649 r3658  
    5151{
    5252  // if( collisioncluster != NULL) delete collisioncluster;
    53   delete this->model;
     53  ResourceManager::unload(this->model);
    5454}
    5555
  • orxonox/trunk/src/world_entities/world_entity.h

    r3655 r3658  
    99#include "p_node.h"
    1010#include "comincl.h"
     11#include "resource_manager.h"
     12
    1113
    1214//class CollisionCluster;
Note: See TracChangeset for help on using the changeset viewer.