Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jun 29, 2009, 2:01:51 PM (15 years ago)
Author:
rgrieder
Message:

Removed OrxonoxClass inheritance from Game and Core: this allows the Core class to deal with everything core-related, including identifier destruction.
Instead I moved the config-values to CoreConfiguration and GameConfiguration which in turn are member variables (as pointers).
Also handled exceptions better: Game or Core must not fail to initialise, otherwise orxonox will not start. This now gets displayed properly.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/core4/src/core/Game.cc

    r3245 r3247  
    5858    SetConsoleCommandShortcutExternAlias(stop_game, "exit");
    5959
    60     struct _CoreExport GameStateTreeNode
     60    std::map<std::string, Game::GameStateInfo> Game::gameStateDeclarations_s;
     61    Game* Game::singletonRef_s = 0;
     62
     63
     64    /**
     65    @brief
     66        Represents one node of the game state tree.
     67    */
     68    struct GameStateTreeNode
    6169    {
    6270        GameState* state_;
     
    6573    };
    6674
    67     std::map<std::string, Game::GameStateInfo> Game::gameStateDeclarations_s;
    68     Game* Game::singletonRef_s = 0;
     75
     76    /**
     77    @brief
     78        Another helper class for the Game singleton: we cannot derive
     79        Game from OrxonoxClass because we need to handle the Identifier
     80        destruction in the Core destructor.
     81    */
     82    class GameConfiguration : public OrxonoxClass
     83    {
     84    public:
     85        GameConfiguration()
     86        {
     87            RegisterRootObject(GameConfiguration);
     88            this->setConfigValues();
     89        }
     90
     91        void setConfigValues()
     92        {
     93            SetConfigValue(statisticsRefreshCycle_, 250000)
     94                .description("Sets the time in microseconds interval at which average fps, etc. get updated.");
     95            SetConfigValue(statisticsAvgLength_, 1000000)
     96                .description("Sets the time in microseconds interval at which average fps, etc. gets calculated.");
     97        }
     98
     99        unsigned int statisticsRefreshCycle_;
     100        unsigned int statisticsAvgLength_;
     101    };
     102
    69103
    70104    /**
     
    99133
    100134        // Create the Core
    101         this->core_ = new orxonox::Core();
    102         this->core_->initialise(argc, argv);
     135        this->core_ = new Core(argc, argv);
    103136
    104137        // After the core has been created, we can safely instantiate the GameStates
     
    118151        this->activeStates_.push_back(this->rootStateNode_->state_);
    119152
    120         // Do this after Core creation!
    121         RegisterRootObject(Game);
    122         this->setConfigValues();
     153        // Do this after the Core creation!
     154        this->configuration_ = new GameConfiguration();
    123155    }
    124156
     
    128160    Game::~Game()
    129161    {
     162        // Destroy the configuration helper class instance
     163        delete this->configuration_;
     164
    130165        // Destroy the GameStates (note that the nodes still point to them, but doesn't matter)
    131166        for (std::map<std::string, GameState*>::const_iterator it = gameStates_.begin();
     
    137172        delete this->gameClock_;
    138173
    139         // Also, take care of the GameStateFactories
     174        // Take care of the GameStateFactories
    140175        GameStateFactory::destroyFactories();
    141176
    142177        // Don't assign singletonRef_s with NULL! Recreation is not supported
    143     }
    144 
    145     void Game::setConfigValues()
    146     {
    147         SetConfigValue(statisticsRefreshCycle_, 250000)
    148             .description("Sets the time in microseconds interval at which average fps, etc. get updated.");
    149         SetConfigValue(statisticsAvgLength_, 1000000)
    150             .description("Sets the time in microseconds interval at which average fps, etc. gets calculated.");
    151178    }
    152179
     
    245272
    246273            // STATISTICS
    247             if (this->periodTime_ > statisticsRefreshCycle_)
     274            if (this->periodTime_ > this->configuration_->statisticsRefreshCycle_)
    248275            {
    249276                std::list<StatisticsTickInfo>::iterator it = this->statisticsTickTimes_.begin();
    250277                assert(it != this->statisticsTickTimes_.end());
    251                 int64_t lastTime = currentTime - this->statisticsAvgLength_;
     278                int64_t lastTime = currentTime - this->configuration_->statisticsAvgLength_;
    252279                if ((int64_t)it->tickTime < lastTime)
    253280                {
     
    266293                this->avgTickTime_ = static_cast<float>(this->periodTickTime_) / framesPerPeriod / 1000.0f;
    267294
    268                 this->periodTime_ -= this->statisticsRefreshCycle_;
     295                this->periodTime_ -= this->configuration_->statisticsRefreshCycle_;
    269296            }
    270297        }
Note: See TracChangeset for help on using the changeset viewer.