Index: orxonox/trunk/src/util/loading/factory.cc
===================================================================
--- orxonox/trunk/src/util/loading/factory.cc	(revision 4261)
+++ orxonox/trunk/src/util/loading/factory.cc	(revision 4261)
@@ -0,0 +1,110 @@
+/* 
+   orxonox - the future of 3D-vertical-scrollers
+
+   Copyright (C) 2004 orx
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   ### File Specific:
+   main-programmer: Christian Meyer
+   co-programmer: Benjamin Grauer
+*/
+
+
+#include "factory.h"
+#include "game_loader.h"
+
+using namespace std;
+
+/*  --------------------------------------------------
+ *		 Factory
+ *   --------------------------------------------------
+ */
+
+/**
+   \brief constructor
+   
+   set everything to zero and define factoryName
+*/
+Factory::Factory (const char* name)
+{
+  this->factoryName = NULL;
+  this->setFactoryName(name);
+  next = NULL;
+  
+  initialize();
+}
+
+/**
+   \brief destructor
+   
+   clear the Q
+*/
+Factory::~Factory ()
+{
+  //  printf("%s\n", this->factoryName);
+  //  Factory* tmpDel = this->next;
+  //  this->next = NULL;
+  if (this->next)
+    delete this->next;
+}
+
+void Factory::setFactoryName(const char* name)
+{
+  if (factoryName)
+    delete factoryName;
+  factoryName = new char[strlen(name)+1];
+  strcpy(factoryName, name);
+}
+
+
+/**
+   \brief generates the associated object from data
+*/
+BaseObject* Factory::fabricate(const TiXmlElement* data)
+{
+  return NULL;
+}
+
+/**
+   \brief make this particular factory known to the LevelFactory
+*/
+void Factory::initialize()
+{
+  GameLoader* gl = GameLoader::getInstance();
+  gl->registerFactory( this);
+}
+
+/**
+   \brief add a Factory to the Q
+*/
+void Factory::registerFactory( Factory* factory)
+{
+  if( next == NULL) setNext( factory);
+  else next->registerFactory( factory);
+}
+
+const char* grabParameter(const TiXmlElement* root, const char* name)
+{
+  const TiXmlElement* element;
+  const TiXmlNode* node;
+	
+  if (root == NULL)
+    return NULL;
+  assert( name != NULL);
+	
+  element = root->FirstChildElement( name);
+  if( element == NULL) return NULL;
+	
+  node = element->FirstChild();
+  while( node != NULL)
+    {
+      if( node->ToText()) return node->Value();
+      node = node->NextSibling();
+    }
+  return NULL;
+}
+
Index: orxonox/trunk/src/util/loading/factory.h
===================================================================
--- orxonox/trunk/src/util/loading/factory.h	(revision 4261)
+++ orxonox/trunk/src/util/loading/factory.h	(revision 4261)
@@ -0,0 +1,95 @@
+/* 
+   orxonox - the future of 3D-vertical-scrollers
+
+   Copyright (C) 2004 orx
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   ### File Specific:
+   main-programmer: Christian Meyer
+   co-programmer: Benjamin Grauer
+*/
+
+/*! 
+  \file factory.h
+  \brief philosophy stuff
+*/
+
+
+#ifndef _FACTORY_H
+#define _FACTORY_H
+
+class BaseObject;
+
+#include "tinyxml.h"
+#include "load_param.h"
+#include "debug.h"
+
+/** 
+    Creates a factory to a Loadable Class.
+    this should be used at the beginning of all the Classes that should be loadable (in the cc-file)
+*/
+#define CREATE_FACTORY(CLASS_NAME) tFactory<CLASS_NAME>* global_##CLASS_NAME##Factory = new tFactory<CLASS_NAME>(#CLASS_NAME)		
+//! The Factory is
+class Factory {
+
+ public:
+  Factory (const char* name = NULL);
+  ~Factory ();
+  
+
+  virtual BaseObject* fabricate(const TiXmlElement* root);
+  void initialize();
+  void registerFactory( Factory* factory);
+  void setFactoryName(const char* name);
+  const char* getFactoryName() {return factoryName;};
+  void setNext( Factory* factory) {next = factory;}
+  Factory* getNext() {return next;}
+	
+ private:
+  char* factoryName;
+	
+  Factory* next;
+};
+
+template<class T> class tFactory : public Factory
+{
+ public:
+  tFactory(const char* name);
+  virtual ~tFactory();
+  
+  private:
+  BaseObject* fabricate(const TiXmlElement* root);
+};
+
+template<class T>
+tFactory<T>::tFactory(const char* name) : Factory(name)
+{
+  PRINTF(5)("fileName: %s\n", name);
+}
+  
+
+template<class T>
+tFactory<T>::~tFactory()
+{}
+
+template<class T>
+BaseObject* tFactory<T>::fabricate(const TiXmlElement* root) 
+{ 
+  if(!strcmp(root->Value(), getFactoryName()))
+    return new T ( root);
+  else if( getNext() != NULL) 
+    return getNext()->fabricate( root);
+  else 
+    return NULL;
+}
+
+// helper function
+
+const char* grabParameter(const TiXmlElement* root, const char* name);
+
+#endif /* _FACTORY_H */
+
Index: orxonox/trunk/src/util/loading/load_param.cc
===================================================================
--- orxonox/trunk/src/util/loading/load_param.cc	(revision 4261)
+++ orxonox/trunk/src/util/loading/load_param.cc	(revision 4261)
@@ -0,0 +1,234 @@
+/* 
+   orxonox - the future of 3D-vertical-scrollers
+
+   Copyright (C) 2004 orx
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   ### File Specific:
+   main-programmer: Christian Meyer
+   co-programmer: ...
+*/
+
+#include "load_param.h"
+
+#include "list.h"
+#include "base_object.h"
+
+#include <stdarg.h>
+
+/**
+   \param object The object this Parameter is loaded too.
+   \param paramName The name of the parameter loaded.
+   \param paramCount how many parameters this loading-function takes
+   \param ... the parameter information
+*/
+BaseLoadParam::BaseLoadParam(BaseObject* object, const char* paramName, int paramCount, ...)
+{
+  this->paramDesc = NULL;
+  if (LoadClassDescription::parametersDescription)
+    {
+      // locating the class
+      this->classDesc = LoadClassDescription::addClass(object->getClassName());
+      this->paramDesc = this->classDesc->addParam(paramName);
+
+      this->paramDesc->types = new char*[paramCount];
+      this->paramDesc->paramCount = paramCount;
+
+      va_list types;
+      va_start (types, paramCount);
+      for(int i = 0; i < paramCount; i++)
+	{
+	  const char* tmpTypeName = va_arg (types, const char*);
+	  this->paramDesc->types[i] = new char[strlen(tmpTypeName)+1];
+	  strcpy(this->paramDesc->types[i], tmpTypeName);
+	}
+      va_end(types);  
+
+      int argCount = 0;
+    }
+}
+
+/**
+   \param descriptionText The text to set as a description for this Parameter
+   \returns a pointer to itself.
+*/
+BaseLoadParam* BaseLoadParam::describe(const char* descriptionText)
+{
+  if (LoadClassDescription::parametersDescription && this->paramDesc && !this->paramDesc->getDescription())
+    {
+      this->paramDesc->setDescription(descriptionText);
+    }
+  return this;
+}
+
+/**
+   \param paramName the name of the parameter to load
+*/
+LoadParamDescription::LoadParamDescription(const char* paramName)
+{
+  this->types = NULL;
+  this->description = NULL;
+  this->paramName = new char[strlen(paramName)+1];
+  strcpy(this->paramName, paramName);
+}
+
+/**
+   \brief removes all the alocated memory
+*/
+LoadParamDescription::~LoadParamDescription(void)
+{
+  for(int i = 0; i < this->paramCount; i++)
+    {
+      delete this->types[i];
+    }
+  delete []this->types;
+  delete []this->paramName;
+  delete []this->description;
+}
+
+/**
+   \param descriptionText The text to set as a description for this Parameter
+*/
+void LoadParamDescription::setDescription(const char* descriptionText)
+{
+  this->description = new char[strlen(descriptionText)+1];
+  strcpy(this->description, descriptionText);
+}
+
+/**
+   \brief prints out this parameter, its input method and the description (if availiable)
+*/
+void LoadParamDescription::print(void) const
+{
+  PRINT(3)(" <%s>", this->paramName);
+  for (int i = 0; i < this->paramCount; i++)
+    {
+      if (i > 0)
+	PRINT(3)(",");
+      PRINT(3)("%s", this->types[i]);
+    }
+  PRINT(3)("</%s>", this->paramName);
+  if (this->description)
+    PRINT(3)(" -- %s", this->description);
+  PRINT(3)("\n");
+}
+
+/**
+   \brief A list, that holds all the classes that are loadable (classes not objects!!)
+*/
+tList<LoadClassDescription>* LoadClassDescription::classList = new tList<LoadClassDescription>;
+
+/**
+   \brief if the description of Parameters should be executed
+*/
+bool LoadClassDescription::parametersDescription = true;
+
+/**
+   \param className the name of the class to be loadable
+*/
+LoadClassDescription::LoadClassDescription(const char* className)
+{
+  this->className = new char[strlen(className)+1];
+  strcpy(this->className, className);
+
+  classList->add(this);
+
+  this->paramList = new tList<LoadParamDescription>;
+}
+
+/**
+   \brief deletes a classDescription (deletes all the parameterDescriptions as well
+*/
+LoadClassDescription::~LoadClassDescription(void)
+{
+  delete []this->className;
+
+  tIterator<LoadParamDescription>* iterator = this->paramList->getIterator();
+  LoadParamDescription* enumParamDesc = iterator->nextElement();
+  while (enumParamDesc)
+    {
+      delete enumParamDesc;
+      enumParamDesc = iterator->nextElement();
+    }
+  delete iterator;
+}
+
+/**
+   \brief adds a class to the list of loadable classes
+   \param className The name of the class to add
+
+   this function searches for the className string, and if found just returns the appropriate Class.
+   Otherwise it returns a new classDescription
+*/
+LoadClassDescription* LoadClassDescription::addClass(const char* className)
+{
+  tIterator<LoadClassDescription>* iterator = LoadClassDescription::classList->getIterator();
+  LoadClassDescription* enumClassDesc = iterator->nextElement();
+  while (enumClassDesc)
+    {
+      if (!strcmp(enumClassDesc->className, className))
+	{
+	  delete iterator;
+	  return enumClassDesc;
+	}
+      enumClassDesc = iterator->nextElement();
+    }
+  delete iterator;
+
+  return new LoadClassDescription(className);
+}
+
+/**
+   \brief does the same as addClass(const char* className), but with params
+   \param paramName the name of the parameter to add.
+*/
+LoadParamDescription* LoadClassDescription::addParam(const char* paramName)
+{
+  tIterator<LoadParamDescription>* iterator = this->paramList->getIterator();
+  LoadParamDescription* enumParamDesc = iterator->nextElement();
+  while (enumParamDesc)
+    {
+      if (!strcmp(enumParamDesc->paramName, paramName))
+	{
+	  delete iterator;
+	  return enumParamDesc;
+	}
+      enumParamDesc = iterator->nextElement();
+    }
+  delete iterator;
+
+  this->paramList->add(new LoadParamDescription(paramName));
+  return paramList->lastElement();
+}
+
+/**
+   \brief prints out all loadable Classes, and their parameters
+*/
+void LoadClassDescription::printAll(const char* fileName)
+{
+  PRINT(3)("===============================================================\n");
+  PRINT(3)(" Listing all the Loadable Options (loaded since Game started).\n\n");
+  tIterator<LoadClassDescription>* classIT = LoadClassDescription::classList->getIterator();
+  LoadClassDescription* enumClassDesc = classIT->nextElement();
+  while (enumClassDesc)
+    {
+      PRINT(3)("<%s>\n", enumClassDesc->className);
+      tIterator<LoadParamDescription>* paramIT = enumClassDesc->paramList->getIterator();
+      LoadParamDescription* enumParamDesc = paramIT->nextElement();
+      while (enumParamDesc)
+	{
+	  enumParamDesc->print();
+	  enumParamDesc = paramIT->nextElement();
+	}
+      delete paramIT;
+
+      PRINT(3)("</%s>\n\n", enumClassDesc->className);
+      enumClassDesc = classIT->nextElement();
+    }
+  delete classIT;
+  PRINT(3)("===============================================================\n");
+}
Index: orxonox/trunk/src/util/loading/load_param.h
===================================================================
--- orxonox/trunk/src/util/loading/load_param.h	(revision 4261)
+++ orxonox/trunk/src/util/loading/load_param.h	(revision 4261)
@@ -0,0 +1,233 @@
+/* 
+   orxonox - the future of 3D-vertical-scrollers
+
+   Copyright (C) 2004 orx
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   ### File Specific:
+   main-programmer: Benjamin Grauer
+   co-programmer: ...
+*/
+
+/*! 
+    \file load_param.h
+    \brief A Class and macro-functions, that makes our lives easy to load-in parameters
+*/
+
+#ifndef _LOAD_PARAM_H
+#define _LOAD_PARAM_H
+
+#include "factory.h"
+#include "debug.h"
+#include "substring.h"
+
+// Forward Declaration //
+template<class T> class tList;
+
+/**
+   useable FunctionParameters are:
+   l_INT:    int
+   l_LONG:   long
+   l_SHORT:  short
+   l_FLOAT:  float
+   l_STRING: const char*
+*/
+
+#define l_INT_TYPE int
+#define l_INT_FUNC atoi
+#define l_INT_NAME "int"
+
+#define l_LONG_TYPE long
+#define l_LONG_FUNC atol
+#define l_LONG_NAME "long"
+
+#define l_SHORT_TYPE short
+#define l_SHORT_FUNC atoi
+#define l_SHORT_NAME "short"
+
+#define l_FLOAT_TYPE float
+#define l_FLOAT_FUNC atof
+#define l_FLOAT_NAME "float"
+
+#define l_STRING_TYPE const char*
+#define l_STRING_FUNC
+#define l_STRING_NAME "string"
+
+
+/**
+   \brief a Macro to easily implement many different Constructors for the LoadParam-Class
+   \param type1 The type of the first functionParameter
+*/
+#define LoadParam1(type1) \
+ LoadParam(const TiXmlElement* root, const char* paramName, T* pt2Object, void(T::*function)(type1##_TYPE)) \
+  : BaseLoadParam(pt2Object, paramName, 1, type1##_NAME) \
+    { \
+      const char* loadString = grabParameter(root, paramName); \
+      if (loadString != NULL && root != NULL) \
+	(*pt2Object.*function)(type1##_FUNC(loadString)); \
+      else \
+	PRINTF(4)("Not loaded parameter %s of %s\n", paramName, pt2Object->getClassName()); \
+    }
+
+
+// 2. TYPES
+#define LoadParam2(type1, type2) \
+ LoadParam(const TiXmlElement* root, const char* paramName, T* pt2Object, void(T::*function)(type1##_TYPE, type2##_TYPE)) \
+  : BaseLoadParam(pt2Object, paramName, 2, type1##_NAME, type2##_NAME) \
+    { \
+      const char* loadString = grabParameter(root, paramName); \
+      if (loadString != NULL && root != NULL) \
+	{ \
+	  SubString subLoads(loadString); \
+	  if (subLoads.getCount() == 2) \
+	    (*pt2Object.*function)(type1##_FUNC(subLoads.getString(0)), type2##_FUNC(subLoads.getString(1))); \
+	  else \
+	    PRINTF(2)("Not loaded Parameter %s of %s, because wrong count of arguments.\n -> Should have %d but have %d\n", \
+		      paramName, pt2Object->getClassName(), 2, subLoads.getCount()); \
+	} \
+      else \
+	PRINTF(4)("Not loaded parameter %s of %s\n", paramName, pt2Object->getClassName()); \
+    }
+
+
+// 3. TYPES
+#define LoadParam3(type1, type2, type3) \
+ LoadParam(const TiXmlElement* root, const char* paramName, T* pt2Object, void(T::*function)(type1##_TYPE, type2##_TYPE, type3##_TYPE))\
+  : BaseLoadParam(pt2Object, paramName, 3, type1##_NAME, type2##_NAME, type3##_NAME) \
+    { \
+      const char* loadString = grabParameter(root, paramName); \
+      if (loadString != NULL && root != NULL) \
+	{ \
+	  SubString subLoads(loadString); \
+	  if (subLoads.getCount() == 3) \
+	    (*pt2Object.*function)(type1##_FUNC(subLoads.getString(0)), type2##_FUNC(subLoads.getString(1)), type3##_FUNC(subLoads.getString(2))); \
+	  else \
+	    PRINTF(2)("Not loaded Parameter %s of %s, because wrong count of arguments.\n -> Should have %d but have %d\n", \
+		      paramName, pt2Object->getClassName(), 3, subLoads.getCount()); \
+	} \
+      else \
+	PRINTF(4)("Not loaded parameter %s of %s\n", paramName, pt2Object->getClassName()); \
+    }
+
+
+// 4. TYPES
+#define LoadParam4(type1, type2, type3, type4) \
+ LoadParam(const TiXmlElement* root, const char* paramName, T* pt2Object, void(T::*function)(type1##_TYPE, type2##_TYPE, type3##_TYPE, type4##_TYPE)) \
+  : BaseLoadParam(pt2Object, paramName, 4, type1##_NAME, type2##_NAME, type3##_NAME, type2##_NAME, type4##_NAME) \
+    { \
+      const char* loadString = grabParameter(root, paramName); \
+      if (loadString != NULL && root != NULL) \
+	{ \
+	  SubString subLoads(loadString); \
+	  if (subLoads.getCount() == 4) \
+	    (*pt2Object.*function)(type1##_FUNC(subLoads.getString(0)), type2##_FUNC(subLoads.getString(1)), type3##_FUNC(subLoads.getString(2)), type4##_FUNC(subLoads.getString(3))); \
+	  else \
+	    PRINTF(2)("Not loaded Parameter %s of %s, because wrong count of arguments.\n -> Should have %d but have %d\n", \
+		      paramName, pt2Object->getClassName(), 4, subLoads.getCount()); \
+	} \
+      else \
+	PRINTF(4)("Not loaded parameter %s of %s\n", paramName, pt2Object->getClassName()); \
+    }
+
+
+// 5. TYPES
+#define LoadParam5(type1, type2, type3, type4, type5) \
+ LoadParam(const TiXmlElement* root, const char* paramName, T* pt2Object, void(T::*function)(type1##_TYPE, type2##_TYPE, type3##_TYPE, type4##_TYPE, type5##_TYPE)) \
+  : BaseLoadParam(pt2Object, paramName, 5, type1##_NAME, type2##_NAME, type3##_NAME, type2##_NAME, type4##_NAME, type5##_NAME) \
+    { \
+      const char* loadString = grabParameter(root, paramName); \
+      if (loadString != NULL && root != NULL) \
+	{ \
+	  SubString subLoads(loadString); \
+	  if (subLoads.getCount() == 5) \
+	    (*pt2Object.*function)(type1##_FUNC(subLoads.getString(0)), type2##_FUNC(subLoads.getString(1)), type3##_FUNC(subLoads.getString(2)), type4##_FUNC(subLoads.getString(3)), type5##_FUNC(subLoads.getString(4))); \
+	  else \
+	    PRINTF(2)("Not loaded Parameter %s of %s, because wrong count of arguments.\n -> Should have %d but have %d\n", \
+		      paramName, pt2Object->getClassName(), 5, subLoads.getCount()); \
+	} \
+      else \
+	PRINTF(4)("Not loaded parameter %s of %s\n", paramName, pt2Object->getClassName()); \
+    }
+
+
+//! A class that handles the description of loadable parameters
+class LoadParamDescription
+{
+  friend class BaseLoadParam;
+  friend class LoadClassDescription;
+ public:
+  LoadParamDescription(const char* paramName);
+  ~LoadParamDescription(void);
+
+  void setDescription(const char* descriptionText);
+  /** \returns the descriptionString */
+  const char* getDescription(void) { return this->description;};
+
+  void print(void) const;
+ private:
+  char* paramName;              //!< The name of the parameter
+  int paramCount;               //!< The count of parameters
+  char** types;                 //!< What kind of parameters does this function take ??
+  char* description;            //!< A longer description about this function
+};
+
+class LoadClassDescription
+{
+  friend class BaseLoadParam;
+ public:
+  LoadClassDescription(const char* className);
+  ~LoadClassDescription(void);
+
+  static LoadClassDescription* addClass(const char* className);
+  LoadParamDescription* addParam(const char* paramName);
+
+  static void printAll(const char* fileName = NULL);
+
+  static bool parametersDescription;             //!< if parameter-description should be enabled.
+  static tList<LoadClassDescription>* classList; //!< a list, that holds all the loadable classes. (after one instance has been loaded)
+ private:
+  char* className;                               //!< name of the class
+  tList<LoadParamDescription>* paramList;        //!< List of parameters this class knows.
+};
+
+// abstract Base class
+class BaseLoadParam
+{
+ public:
+  BaseLoadParam* describe(const char* descriptionText);
+
+ protected:
+  BaseLoadParam(BaseObject* object, const char* paramName, int paramCount, ...);
+
+ protected:
+  LoadClassDescription* classDesc;               //!< The LoadClassDescription of this LoadParameter
+  LoadParamDescription* paramDesc;               //!< The LoadParameterDescription of this LoadParameter
+};
+
+
+//! derived template class, so all the Classes can load something.
+template<class T> class LoadParam : public BaseLoadParam
+{
+ public:
+  LoadParam1(l_STRING);
+  LoadParam2(l_STRING, l_STRING);
+  LoadParam3(l_STRING, l_STRING, l_STRING);
+  LoadParam4(l_STRING, l_STRING, l_STRING, l_STRING);
+
+  LoadParam1(l_INT);
+  LoadParam2(l_INT, l_INT);
+  LoadParam3(l_INT, l_INT, l_INT);
+  LoadParam4(l_INT, l_INT, l_INT, l_INT);
+
+  LoadParam1(l_FLOAT);
+  LoadParam2(l_FLOAT, l_FLOAT);
+  LoadParam3(l_FLOAT, l_FLOAT, l_FLOAT);
+  LoadParam4(l_FLOAT, l_FLOAT, l_FLOAT, l_FLOAT);
+};
+
+
+#endif /* _LOAD_PARAM_H */
