]> de.git.xonotic.org Git - xonotic/netradiant.git/blobdiff - libs/entitylib.h
fixed camera freemove shortcuts bug
[xonotic/netradiant.git] / libs / entitylib.h
index 5c477c6608978ddcc096ff5884775539569a5440..4a34f0a53722a910538d2b8f5bd45839417988ba 100644 (file)
@@ -34,7 +34,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 #include "math/vector.h"
 #include "math/aabb.h"
 #include "undolib.h"
-#include "string/string.h"
+#include "string/pooledstring.h"
 #include "generic/referencecounted.h"
 #include "scenelib.h"
 #include "container/container.h"
@@ -304,13 +304,11 @@ public:
 };
 
 
-typedef Callback1<const char*> KeyObserver;
-
 /// \brief A key/value pair of strings.
 ///
 /// - Notifies observers when value changes - value changes to "" on destruction.
 /// - Provides undo support through the global undo system.
-class KeyValue
+class KeyValue : public EntityKeyValue
 {
   typedef UnsortedSet<KeyObserver> KeyObservers;
 
@@ -414,21 +412,21 @@ class EntityKeyValues : public Entity
 public:
   typedef KeyValue Value;
 
-  class Observer
+  static StringPool& getPool()
   {
-  public:
-    virtual void insert(const char* key, Value& value) = 0;
-    virtual void erase(const char* key, Value& value) = 0;
-  };
-
+    return Static<StringPool, KeyContext>::instance();
+  }
 private:
   static EntityCreator::KeyValueChangedFunc m_entityKeyValueChanged;
   static Counter* m_counter;
 
   EntityClass* m_eclass;
 
+  class KeyContext{};
+  typedef Static<StringPool, KeyContext> KeyPool;
+  typedef PooledString<KeyPool> Key;
   typedef SmartPointer<KeyValue> KeyValuePtr;
-  typedef UnsortedMap<CopiedString, KeyValuePtr > KeyValues;
+  typedef UnsortedMap<Key, KeyValuePtr> KeyValues;
   KeyValues m_keyValues;
 
   typedef UnsortedSet<Observer*> Observers;
@@ -504,7 +502,7 @@ private:
       (*i).second->instanceDetach(m_undo.map());
     }
 
-    CopiedString key((*i).first);
+    Key key((*i).first);
     KeyValuePtr value((*i).second);
     m_keyValues.erase(i);
     notifyErase(key.c_str(), *value);
@@ -546,6 +544,11 @@ public:
   }
   ~EntityKeyValues()
   {
+    for(Observers::iterator i = m_observers.begin(); i != m_observers.end();)
+    {
+      // post-increment to allow current element to be removed safely
+      (*i++)->clear();
+    }
     ASSERT_MESSAGE(m_observers.empty(), "EntityKeyValues::~EntityKeyValues: observers still attached");
   }