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:
2 edited

Legend:

Unmodified
Added
Removed
  • code/trunk

  • code/trunk/src/libraries/tools/Timer.cc

    r7401 r8079  
    3535
    3636#include <set>
     37
     38#include <boost/bimap.hpp>
    3739
    3840#include "util/Clock.h"
     
    4143#include "core/command/CommandExecutor.h"
    4244#include "core/command/Functor.h"
     45#include "tools/interfaces/TimeFactorListener.h"
    4346
    4447namespace orxonox
    4548{
    4649    SetConsoleCommand("delay", &delay).argumentCompleter(1, autocompletion::command());
     50    SetConsoleCommand("delayreal", &delayreal).argumentCompleter(1, autocompletion::command());
     51    SetConsoleCommand("killdelay", &killdelay);
    4752    SetConsoleCommand("killdelays", &killdelays);
    4853
    49     static std::set<Timer*> delaytimerset;
    50 
    51     /**
    52         @brief Console-command: Calls another console command after @a delay seconds.
     54    static boost::bimap<unsigned int, Timer*> delaytimers;
     55    static unsigned int delayHandleCounter = 0;
     56
     57    /**
     58        @brief Console-command: Calls another console command after @a delay seconds (game time).
    5359        @param delay The delay in seconds
    5460        @param command The console command
    55     */
    56     void delay(float delay, const std::string& command)
    57     {
    58         Timer* delaytimer = new Timer();
    59         delaytimerset.insert(delaytimer);
     61        @return The handle of the delayed command, can be used as argument for killdelay()
     62    */
     63    unsigned int delay(float delay, const std::string& command)
     64    {
     65        return addDelayedCommand(new Timer(), delay, command);
     66    }
     67
     68    /**
     69        @brief Console-command: Calls another console command after @a delay seconds (real time)
     70        @param delay The delay in seconds
     71        @param command The console command
     72        @return The handle of the delayed command, can be used as argument for killdelay()
     73    */
     74    unsigned int delayreal(float delay, const std::string& command)
     75    {
     76        return addDelayedCommand(new RealTimer(), delay, command);
     77    }
     78
     79    /**
     80        @brief Helper function, used by delay() and delayreal() to add a delayed command.
     81        @param timer The timer which will execute the command
     82        @param delay The delay in seconds
     83        @param command The console command
     84        @return The handle of the delayed command, can be used as argument for killdelay()
     85    */
     86    unsigned int addDelayedCommand(Timer* timer, float delay, const std::string& command)
     87    {
     88        delaytimers.insert(boost::bimap<unsigned int, Timer*>::value_type(++delayHandleCounter, timer));
    6089
    6190        const ExecutorStaticPtr& delayexecutor = createExecutor(createFunctor(&executeDelayedCommand));
    62         delayexecutor->setDefaultValues(delaytimer, command);
    63         delaytimer->setTimer(delay, false, delayexecutor);
     91        delayexecutor->setDefaultValues(timer, command);
     92        timer->setTimer(delay, false, delayexecutor);
     93
     94        return delayHandleCounter;
    6495    }
    6596
     
    73104        CommandExecutor::execute(command);
    74105        timer->destroy();
    75         delaytimerset.erase(timer);
     106        delaytimers.right.erase(timer);
    76107    }
    77108
     
    81112    void killdelays()
    82113    {
    83         for (std::set<Timer*>::iterator it = delaytimerset.begin(); it != delaytimerset.end(); ++it)
    84             (*it)->destroy();
    85 
    86         delaytimerset.clear();
     114        for (boost::bimap<unsigned int, Timer*>::left_map::iterator it = delaytimers.left.begin(); it != delaytimers.left.end(); ++it)
     115            it->second->destroy();
     116
     117        delaytimers.clear();
     118    }
     119
     120    /**
     121        @brief Console-command: Kills a delayed command with given handle.
     122    */
     123    void killdelay(unsigned int handle)
     124    {
     125        boost::bimap<unsigned int, Timer*>::left_map::iterator it = delaytimers.left.find(handle);
     126        if (it != delaytimers.left.end())
     127        {
     128            it->second->destroy();
     129            delaytimers.left.erase(it);
     130        }
    87131    }
    88132
     
    93137    {
    94138        this->init();
    95         RegisterObject(Timer);
     139        RegisterRootObject(Timer);
    96140    }
    97141
     
    106150    {
    107151        this->init();
    108         RegisterObject(Timer);
     152        RegisterRootObject(Timer);
    109153
    110154        this->setTimer(interval, bLoop, executor, bKillAfterCall);
     
    123167
    124168        this->time_ = 0;
     169    }
     170
     171    /**
     172        @brief Returns the current time factor of the game.
     173    */
     174    float Timer::getTimeFactor()
     175    {
     176        return TimeFactorListener::getTimeFactor();
    125177    }
    126178
     
    168220        }
    169221    }
     222
     223    ///////////////
     224    // RealTimer //
     225    ///////////////
     226    /// @copydoc Timer::Timer
     227    RealTimer::RealTimer()
     228    {
     229        RegisterObject(RealTimer);
     230    }
     231
     232    /// @copydoc Timer::Timer(float, bool, const ExecutorPtr&, bool)
     233    RealTimer::RealTimer(float interval, bool bLoop, const ExecutorPtr& executor, bool bKillAfterCall) : Timer(interval, bLoop, executor, bKillAfterCall)
     234    {
     235        RegisterObject(RealTimer);
     236    }
     237
     238    /// Returns always 1 because RealTimer doesn't depend on the game time.
     239    float RealTimer::getTimeFactor()
     240    {
     241        return 1;
     242    }
    170243}
Note: See TracChangeset for help on using the changeset viewer.