X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fobject_factory.hpp;h=40445d322ee6f6abd56d782e14989a524195a3f1;hb=aee6c4dede5a9c4fa0f7eb134fba61fef738a573;hp=a6e431051925a1dda18149f632d13a9d9797087a;hpb=7c579d3ef0a6667c18b53dad84c63c05d2760a84;p=supertux.git diff --git a/src/object_factory.hpp b/src/object_factory.hpp index a6e431051..40445d322 100644 --- a/src/object_factory.hpp +++ b/src/object_factory.hpp @@ -23,6 +23,8 @@ #include #include +#include "direction.hpp" + namespace lisp { class Lisp; } class Vector; class GameObject; @@ -37,13 +39,18 @@ public: * Remember to delete the objects later */ virtual GameObject* create_object(const lisp::Lisp& reader) = 0; -}; -typedef std::map Factories; -extern Factories* object_factories; + typedef std::map 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_badguy_object(const std::string& name, const Vector& pos, Direction dir = LEFT); /** comment from Matze: * Yes I know macros are evil, but in this specific case they save @@ -57,10 +64,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) \