Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Mar 15, 2011, 9:47:11 PM (14 years ago)
Author:
landauf
Message:

merged usability branch back to trunk

incomplete summary of the changes in this branch:

  • enhanced keyboard navigation in GUIs
  • implemented new graphics menu and changeable window size at runtime
  • added developer mode
  • HUD shows if game is paused, game pauses if ingame menu is opened
  • removed a few obsolete commands and hid some that are more for internal use
  • numpad works in console and gui
  • faster loading of level info
  • enhanced usage of compositors (Shader class)
  • improved camera handling, configurable FOV and aspect ratio
Location:
code/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/trunk

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

    r7874 r8079  
    4949#include "SpecialConfig.h"
    5050#include "util/Clock.h"
     51#include "util/Convert.h"
    5152#include "util/Exception.h"
    5253#include "util/StringUtils.h"
     
    5758#include "Game.h"
    5859#include "GameMode.h"
     60#include "GUIManager.h"
    5961#include "Loader.h"
    6062#include "MemoryArchive.h"
    6163#include "PathConfig.h"
     64#include "ViewportEventListener.h"
    6265#include "WindowEventListener.h"
    6366#include "XMLFile.h"
    6467#include "command/ConsoleCommand.h"
     68#include "input/InputManager.h"
    6569
    6670namespace orxonox
    6771{
     72    static const std::string __CC_GraphicsManager_group = "GraphicsManager";
     73    static const std::string __CC_setScreenResolution_name = "setScreenResolution";
     74    static const std::string __CC_setFSAA_name = "setFSAA";
     75    static const std::string __CC_setVSync_name = "setVSync";
     76    DeclareConsoleCommand(__CC_GraphicsManager_group, __CC_setScreenResolution_name, &prototype::string__uint_uint_bool);
     77    DeclareConsoleCommand(__CC_GraphicsManager_group, __CC_setFSAA_name, &prototype::string__string);
     78    DeclareConsoleCommand(__CC_GraphicsManager_group, __CC_setVSync_name, &prototype::string__bool);
     79
    6880    static const std::string __CC_printScreen_name = "printScreen";
    6981    DeclareConsoleCommand(__CC_printScreen_name, &prototype::void__void);
     
    95107        , renderWindow_(0)
    96108        , viewport_(0)
     109        , lastFrameStartTime_(0.0f)
     110        , lastFrameEndTime_(0.0f)
    97111    {
    98112        RegisterObject(GraphicsManager);
     
    136150        Ogre::WindowEventUtilities::removeWindowEventListener(renderWindow_, ogreWindowEventListener_.get());
    137151        ModifyConsoleCommand(__CC_printScreen_name).resetFunction();
     152        ModifyConsoleCommand(__CC_GraphicsManager_group, __CC_setScreenResolution_name).resetFunction();
     153        ModifyConsoleCommand(__CC_GraphicsManager_group, __CC_setFSAA_name).resetFunction();
     154        ModifyConsoleCommand(__CC_GraphicsManager_group, __CC_setVSync_name).resetFunction();
    138155
    139156        // Undeclare the resources
     
    304321        CCOUT(4) << "Configuring Renderer" << std::endl;
    305322
    306         if (!ogreRoot_->restoreConfig() || Core::getInstance().getOgreConfigTimestamp() > Core::getInstance().getLastLevelTimestamp())
     323        bool updatedConfig = Core::getInstance().getOgreConfigTimestamp() > Core::getInstance().getLastLevelTimestamp();
     324        if (updatedConfig)
     325            COUT(2) << "Ogre config file has changed, but no level was started since then. Displaying config dialogue again to verify the changes." << std::endl;
     326
     327        if (!ogreRoot_->restoreConfig() || updatedConfig)
    307328        {
    308329            if (!ogreRoot_->showConfigDialog())
     
    330351        // add console commands
    331352        ModifyConsoleCommand(__CC_printScreen_name).setFunction(&GraphicsManager::printScreen, this);
     353        ModifyConsoleCommand(__CC_GraphicsManager_group, __CC_setScreenResolution_name).setFunction(&GraphicsManager::setScreenResolution, this);
     354        ModifyConsoleCommand(__CC_GraphicsManager_group, __CC_setFSAA_name).setFunction(&GraphicsManager::setFSAA, this);
     355        ModifyConsoleCommand(__CC_GraphicsManager_group, __CC_setVSync_name).setFunction(&GraphicsManager::setVSync, this);
    332356    }
    333357
     
    343367    @note
    344368        A note about the Ogre::FrameListener: Even though we don't use them,
    345         they still get called. However, the delta times are not correct (except
    346         for timeSinceLastFrame, which is the most important). A little research
    347         as shown that there is probably only one FrameListener that doesn't even
    348         need the time. So we shouldn't run into problems.
     369        they still get called.
    349370    */
    350371    void GraphicsManager::postUpdate(const Clock& time)
    351372    {
     373        // Time before rendering
     374        uint64_t timeBeforeTick = time.getRealMicroseconds();
     375
     376        // Ogre's time keeping object
    352377        Ogre::FrameEvent evt;
    353         evt.timeSinceLastFrame = time.getDeltaTime();
    354         evt.timeSinceLastEvent = time.getDeltaTime(); // note: same time, but shouldn't matter anyway
    355 
    356         // don't forget to call _fireFrameStarted to OGRE to make sure
    357         // everything goes smoothly
     378
     379        // Translate to Ogre float times before the update
     380        float temp = lastFrameStartTime_;
     381        lastFrameStartTime_ = (float)timeBeforeTick * 0.000001f;
     382        evt.timeSinceLastFrame = lastFrameStartTime_ - temp;
     383        evt.timeSinceLastEvent = lastFrameStartTime_ - lastFrameEndTime_;
     384
     385        // Ogre requires the time too
    358386        ogreRoot_->_fireFrameStarted(evt);
    359387
     
    361389        // This calls the WindowEventListener objects.
    362390        Ogre::WindowEventUtilities::messagePump();
    363         // make sure the window stays active even when not focused
     391        // Make sure the window stays active even when not focused
    364392        // (probably only necessary on windows)
    365393        this->renderWindow_->setActive(true);
    366 
    367         // Time before rendering
    368         uint64_t timeBeforeTick = time.getRealMicroseconds();
    369394
    370395        // Render frame
     
    375400        Game::getInstance().subtractTickTime((int32_t)(timeAfterTick - timeBeforeTick));
    376401
    377         // again, just to be sure OGRE works fine
    378         ogreRoot_->_fireFrameEnded(evt); // note: uses the same time as _fireFrameStarted
     402        // Translate to Ogre float times after the update
     403        temp = lastFrameEndTime_;
     404        lastFrameEndTime_ = (float)timeBeforeTick * 0.000001f;
     405        evt.timeSinceLastFrame = lastFrameEndTime_ - temp;
     406        evt.timeSinceLastEvent = lastFrameEndTime_ - lastFrameStartTime_;
     407
     408        // Ogre also needs the time after the frame finished
     409        ogreRoot_->_fireFrameEnded(evt);
    379410    }
    380411
    381412    void GraphicsManager::setCamera(Ogre::Camera* camera)
    382413    {
     414        Ogre::Camera* oldCamera = this->viewport_->getCamera();
     415
    383416        this->viewport_->setCamera(camera);
     417        GUIManager::getInstance().setCamera(camera);
     418
     419        for (ObjectList<ViewportEventListener>::iterator it = ObjectList<ViewportEventListener>::begin(); it != ObjectList<ViewportEventListener>::end(); ++it)
     420            it->cameraChanged(this->viewport_, oldCamera);
    384421    }
    385422
     
    440477    bool GraphicsManager::isFullScreen() const
    441478    {
     479        return this->renderWindow_->isFullScreen();
     480    }
     481
     482    unsigned int GraphicsManager::getWindowWidth() const
     483    {
     484        return this->renderWindow_->getWidth();
     485    }
     486
     487    unsigned int GraphicsManager::getWindowHeight() const
     488    {
     489        return this->renderWindow_->getHeight();
     490    }
     491
     492    bool GraphicsManager::hasVSyncEnabled() const
     493    {
    442494        Ogre::ConfigOptionMap& options = ogreRoot_->getRenderSystem()->getConfigOptions();
    443         if (options.find("Full Screen") != options.end())
    444         {
    445             if (options["Full Screen"].currentValue == "Yes")
    446                 return true;
    447             else
    448                 return false;
    449         }
     495        Ogre::ConfigOptionMap::iterator it = options.find("VSync");
     496        if (it != options.end())
     497            return (it->second.currentValue == "Yes");
    450498        else
    451         {
    452             COUT(0) << "Could not find 'Full Screen' render system option. Fix This!!!" << std::endl;
    453499            return false;
    454         }
     500    }
     501
     502    std::string GraphicsManager::getFSAAMode() const
     503    {
     504        Ogre::ConfigOptionMap& options = ogreRoot_->getRenderSystem()->getConfigOptions();
     505        Ogre::ConfigOptionMap::iterator it = options.find("FSAA");
     506        if (it != options.end())
     507            return it->second.currentValue;
     508        else
     509            return "";
     510    }
     511
     512    std::string GraphicsManager::setScreenResolution(unsigned int width, unsigned int height, bool fullscreen)
     513    {
     514        // workaround to detect if the colour depth should be written to the config file
     515        bool bWriteColourDepth = false;
     516        Ogre::ConfigOptionMap& options = ogreRoot_->getRenderSystem()->getConfigOptions();
     517        Ogre::ConfigOptionMap::iterator it = options.find("Video Mode");
     518        if (it != options.end())
     519            bWriteColourDepth = (it->second.currentValue.find('@') != std::string::npos);
     520
     521        if (bWriteColourDepth)
     522        {
     523            this->ogreRoot_->getRenderSystem()->setConfigOption("Video Mode", multi_cast<std::string>(width)
     524                                                                    + " x " + multi_cast<std::string>(height)
     525                                                                    + " @ " + multi_cast<std::string>(this->getRenderWindow()->getColourDepth()) + "-bit colour");
     526        }
     527        else
     528        {
     529            this->ogreRoot_->getRenderSystem()->setConfigOption("Video Mode", multi_cast<std::string>(width)
     530                                                                    + " x " + multi_cast<std::string>(height));
     531        }
     532
     533        this->ogreRoot_->getRenderSystem()->setConfigOption("Full Screen", fullscreen ? "Yes" : "No");
     534
     535        std::string validate = this->ogreRoot_->getRenderSystem()->validateConfigOptions();
     536
     537        if (validate == "")
     538        {
     539            GraphicsManager::getInstance().getRenderWindow()->setFullscreen(fullscreen, width, height);
     540            this->ogreRoot_->saveConfig();
     541            Core::getInstance().updateOgreConfigTimestamp();
     542            // Also reload the input devices
     543            InputManager::getInstance().reload();
     544        }
     545
     546        return validate;
     547    }
     548
     549    std::string GraphicsManager::setFSAA(const std::string& mode)
     550    {
     551        this->ogreRoot_->getRenderSystem()->setConfigOption("FSAA", mode);
     552
     553        std::string validate = this->ogreRoot_->getRenderSystem()->validateConfigOptions();
     554
     555        if (validate == "")
     556        {
     557            //this->ogreRoot_->getRenderSystem()->reinitialise(); // can't use this that easily, because it recreates the render window, invalidating renderWindow_
     558            this->ogreRoot_->saveConfig();
     559            Core::getInstance().updateOgreConfigTimestamp();
     560        }
     561
     562        return validate;
     563    }
     564
     565    std::string GraphicsManager::setVSync(bool vsync)
     566    {
     567        this->ogreRoot_->getRenderSystem()->setConfigOption("VSync", vsync ? "Yes" : "No");
     568
     569        std::string validate = this->ogreRoot_->getRenderSystem()->validateConfigOptions();
     570
     571        if (validate == "")
     572        {
     573            //this->ogreRoot_->getRenderSystem()->reinitialise(); // can't use this that easily, because it recreates the render window, invalidating renderWindow_
     574            this->ogreRoot_->saveConfig();
     575            Core::getInstance().updateOgreConfigTimestamp();
     576        }
     577
     578        return validate;
    455579    }
    456580
Note: See TracChangeset for help on using the changeset viewer.