void Room::startGame(ThreadPool & tp) { _game.init(_playerList); _game.setDelegate(this); _playing = true; tp.addTask(new Task(&runGame, &_game)); }
void Scene::computeColorsAntialiasing(std::function<void(int, int, ColorCRef)> paint, int threadCount, int level) { upto(threadCount, 1); downto(threadCount, 4); std::vector< std::vector <ColorFloat> > m(screen.width, std::vector<ColorFloat> (screen.height, ColorFloat())); computeColors([paint, &m](int x, int y, ColorCRef c) { m[x][y] = c; paint(x, y, c); }, threadCount); if (level > 1) { for (int x = 1; x + 1 < screen.width; x++) { for (int y = 1; y + 1 < screen.height; y++) { int badness = 0; for (int dx : {-1, 1}) for (int dy : {-1, 1}) badness += (m[x][y] - m[x + dx][y + dy]).norm(); if (badness > badnessLimit) { paint(x, y, Color(255, 0, 0)); } } } int taskCount = 10; ThreadPool pool; for (int t = 0; t < taskCount; t++) pool.addTask([this, &paint, &m, level, t, taskCount]() { multiThreadAntialiasePart(paint, m, level, t, taskCount); }); pool.executeAll(threadCount); } }
int main() { ThreadPool<Thread> *threadPool = new ThreadPool<Thread>(3); for (int i = 0; i < 999; ++ i) { usleep(1000 * 1000); cout<<"add Task " << endl; threadPool->addTask(); } //threadPool->stop(); delete threadPool; }
void Scene::computeColors(std::function<void(int, int, ColorCRef)> paint, int threadCount) { figuresKDTree.init(figures); upto(threadCount, 1); downto(threadCount, 4); int taskCount = 10; ThreadPool pool; for (int t = 0; t < taskCount; t++) pool.addTask([this, &paint, t, taskCount]() { multiThreadComputePartOfColors(paint, t, taskCount); }); pool.executeAll(threadCount); }
void ThreadPool::addGlobalTask (Task* task) { gThreadPool.addTask (task); }