Index: orxonox/trunk/src/util/object_manager.cc
===================================================================
--- orxonox/trunk/src/util/object_manager.cc	(revision 4932)
+++ orxonox/trunk/src/util/object_manager.cc	(revision 4933)
@@ -29,5 +29,5 @@
  *  constructor, sets everything to zero and define factoryName
  */
-FastFactory::FastFactory (const char* fastFactoryName, ClassID classID)
+FastFactory::FastFactory (ClassID classID, const char* fastFactoryName)
 {
   this->setClassID(CL_FAST_FACTORY, "FastFactory");
@@ -36,4 +36,6 @@
   this->storedClassID = classID;
   this->next = NULL;
+
+  this->storedDeadObjects = 0;
 
   FastFactory::registerFastFactory(this);
@@ -56,26 +58,42 @@
 }
 
-/**
- * add a FastFactory to the FastFactory Queue
- * @param factory a FastFactory to be registered
- */
-void FastFactory::registerFastFactory( FastFactory* factory)
+void FastFactory::registerFastFactory(FastFactory* fastFactory)
 {
-  PRINTF(3)("Registered FastFactory for '%s'\n", factory->getName());
+  PRINTF(4)("Registered FastFactory for '%s'\n", fastFactory->getName());
 
   if( FastFactory::first == NULL)
-    FastFactory::first = factory;
+    FastFactory::first = fastFactory;
   else
   {
     FastFactory* tmpFac = FastFactory::first;
     while( tmpFac->next != NULL)
-    {
       tmpFac = tmpFac->next;
-    }
-    tmpFac->setNext(factory);
+    tmpFac->setNext(fastFactory);
   }
 }
 
 
+/**
+ * searches for a FastFactory
+ * @param factoryName the Name of the Factory to search for (not used)
+ * @param classID the ClassID of the FastFactory to search for
+ * @returns true if found, false otherwise.
+ */
+FastFactory* FastFactory::searchFastFactory(ClassID classID, const char* fastFactoryName)
+{
+  if (FastFactory::first == NULL)
+    return NULL;
+   else
+   {
+     FastFactory* tmpFac = FastFactory::first;
+     while (tmpFac != NULL)
+     {
+       if (tmpFac->storedClassID == classID)
+         return tmpFac;
+       tmpFac = tmpFac->next;
+     }
+   }
+   return NULL;
+}
 
 
Index: orxonox/trunk/src/util/object_manager.h
===================================================================
--- orxonox/trunk/src/util/object_manager.h	(revision 4932)
+++ orxonox/trunk/src/util/object_manager.h	(revision 4933)
@@ -30,30 +30,32 @@
  * Creates a FastFactory to a Loadable FastFactory.
  */
-#define CREATE_FAST_FACTORY(CLASS_NAME, CLASS_ID) \
-    tFastFactory<CLASS_NAME>* global_##CLASS_NAME##_FastFactory = new tFastFactory<CLASS_NAME>(#CLASS_NAME, CLASS_ID)
+//#define CREATE_FAST_FACTORY(CLASS_NAME, CLASS_ID) \
+    //tFastFactory<CLASS_NAME>* global_##CLASS_NAME##_FastFactory = new tFastFactory<CLASS_NAME>(#CLASS_NAME, CLASS_ID)
 
 //! A struct, that holds Lists of Objects of a certain type.
-typedef struct FastObjectMember
-{
-  BaseObject*          objectPointer;
-
-  FastObjectMember*    next;
+template <class T> struct FastObjectMember
+{
+  T*                      objectPointer;
+
+  FastObjectMember<T>*    next;
 };
 
 //! The FastFactory is a fast loadable object creator, and Dynamic List of dead object handler.
+/**
+ * FastFactory is needed to glue all the tFastFactory<T>'s together.
+ * Furthermore one can retrieve the corresponding tFastFactory over
+ * tFastFactory<T>* = FastFacroty::getFastFactory(ID);
+ */
 class FastFactory : public BaseObject {
 
   public:
-    FastFactory (const char* fastFactoryName, ClassID classID);
     virtual ~FastFactory ();
 
-
+    // functions to push and pop elements of this class
     BaseObject* resurect(ClassID classID);
     void kill(ClassID classID, BaseObject* object);
 
-    virtual BaseObject* fabricate(ClassID classID) = NULL;
-
-    static void registerFastFactory(FastFactory* fastFactory);
-    static void registerFastFactory(const char* fastFactoryName, ClassID classID);
+    // retrival functions for fast Ineraction
+    //FastFactory* getFastFactory(ClassID classID);
 
     /** @returns the first FastFactory */
@@ -66,6 +68,14 @@
     FastFactory* getNext() const { return this->next; };
 
+    virtual BaseObject* fabricate(ClassID classID) = NULL;
+
+  private:
+    FastFactory (ClassID classID, const char* fastFactoryName = NULL);
+    static void registerFastFactory(FastFactory* fastFactory);
+    static FastFactory* searchFastFactory(ClassID classID, const char* fastFactoryName = NULL);
+
   protected:
     ClassID               storedClassID;        //!< The classID of the specified class.
+    unsigned int          storedDeadObjects;    //!< How many dead objects are stored in this class
 
   private:
@@ -82,8 +92,20 @@
 {
   public:
-    tFastFactory(const char* fastFactoryName, ClassID fastFactory);
-
-  private:
-    virtual BaseObject* fabricate(ClassID classID);
+    static FastFactory* getFastFactory(ClassID classID, const char* fastFactoryName = NULL);
+
+    void prepare(unsigned int count);
+
+    T* resurect();
+    void kill(T* object);
+
+  private:
+    tFastFactory(ClassID classID, const char* fastFactoryName);
+
+    T* fabricate();
+
+  private:
+    FastObjectMember<T>*     deadList;             //!< A List of all stored dead Objects of this class.
+    FastObjectMember<T>*     unusedContainers;     //!< This is a List of unused containers, that will be reused by kill.
+
 };
 
@@ -94,22 +116,90 @@
  */
 template<class T>
-    tFastFactory<T>::tFastFactory(const char* fastFactoryName, ClassID fastFactory) : FastFactory(fastFactoryName, fastFactory)
+    tFastFactory<T>::tFastFactory(ClassID classID, const char* fastFactoryName)
+  : FastFactory(classID, fastFactoryName)
 {
   PRINTF(5)("Class: %s loadable as a FastFactory\n", this->getName());
-}
-
-template<class T>
-BaseObject* tFastFactory<T>::fabricate(ClassID classID)
-{
-  if (this->storedClassID == classID)
-    return new T ();
-  else if( getNext() != NULL)
-    return getNext()->fabricate(classID);
+
+  this->deadList = NULL;
+  this->unusedContainers = NULL;
+}
+
+template<class T>
+    FastFactory* tFastFactory<T>::getFastFactory(ClassID classID, const char* fastFactoryName)
+{
+  tFastFactory<T>* tmpFac = NULL;
+  if (FastFactory::getFirst() != NULL)
+    tmpFac = FastFactory::getFirst()->searchFastFactory(classID, fastFactoryName);
+
+  if (tmpFac != NULL)
+    return tmpFac;
   else
-    return NULL;
-}
-
-
-
+    return new tFastFactory<T>;
+}
+
+
+template<class T>
+    T* tFastFactory<T>::fabricate()
+{
+  FastObjectMember<T>* tmpFirstDead = this->deadList;
+  tmpFirstDead->objectPointer = new T();
+  tmpFirstDead->next = this->deadList;
+  ++this->storedDeadObjects;
+
+  this->deadList = tmpFirstDead;
+  return this->deadList;
+}
+
+template<class T>
+    void tFastFactory<T>::prepare(unsigned int count)
+{
+  if (this->storedDeadObjects + this->storedLivingObjects >= count)
+  {
+    PRINTF(3)("not creating new Objects for class %s, because the requested count already exists\n", this->getClassName());
+  }
+  for (int i = this->storedDeadObjects + this->storedLivingObjects; i < count; i++)
+  {
+    this->fabricate();
+  }
+}
+
+template<class T>
+    T* tFastFactory<T>::resurect()
+{
+  if (unlikely(this->deadList == NULL))
+  {
+    PRINTF(2)("The deadList of Class %s is empty, this may be either because it has not been filled yet, or the cache is to small.\n" \
+        "Fabricating a new %s", this->getName(), this->getName());
+    return this->fabricate();
+  }
+  else
+  {
+    FastObjectMember<T>* tmpC = deadList;
+    this->deadList = this->deadList->next;
+
+    tmpC->next = this->unusedContainers;
+    this->unusedContainers->tmpC;
+
+    return tmpC;
+  }
+}
+
+template<class T>
+    void tFastFactory<T>::kill(T* object)
+{
+  FastObjectMember<T>* tmpC;
+  if (unlikely(this->unusedContainers == NULL))
+  {
+    tmpC = new FastObjectMember<T>;
+  }
+  else
+  {
+    tmpC = this->unusedContainers;
+    this->unusedContainers = this->unusedContainers->next;
+  }
+
+  tmpC->next = this->deadList;
+  tmpC->objectPointer = object;
+}
 
 ////////////////////
