New grow and skid sounds from remaxim
[supertux.git] / src / object_factory.hpp
index 922eec4..572a958 100644 (file)
 #include <string>
 #include <map>
 
-#include "lisp/lisp.hpp"
-#include "game_object.hpp"
-#include "math/vector.hpp"
+#include "direction.hpp"
+
+namespace lisp { class Lisp; }
+class Vector;
+class GameObject;
 
 class Factory
 {
 public:
   virtual ~Factory()
   { }
-    
+
   /** Creates a new gameobject from a lisp node.
    * Remember to delete the objects later
    */
   virtual GameObject* create_object(const lisp::Lisp& reader) = 0;
-};
 
-typedef std::map<std::string, Factory*> Factories;
-extern Factories* object_factories;
+  typedef std::map<std::string, Factory*> Factories;
+  static Factories &get_factories()
+  {
+    static Factories object_factories;
+    return object_factories;
+  }
+};
 
 GameObject* create_object(const std::string& name, const lisp::Lisp& reader);
-GameObject* create_object(const std::string& name, const Vector& pos);
+GameObject* create_object(const std::string& name, const Vector& pos, const Direction dir = AUTO);
 
 /** comment from Matze:
  * Yes I know macros are evil, but in this specific case they save
@@ -57,10 +63,12 @@ class INTERN_##CLASS##Factory : public Factory                    \
 public:                                                           \
   INTERN_##CLASS##Factory()                                       \
   {                                                               \
-    if(object_factories == 0)                                     \
-      object_factories = new Factories;                           \
+    get_factories()[NAME] = this;                                \
+  }                                                               \
                                                                   \
-    object_factories->insert(std::make_pair(NAME, this));         \
+  ~INTERN_##CLASS##Factory()                                      \
+  {                                                               \
+    get_factories().erase(NAME);                                 \
   }                                                               \
                                                                   \
   virtual GameObject* create_object(const lisp::Lisp& reader)     \