示例#1
0
 void popAll() {
     std::vector<Invocation> others;
     mutex.Lock();
     others.reserve(q.size());
     for (int i = 0, n = q.size(); i < n; i++) {
         others.push_back(q.front());
         q.pop();
     }
     mutex.Unlock();
     for (Invocation& invok : others) {
         invok.invoke();
     }
 }
            virtual void Run() {
                mapIsUpdating = true;
//                std::cout << "maxAfterWallPos: " << maxAfterWallPos << ", wallPos: " << wallPos << std::endl;
                GlobalMutex.Lock();
                
                while (true) {
                    if (direction == util::Key::LEFT && leftWallPos > maxAfterWallPos && leftWallPos > 0)
                        leftWallPos--;
                    else if (direction == util::Key::RIGHT && leftWallPos < maxAfterWallPos && leftWallPos < mapModel->getMapWidth() - subMapWidth)
                        leftWallPos++;
                    else if (direction == util::Key::DOWN && topWallPos < maxAfterWallPos && topWallPos < mapModel->getMapHeight() - subMapHeight)
                        topWallPos++;
                    else if (direction == util::Key::UP && topWallPos > maxAfterWallPos && topWallPos > 0)
                        topWallPos--;
                    else
                        break;
                    
                    sf::Sleep(0.1f);
                }
                GlobalMutex.Unlock();
                
                mapIsUpdating = false;
            }