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)
26 GameObject::GameObject(const GameObject& rhs) :
27 wants_to_die(rhs.wants_to_die),
28 remove_listeners(NULL)
32 GameObject::~GameObject()
34 // call remove listeners (and remove them from the list)
35 RemoveListenerListEntry* entry = remove_listeners;
36 while(entry != NULL) {
37 RemoveListenerListEntry* next = entry->next;
38 entry->listener->object_removed(this);
45 GameObject::add_remove_listener(ObjectRemoveListener* listener)
47 RemoveListenerListEntry* entry = new RemoveListenerListEntry();
48 entry->next = remove_listeners;
49 entry->listener = listener;
50 remove_listeners = entry;
54 GameObject::del_remove_listener(ObjectRemoveListener* listener)
56 RemoveListenerListEntry* entry = remove_listeners;
57 if (entry->listener == listener) {
58 remove_listeners = entry->next;
62 RemoveListenerListEntry* next = entry->next;
64 if (next->listener == listener) {
65 entry->next = next->next;