Added --developer option, also Ctrl-F2, which enabled cheats
[supertux.git] / src / supertux / game_object.cpp
1 //  SuperTux
2 //  Copyright (C) 2006 Matthias Braun <matze@braunis.de>
3 //
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.
8 //
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.
13 //
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/>.
16
17 #include "supertux/game_object.hpp"
18 #include "supertux/object_remove_listener.hpp"
19
20 GameObject::GameObject() :
21   wants_to_die(false),
22   remove_listeners(NULL),
23   name()
24 {
25 }
26
27 GameObject::GameObject(const GameObject& rhs) :
28   RefCounter(),
29   wants_to_die(rhs.wants_to_die),
30   remove_listeners(NULL),
31   name(rhs.name)
32 {
33 }
34
35 GameObject::~GameObject()
36 {
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);
42     delete entry;
43     entry = next;
44   }
45 }
46
47 void
48 GameObject::add_remove_listener(ObjectRemoveListener* listener)
49 {
50   RemoveListenerListEntry* entry = new RemoveListenerListEntry();
51   entry->next = remove_listeners;
52   entry->listener = listener;
53   remove_listeners = entry;
54 }
55
56 void
57 GameObject::del_remove_listener(ObjectRemoveListener* listener)
58 {
59   RemoveListenerListEntry* entry = remove_listeners;
60   if (entry->listener == listener) {
61     remove_listeners = entry->next;
62     delete entry;
63     return;
64   }
65   RemoveListenerListEntry* next = entry->next;
66   while(next != NULL) {
67     if (next->listener == listener) {
68       entry->next = next->next;
69       delete next;
70       break;
71     }
72     entry = next;
73     next = next->next;
74   }
75 }
76
77 /* EOF */