4 // Copyright (C) 2006 Matthias Braun <matze@braunis.de>
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 #ifndef SUPERTUX_GAMEOBJECT_H
20 #define SUPERTUX_GAMEOBJECT_H
23 #include "refcounter.hpp"
26 class ObjectRemoveListener;
29 * Base class for all the things that make up Levels' Sectors.
31 * Each sector of a level will hold a list of active GameObject while the
34 * This class is responsible for:
35 * - Updating and Drawing the object. This should happen in the update() and
36 * draw() functions. Both are called once per frame.
37 * - Providing a safe way to remove the object by calling the remove_me
40 class GameObject : public RefCounter
44 virtual ~GameObject();
46 /** This function is called once per frame and allows the object to update
47 * it's state. The elapsed_time is the time since the last frame in
48 * seconds and should be the base for all timed calculations (don't use
49 * SDL_GetTicks directly as this will fail in pause mode)
51 virtual void update(float elapsed_time) = 0;
53 /** The GameObject should draw itself onto the provided DrawingContext if this
56 virtual void draw(DrawingContext& context) = 0;
58 /** returns true if the object is not scheduled to be removed yet */
64 /** schedules this object to be removed at the end of the frame */
70 /** registers a remove listener which will be called if the object
71 * gets removed/destroyed
73 void add_remove_listener(ObjectRemoveListener* listener);
76 * unregisters a remove listener, so it will no longer be called if the object
77 * gets removed/destroyed
79 void del_remove_listener(ObjectRemoveListener* listener);
81 const std::string& get_name() const
87 /** this flag indicates if the object should be removed at the end of the
92 struct RemoveListenerListEntry
94 RemoveListenerListEntry* next;
95 ObjectRemoveListener* listener;
97 RemoveListenerListEntry* remove_listeners;
101 * a name for the gameobject, this is mostly a hint for scripts and for
102 * debugging, don't rely on names being set or being unique
107 #endif /*SUPERTUX_GAMEOBJECT_H*/