Skip to content

Commit 63c7a88

Browse files
committed
lazy loading
1 parent 3845437 commit 63c7a88

3 files changed

Lines changed: 31 additions & 5 deletions

File tree

src/animationlayer.cpp

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include "aoapplication.h"
44
#include "options.h"
5+
#include "webcache.h"
56

67
#include <QRectF>
78
#include <QThreadPool>
@@ -452,12 +453,23 @@ void CharacterAnimationLayer::loadCharacterEmote(QString character, QString file
452453
}
453454

454455
int index = -1;
456+
int non_placeholder_count = placeholder_fallback ? path_list.size() - 2 : path_list.size();
455457
QString file_path = ao_app->get_image_path(path_list, index);
456458
if (index != -1)
457459
{
458460
m_resolved_emote = prefixed_emote_list[index];
459461
}
460462

463+
// Trigger webcache download if actual character emote not found (fell back to placeholder or not found at all)
464+
if ((index == -1 || index >= non_placeholder_count) && Options::getInstance().webcacheEnabled())
465+
{
466+
static const QStringList image_suffixes{".webp", ".apng", ".gif", ".png"};
467+
for (int i = 0; i < non_placeholder_count; ++i)
468+
{
469+
ao_app->webcache()->resolveOrDownload(path_list[i].toQString(), image_suffixes);
470+
}
471+
}
472+
461473
setFileName(file_path);
462474
setPlayOnce(play_once);
463475
setResizeMode(ao_app->get_scaling(ao_app->get_emote_property(character, fileName, "scaling")));
@@ -589,7 +601,15 @@ BackgroundAnimationLayer::BackgroundAnimationLayer(AOApplication *ao_app, QWidge
589601

590602
void BackgroundAnimationLayer::loadAndPlayAnimation(QString fileName)
591603
{
592-
QString file_path = ao_app->get_image_suffix(ao_app->get_background_path(fileName));
604+
VPath vpath = ao_app->get_background_path(fileName);
605+
QString file_path = ao_app->get_image_suffix(vpath);
606+
607+
// Trigger webcache download if file not found locally
608+
if (file_path.isEmpty() && Options::getInstance().webcacheEnabled())
609+
{
610+
ao_app->webcache()->resolveOrDownload(vpath.toQString(), {".webp", ".apng", ".gif", ".png"});
611+
}
612+
593613
#ifdef DEBUG_MOVIE
594614
if (file_path.isEmpty())
595615
{

src/aomusicplayer.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include "file_functions.h"
44
#include "options.h"
5+
#include "webcache.h"
56

67
#include <bass.h>
78

@@ -50,7 +51,15 @@ QString AOMusicPlayer::playStream(QString song, int streamId, bool loopEnabled,
5051
{
5152
flags |= BASS_STREAM_PRESCAN | BASS_UNICODE | BASS_ASYNCFILE;
5253

53-
f_path = ao_app->get_real_path(ao_app->get_music_path(song));
54+
VPath vpath = ao_app->get_music_path(song);
55+
f_path = ao_app->get_real_path(vpath);
56+
57+
// Trigger webcache download if file not found locally
58+
if (f_path.isEmpty() && Options::getInstance().webcacheEnabled())
59+
{
60+
ao_app->webcache()->resolveOrDownload(vpath.toQString(), {".opus", ".ogg", ".mp3", ".wav"});
61+
}
62+
5463
newstream = BASS_StreamCreateFile(FALSE, f_path.utf16(), 0, 0, flags);
5564
}
5665

src/path_functions.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -431,9 +431,6 @@ QString AOApplication::get_real_path(const VPath &vpath, const QStringList &suff
431431
asset_lookup_cache.insert(qHash(vpath), cached);
432432
return cached;
433433
}
434-
435-
// Initiate background download for future requests
436-
m_webcache->resolveOrDownload(vpath.toQString(), suffixes);
437434
}
438435

439436
// Not found in mount paths; check if the file is remote

0 commit comments

Comments
 (0)