mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-17 04:27:45 -07:00
Convert queue to while loop.
Took 19 seconds
This commit is contained in:
parent
bba5b775ec
commit
5c021f0aad
1 changed files with 53 additions and 50 deletions
|
|
@ -79,65 +79,68 @@ void UserCardArtProvider::processQueue()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (queue.isEmpty()) {
|
while (!queue.isEmpty()) {
|
||||||
return;
|
const QString key = queue.dequeue();
|
||||||
}
|
|
||||||
|
|
||||||
const QString key = queue.dequeue();
|
const QStringList parts = key.split(u'|');
|
||||||
|
if (parts.size() != 2) {
|
||||||
const QStringList parts = key.split(u'|');
|
pending.remove(key);
|
||||||
if (parts.size() != 2) {
|
continue;
|
||||||
pending.remove(key);
|
|
||||||
processQueue();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const QString userName = parts.at(0);
|
|
||||||
const QString cardName = parts.at(1);
|
|
||||||
|
|
||||||
ExactCard card = CardDatabaseManager::query()->getCard({cardName});
|
|
||||||
|
|
||||||
if (!card) {
|
|
||||||
pending.remove(key);
|
|
||||||
processQueue();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
QPixmap fullRes;
|
|
||||||
CardPictureLoader::getPixmap(fullRes, card, QSize(745, 1040));
|
|
||||||
|
|
||||||
// If already available, store immediately
|
|
||||||
if (!fullRes.isNull()) {
|
|
||||||
insertIntoCache(key, cropCardArt(fullRes));
|
|
||||||
pending.remove(key);
|
|
||||||
|
|
||||||
emit cardArtUpdated(userName);
|
|
||||||
processQueue();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Otherwise wait for async load
|
|
||||||
QPointer<UserCardArtProvider> self(this);
|
|
||||||
|
|
||||||
connect(card.getCardPtr().data(), &CardInfo::pixmapUpdated, this, [self, key, userName, card]() mutable {
|
|
||||||
if (!self) {
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
disconnect(card.getCardPtr().data(), &CardInfo::pixmapUpdated, self, nullptr);
|
const QString userName = parts.at(0);
|
||||||
|
const QString cardName = parts.at(1);
|
||||||
|
|
||||||
|
ExactCard card = CardDatabaseManager::query()->getCard({cardName});
|
||||||
|
|
||||||
|
if (!card) {
|
||||||
|
pending.remove(key);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
QPixmap fullRes;
|
QPixmap fullRes;
|
||||||
CardPictureLoader::getPixmap(fullRes, card, QSize(745, 1040));
|
CardPictureLoader::getPixmap(fullRes, card, QSize(745, 1040));
|
||||||
|
|
||||||
|
// Synchronous hit (already loaded/on disk)
|
||||||
if (!fullRes.isNull()) {
|
if (!fullRes.isNull()) {
|
||||||
self->insertIntoCache(key, self->cropCardArt(fullRes));
|
insertIntoCache(key, cropCardArt(fullRes));
|
||||||
} else {
|
pending.remove(key);
|
||||||
self->insertIntoCache(key, QPixmap());
|
|
||||||
|
emit cardArtUpdated(userName);
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
self->pending.remove(key);
|
// Async load required.
|
||||||
|
QPointer<UserCardArtProvider> self(this);
|
||||||
|
|
||||||
emit self->cardArtUpdated(userName);
|
auto conn = std::make_shared<QMetaObject::Connection>();
|
||||||
self->processQueue();
|
|
||||||
});
|
*conn = connect(card.getCardPtr().data(), &CardInfo::pixmapUpdated, this,
|
||||||
|
[self, key, userName, card, conn]() mutable {
|
||||||
|
if (!self) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QObject::disconnect(*conn);
|
||||||
|
|
||||||
|
QPixmap fullRes;
|
||||||
|
CardPictureLoader::getPixmap(fullRes, card, QSize(745, 1040));
|
||||||
|
|
||||||
|
if (!fullRes.isNull()) {
|
||||||
|
self->insertIntoCache(key, self->cropCardArt(fullRes));
|
||||||
|
} else {
|
||||||
|
self->insertIntoCache(key, QPixmap());
|
||||||
|
}
|
||||||
|
|
||||||
|
self->pending.remove(key);
|
||||||
|
|
||||||
|
emit self->cardArtUpdated(userName);
|
||||||
|
|
||||||
|
// Resume processing remaining queued items.
|
||||||
|
self->processQueue();
|
||||||
|
});
|
||||||
|
|
||||||
|
// Stop here. We'll continue when the async load finishes.
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue