Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8020 for code/branches


Ignore:
Timestamp:
Mar 5, 2011, 6:30:06 PM (14 years ago)
Author:
landauf
Message:

delayed commands now return a handle which allows to kill them selectively

Location:
code/branches/usability/src/libraries/tools
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/branches/usability/src/libraries/tools/Timer.cc

    r7401 r8020  
    3636#include <set>
    3737
     38#include <boost/bimap.hpp>
     39
    3840#include "util/Clock.h"
    3941#include "core/CoreIncludes.h"
     
    4547{
    4648    SetConsoleCommand("delay", &delay).argumentCompleter(1, autocompletion::command());
     49    SetConsoleCommand("killdelay", &killdelay);
    4750    SetConsoleCommand("killdelays", &killdelays);
    4851
    49     static std::set<Timer*> delaytimerset;
     52    static boost::bimap<unsigned int, Timer*> delaytimers;
     53    static unsigned int delayHandleCounter = 0;
    5054
    5155    /**
     
    5357        @param delay The delay in seconds
    5458        @param command The console command
     59        @return The handle of the delayed command, can be used as argument for killdelay()
    5560    */
    56     void delay(float delay, const std::string& command)
     61    unsigned int delay(float delay, const std::string& command)
    5762    {
    5863        Timer* delaytimer = new Timer();
    59         delaytimerset.insert(delaytimer);
     64        delaytimers.insert(boost::bimap<unsigned int, Timer*>::value_type(++delayHandleCounter, delaytimer));
    6065
    6166        const ExecutorStaticPtr& delayexecutor = createExecutor(createFunctor(&executeDelayedCommand));
    6267        delayexecutor->setDefaultValues(delaytimer, command);
    6368        delaytimer->setTimer(delay, false, delayexecutor);
     69
     70        return delayHandleCounter;
    6471    }
    6572
     
    7380        CommandExecutor::execute(command);
    7481        timer->destroy();
    75         delaytimerset.erase(timer);
     82        delaytimers.right.erase(timer);
    7683    }
    7784
     
    8188    void killdelays()
    8289    {
    83         for (std::set<Timer*>::iterator it = delaytimerset.begin(); it != delaytimerset.end(); ++it)
    84             (*it)->destroy();
     90        for (boost::bimap<unsigned int, Timer*>::left_map::iterator it = delaytimers.left.begin(); it != delaytimers.left.end(); ++it)
     91            it->second->destroy();
    8592
    86         delaytimerset.clear();
     93        delaytimers.clear();
     94    }
     95
     96    /**
     97        @brief Console-command: Kills a delayed command with given handle.
     98    */
     99    void killdelay(unsigned int handle)
     100    {
     101        boost::bimap<unsigned int, Timer*>::left_map::iterator it = delaytimers.left.find(handle);
     102        if (it != delaytimers.left.end())
     103        {
     104            it->second->destroy();
     105            delaytimers.left.erase(it);
     106        }
    87107    }
    88108
  • code/branches/usability/src/libraries/tools/Timer.h

    r7851 r8020  
    8585namespace orxonox
    8686{
    87     void delay(float delay, const std::string& command);
     87    unsigned int delay(float delay, const std::string& command);
     88    void killdelay(unsigned int handle);
    8889    void killdelays();
    8990    void executeDelayedCommand(Timer* timer, const std::string& command);
Note: See TracChangeset for help on using the changeset viewer.