2 // Copyright (C) 2006 Matthias Braun <matze@braunis.de>
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #include "supertux/game_object.hpp"
18 #include "supertux/object_remove_listener.hpp"
20 GameObject::GameObject() :
22 remove_listeners(NULL),
27 GameObject::GameObject(const GameObject& rhs) :
29 wants_to_die(rhs.wants_to_die),
30 remove_listeners(NULL),
35 GameObject::~GameObject()
37 // call remove listeners (and remove them from the list)
38 RemoveListenerListEntry* entry = remove_listeners;
39 while(entry != NULL) {
40 RemoveListenerListEntry* next = entry->next;
41 entry->listener->object_removed(this);
48 GameObject::add_remove_listener(ObjectRemoveListener* listener)
50 RemoveListenerListEntry* entry = new RemoveListenerListEntry();
51 entry->next = remove_listeners;
52 entry->listener = listener;
53 remove_listeners = entry;
57 GameObject::del_remove_listener(ObjectRemoveListener* listener)
59 RemoveListenerListEntry* entry = remove_listeners;
60 if (entry->listener == listener) {
61 remove_listeners = entry->next;
65 RemoveListenerListEntry* next = entry->next;
67 if (next->listener == listener) {
68 entry->next = next->next;