X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fgame_object.hpp;h=7c4b59f6c8b069aa9129b07a4b69a4a02c28f930;hb=43db9a6c44b6ee544e7694d1bb234ba559b0849c;hp=1131847fb9d00adebcc78be6e94027cc3be50684;hpb=5b7f9214cb929399f1a855ef5807018a9447d510;p=supertux.git diff --git a/src/game_object.hpp b/src/game_object.hpp index 1131847fb..7c4b59f6c 100644 --- a/src/game_object.hpp +++ b/src/game_object.hpp @@ -1,7 +1,7 @@ -// $Id: game_object.h 2293 2005-03-25 20:39:56Z matzebraun $ +// $Id$ // -// SuperTux - A Jump'n Run -// Copyright (C) 2004 Matthias Braun +// SuperTux +// Copyright (C) 2006 Matthias Braun // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License @@ -20,22 +20,24 @@ #define SUPERTUX_GAMEOBJECT_H #include +#include "refcounter.hpp" class DrawingContext; class ObjectRemoveListener; /** - * This is a base class for all game objects. Each sector of a level will hold a - * list of active GameObject while the game is played. + * Base class for all the things that make up Levels' Sectors. + * + * Each sector of a level will hold a list of active GameObject while the + * game is played. * * This class is responsible for: * - Updating and Drawing the object. This should happen in the update() and * draw() functions. Both are called once per frame. * - Providing a safe way to remove the object by calling the remove_me * functions. - * - a 32bit bitset for flags... */ -class GameObject +class GameObject : public RefCounter { public: GameObject(); @@ -55,37 +57,30 @@ public: /** returns true if the object is not scheduled to be removed yet */ bool is_valid() const - { - return !wants_to_die; - } + { + return !wants_to_die; + } + /** schedules this object to be removed at the end of the frame */ void remove_me() { wants_to_die = true; } - /** registers a remove listener which will be called if the object + + /** registers a remove listener which will be called if the object * gets removed/destroyed */ - void add_remove_listener(ObjectRemoveListener* listener) - { - RemoveListenerListEntry* entry = new RemoveListenerListEntry(); - entry->next = remove_listeners; - entry->listener = listener; - - remove_listeners = entry; - } + void add_remove_listener(ObjectRemoveListener* listener); - // flags - enum { - /// the tile so you can stand on it - FLAG_SOLID = 0x0001, - /// can be used to temporatily disable collision detection - FLAG_NO_COLLDET = 0x0002 - }; + /** + * unregisters a remove listener, so it will no longer be called if the object + * gets removed/destroyed + */ + void del_remove_listener(ObjectRemoveListener* listener); - int get_flags() const + const std::string& get_name() const { - return flags; + return name; } private: @@ -102,8 +97,11 @@ private: RemoveListenerListEntry* remove_listeners; protected: - int flags; + /** + * a name for the gameobject, this is mostly a hint for scripts and for + * debugging, don't rely on names being set or being unique + */ + std::string name; }; #endif /*SUPERTUX_GAMEOBJECT_H*/ -