Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Mar 15, 2011, 9:47:11 PM (13 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:
26 edited
2 copied

Legend:

Unmodified
Added
Removed
  • code/trunk

  • code/trunk/src/libraries/core/CMakeLists.txt

    r7284 r8079  
    3535  OrxonoxClass.cc
    3636  Resource.cc
    37   WindowEventListener.cc
    3837
    3938  # hierarchy
     
    4948  Template.cc
    5049  XMLPort.cc
     50
     51COMPILATION_BEGIN ListenerCompilation.cc
     52  ViewportEventListener.cc
     53  WindowEventListener.cc
    5154  XMLNameListener.cc
     55COMPILATION_END
    5256
    5357COMPILATION_BEGIN FilesystemCompilation.cc
     
    7680    Game.h
    7781    GameMode.h
     82    GraphicsManager.h
    7883    GUIManager.h
    7984    Loader.h
  • code/trunk/src/libraries/core/Core.cc

    r7872 r8079  
    208208#ifdef ORXONOX_RELEASE
    209209        const unsigned int defaultLevelLogFile = 3;
     210        SetConfigValue(bDevMode_, false)
     211            .description("Developer mode. If not set, hides some things from the user to not confuse him.");
    210212#else
    211213        const unsigned int defaultLevelLogFile = 4;
     214        SetConfigValue(bDevMode_, true)
     215            .description("Developer mode. If not set, hides some things from the user to not confuse him.");
    212216#endif
    213217        SetConfigValueExternal(softDebugLevelLogFile_, "OutputHandler", "softDebugLevelLogFile", defaultLevelLogFile)
  • code/trunk/src/libraries/core/Core.h

    r7870 r8079  
    9191                { return this->ogreConfigTimestamp_; }
    9292
     93            inline bool inDevMode(void) const
     94                { return this->bDevMode_; }
     95
    9396        private:
    9497            Core(const Core&); //!< Don't use (undefined symbol)
     
    130133            long long                     lastLevelTimestamp_;         ///< Timestamp when the last level was started
    131134            long long                     ogreConfigTimestamp_;        ///< Timestamp wehen the ogre config level was modified
     135            bool                          bDevMode_;                   //!< Developers bit. If set to false, some options are not available as to not confuse the normal user.
    132136
    133137            static Core*                  singletonPtr_s;
  • code/trunk/src/libraries/core/CorePrereqs.h

    r7849 r8079  
    182182    class Thread;
    183183    class ThreadPool;
     184    class ViewportEventListener;
    184185    template <class T>
    185186    class WeakPtr;
  • code/trunk/src/libraries/core/GUIManager.cc

    r7876 r8079  
    3232#include <boost/bind.hpp>
    3333#include <memory>
    34 extern "C" {
    35 #include <lua.h>
    36 }
     34
    3735#include <CEGUIDefaultLogger.h>
    3836#include <CEGUIExceptions.h>
     
    107105    SetConsoleCommand("showGUI", &GUIManager::showGUI).defaultValue(1, false).defaultValue(2, false);
    108106    SetConsoleCommand("hideGUI", &GUIManager::hideGUI);
     107    SetConsoleCommand("toggleGUI", &GUIManager::toggleGUI).defaultValue(1, false).defaultValue(2, false);
    109108
    110109    /**
     
    284283    {
    285284        GUIManager::getInstance().executeCode("hideMenuSheet(\"" + name + "\")");
     285    }
     286
     287    /**
     288    @brief
     289        Toggles specified GUI.
     290        If the GUI with the input name is already shown and on the top, it is hidden, else it is shown.
     291    */
     292    /*static*/ void GUIManager::toggleGUI(const std::string& name, bool bHidePrevious, bool bNoInput)
     293    {
     294        GUIManager::getInstance().executeCode("getGUIFirstActive(\"" + name + "\", " + multi_cast<std::string>(bHidePrevious) + ", " + multi_cast<std::string>(bNoInput) + ")");
     295    }
     296
     297    /**
     298    @brief
     299        Helper method to toggle a specified GUI.
     300        Is called by lua.
     301    */
     302    void GUIManager::toggleGUIHelper(const std::string& name, bool bHidePrevious, bool bNoInput, bool show)
     303    {
     304        if(show)
     305            GUIManager::showGUI(name, bHidePrevious, bNoInput);
     306        else
     307            GUIManager::hideGUI(name);
    286308    }
    287309
     
    512534    void GUIManager::windowResized(unsigned int newWidth, unsigned int newHeight)
    513535    {
    514         this->guiRenderer_->setDisplaySize(CEGUI::Size(newWidth, newHeight));
    515     }
    516 
    517     /**
    518         @brief Notify CEGUI if the windows loses the focus (stops higlight of menu items, etc).
     536        this->guiRenderer_->setDisplaySize(CEGUI::Size((float)newWidth, (float)newHeight));
     537    }
     538
     539    /**
     540        @brief Notify CEGUI if the windows loses the focus (stops highlighting of menu items, etc).
    519541    */
    520542    void GUIManager::windowFocusChanged(bool bFocus)
  • code/trunk/src/libraries/core/GUIManager.h

    r7874 r8079  
    4949#include "util/Singleton.h"
    5050#include "input/InputHandler.h"
     51#include "Core.h"
    5152#include "OrxonoxClass.h"
    5253#include "WindowEventListener.h"
     
    8889        void showGUIExtra(const std::string& name, const std::string& ptr, bool bHidePrevious = false, bool bNoInput = false);
    8990        static void hideGUI(const std::string& name);
     91        static void toggleGUI(const std::string& name, bool bHidePrevious = false, bool bNoInput = false);
     92        void toggleGUIHelper(const std::string& name, bool bHidePrevious, bool bNoInput, bool show); // tolua_export
    9093        void keyESC();
    9194        void setBackgroundImage(const std::string& imageSet, const std::string imageName); // tolua_export
    9295        void setBackgroundImage(const std::string& image);
     96
     97        /**
     98        @brief Helper method to get the developer's mode without having to export Core.h.
     99        @see Core::inDevMode
     100        */
     101        static bool inDevMode(void) { return Core::getInstance().inDevMode(); } // tolua_export
    93102
    94103        //! Creates a new InputState to be used with a GUI Sheet
  • code/trunk/src/libraries/core/Game.cc

    r7284 r8079  
    5050#include "GameMode.h"
    5151#include "GameState.h"
     52#include "GraphicsManager.h"
    5253#include "GUIManager.h"
    5354#include "command/ConsoleCommand.h"
     
    6061    static void printFPS()
    6162        { COUT(0) << Game::getInstance().getAvgFPS() << std::endl; }
    62     SetConsoleCommand("printFPS", &printFPS);
     63    SetConsoleCommand("Stats", "printFPS", &printFPS);
    6364    static void printTickTime()
    6465        { COUT(0) << Game::getInstance().getAvgTickTime() << std::endl; }
    65     SetConsoleCommand("printTickTime", &printTickTime);
     66    SetConsoleCommand("Stats", "printTickTime", &printTickTime);
    6667
    6768    std::map<std::string, GameStateInfo> Game::gameStateDeclarations_s;
     
    142143        SetConfigValue(statisticsAvgLength_, 1000000)
    143144            .description("Sets the time in microseconds interval at which average fps, etc. gets calculated.");
    144         SetConfigValue(fpsLimit_, 50)
     145
     146        SetConfigValueExternal(fpsLimit_, "GraphicsSettings", "fpsLimit", 50)
    145147            .description("Sets the desired frame rate (0 for no limit).");
    146148    }
     
    207209
    208210            // Limit frame rate
    209             this->updateFPSLimiter();
     211            static bool hasVSync = GraphicsManager::getInstance().hasVSyncEnabled(); // can be static since changes of VSync currently require a restart
     212            if (this->fpsLimit_ > 0 && !hasVSync)
     213                this->updateFPSLimiter();
    210214        }
    211215
  • 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
  • code/trunk/src/libraries/core/GraphicsManager.h

    r7401 r8079  
    5454#include "OrxonoxClass.h"
    5555
     56// tolua_begin
    5657namespace orxonox
    5758{
     
    6061        Graphics engine manager class
    6162    */
    62     class _CoreExport GraphicsManager : public Singleton<GraphicsManager>, public OrxonoxClass, public Ogre::LogListener
    63     {
     63    class _CoreExport GraphicsManager
     64// tolua_end
     65        : public Singleton<GraphicsManager>, public OrxonoxClass, public Ogre::LogListener
     66    { // tolua_export
    6467        friend class Singleton<GraphicsManager>;
    6568    public:
     
    7477        Ogre::RenderWindow* getRenderWindow() { return this->renderWindow_; }
    7578        size_t getRenderWindowHandle();
     79
     80// tolua_begin
     81        static GraphicsManager& getInstance() { return Singleton<GraphicsManager>::getInstance(); } // tolua_export
     82
    7683        bool isFullScreen() const;
     84        unsigned int getWindowWidth() const;
     85        unsigned int getWindowHeight() const;
     86
     87        bool hasVSyncEnabled() const;
     88        std::string getFSAAMode() const;
     89// tolua_end
    7790
    7891        void upgradeToGraphics();
     
    96109        // console commands
    97110        void printScreen();
     111        std::string setScreenResolution(unsigned int width, unsigned int height, bool fullscreen);
     112        std::string setFSAA(const std::string& mode);
     113        std::string setVSync(bool vsync);
    98114
    99115        scoped_ptr<OgreWindowEventListener> ogreWindowEventListener_; //!< Pimpl to hide OgreWindowUtilities.h
     
    105121        Ogre::RenderWindow* renderWindow_;             //!< the one and only render window
    106122        Ogre::Viewport*     viewport_;                 //!< default full size viewport
     123        float               lastFrameStartTime_;       //!< Time stamp of the beginning of the last frame
     124        float               lastFrameEndTime_;         //!< Time stamp of the end of the last frame
    107125
    108126        // XML files for the resources and the debug overlay
     
    121139
    122140        static GraphicsManager* singletonPtr_s;        //!< Pointer to the Singleton
     141// tolua_begin
    123142    };
    124143}
     144// tolua_end
    125145
    126146#endif /* _GraphicsManager_H__ */
  • code/trunk/src/libraries/core/Loader.cc

    r7648 r8079  
    147147        Returns true if successful.
    148148    */
    149     bool Loader::load(const XMLFile* file, const ClassTreeMask& mask, bool verbose)
     149    bool Loader::load(const XMLFile* file, const ClassTreeMask& mask, bool verbose, bool bRemoveLuaTags)
    150150    {
    151151        if (!file)
     
    155155
    156156        std::string xmlInput;
    157         if (file->getLuaSupport())
     157        if (file->getLuaSupport() && !bRemoveLuaTags)
    158158        {
    159159            // Use the LuaState to replace the XML tags (calls our function)
     
    172172            }
    173173            xmlInput = Resource::open(file->getFilename())->getAsString();
     174
     175            if (bRemoveLuaTags)
     176            {
     177                // Remove all Lua code.
     178                // Note: we only need this to speed up parsing of level files at the
     179                // start of the program.
     180                // Assumption: the LevelInfo tag does not use Lua scripting
     181                xmlInput = removeLuaTags(xmlInput);
     182            }
    174183        }
    175184
     
    271280    }
    272281
    273     std::string Loader::replaceLuaTags(const std::string& text)
    274     {
    275         // create map with all Lua tags
    276         std::map<size_t, bool> luaTags;
     282    bool Loader::getLuaTags(const std::string& text, std::map<size_t, bool>& luaTags)
     283    {
     284        // fill map with all Lua tags
    277285        {
    278286            size_t pos = 0;
     
    328336            {
    329337                COUT(2) << "Warning: Error in level file" << std::endl;
    330                 // todo: errorhandling
    331                 return "";
    332             }
    333         }
     338                // TODO: error handling
     339                return false;
     340            }
     341        }
     342
     343        return true;
     344    }
     345
     346    std::string Loader::replaceLuaTags(const std::string& text)
     347    {
     348        // create a map with all lua tags
     349        std::map<size_t, bool> luaTags;
     350        if (!getLuaTags(text, luaTags))
     351            return "";
    334352
    335353        // Use a stringstream object to speed up the parsing
     
    421439        return output.str();
    422440    }
     441
     442    std::string Loader::removeLuaTags(const std::string& text)
     443    {
     444        // create a map with all lua tags
     445        std::map<size_t, bool> luaTags;
     446        if (!getLuaTags(text, luaTags))
     447            return "";
     448
     449        // Use a stringstream object to speed up the concatenation
     450        std::ostringstream output;
     451
     452        // cut the original string into pieces and only write the non Lua parts
     453        std::map<size_t, bool>::iterator it = luaTags.begin();
     454        bool bLuaCode = false;
     455        size_t start = 0;
     456        size_t end = 0;
     457
     458        do
     459        {
     460            if (it != luaTags.end())
     461                end = (it++)->first;
     462            else
     463                end = std::string::npos;
     464
     465            if (!bLuaCode)
     466            {
     467                output << text.substr(start, end - start);
     468                start = end + 5;
     469            }
     470            else
     471                start = end + 2;
     472
     473            bLuaCode = !bLuaCode;
     474        }
     475        while (end != std::string::npos);
     476
     477        return output.str();
     478    }
    423479}
  • code/trunk/src/libraries/core/Loader.h

    r7648 r8079  
    4242#include "CorePrereqs.h"
    4343
     44#include <map>
    4445#include <vector>
    4546#include "ClassTreeMask.h"
     
    6162            static bool reload(const ClassTreeMask& mask = ClassTreeMask(), bool verbose = true);
    6263
    63             static bool load(const XMLFile* file, const ClassTreeMask& mask = ClassTreeMask(), bool verbose = true);
     64            static bool load(const XMLFile* file, const ClassTreeMask& mask = ClassTreeMask(),
     65                             bool verbose = true, bool bRemoveLuaTags = false);
    6466            static void unload(const XMLFile* file, const ClassTreeMask& mask = ClassTreeMask());
    6567            static bool reload(const XMLFile* file, const ClassTreeMask& mask = ClassTreeMask(), bool verbose = true);
    6668
    6769            static std::string replaceLuaTags(const std::string& text);
     70            static std::string removeLuaTags(const std::string& text);
    6871
    6972            static ClassTreeMask currentMask_s;
    7073
    7174        private:
     75            static bool getLuaTags(const std::string& text, std::map<size_t, bool>& luaTags);
     76
    7277            static std::vector<std::pair<const XMLFile*, ClassTreeMask> > files_s;
    7378    };
  • code/trunk/src/libraries/core/OrxonoxClass.h

    r7850 r8079  
    194194
    195195        protected:
     196            virtual ~DestructionListener() {}
     197
    196198            inline void registerAsDestructionListener(OrxonoxClass* object)
    197199                { if (object) { object->registerDestructionListener(this); } }
  • code/trunk/src/libraries/core/WeakPtr.h

    r7850 r8079  
    129129
    130130            /// Destructor
    131             inline ~WeakPtr()
     131            inline virtual ~WeakPtr()
    132132            {
    133133                this->unregisterAsDestructionListener(this->base_);
  • code/trunk/src/libraries/core/command/CommandEvaluation.h

    r7401 r8079  
    7070
    7171        @remarks execCommand_ and hintCommand_ can be different in this case: There are multiple
    72         commands avaliable, let's say "tcl", "tclexecute", and "tclquery". The user enters
    73         "tcl", which is already a valid command. Now execCommand_ points to the "tcl"-command,
    74         but hintCommand_ still points to the autocompletion command of CommandExecutor, because
    75         the auto-completion list must still return the three possible commands, "tcl tclexecute tclquery"
    76         because the user may want to execute "tclquery" and needs auto-completion.
     72        commands avaliable, let's say "tcl" and "TclThreadManager". The user enters "tcl", which
     73        is already a valid command. Now execCommand_ points to the "tcl"-command, but hintCommand_
     74        still points to the autocompletion command of CommandExecutor, because the auto-completion
     75        list must still return the two possible commands, "tcl TclThreadManager" because the user
     76        may want to write "TclThreadManager ..." and needs auto-completion.
    7777
    7878        @see See @ref CommandExecutorExample "this description" for an example.
  • code/trunk/src/libraries/core/command/ConsoleCommand.h

    r7861 r8079  
    317317        inline void void__void(void) {}
    318318        inline void void__string(const std::string&) {}
     319
     320        inline std::string string__bool(bool) { return ""; }
     321        inline std::string string__string(const std::string&) { return ""; }
     322        inline std::string string__uint_uint_bool(unsigned int, unsigned int, bool) { return ""; }
    319323    }
    320324
  • code/trunk/src/libraries/core/command/ConsoleCommandCompilation.cc

    r7401 r8079  
    4646namespace orxonox
    4747{
    48     SetConsoleCommand("source", source).argumentCompleter(0, autocompletion::files());
     48//    SetConsoleCommand("source", source).argumentCompleter(0, autocompletion::files());  // disabled because we use the implementation in Tcl
    4949    SetConsoleCommand("echo", echo);
    50     SetConsoleCommand("puts", puts);
    51 
    52     SetConsoleCommand("read", read).argumentCompleter(0, autocompletion::files());
    53     SetConsoleCommand("append", append).argumentCompleter(0, autocompletion::files());
    54     SetConsoleCommand("write", write).argumentCompleter(0, autocompletion::files());
     50//    SetConsoleCommand("puts", puts);                                                    // disabled because we use the implementation in Tcl
     51
     52//    SetConsoleCommand("read", read).argumentCompleter(0, autocompletion::files());      // disabled because we use the implementation in Tcl
     53//    SetConsoleCommand("append", append).argumentCompleter(0, autocompletion::files());  // disabled because we use the implementation in Tcl
     54//    SetConsoleCommand("write", write).argumentCompleter(0, autocompletion::files());    // disabled because we use the implementation in Tcl
    5555
    5656    SetConsoleCommand("calculate", calculate);
  • code/trunk/src/libraries/core/command/Shell.cc

    r7401 r8079  
    4646{
    4747    SetConsoleCommand("log",     OutputHandler::log    );
    48     SetConsoleCommand("error",   OutputHandler::error  );
    49     SetConsoleCommand("warning", OutputHandler::warning);
    50     SetConsoleCommand("info",    OutputHandler::info   );
    51     SetConsoleCommand("debug",   OutputHandler::debug  );
     48    SetConsoleCommand("error",   OutputHandler::error  ).hide();
     49    SetConsoleCommand("warning", OutputHandler::warning).hide();
     50    SetConsoleCommand("info",    OutputHandler::info   ).hide();
     51    SetConsoleCommand("debug",   OutputHandler::debug  ).hide();
    5252
    5353    unsigned int Shell::cacheSize_s;
  • code/trunk/src/libraries/core/command/TclBind.cc

    r7401 r8079  
    4545{
    4646    SetConsoleCommand("tcl", &TclBind::tcl);
    47     SetConsoleCommand("bgerror", &TclBind::bgerror);
     47    SetConsoleCommand("bgerror", &TclBind::bgerror).hide();
    4848
    4949    TclBind* TclBind::singletonPtr_s = 0;
     
    9191
    9292            this->interpreter_->def("::orxonox::query", TclBind::tcl_query, Tcl::variadic());
     93            this->interpreter_->def("::orxonox::execute", TclBind::tcl_execute, Tcl::variadic());
    9394            this->interpreter_->def("::orxonox::crossquery", TclThreadManager::tcl_crossquery, Tcl::variadic());
    94             this->interpreter_->def("execute", TclBind::tcl_execute, Tcl::variadic());
    9595            this->interpreter_->def("::orxonox::crossexecute", TclThreadManager::tcl_crossexecute, Tcl::variadic());
    9696
    9797            try
    9898            {
    99                 this->interpreter_->eval("proc query        {args}    { ::orxonox::query $args }");
     99                this->interpreter_->def("query", TclBind::tcl_query, Tcl::variadic());
     100                this->interpreter_->def("execute", TclBind::tcl_execute, Tcl::variadic());
    100101                this->interpreter_->eval("proc crossquery   {id args} { ::orxonox::crossquery 0 $id $args }");
    101                 this->interpreter_->eval("proc crossexecute {id args} { ::orxonox::crossquery 0 $id $args }");
     102                this->interpreter_->eval("proc crossexecute {id args} { ::orxonox::crossexecute 0 $id $args }");
    102103                this->interpreter_->eval("proc running      {}        { return 1 }");
    103104                this->interpreter_->eval("set id 0");
     
    154155    {
    155156        COUT(4) << "Tcl_query: " << args.get() << std::endl;
    156 
     157        return TclBind::tcl_helper(args, true);
     158    }
     159
     160    /**
     161        @brief Callback: Used to send an Orxonox-command from Tcl to the CommandExecutor.
     162    */
     163    void TclBind::tcl_execute(Tcl::object const &args)
     164    {
     165        COUT(4) << "Tcl_execute: " << args.get() << std::endl;
     166        TclBind::tcl_helper(args, false);
     167    }
     168
     169    /**
     170        @brief Helper function, used by tcl_query() and tcl_execute().
     171    */
     172    std::string TclBind::tcl_helper(Tcl::object const &args, bool bQuery)
     173    {
    157174        const std::string& command = stripEnclosingBraces(args.get());
    158175
    159176        int error;
     177        std::string result;
     178
    160179        CommandEvaluation evaluation = CommandExecutor::evaluate(command);
    161         const std::string& result = evaluation.query(&error);
     180
     181        if (bQuery)
     182            result = evaluation.query(&error).getString();
     183        else
     184            error = evaluation.execute();
     185
    162186        switch (error)
    163187        {
     
    175199
    176200    /**
    177         @brief Callback: Used to send an Orxonox-command from Tcl to the CommandExecutor.
    178     */
    179     void TclBind::tcl_execute(Tcl::object const &args)
    180     {
    181         COUT(4) << "Tcl_execute: " << args.get() << std::endl;
    182         const std::string& command = stripEnclosingBraces(args.get());
    183 
    184         if (CommandExecutor::execute(command, false))
    185         {
    186             COUT(1) << "Error: Can't execute command \"" << command << "\"!" << std::endl;
    187         }
    188     }
    189 
    190     /**
    191201        @brief Console command, executes Tcl code. Can be used to bind Tcl-commands to a key, because native
    192202        Tcl-commands can not be evaluated and are thus not supported by the key-binder.
     
    198208            try
    199209            {
    200                 const std::string& output = TclBind::getInstance().interpreter_->eval("uplevel #0 " + tclcode);
    201                 if (!output.empty())
    202                 {
    203                     COUT(0) << "tcl> " << output << std::endl;
    204                 }
    205                 return output;
     210                return TclBind::getInstance().interpreter_->eval("uplevel #0 " + tclcode);
    206211            }
    207212            catch (Tcl::tcl_error const &e)
    208             {   COUT(1) << "tcl> Error: " << e.what() << std::endl;   }
     213            {   COUT(1) << "Tcl error: " << e.what() << std::endl;   }
    209214        }
    210215
  • code/trunk/src/libraries/core/command/TclBind.h

    r7401 r8079  
    126126            TclBind(const TclBind& other);      ///< Copy-constructor, not implemented
    127127
     128            static std::string tcl_helper(Tcl::object const &args, bool bQuery);
     129
    128130            Tcl::interpreter* interpreter_;     ///< The wrapped Tcl interpreter
    129131            std::string tclDataPath_;           ///< The path to the directory that contains the Orxonox-specific Tcl-files
  • code/trunk/src/libraries/core/command/TclThreadManager.cc

    r7401 r8079  
    5555    const float TCLTHREADMANAGER_MAX_CPU_USAGE = 0.50f;
    5656
    57     SetConsoleCommand("tclexecute", &TclThreadManager::execute).argumentCompleter(0, autocompletion::tclthreads());
    58     SetConsoleCommand("tclquery",   &TclThreadManager::query  ).argumentCompleter(0, autocompletion::tclthreads());
    5957    SetConsoleCommand("TclThreadManager", "create",  &TclThreadManager::create);
    6058    SetConsoleCommand("TclThreadManager", "destroy", &TclThreadManager::destroy).argumentCompleter(0, autocompletion::tclthreads());
  • code/trunk/src/libraries/core/input/InputManager.cc

    r7874 r8079  
    641641        state->destroy();
    642642    }
     643
     644    bool InputManager::setMouseExclusive(const std::string& name, TriBool::Value value)
     645    {
     646        if (name == "empty")
     647        {
     648            COUT(2) << "InputManager: Changing the empty state is not allowed!" << std::endl;
     649            return false;
     650        }
     651        std::map<std::string, InputState*>::iterator it = statesByName_.find(name);
     652        if (it != statesByName_.end())
     653        {
     654            it->second->setMouseExclusive(value);
     655            return true;
     656        }
     657        return false;
     658    }
    643659}
  • code/trunk/src/libraries/core/input/InputManager.h

    r7874 r8079  
    163163        */
    164164        bool destroyState(const std::string& name); // tolua_export
     165        /**
     166        @brief
     167            Changes the mouse mode of an input state.
     168        @return
     169            True if the call was successful, fals if the name was not found
     170        */
     171        bool setMouseExclusive(const std::string& name, TriBool::Value value); // tolua_export
    165172
    166173        //-------------------------------
  • code/trunk/src/libraries/core/input/KeyBinder.cc

    r7958 r8079  
    431431                        // decrease counter
    432432                        button->nCommands_[mode_index]--;
    433                         // note: we don't replace the old array - it's not one element too large, but no one cares since nCommands_ defines the size
     433                        // old array would not get deleted if nCommands_ is now 0
     434                        // otherwise: nobody cares about an array that is one element too large - nCommands_ defines the size
     435                        if (button->nCommands_[mode_index] == 0)
     436                        {
     437                            delete[] button->commands_[mode_index];
     438                            button->commands_[mode_index] = 0;
     439                        }
    434440
    435441                        // decrement the index since we shifted the array and continue searching for more occurrences of the command
  • code/trunk/src/libraries/core/input/Keyboard.cc

    r6422 r8079  
    3636    {
    3737        // update modifiers
    38         if (arg.key == OIS::KC_RMENU    || arg.key == OIS::KC_LMENU)
    39             modifiers_ |= KeyboardModifier::Alt;   // alt key
    40         if (arg.key == OIS::KC_RCONTROL || arg.key == OIS::KC_LCONTROL)
    41             modifiers_ |= KeyboardModifier::Ctrl;  // ctrl key
    42         if (arg.key == OIS::KC_RSHIFT   || arg.key == OIS::KC_LSHIFT)
    43             modifiers_ |= KeyboardModifier::Shift; // shift key
     38        switch (arg.key)
     39        {
     40            case OIS::KC_RMENU:
     41            case OIS::KC_LMENU:
     42                modifiers_ |= KeyboardModifier::Alt;   // alt key
     43                break;
     44            case OIS::KC_RCONTROL:
     45            case OIS::KC_LCONTROL:
     46                modifiers_ |= KeyboardModifier::Ctrl;  // ctrl key
     47                break;
     48            case OIS::KC_RSHIFT:
     49            case OIS::KC_LSHIFT:
     50                modifiers_ |= KeyboardModifier::Shift; // shift key
     51                break;
     52            case OIS::KC_TAB:
     53                // Do not distribute the alt+tab event (messes with the operating system)
     54                if ((modifiers_ & KeyboardModifier::Alt) != 0)
     55                    return true;
     56            default:;
     57        }
    4458
    45         // Do not distribute the alt+tab event (messes with the operating system)
    46         if ((modifiers_ & KeyboardModifier::Alt) != 0 && arg.key == OIS::KC_TAB)
    47             return true;
    48 
    49         KeyEvent evt(arg);
     59        KeyEvent evt(static_cast<KeyCode::ByEnum>(arg.key), Keyboard::getKeyText(arg), 0);
    5060        super::buttonPressed(evt);
    5161        return true;
     
    5666    {
    5767        // update modifiers
    58         if (arg.key == OIS::KC_RMENU    || arg.key == OIS::KC_LMENU)
    59             modifiers_ &= ~KeyboardModifier::Alt;   // alt key
    60         if (arg.key == OIS::KC_RCONTROL || arg.key == OIS::KC_LCONTROL)
    61             modifiers_ &= ~KeyboardModifier::Ctrl;  // ctrl key
    62         if (arg.key == OIS::KC_RSHIFT   || arg.key == OIS::KC_LSHIFT)
    63             modifiers_ &= ~KeyboardModifier::Shift; // shift key
     68        switch (arg.key)
     69        {
     70            case OIS::KC_RMENU:
     71            case OIS::KC_LMENU:
     72                modifiers_ &= ~KeyboardModifier::Alt;   // alt key
     73                break;
     74            case OIS::KC_RCONTROL:
     75            case OIS::KC_LCONTROL:
     76                modifiers_ &= ~KeyboardModifier::Ctrl;  // ctrl key
     77                break;
     78            case OIS::KC_RSHIFT:
     79            case OIS::KC_LSHIFT:
     80                modifiers_ &= ~KeyboardModifier::Shift; // shift key
     81                break;
     82            default:;
     83        }
    6484
    65         KeyEvent evt(arg);
     85        KeyEvent evt(static_cast<KeyCode::ByEnum>(arg.key), Keyboard::getKeyText(arg), 0);
    6686        super::buttonReleased(evt);
    6787        return true;
    6888    }
     89
     90    /// A map which returns the corresponding chars for some key codes
     91    unsigned int Keyboard::getKeyText(const OIS::KeyEvent& arg)
     92    {
     93        switch (arg.key)
     94        {
     95            case OIS::KC_NUMPAD0:     return static_cast<unsigned int>('0');
     96            case OIS::KC_NUMPAD1:     return static_cast<unsigned int>('1');
     97            case OIS::KC_NUMPAD2:     return static_cast<unsigned int>('2');
     98            case OIS::KC_NUMPAD3:     return static_cast<unsigned int>('3');
     99            case OIS::KC_NUMPAD4:     return static_cast<unsigned int>('4');
     100            case OIS::KC_NUMPAD5:     return static_cast<unsigned int>('5');
     101            case OIS::KC_NUMPAD6:     return static_cast<unsigned int>('6');
     102            case OIS::KC_NUMPAD7:     return static_cast<unsigned int>('7');
     103            case OIS::KC_NUMPAD8:     return static_cast<unsigned int>('8');
     104            case OIS::KC_NUMPAD9:     return static_cast<unsigned int>('9');
     105            case OIS::KC_DECIMAL:     return static_cast<unsigned int>('.');
     106            case OIS::KC_DIVIDE:      return static_cast<unsigned int>('/');
     107            case OIS::KC_NUMPADENTER: return static_cast<unsigned int>('\n');
     108            default:                  return arg.text;
     109        }
     110    }
    69111}
  • code/trunk/src/libraries/core/input/Keyboard.h

    r7809 r8079  
    8383        static std::string getClassNameImpl() { return "Keyboard"; }
    8484
     85        static unsigned int getKeyText(const OIS::KeyEvent& arg);
     86
    8587        //! Bit mask representing keyboard modifiers
    8688        int modifiers_;
Note: See TracChangeset for help on using the changeset viewer.