added object remove_listener so that you can get a message if some objects are remove...
[supertux.git] / lib / special / game_object.cpp
index c3fd98d..7a9db2b 100644 (file)
 
 #include <config.h>
 
-#include "special/game_object.h"
+#include "game_object.h"
+#include "object_remove_listener.h"
 
 namespace SuperTux
 {
 
 GameObject::GameObject()
-  : wants_to_die(false), flags(0)
+  : wants_to_die(false), remove_listeners(0), flags(0)
 {
 }
 
 GameObject::~GameObject()
 {
+  // call remove listeners (and remove them from the list)
+  RemoveListenerListEntry* entry = remove_listeners;
+  while(entry != 0) {
+    RemoveListenerListEntry* next = entry->next;
+    entry->listener->object_removed(this);
+    delete entry;
+    entry = next;
+  }
 }
 
 }