X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=lib%2Fspecial%2Fgame_object.h;h=b235c01acffb6c72246b6116b3f810e76e07498c;hb=40e6e7cdc59c09befbd2595aea0c6e10428315d4;hp=88e1ccb52c1c601290ee00b00eff1f66d605d55c;hpb=32c639e36abc3b7bd99380c8b5da768a127fafd6;p=supertux.git diff --git a/lib/special/game_object.h b/lib/special/game_object.h index 88e1ccb52..b235c01ac 100644 --- a/lib/special/game_object.h +++ b/lib/special/game_object.h @@ -27,6 +27,8 @@ namespace SuperTux class DrawingContext; + class ObjectRemoveListener; + /** * Base class for all game objects. This contains functions for: * -querying the actual type of the object @@ -67,6 +69,18 @@ namespace SuperTux { wants_to_die = true; } + /** 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; + } + // flags enum { @@ -87,6 +101,13 @@ namespace SuperTux */ bool wants_to_die; + struct RemoveListenerListEntry + { + RemoveListenerListEntry* next; + ObjectRemoveListener* listener; + }; + RemoveListenerListEntry* remove_listeners; + protected: int flags; };