Index: orxonox/trunk/src/lib/graphics/importer/Makefile.am
===================================================================
--- orxonox/trunk/src/lib/graphics/importer/Makefile.am	(revision 3657)
+++ orxonox/trunk/src/lib/graphics/importer/Makefile.am	(revision 3658)
@@ -33,5 +33,6 @@
 		  $(MAINSRCDIR)/lib/graphics/graphics_engine.cc \
 		  $(MAINSRCDIR)/lib/lang/base_object.cc \
-		  $(MAINSRCDIR)/lib/math/vector.cc
+		  $(MAINSRCDIR)/lib/math/vector.cc \
+		  $(MAINSRCDIR)/lib/util/resource_manager.cc
 
 noinst_HEADERS= framework.h \
Index: orxonox/trunk/src/lib/graphics/importer/Makefile.in
===================================================================
--- orxonox/trunk/src/lib/graphics/importer/Makefile.in	(revision 3657)
+++ orxonox/trunk/src/lib/graphics/importer/Makefile.in	(revision 3658)
@@ -57,5 +57,5 @@
 	array.$(OBJEXT) material.$(OBJEXT) texture.$(OBJEXT) \
 	graphics_engine.$(OBJEXT) base_object.$(OBJEXT) \
-	vector.$(OBJEXT)
+	vector.$(OBJEXT) resource_manager.$(OBJEXT)
 importer_OBJECTS = $(am_importer_OBJECTS)
 importer_LDADD = $(LDADD)
@@ -70,4 +70,5 @@
 @AMDEP_TRUE@	./$(DEPDIR)/objModel.Po \
 @AMDEP_TRUE@	./$(DEPDIR)/primitive_model.Po \
+@AMDEP_TRUE@	./$(DEPDIR)/resource_manager.Po \
 @AMDEP_TRUE@	./$(DEPDIR)/texture.Po ./$(DEPDIR)/vector.Po \
 @AMDEP_TRUE@	./$(DEPDIR)/windowHandler.Po
@@ -204,5 +205,6 @@
 		  $(MAINSRCDIR)/lib/graphics/graphics_engine.cc \
 		  $(MAINSRCDIR)/lib/lang/base_object.cc \
-		  $(MAINSRCDIR)/lib/math/vector.cc
+		  $(MAINSRCDIR)/lib/math/vector.cc \
+		  $(MAINSRCDIR)/lib/util/resource_manager.cc
 
 noinst_HEADERS = framework.h \
@@ -289,4 +291,5 @@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/objModel.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/primitive_model.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/resource_manager.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/texture.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/vector.Po@am__quote@
@@ -356,4 +359,20 @@
 @AMDEP_TRUE@@am__fastdepCXX_FALSE@	$(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
 @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`
+
+resource_manager.o: $(MAINSRCDIR)/lib/util/resource_manager.cc
+@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; \
+@am__fastdepCXX_TRUE@	then mv -f "$(DEPDIR)/resource_manager.Tpo" "$(DEPDIR)/resource_manager.Po"; else rm -f "$(DEPDIR)/resource_manager.Tpo"; exit 1; fi
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@	source='$(MAINSRCDIR)/lib/util/resource_manager.cc' object='resource_manager.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@	depfile='$(DEPDIR)/resource_manager.Po' tmpdepfile='$(DEPDIR)/resource_manager.TPo' @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@	$(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@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
+
+resource_manager.obj: $(MAINSRCDIR)/lib/util/resource_manager.cc
+@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`; \
+@am__fastdepCXX_TRUE@	then mv -f "$(DEPDIR)/resource_manager.Tpo" "$(DEPDIR)/resource_manager.Po"; else rm -f "$(DEPDIR)/resource_manager.Tpo"; exit 1; fi
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@	source='$(MAINSRCDIR)/lib/util/resource_manager.cc' object='resource_manager.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@	depfile='$(DEPDIR)/resource_manager.Po' tmpdepfile='$(DEPDIR)/resource_manager.TPo' @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@	$(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@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`
 uninstall-info-am:
 
Index: orxonox/trunk/src/lib/graphics/importer/material.cc
===================================================================
--- orxonox/trunk/src/lib/graphics/importer/material.cc	(revision 3657)
+++ orxonox/trunk/src/lib/graphics/importer/material.cc	(revision 3658)
@@ -21,4 +21,5 @@
 #include "texture.h"
 #include "debug.h"
+#include "resource_manager.h"
 #include <stdlib.h>
 #include <string.h>
@@ -61,5 +62,5 @@
     delete []this->name;
   if (this->diffuseTexture)
-    this->diffuseTexture;
+    ResourceManager::unload(this->diffuseTexture);
   if (this->nextMat)
     delete this->nextMat;
@@ -92,5 +93,5 @@
   this->nextMat = NULL;
   this->name ="";
-  this->setIllum(1);
+  this->setIllum(3);
   this->setDiffuse(0,0,0);
   this->setAmbient(0,0,0);
@@ -168,5 +169,4 @@
 }
 
-
 /**
    \brief Set the Name of the Material. (Important for searching)
@@ -322,5 +322,5 @@
 void Material::addTexturePath(char* pathName)
 {
-  PathList::getInstance()->addPath(pathName);
+  ResourceManager::getInstance()->addImageDir(pathName);
 }
 
@@ -334,9 +334,10 @@
 {
   PRINTF(4)("setting Diffuse Map %s\n", dMap);
-    diffuseTexture = new Texture();
-    this->diffuseTextureSet = diffuseTexture->loadImage(dMap);
+  //    diffuseTexture = new Texture();
+  //    this->diffuseTextureSet = diffuseTexture->loadImage(dMap);
 
   //! \todo check if RESOURCE MANAGER is availiable
-  //this->diffuseTextureSet = this->diffuseTexture = (Texture*)ResourceManager::load(dMap, IMAGE);
+  //! \todo Textures from .mtl-file need special care.
+  this->diffuseTextureSet = this->diffuseTexture = (Texture*)ResourceManager::load(dMap, IMAGE);
 }
 
Index: orxonox/trunk/src/lib/graphics/importer/objModel.cc
===================================================================
--- orxonox/trunk/src/lib/graphics/importer/objModel.cc	(revision 3657)
+++ orxonox/trunk/src/lib/graphics/importer/objModel.cc	(revision 3658)
@@ -185,5 +185,4 @@
   delete []fileName;
   return true;
-
 }
 
Index: orxonox/trunk/src/lib/graphics/importer/primitive_model.cc
===================================================================
--- orxonox/trunk/src/lib/graphics/importer/primitive_model.cc	(revision 3657)
+++ orxonox/trunk/src/lib/graphics/importer/primitive_model.cc	(revision 3658)
@@ -24,20 +24,4 @@
 using namespace std;
 
-
-/**
-   \brief standard constructor
-   \todo this constructor is not jet implemented - do it
-*/
-PrimitiveModel::PrimitiveModel () 
-{
-  this->initialize();
-
-  this->cubeModel();
-
-  this->importToGL ();
-
-  this->cleanup();
-}
-
 /**
    \brief Creates a 3D-Model of Primitive-Type type
@@ -75,5 +59,4 @@
 }
 
-
 /**
    \brief standard deconstructor
@@ -83,81 +66,4 @@
 {
   // delete what has to be deleted here
-}
-
-
-
-
-/**
-   \brief Includes a default model
-
-   This will inject a Cube, because this is the most basic model.
-*/
-void PrimitiveModel::cubeModel(void)
-{
-  this->addVertex (-0.5, -0.5, 0.5);
-  this->addVertex (0.5, -0.5, 0.5);
-  this->addVertex (-0.5, 0.5, 0.5);
-  this->addVertex (0.5, 0.5, 0.5);
-  this->addVertex (-0.5, 0.5, -0.5);
-  this->addVertex (0.5, 0.5, -0.5);
-  this->addVertex (-0.5, -0.5, -0.5);
-  this->addVertex (0.5, -0.5, -0.5);
-
-  this->addVertexTexture (0.0, 0.0);
-  this->addVertexTexture (1.0, 0.0);
-  this->addVertexTexture (0.0, 1.0);
-  this->addVertexTexture (1.0, 1.0);
-  this->addVertexTexture (0.0, 2.0);
-  this->addVertexTexture (1.0, 2.0);
-  this->addVertexTexture (0.0, 3.0);
-  this->addVertexTexture (1.0, 3.0);
-  this->addVertexTexture (0.0, 4.0);
-  this->addVertexTexture (1.0, 4.0);
-  this->addVertexTexture (2.0, 0.0);
-  this->addVertexTexture (2.0, 1.0);
-  this->addVertexTexture (-1.0, 0.0);
-  this->addVertexTexture (-1.0, 1.0);
-
-  this->addVertexNormal (0.0, 0.0, 1.0);
-  this->addVertexNormal (0.0, 0.0, 1.0);
-  this->addVertexNormal (0.0, 0.0, 1.0);
-  this->addVertexNormal (0.0, 0.0, 1.0);
-  this->addVertexNormal (0.0, 1.0, 0.0);
-  this->addVertexNormal (0.0, 1.0, 0.0);
-  this->addVertexNormal (0.0, 1.0, 0.0);
-  this->addVertexNormal (0.0, 1.0, 0.0);
-  this->addVertexNormal (0.0, 0.0, -1.0);
-  this->addVertexNormal (0.0, 0.0, -1.0);
-  this->addVertexNormal (0.0, 0.0, -1.0);
-  this->addVertexNormal (0.0, 0.0, -1.0);
-  this->addVertexNormal (0.0, -1.0, 0.0);
-  this->addVertexNormal (0.0, -1.0, 0.0);
-  this->addVertexNormal (0.0, -1.0, 0.0);
-  this->addVertexNormal (0.0, -1.0, 0.0);
-  this->addVertexNormal (1.0, 0.0, 0.0);
-  this->addVertexNormal (1.0, 0.0, 0.0);
-  this->addVertexNormal (1.0, 0.0, 0.0);
-  this->addVertexNormal (1.0, 0.0, 0.0);
-  this->addVertexNormal (-1.0, 0.0, 0.0);
-  this->addVertexNormal (-1.0, 0.0, 0.0);
-  this->addVertexNormal (-1.0, 0.0, 0.0);
-  this->addVertexNormal (-1.0, 0.0, 0.0);
-
-  /* normaleLess-testingMode
-  this->addFace ("1 2 4 3");
-  this->addFace ("3 4 6 5");
-  this->addFace ("5 6 8 7");
-  this->addFace ("7 8 2 1");
-  this->addFace ("2 8 6 4");
-  this->addFace ("7 1 3 5");
-  */
-
-  this->addFace (4, 3, 1,1,1, 2,2,2, 4,4,3, 3,3,4);
-  this->addFace (4, 3, 3,3,5, 4,4,6, 6,6,7, 5,5,8);
-  this->addFace (4, 3, 5,5,9, 6,6,10, 8,8,11, 7,7,12);
-  this->addFace (4, 3, 7,7,13, 8,8,14, 2,10,15, 1,9,16);
-  this->addFace (4, 3, 2,2,17, 8,11,18, 6,12,19, 4,4,20);
-  this->addFace (4, 3, 7,13,21, 1,1,22, 3,3,23, 5,14,24);
-
 }
 
@@ -247,5 +153,4 @@
   this->addVertex(0, 0, size);
 
-  
   if (count != detail)
     PRINTF(1)("calculation error, count should be %d but is %d.\n", detail, count);
Index: orxonox/trunk/src/lib/graphics/importer/primitive_model.h
===================================================================
--- orxonox/trunk/src/lib/graphics/importer/primitive_model.h	(revision 3657)
+++ orxonox/trunk/src/lib/graphics/importer/primitive_model.h	(revision 3658)
@@ -1,5 +1,6 @@
 /*! 
-    \file primitive_model.h
-
+    \file primitive_model.h 
+    \brief a Class to handle different simple models like planes cubes spheres and so on.
+    (cube is also an option of Model, but is extended here.
 */
 
@@ -10,5 +11,5 @@
 
 //! Specification of different primitives the Model knows
-enum PRIMITIVE {PLANE, CUBE, SPHERE, CYLINDER, CONE};
+enum PRIMITIVE {CUBE, SPHERE, PLANE, CYLINDER, CONE};
 
 // FORWARD DEFINITION \\
@@ -18,11 +19,8 @@
 
  public:
-  PrimitiveModel();
   PrimitiveModel(PRIMITIVE type, float size = 1.0, unsigned int detail = 10);
-
   virtual ~PrimitiveModel();
 
  protected:
-  void cubeModel(void);
   void sphereModel(float size = 1.0, unsigned int detail = 10);
   void cylinderModel(float size = 1.0, unsigned int detail = 10);
Index: orxonox/trunk/src/lib/util/resource_manager.cc
===================================================================
--- orxonox/trunk/src/lib/util/resource_manager.cc	(revision 3657)
+++ orxonox/trunk/src/lib/util/resource_manager.cc	(revision 3658)
@@ -23,4 +23,6 @@
 #include "texture.h"
 
+#include "list.h"
+
 // File Handling Includes
 #include <sys/types.h>
@@ -28,8 +30,6 @@
 #include <unistd.h>
 
-
 using namespace std;
 
-
 /**
    \brief standard constructor
@@ -38,5 +38,7 @@
 {
    this->setClassName ("ResourceManager");
-   this->dataDir = NULL;
+   dataDir = NULL;
+   imageDirs = new tList<char>();
+   resourceList = new tList<Resource>();
 }
 
@@ -48,5 +50,12 @@
 }
 
+//! Singleton Reference to the ResourceManager
 ResourceManager* ResourceManager::singletonRef = NULL;
+//! The List of Resources, that has already been loaded.
+tList<Resource>* ResourceManager::resourceList = NULL;
+//! The Data Directory, where all relevant Data is stored.
+char* ResourceManager::dataDir = NULL;
+//! A list of directories in which images are stored.
+tList<char>* ResourceManager::imageDirs = NULL;
 
 /**
@@ -55,8 +64,9 @@
 ResourceManager::~ResourceManager (void) 
 {
+
+  delete resourceList;
+  resourceList = NULL;
   ResourceManager::singletonRef = NULL;
 }
-
-
 
 /**
@@ -68,10 +78,24 @@
   if (isDir(dataDir))
     {
-      this->dataDir = new char[strlen(dataDir)+1];
-      strcpy(this->dataDir, dataDir);
+      ResourceManager::dataDir = new char[strlen(dataDir)+1];
+      strcpy(ResourceManager::dataDir, dataDir);
     }
   else
     {
       PRINTF(1)("%s is not a Directory, and can not be the Data Directory\n", dataDir);
+    }
+}
+
+bool ResourceManager::addImageDir(char* imageDir)
+{
+  if (isDir(imageDir))
+    {
+      char* tmpDir  = new char[strlen(imageDir)+1];
+      strcpy(tmpDir, imageDir);
+      imageDirs->add(tmpDir);
+    }
+  else
+    {
+      PRINTF(1)("%s is not a Directory, and can not be added to the Paths of Images\n", dataDir);
     }
 }
@@ -87,4 +111,18 @@
   if (!strncmp(fileName+(strlen(fileName)-4), ".obj", 4))
     tmpType = OBJ;
+  else if (!strncmp(fileName+(strlen(fileName)-4), ".wav", 4))
+    tmpType = WAV;
+  else if (!strncmp(fileName+(strlen(fileName)-4), ".mp3", 4))
+    tmpType = MP3;
+  else if (!strncmp(fileName+(strlen(fileName)-4), ".ogg", 4))
+    tmpType = OGG;
+  else if (!strcmp(fileName, "cube") ||
+           !strcmp(fileName, "sphere") ||
+	   !strcmp(fileName, "plane") ||
+           !strcmp(fileName, "cylinder") ||
+           !strcmp(fileName, "cone"))
+    tmpType = PRIM;
+  else 
+    tmpType = IMAGE;
 
   return ResourceManager::load(fileName, tmpType);
@@ -99,40 +137,164 @@
 void* ResourceManager::load(const char* fileName, ResourceType type)
 {
-  void* tmpResource = NULL;
-  char* tmpName = new char[strlen(fileName)+1];
-  strcpy(tmpName, fileName);
-  // Checking for the type of resource \see ResourceType
-  switch(type)
-    {
-    case OBJ:
-      if(isFile(tmpName))
-	tmpResource = new OBJModel(tmpName);
-      else
+  // searching if the resource was loaded before.
+  Resource* tmpResource = ResourceManager::locateResourceByName(fileName);
+  char* tmpDir;
+  if (!tmpResource) // if the resource was not loaded before.
+    {
+      // Setting up the new Resource
+      tmpResource = new Resource;
+      tmpResource->count = 1;
+      tmpResource->type = type;
+      tmpResource->name = new char[strlen(fileName)+1];
+      strcpy(tmpResource->name, fileName);
+
+      // creating the full name. (directoryName + FileName)
+      char* fullName = new char[strlen(dataDir)+strlen(fileName)+1];
+      sprintf(fullName, "%s%s", dataDir, fileName);
+      
+      // Checking for the type of resource \see ResourceType
+      switch(type)
 	{
-	  PRINTF(2)("Sorry, %s does not exist. Loading a cube-Model instead\n", tmpName);
-	  tmpResource = new PrimitiveModel(CUBE);
+	case OBJ:
+	  if(isFile(fullName))
+	    tmpResource->pointer = new OBJModel(fullName);
+	  else
+	    {
+	      PRINTF(2)("Sorry, %s does not exist. Loading a cube-Model instead\n", fullName);
+	      tmpResource->pointer = ResourceManager::load("cube", PRIM);
+	    }
+	  break;
+	case PRIM:
+	  if (!strcmp(tmpResource->name, "cube"))
+	    tmpResource->pointer = new PrimitiveModel(CUBE);
+	  else if (!strcmp(tmpResource->name, "sphere"))
+	    tmpResource->pointer = new PrimitiveModel(SPHERE);
+	  else if (!strcmp(tmpResource->name, "plane"))
+	    tmpResource->pointer = new PrimitiveModel(PLANE);
+	  else if (!strcmp(tmpResource->name, "cylinder"))
+	    tmpResource->pointer = new PrimitiveModel(CYLINDER);
+	  else if (!strcmp(tmpResource->name, "cone"))
+	    tmpResource->pointer = new PrimitiveModel(CONE);
+	  break;
+	case IMAGE:
+	  if(isFile(fullName))
+	    {
+	      tmpResource->pointer = new Texture(fullName);
+	    }
+	  else
+	    {
+	      tmpDir = imageDirs->enumerate();
+	      while(tmpDir)
+		{
+		  char* imgName = new char[strlen(tmpDir)+strlen(fileName)+1];
+		  sprintf(imgName, "%s%s", tmpDir, fileName);
+		  if(isFile(imgName))
+		    tmpResource->pointer = new Texture(imgName);
+		  delete []imgName;
+		  tmpDir = imageDirs->nextElement();
+		}
+	    }
+	  if(!tmpResource)
+	     PRINTF(2)("!!Image %s not Found!!\n", fileName);
+	  break;
+	default:
+	  tmpResource->pointer = NULL;
+	  PRINTF(1)("No type found for %s.\n   !!This should not happen unless the Type is not supported yet.!!\n", tmpResource->name);
+	  break;
 	}
-      break;
-    case IMAGE:
-      if(isFile(tmpName))
+      
+      // checking if the File really exists.
+      if(!isFile(fullName))
 	{
-	  tmpResource = new Texture(tmpName);
+	  PRINTF(2)("Sorry, %s is not a regular file.\n", fullName);
+	  tmpResource->pointer = NULL;
 	}
-      else
-	PRINTF(1)("!!Texture %s not Found!!\n", tmpName);
-      break;
-    default:
-      tmpResource = NULL;
-      PRINTF(2)("No type found for %s.\n   !!This should not happen unless the Type is not supported yet.!!\n", tmpName);
-      break;
-    }
-
-  // checking if the File really exists.
-  if(!isFile(tmpName))
-    {
-      PRINTF(2)("Sorry, %s is not a regular file.\n", tmpName);
-      tmpResource = NULL;
-    }
-  return tmpResource;
+      resourceList->add(tmpResource);
+      delete []fullName;
+
+    }
+  else
+    {
+      tmpResource->count++;
+    }
+
+  return tmpResource->pointer;
+}
+
+/**
+   \brief unloads a Resource
+   \param pointer The pointer to free
+   \returns true if successful (pointer found, and deleted), false otherwise
+   
+*/
+bool ResourceManager::unload(void* pointer)
+{
+  // if pointer is existent. and only one resource of this type exists.
+  Resource* tmpResource = ResourceManager::locateResourceByPointer(pointer);
+  if (!tmpResource)
+    {
+      PRINTF(2)("Resource not Found %p\n", pointer);
+      return false;
+    }
+  tmpResource->count--;
+  if (tmpResource->count <= 0)
+    {
+      // deleting the Resource
+      switch(tmpResource->type)
+	{
+	case OBJ:
+	case PRIM:
+	  delete (Model*)tmpResource->pointer;
+	  break;
+	case IMAGE:
+	  delete (Texture*)tmpResource->pointer;
+	  break;
+	default:
+	  PRINTF(1)("NOT YET IMPLEMENTED FIX FIX\n");
+	  return false;
+	  break;
+	}
+      // deleting the List Entry:
+      PRINTF(4)("Resource %s Safely removed.\n", tmpResource->name);
+      delete []tmpResource->name;
+      resourceList->remove(tmpResource);
+    }
+  else
+    PRINTF(4)("Resource not removed, because there are still %d References to it.\n", tmpResource->count);
+  return true;
+}
+
+/**
+   \brief Searches for a Resource by Name
+   \param fileName The name to look for
+   \returns a Pointer to the Resource if found, NULL otherwise.
+*/
+Resource* ResourceManager::locateResourceByName(const char* fileName)
+{
+  Resource* enumRes = resourceList->enumerate();
+  while (enumRes)
+    {
+      if (!strcmp(fileName, enumRes->name))
+	return enumRes;
+      enumRes = resourceList->nextElement();
+    }
+  return NULL;
+}
+
+/**
+   \brief Searches for a Resource by Pointer
+   \param pointer the Pointer to search for
+   \returns a Pointer to the Resource if found, NULL otherwise.
+*/
+Resource* ResourceManager::locateResourceByPointer(const void* pointer)
+{
+  Resource* enumRes = resourceList->enumerate();
+  while (enumRes)
+    {
+      if (pointer == enumRes->pointer);
+	return enumRes;
+      enumRes = resourceList->nextElement();
+    }
+  return NULL;
 }
 
@@ -148,5 +310,5 @@
   if (status.st_mode & (S_IFDIR | S_IFLNK))
     return true;
-  else 
+  else
     return false;
 }
Index: orxonox/trunk/src/lib/util/resource_manager.h
===================================================================
--- orxonox/trunk/src/lib/util/resource_manager.h	(revision 3657)
+++ orxonox/trunk/src/lib/util/resource_manager.h	(revision 3658)
@@ -15,7 +15,17 @@
 
 // FORWARD DEFINITION \\
+//template<class T> class tList;
+#include "list.h"                //! \todo do this by forward definition (ask Patrick)
+enum ResourceType {OBJ, PRIM, WAV, MP3, OGG, IMAGE};
 
+struct Resource
+{
+  void* pointer;             //!< Pointer to the Resource.
+  
+  char* name;                //!< Name of the Resource.
+  ResourceType type;         //!< ResourceType of this Resource.
+  int count;                 //!< How many times this Resource has been loaded.
+};
 
-enum ResourceType {OBJ, WAV, MP3, OGG, IMAGE};
 
 //! The ResourceManager is a class, that decides if a file/resource should be loaded
@@ -34,7 +44,9 @@
   virtual ~ResourceManager();
 
-  bool setDataDir(char* dataDir);
+  static bool setDataDir(char* dataDir);
+  static bool addImageDir(char* imageDir);
   static void* load(const char* fileName);
   static void* load(const char* fileName, ResourceType type);
+  static bool unload(void* pointer);
 
  private:
@@ -42,19 +54,11 @@
   static ResourceManager* singletonRef;
 
+  static tList<Resource>* resourceList;
+  static char* dataDir;
+  static tList<char>* imageDirs;
 
-  struct file;
-  struct folder
-  {
-    char* name;
-    folder** subfolders;             //!< 
-    file** files;                    //!< Files in the directory
-  };
-  struct file
-  {
-    char* name;                      //!< exact Name of a file
-    void* pointer;
-  };
-
-  char* dataDir;                     //!< The main data directory
+  static Resource* locateResourceByName(const char* fileName);
+  static Resource* locateResourceByPointer(const void* pointer);
+  
 
   static bool isDir(const char* directory);
