Changeset 8020 for code/branches/usability/src
- Timestamp:
- Mar 5, 2011, 6:30:06 PM (14 years ago)
- Location:
- code/branches/usability/src/libraries/tools
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/usability/src/libraries/tools/Timer.cc
r7401 r8020 36 36 #include <set> 37 37 38 #include <boost/bimap.hpp> 39 38 40 #include "util/Clock.h" 39 41 #include "core/CoreIncludes.h" … … 45 47 { 46 48 SetConsoleCommand("delay", &delay).argumentCompleter(1, autocompletion::command()); 49 SetConsoleCommand("killdelay", &killdelay); 47 50 SetConsoleCommand("killdelays", &killdelays); 48 51 49 static std::set<Timer*> delaytimerset; 52 static boost::bimap<unsigned int, Timer*> delaytimers; 53 static unsigned int delayHandleCounter = 0; 50 54 51 55 /** … … 53 57 @param delay The delay in seconds 54 58 @param command The console command 59 @return The handle of the delayed command, can be used as argument for killdelay() 55 60 */ 56 voiddelay(float delay, const std::string& command)61 unsigned int delay(float delay, const std::string& command) 57 62 { 58 63 Timer* delaytimer = new Timer(); 59 delaytimers et.insert(delaytimer);64 delaytimers.insert(boost::bimap<unsigned int, Timer*>::value_type(++delayHandleCounter, delaytimer)); 60 65 61 66 const ExecutorStaticPtr& delayexecutor = createExecutor(createFunctor(&executeDelayedCommand)); 62 67 delayexecutor->setDefaultValues(delaytimer, command); 63 68 delaytimer->setTimer(delay, false, delayexecutor); 69 70 return delayHandleCounter; 64 71 } 65 72 … … 73 80 CommandExecutor::execute(command); 74 81 timer->destroy(); 75 delaytimers et.erase(timer);82 delaytimers.right.erase(timer); 76 83 } 77 84 … … 81 88 void killdelays() 82 89 { 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(); 85 92 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 } 87 107 } 88 108 -
code/branches/usability/src/libraries/tools/Timer.h
r7851 r8020 85 85 namespace orxonox 86 86 { 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); 88 89 void killdelays(); 89 90 void executeDelayedCommand(Timer* timer, const std::string& command);
Note: See TracChangeset
for help on using the changeset viewer.