src/supertux/game_object.cpp

Go to the documentation of this file.
00001 //  SuperTux
00002 //  Copyright (C) 2006 Matthias Braun <matze@braunis.de>
00003 //
00004 //  This program is free software: you can redistribute it and/or modify
00005 //  it under the terms of the GNU General Public License as published by
00006 //  the Free Software Foundation, either version 3 of the License, or
00007 //  (at your option) any later version.
00008 //
00009 //  This program is distributed in the hope that it will be useful,
00010 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 //  GNU General Public License for more details.
00013 //
00014 //  You should have received a copy of the GNU General Public License
00015 //  along with this program.  If not, see <http://www.gnu.org/licenses/>.
00016 
00017 #include "supertux/game_object.hpp"
00018 #include "supertux/object_remove_listener.hpp"
00019 
00020 GameObject::GameObject() :
00021   wants_to_die(false), 
00022   remove_listeners(NULL),
00023   name()
00024 {
00025 }
00026 
00027 GameObject::GameObject(const GameObject& rhs) :
00028   RefCounter(),
00029   wants_to_die(rhs.wants_to_die),
00030   remove_listeners(NULL),
00031   name(rhs.name)
00032 {  
00033 }
00034 
00035 GameObject::~GameObject()
00036 {
00037   // call remove listeners (and remove them from the list)
00038   RemoveListenerListEntry* entry = remove_listeners;
00039   while(entry != NULL) {
00040     RemoveListenerListEntry* next = entry->next;
00041     entry->listener->object_removed(this);
00042     delete entry;
00043     entry = next;
00044   }
00045 }
00046  
00047 void 
00048 GameObject::add_remove_listener(ObjectRemoveListener* listener)
00049 {
00050   RemoveListenerListEntry* entry = new RemoveListenerListEntry();
00051   entry->next = remove_listeners;
00052   entry->listener = listener;
00053   remove_listeners = entry;
00054 }
00055 
00056 void
00057 GameObject::del_remove_listener(ObjectRemoveListener* listener)
00058 {
00059   RemoveListenerListEntry* entry = remove_listeners;
00060   if (entry->listener == listener) {
00061     remove_listeners = entry->next;
00062     delete entry;
00063     return;
00064   }
00065   RemoveListenerListEntry* next = entry->next;
00066   while(next != NULL) {
00067     if (next->listener == listener) {
00068       entry->next = next->next;
00069       delete next;
00070       break;
00071     }
00072     entry = next;
00073     next = next->next;
00074   }
00075 }
00076 
00077 /* EOF */

Generated on Mon Jun 9 03:38:22 2014 for SuperTux by  doxygen 1.5.1