Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 25, 2009, 10:23:58 PM (14 years ago)
Author:
rgrieder
Message:

Merged presentation2 branch back to trunk.
Major new features:

  • Actual GUI with settings, etc.
  • Improved space ship steering (human interaction)
  • Rocket fire and more particle effects
  • Advanced sound framework
Location:
code/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/trunk

  • code/trunk/src/libraries/core/Game.cc

    r6021 r6417  
    5151#include "GameMode.h"
    5252#include "GameState.h"
     53#include "GUIManager.h"
    5354
    5455namespace orxonox
     
    6768    Game* Game::singletonPtr_s = 0;
    6869
    69 
    70     /**
    71     @brief
    72         Represents one node of the game state tree.
    73     */
     70    //! Represents one node of the game state tree.
    7471    struct GameStateTreeNode
    7572    {
     
    7976    };
    8077
    81 
    82     /**
    83     @brief
    84         Another helper class for the Game singleton: we cannot derive
    85         Game from OrxonoxClass because we need to handle the Identifier
    86         destruction in the Core destructor.
    87     */
    88     class GameConfiguration : public OrxonoxClass
    89     {
    90     public:
    91         GameConfiguration()
    92         {
    93             RegisterRootObject(GameConfiguration);
    94             this->setConfigValues();
    95         }
    96 
    97         void setConfigValues()
    98         {
    99             SetConfigValue(statisticsRefreshCycle_, 250000)
    100                 .description("Sets the time in microseconds interval at which average fps, etc. get updated.");
    101             SetConfigValue(statisticsAvgLength_, 1000000)
    102                 .description("Sets the time in microseconds interval at which average fps, etc. gets calculated.");
    103             SetConfigValue(fpsLimit_, 50)
    104                 .description("Sets the desired framerate (0 for no limit).");
    105         }
    106 
    107         unsigned int statisticsRefreshCycle_;
    108         unsigned int statisticsAvgLength_;
    109         unsigned int fpsLimit_;
    110     };
    111 
    112 
    113     /**
    114     @brief
    115         Non-initialising constructor.
    116     */
    11778    Game::Game(const std::string& cmdLine)
    11879        // Destroy factories before the Core!
     
    12889#endif
    12990
     91        // reset statistics
     92        this->statisticsStartTime_ = 0;
     93        this->statisticsTickTimes_.clear();
     94        this->periodTickTime_ = 0;
     95        this->periodTime_ = 0;
     96        this->avgFPS_ = 0.0f;
     97        this->avgTickTime_ = 0.0f;
     98        this->excessSleepTime_ = 0;
     99
    130100        // Create an empty root state
    131101        this->declareGameState<GameState>("GameState", "emptyRootGameState", true, false);
     
    136106        // Create the Core
    137107        this->core_.reset(new Core(cmdLine));
     108
     109        // Do this after the Core creation!
     110        ClassIdentifier<Game>::getIdentifier("Game")->initialiseObject(this, "Game", true);
     111        this->setConfigValues();
    138112
    139113        // After the core has been created, we can safely instantiate the GameStates that don't require graphics
     
    150124        this->loadedTopStateNode_ = this->rootStateNode_;
    151125        this->loadedStates_.push_back(this->getState(rootStateNode_->name_));
    152 
    153         // Do this after the Core creation!
    154         this->configuration_.reset(new GameConfiguration());
    155126    }
    156127
     
    161132    Game::~Game()
    162133    {
     134        // Remove us from the object lists again to avoid problems when destroying them
     135        this->unregisterObject();
     136    }
     137
     138    void Game::setConfigValues()
     139    {
     140        SetConfigValue(statisticsRefreshCycle_, 250000)
     141            .description("Sets the time in microseconds interval at which average fps, etc. get updated.");
     142        SetConfigValue(statisticsAvgLength_, 1000000)
     143            .description("Sets the time in microseconds interval at which average fps, etc. gets calculated.");
     144        SetConfigValue(fpsLimit_, 50)
     145            .description("Sets the desired frame rate (0 for no limit).");
    163146    }
    164147
     
    176159            COUT(0) << "Warning: Starting game without requesting GameState. This automatically terminates the program." << std::endl;
    177160
    178         // reset statistics
    179         this->statisticsStartTime_ = 0;
    180         this->statisticsTickTimes_.clear();
    181         this->periodTickTime_ = 0;
    182         this->periodTime_ = 0;
    183         this->avgFPS_ = 0.0f;
    184         this->avgTickTime_ = 0.0f;
    185         this->excessSleepTime_ = 0;
    186 
    187161        // START GAME
    188162        // first delta time should be about 0 seconds
     
    204178            this->updateGameStateStack();
    205179
    206             // Core preUpdate (doesn't throw)
     180            // Core preUpdate
    207181            try
    208182                { this->core_->preUpdate(*this->gameClock_); }
     
    218192            this->updateGameStates();
    219193
    220             // Core postUpdate (doesn't throw)
     194            // Core postUpdate
    221195            try
    222196                { this->core_->postUpdate(*this->gameClock_); }
     
    232206            this->updateStatistics();
    233207
    234             // Limit framerate
     208            // Limit frame rate
    235209            this->updateFPSLimiter();
    236210        }
     
    312286        this->statisticsTickTimes_.back().tickLength += currentRealTime - currentTime;
    313287        this->periodTickTime_ += currentRealTime - currentTime;
    314         if (this->periodTime_ > this->configuration_->statisticsRefreshCycle_)
     288        if (this->periodTime_ > this->statisticsRefreshCycle_)
    315289        {
    316290            std::list<StatisticsTickInfo>::iterator it = this->statisticsTickTimes_.begin();
    317291            assert(it != this->statisticsTickTimes_.end());
    318             int64_t lastTime = currentTime - this->configuration_->statisticsAvgLength_;
     292            int64_t lastTime = currentTime - this->statisticsAvgLength_;
    319293            if (static_cast<int64_t>(it->tickTime) < lastTime)
    320294            {
     
    330304
    331305            uint32_t framesPerPeriod = this->statisticsTickTimes_.size();
    332             this->avgFPS_ = static_cast<float>(framesPerPeriod) / (currentTime - this->statisticsTickTimes_.front().tickTime) * 1000000.0f;
     306            // Why minus 1? No idea, but otherwise the fps rate is always (from 10 to 200!) one frame too low
     307            this->avgFPS_ = -1 + static_cast<float>(framesPerPeriod) / (currentTime - this->statisticsTickTimes_.front().tickTime) * 1000000.0f;
    333308            this->avgTickTime_ = static_cast<float>(this->periodTickTime_) / framesPerPeriod / 1000.0f;
    334309
    335             this->periodTime_ -= this->configuration_->statisticsRefreshCycle_;
     310            this->periodTime_ -= this->statisticsRefreshCycle_;
    336311        }
    337312    }
     
    339314    void Game::updateFPSLimiter()
    340315    {
    341         // Why configuration_->fpsLimit_ - 1? No idea, but otherwise the fps rate is always (from 10 to 200!) one frame too high
    342         uint32_t nextTime = gameClock_->getMicroseconds() - excessSleepTime_ + static_cast<uint32_t>(1000000.0f / (configuration_->fpsLimit_ - 1));
     316        uint64_t nextTime = gameClock_->getMicroseconds() - excessSleepTime_ + static_cast<uint32_t>(1000000.0f / fpsLimit_);
    343317        uint64_t currentRealTime = gameClock_->getRealMicroseconds();
    344318        while (currentRealTime < nextTime - minimumSleepTime_)
     
    584558
    585559        shared_ptr<GameState> state = this->getState(name);
    586         state->activate();
     560        state->activateInternal();
    587561        if (!this->loadedStates_.empty())
    588562            this->loadedStates_.back()->activity_.topState = false;
     
    603577            if (!this->loadedStates_.empty())
    604578                this->loadedStates_.back()->activity_.topState = true;
    605             state->deactivate();
     579            state->deactivateInternal();
    606580        }
    607581        catch (...)
Note: See TracChangeset for help on using the changeset viewer.