Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jul 29, 2009, 5:24:39 PM (15 years ago)
Author:
rgrieder
Message:

Exception-safety for the Game and Core c'tors as well as load/unload-Graphics.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/resource/src/core/Game.h

    r3356 r3363  
    4444#include <vector>
    4545#include <boost/shared_ptr.hpp>
     46#include <boost/scoped_ptr.hpp>
    4647#include <boost/preprocessor/cat.hpp>
    4748
     
    5960{
    6061    class GameConfiguration;
     62    using boost::scoped_ptr;
     63    using boost::shared_ptr;
    6164
    6265    //! Helper object required before GameStates are being constructed
     
    7578    class _CoreExport Game
    7679    {
     80        typedef std::vector<shared_ptr<GameState> > GameStateVector;
     81        typedef std::map<std::string, shared_ptr<GameState> > GameStateMap;
    7782        typedef boost::shared_ptr<GameStateTreeNode> GameStateTreeNodePtr;
    7883    public:
     
    8186
    8287        void setStateHierarchy(const std::string& str);
    83         GameState* getState(const std::string& name);
     88        shared_ptr<GameState> getState(const std::string& name);
    8489
    8590        void run();
     
    106111        public:
    107112            virtual ~GameStateFactory() { }
    108             static GameState* fabricate(const GameStateInfo& info);
     113            static shared_ptr<GameState> fabricate(const GameStateInfo& info);
    109114            template <class T>
    110115            static void createFactory(const std::string& className)
    111                 { factories_s[className] = new TemplateGameStateFactory<T>(); }
    112             static void destroyFactories();
     116                { factories_s[className].reset(new TemplateGameStateFactory<T>()); }
    113117        private:
    114             virtual GameState* fabricateInternal(const GameStateInfo& info) = 0;
    115             static std::map<std::string, GameStateFactory*> factories_s;
     118            virtual shared_ptr<GameState> fabricateInternal(const GameStateInfo& info) = 0;
     119            static std::map<std::string, shared_ptr<GameStateFactory> > factories_s;
    116120        };
    117121        template <class T>
     
    119123        {
    120124        public:
    121             GameState* fabricateInternal(const GameStateInfo& info)
    122                 { return new T(info); }
     125            shared_ptr<GameState> fabricateInternal(const GameStateInfo& info)
     126                { return shared_ptr<GameState>(new T(info)); }
    123127        };
    124128
     
    144148        void updateFPSLimiter();
    145149
    146         std::map<std::string, GameState*>  constructedStates_;
    147         std::vector<GameState*>            loadedStates_;
     150        // ScopeGuard helper function
     151        void resetChangingState() { this->bChangingState_ = false; }
     152
     153        scoped_ptr<Clock>                  gameClock_;
     154        scoped_ptr<Core>                   core_;
     155        scoped_ptr<GameConfiguration>      configuration_;
     156
     157        GameStateMap                       constructedStates_;
     158        GameStateVector                    loadedStates_;
    148159        GameStateTreeNodePtr               rootStateNode_;
    149160        GameStateTreeNodePtr               loadedTopStateNode_;
    150         std::vector<GameStateTreeNodePtr > requestedStateNodes_;
    151 
    152         Core*                              core_;
    153         Clock*                             gameClock_;
    154         GameConfiguration*                 configuration_;
     161        std::vector<GameStateTreeNodePtr>  requestedStateNodes_;
    155162
    156163        bool                               bChangingState_;
Note: See TracChangeset for help on using the changeset viewer.