diff --git a/doomsday/client/include/games.h b/doomsday/client/include/games.h index d357728ef0..d1465fc9fc 100644 --- a/doomsday/client/include/games.h +++ b/doomsday/client/include/games.h @@ -25,6 +25,7 @@ #include "dd_share.h" #include #include +#include #include namespace de { @@ -61,9 +62,13 @@ class Games /// Game instances. typedef QList All; + /** + * Notified when the current game is changed. + */ + DENG2_DEFINE_AUDIENCE(GameChange, void currentGameChanged(Game &newGame)) + public: Games(); - ~Games(); /// Register the console commands, variables, etc..., of this module. static void consoleRegister(); @@ -110,6 +115,8 @@ class Games */ Game &byIndex(int idx) const; + void clear(); + /** * Add a new Game to this collection. If @a game is already present in the * collection this is no-op. @@ -148,8 +155,7 @@ class Games void locateStartupResources(Game &game); private: - struct Instance; - Instance *d; + DENG2_PRIVATE(d) }; } // namespace de diff --git a/doomsday/client/src/games.cpp b/doomsday/client/src/games.cpp index 9c98bce34d..fc78f6a450 100644 --- a/doomsday/client/src/games.cpp +++ b/doomsday/client/src/games.cpp @@ -40,30 +40,33 @@ DENG2_PIMPL(Games) /// Special "null-game" object for this collection. NullGame *nullGame; - Instance(Public &a) - : Base(a), games(), currentGame(0), nullGame(0) - {} + Instance(Public *i) : Base(i), games(), currentGame(0), nullGame(0) + { + /* + * One-time creation and initialization of the special "null-game" + * object (activated once created). + */ + currentGame = nullGame = new NullGame; + } ~Instance() { + clear(); + delete nullGame; + } + + void clear() + { + DENG2_ASSERT(nullGame != 0); + qDeleteAll(games); - if(nullGame) delete nullGame; + games.clear(); + currentGame = nullGame; } }; -Games::Games() : d(new Instance(*this)) -{ - /* - * One-time creation and initialization of the special "null-game" - * object (activated once created). - */ - d->currentGame = d->nullGame = new NullGame(); -} - -Games::~Games() -{ - delete d; -} +Games::Games() : d(new Instance(this)) +{} Game &Games::current() const { @@ -80,6 +83,8 @@ void Games::setCurrent(Game &game) // Ensure the specified game is actually in this collection (NullGame is implicitly). DENG_ASSERT(isNullGame(game) || id(game) > 0); d->currentGame = &game; + + DENG2_FOR_AUDIENCE(GameChange, i) i->currentGameChanged(game); } int Games::numPlayable() const @@ -149,6 +154,11 @@ Game &Games::byIndex(int idx) const return *d->games[idx]; } +void Games::clear() +{ + d->clear(); +} + Games::All const &Games::all() const { return d->games;