src/supertux/game_object.hpp

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 #ifndef HEADER_SUPERTUX_SUPERTUX_GAME_OBJECT_HPP
00018 #define HEADER_SUPERTUX_SUPERTUX_GAME_OBJECT_HPP
00019 
00020 #include <string>
00021 
00022 #include "util/refcounter.hpp"
00023 
00024 class DrawingContext;
00025 class ObjectRemoveListener;
00026 
00039 class GameObject : public RefCounter
00040 {
00041 public:
00042   GameObject();
00043   GameObject(const GameObject& rhs);
00044   virtual ~GameObject();
00045 
00051   virtual void update(float elapsed_time) = 0;
00052 
00056   virtual void draw(DrawingContext& context) = 0;
00057 
00059   bool is_valid() const
00060   {
00061     return !wants_to_die;
00062   }
00063 
00065   void remove_me()
00066   {
00067     wants_to_die = true;
00068   }
00069 
00073   void add_remove_listener(ObjectRemoveListener* listener);
00074   
00079   void del_remove_listener(ObjectRemoveListener* listener);
00080 
00081   const std::string& get_name() const
00082   {
00083     return name;
00084   }
00085 
00086 private:
00090   bool wants_to_die;
00091 
00092   struct RemoveListenerListEntry
00093   {
00094     RemoveListenerListEntry* next;
00095     ObjectRemoveListener* listener;
00096   };
00097   RemoveListenerListEntry* remove_listeners;
00098 
00099 protected:
00104   std::string name;
00105 
00106 private:
00107   GameObject& operator=(const GameObject&);
00108 };
00109 
00110 #endif /*SUPERTUX_GAMEOBJECT_H*/
00111 
00112 /* EOF */

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