Image ParallelRenderer::render (World& _world, Settings& _settings, Engine& _engine, SuperSampling& _super_sampling) { TaskDispatcher task_dispatcher(_settings); std::vector<std::future<Tiles>> futures(0); for (unsigned i = 0; i < _settings.max_thread_count; i++) { // TODO can this be done better? it must be possible futures.push_back(std::async(std::launch::async, [this, &task_dispatcher, &_world, &_settings, &_engine, &_super_sampling] () { return worker(task_dispatcher, _world, _settings, _engine, _super_sampling); })); } for (unsigned i = 0; i < futures.size(); i++) { futures[i].wait(); } Image final_image(_settings.area.size); for (unsigned i = 0; i < futures.size(); i++) { Tiles tiles = futures[i].get(); for (unsigned j = 0; j < tiles.size(); j++) { final_image.paste(tiles[j].task.start, tiles[j].image); } } return final_image; }
const Tile* get(uint32_t id) const { //FIXME: Commenting out tiles in sprites.strf makes tiles.size() fail - it's being set to the first tile commented out. assert(id < tiles.size()); Tile* tile = tiles[id]; if(!tile) { log_warning << "Invalid tile: " << id << std::endl; return tiles[0]; } if(tile->images.size() == 0 && tile->imagespecs.size() != 0) tile->load_images(tiles_path); return tile; }
inline Tile* Map::GetRandomTile(){ int randomTileIndex = GetRandomIntInRange(1, m_tiles.size()-1); return &(m_tiles[randomTileIndex]); }
uint32_t get_max_tileid() const { return tiles.size(); }