Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 3349 for code/branches


Ignore:
Timestamp:
Jul 25, 2009, 2:14:05 PM (15 years ago)
Author:
rgrieder
Message:

Moved InputManager, GUIManager and GraphicsManager handling from GSGraphics to Core.

Location:
code/branches/resource/src
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • code/branches/resource/src/core/Core.cc

    r3348 r3349  
    4141#include <cstdio>
    4242#include <boost/filesystem.hpp>
     43#include <OgreRenderWindow.h>
    4344
    4445#ifdef ORXONOX_PLATFORM_WINDOWS
     
    6970#include "Factory.h"
    7071#include "GameMode.h"
     72#include "GraphicsManager.h"
     73#include "GUIManager.h"
    7174#include "Identifier.h"
    7275#include "Language.h"
     
    7578#include "TclBind.h"
    7679#include "TclThreadManager.h"
     80#include "input/InputManager.h"
    7781
    7882namespace orxonox
     
    346350            return;
    347351
     352        // Load OGRE including the render window
     353        this->graphicsManager_ = new GraphicsManager();
     354
     355        // The render window width and height are used to set up the mouse movement.
     356        size_t windowHnd = 0;
     357        Ogre::RenderWindow* renderWindow = GraphicsManager::getInstance().getRenderWindow();
     358        renderWindow->getCustomAttribute("WINDOW", &windowHnd);
     359
     360        // Calls the InputManager which sets up the input devices.
     361        inputManager_ = new InputManager(windowHnd);
     362
     363        // load the CEGUI interface
     364        guiManager_ = new GUIManager(renderWindow);
     365
    348366        GameMode::setShowsGraphics(true);
    349367        bGraphicsLoaded_ = true;
     
    354372        if (!bGraphicsLoaded_)
    355373            return;
     374
     375        delete this->guiManager_;
     376        delete this->inputManager_;
     377        delete graphicsManager_;
    356378
    357379        bGraphicsLoaded_ = false;
     
    646668    }
    647669
    648     void Core::update(const Clock& time)
    649     {
    650         this->tclThreadManager_->update(time);
     670    bool Core::preUpdate(const Clock& time) throw()
     671    {
     672        std::string exceptionMessage;
     673        try
     674        {
     675            // process input events
     676            this->inputManager_->update(time);
     677            // process gui events
     678            this->guiManager_->update(time);
     679            // process thread commands
     680            this->tclThreadManager_->update(time);
     681        }
     682        catch (const std::exception& ex)
     683        { exceptionMessage = ex.what(); }
     684        catch (...)
     685        { exceptionMessage = "Unknown exception"; }
     686        if (!exceptionMessage.empty())
     687        {
     688            COUT(0) << "An exception occurred in the Core preUpdate: " << exceptionMessage << std::endl;
     689            COUT(0) << "This should really never happen! Closing the program." << std::endl;
     690            return false;
     691        }
     692        return true;
     693    }
     694
     695    bool Core::postUpdate(const Clock& time) throw()
     696    {
     697        std::string exceptionMessage;
     698        try
     699        {
     700            // Render (doesn't throw)
     701            this->graphicsManager_->update(time);
     702        }
     703        catch (const std::exception& ex)
     704        { exceptionMessage = ex.what(); }
     705        catch (...)
     706        { exceptionMessage = "Unknown exception"; }
     707        if (!exceptionMessage.empty())
     708        {
     709            COUT(0) << "An exception occurred in the Core postUpdate: " << exceptionMessage << std::endl;
     710            COUT(0) << "This should really never happen! Closing the program." << std::endl;
     711            return false;
     712        }
     713        return true;
    651714    }
    652715}
  • code/branches/resource/src/core/Core.h

    r3345 r3349  
    7171            void setConfigValues();
    7272
    73             void update(const Clock& time);
     73            bool preUpdate(const Clock& time) throw();
     74            bool postUpdate(const Clock& time) throw();
    7475
    7576            void loadGraphics();
     
    119120            TclBind*              tclBind_;
    120121            TclThreadManager*     tclThreadManager_;
     122            // graphical
     123            InputManager*         inputManager_;        //!< Interface to OIS
     124            GUIManager*           guiManager_;          //!< Interface to GUI
     125            GraphicsManager*      graphicsManager_;     //!< Interface to OGRE
    121126
    122127            bool                  bDevRun_;             //!< True for runs in the build directory (not installed)
  • code/branches/resource/src/core/Game.cc

    r3323 r3349  
    245245            }
    246246
    247             // UPDATE, Core first
    248             bool threwException = false;
    249             try
    250             {
    251                 this->core_->update(*this->gameClock_);
    252             }
    253             catch (const std::exception& ex)
    254             {
    255                 threwException = true;
    256                 COUT(0) << "Exception while ticking the Core: " << ex.what() << std::endl;
    257             }
    258             catch (...)
    259             {
    260                 threwException = true;
    261             }
    262             if (threwException)
    263             {
    264                 COUT(0) << "An exception occured while ticking the Core. This should really never happen!" << std::endl;
    265                 COUT(0) << "Closing the program." << std::endl;
     247            // UPDATE, Core preUpdate (doesn't throw)
     248            if (!this->core_->preUpdate(*this->gameClock_))
     249            {
    266250                this->stop();
    267251                break;
     
    273257                it != this->activeStates_.end(); ++it)
    274258            {
    275                 bool threwException = false;
     259                std::string exceptionMessage;
    276260                try
    277261                {
    278262                    // Add tick time for most of the states
    279263                    uint64_t timeBeforeTick;
    280                     if (!(*it)->ignoreTickTime())
     264                    if ((*it)->ignoreTickTime())
    281265                        timeBeforeTick = this->gameClock_->getRealMicroseconds();
    282266                    (*it)->update(*this->gameClock_);
    283                     if (!(*it)->ignoreTickTime())
    284                         this->addTickTime(static_cast<uint32_t>(this->gameClock_->getRealMicroseconds() - timeBeforeTick));
     267                    if ((*it)->ignoreTickTime())
     268                        this->subtractTickTime(static_cast<int32_t>(this->gameClock_->getRealMicroseconds() - timeBeforeTick));
    285269                }
    286270                catch (const std::exception& ex)
     271                { exceptionMessage = ex.what(); }
     272                catch (...)
     273                { exceptionMessage = "Unknown exception"; }
     274                if (!exceptionMessage.empty())
    287275                {
    288                     threwException = true;
    289                     COUT(0) << "Exception while ticking: " << ex.what() << std::endl;
    290                 }
    291                 catch (...)
    292                 {
    293                     threwException = true;
    294                 }
    295                 if (threwException)
    296                 {
    297                     COUT(1) << "An exception occured while ticking GameState '" << (*it)->getName() << "'. This should really never happen!" << std::endl;
     276                    COUT(1) << "An exception occurred while updating '" << (*it)->getName() << "': " << exceptionMessage << std::endl;
     277                    COUT(1) << "This should really never happen!" << std::endl;
    298278                    COUT(1) << "Unloading all GameStates depending on the one that crashed." << std::endl;
    299279                    if ((*it)->getParent() != NULL)
     
    304284                }
    305285
     286            }
     287
     288            // UPDATE, Core postUpdate (doesn't throw)
     289            if (!this->core_->postUpdate(*this->gameClock_))
     290            {
     291                this->stop();
     292                break;
    306293            }
    307294
     
    344331    }
    345332
    346     void Game::addTickTime(uint32_t length)
     333    void Game::subtractTickTime(int32_t length)
    347334    {
    348335        assert(!this->statisticsTickTimes_.empty());
    349         this->statisticsTickTimes_.back().tickLength += length;
    350         this->periodTickTime_+=length;
     336        this->statisticsTickTimes_.back().tickLength -= length;
     337        this->periodTickTime_ -= length;
    351338    }
    352339
  • code/branches/resource/src/core/Game.h

    r3323 r3349  
    8686        float getAvgFPS()      { return this->avgFPS_; }
    8787
    88         void addTickTime(uint32_t length);
     88        void subtractTickTime(int32_t length);
    8989
    9090        template <class T>
  • code/branches/resource/src/core/GraphicsManager.cc

    r3346 r3349  
    196196        this->renderWindow_->setActive(true);
    197197
    198         // render
     198        // Time before rendering
     199        uint64_t timeBeforeTick = time.getRealMicroseconds();
     200
     201        // Render frame
    199202        ogreRoot_->_updateAllRenderTargets();
     203
     204        uint64_t timeAfterTick = time.getRealMicroseconds();
     205        // Subtract the time used for rendering from the tick time counter
     206        Game::getInstance().subtractTickTime(timeAfterTick - timeBeforeTick);
    200207
    201208        // again, just to be sure OGRE works fine
  • code/branches/resource/src/orxonox/gamestates/GSGraphics.cc

    r3346 r3349  
    3535#include "GSGraphics.h"
    3636
    37 #include <boost/filesystem.hpp>
    38 #include <OgreRenderWindow.h>
    39 
    4037#include "util/Convert.h"
    4138#include "core/Clock.h"
     
    4441#include "core/Core.h"
    4542#include "core/Game.h"
    46 #include "core/GameMode.h"
    47 #include "core/GraphicsManager.h"
    4843#include "core/GUIManager.h"
    4944#include "core/input/InputManager.h"
     
    6055namespace orxonox
    6156{
    62     DeclareGameState(GSGraphics, "graphics", true, true);
     57    DeclareGameState(GSGraphics, "graphics", false, true);
    6358
    6459    GSGraphics::GSGraphics(const GameStateConstrParams& params)
    6560        : GameState(params)
    66         , inputManager_(0)
    6761        , console_(0)
    68         , guiManager_(0)
    69         , graphicsManager_(0)
    7062        , soundManager_(0)
    7163        , masterKeyBinder_(0)
     
    9991        Core::getInstance().loadGraphics();
    10092
    101         // Load OGRE including the render window
    102         this->graphicsManager_ = new GraphicsManager();
    103 
    10493        // load debug overlay
    10594        COUT(3) << "Loading Debug Overlay..." << std::endl;
    106         this->debugOverlay_ = new XMLFile((Core::getMediaPath() / "overlay" / "debug.oxo").string());
     95        this->debugOverlay_ = new XMLFile(Core::getMediaPathString() + "overlay/debug.oxo");
    10796        Loader::open(debugOverlay_);
    108 
    109         // The render window width and height are used to set up the mouse movement.
    110         size_t windowHnd = 0;
    111         Ogre::RenderWindow* renderWindow = GraphicsManager::getInstance().getRenderWindow();
    112         renderWindow->getCustomAttribute("WINDOW", &windowHnd);
    113 
    114         // Calls the InputManager which sets up the input devices.
    115         inputManager_ = new InputManager(windowHnd);
    116 
    11797        // load master key bindings
    11898        masterInputState_ = InputManager::getInstance().createInputState("master", true);
     
    127107        console_ = new InGameConsole();
    128108        console_->initialise();
    129 
    130         // load the CEGUI interface
    131         guiManager_ = new GUIManager(renderWindow);
    132109
    133110        // add console command to toggle GUI
     
    161138        delete this->masterKeyBinder_;
    162139
    163         delete this->guiManager_;
    164140        delete this->console_;
    165141
     
    169145        delete this->soundManager_;
    170146
    171         delete this->inputManager_;
    172         this->inputManager_ = 0;
    173 
    174         // HACK:
     147        // HACK: (destroys a resource smart pointer)
    175148        Map::hackDestroyMap();
    176 
    177         delete graphicsManager_;
    178149
    179150        // Unload OGRE, CEGUI and OIS
     
    210181        }
    211182
    212         uint64_t timeBeforeTick = time.getRealMicroseconds();
    213 
    214         this->inputManager_->update(time);
    215183        this->console_->update(time);
    216 
    217         uint64_t timeAfterTick = time.getRealMicroseconds();
    218 
    219         // Also add our tick time
    220         Game::getInstance().addTickTime(timeAfterTick - timeBeforeTick);
    221 
    222         // Process gui events
    223         this->guiManager_->update(time);
    224         // Render
    225         this->graphicsManager_->update(time);
    226184    }
    227185}
  • code/branches/resource/src/orxonox/gamestates/GSGraphics.h

    r3327 r3349  
    6161    private:
    6262        // managed singletons
    63         InputManager*         inputManager_;        //!< Reference to input management
    6463        InGameConsole*        console_;
    65         GUIManager*           guiManager_;          //!< Interface to GUI
    66         GraphicsManager*      graphicsManager_;     //!< Interface to Ogre
    6764        SoundManager*         soundManager_;        //!< Keeps track of SoundBase objects
    6865
  • code/branches/resource/src/orxonox/gamestates/GSRoot.cc

    r3340 r3349  
    4545namespace orxonox
    4646{
    47     DeclareGameState(GSRoot, "root", true, false);
     47    DeclareGameState(GSRoot, "root", false, false);
    4848    SetCommandLineSwitch(console).information("Start in console mode (text IO only)");
    4949    // Shortcuts for easy direct loading
     
    155155        }
    156156
    157         uint64_t timeBeforeTick = time.getRealMicroseconds();
    158 
    159157        for (ObjectList<TimerBase>::iterator it = ObjectList<TimerBase>::begin(); it; ++it)
    160158            it->tick(time);
     
    171169            it->tick(leveldt * this->timeFactor_);
    172170        /*** HACK *** HACK ***/
    173 
    174         uint64_t timeAfterTick = time.getRealMicroseconds();
    175 
    176         // Also add our tick time
    177         Game::getInstance().addTickTime(timeAfterTick - timeBeforeTick);
    178171    }
    179172
  • code/branches/resource/src/orxonox/objects/quest/QuestListener.cc

    r3280 r3349  
    8181    /**
    8282    @brief
    83         Makes all QuestListener in the list aware that a certain status change has occured and executes them if the status change affects them.
     83        Makes all QuestListener in the list aware that a certain status change has occurred and executes them if the status change affects them.
    8484    @param listeners
    8585        The list of QuestListeners that have to be made aware of the status change.
     
    182182        else
    183183        {
    184             COUT(1) << "An unforseen, never to happen, Error has occured. This is impossible!" << std::endl;
     184            COUT(1) << "An unforseen, never to happen, Error has occurred. This is impossible!" << std::endl;
    185185        return "";
    186186        }
  • code/branches/resource/src/orxonox/objects/quest/QuestManager.cc

    r3337 r3349  
    323323        {
    324324            container->status = "";
    325             COUT(1) << "An error occured. A Quest of un-specified status wanted to be displayed." << std::endl;
     325            COUT(1) << "An error occurred. A Quest of un-specified status wanted to be displayed." << std::endl;
    326326        }
    327327       
Note: See TracChangeset for help on using the changeset viewer.