commander.cpp

Go to the documentation of this file.
00001 /* MANTAINER: Bernard */
00002 
00003 #include "commander.h"
00004 #include "log.h"
00005 
00006 using namespace std;
00007 
00008 void Commander::addCommand(const std::string &command, int playerID)
00009 {
00010         sCommand cmd(command, playerID);
00011         mQueueMutex.lock();
00012 
00013         // add command to new position in commands queue
00014         mCommQueue.push_back(cmd);
00015         
00016         mQueueMutex.unlock();
00017 }
00018 
00019 void Commander::processAllCommands()
00020 {
00021         sCommand cmd("", -1);
00022 
00023         mQueueMutex.lock();
00024         // empty queue with commands
00025         while (!mCommQueue.empty())
00026         {
00027                 cmd = mCommQueue.front();
00028                 mCommQueue.pop_front();
00029                 mQueueMutex.unlock();
00030 
00031                 // process one command
00032                 processCommand(cmd.command, cmd.playerID);
00033 
00034                 mQueueMutex.lock();
00035         }
00036         
00037         mQueueMutex.unlock();
00038 }
00039 
00040 void Commander::update(int atime)
00041 {
00042         processAllCommands();
00043 }

Generated on Wed Apr 12 13:55:27 2006 for bjs by  doxygen 1.4.5